summaryrefslogtreecommitdiff
path: root/src/debug.c
blob: a4c209abcb5dbee3c2262424858e1ec29b8990ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
 * @file
 * @section AUTHORS
 *
 *  Authors:
 *       Eamon Walsh <ewalsh@tycho.nsa.gov>
 *
 * @section LICENSE
 *
 * This file is in the public domain.
 *
 * @section DESCRIPTION
 *
 * This is the linpicker-cli program that can send debugging commands to
 * linpicker-server over a local socket if linpicker-server was compiled
 * with the "enable-socket" configure-time option (default: disabled).
 */

#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>

#include "local.h"

static void
bail(const char *msg)
{
	fprintf(stderr, "%s\n", msg);
	exit(1);
}

int
main(int argc, char **argv)
{
	char msg;
	struct sockaddr_un addr;
	int sd;

	if (argc != 2)
		bail("Usage: linpicker-cli <code>\n\t0 - Dump views\n");
	msg = atoi(argv[1]);

	sd = socket(AF_UNIX, SOCK_DGRAM, 0);
	if (sd < 0)
		bail("socket failed");

	memset(&addr, 0, sizeof(addr));
	addr.sun_family = AF_UNIX;
	memcpy(addr.sun_path, LINPICKER_SOCKNAME, sizeof(LINPICKER_SOCKNAME));
	sendto(sd, &msg, 1, 0, (struct sockaddr *)&addr, sizeof(addr));

	close(sd);
	return 0;
}