2 * Copyright (c) 2021 Omar Polo <op@omarpolo.com>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #include <sys/socket.h>
27 #include "ctl_parser.h"
31 ATTR_DEAD void usage(void);
39 * XXX: this will print `kamid' if compat/getprogname.c is
42 fprintf(stderr, "usage: %s [-s socket] command [argument ...]\n",
48 main(int argc, char **argv)
50 struct sockaddr_un sun;
51 struct parse_result *res;
59 log_init(1, LOG_DAEMON); /* Log to stderr. */
62 while ((ch = getopt(argc, argv, "s:")) != -1) {
74 /* parse command line */
75 if ((res = parse(argc, argv)) == NULL)
78 /* connect to control socket */
79 if ((ctl_sock = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
82 memset(&sun, 0, sizeof(sun));
83 sun.sun_family = AF_UNIX;
84 strlcpy(sun.sun_path, sockname, sizeof(sun.sun_path));
86 if (connect(ctl_sock, (struct sockaddr*)&sun, sizeof(sun)) == -1)
87 err(1, "connect: %s", sockname);
90 if (pledge("stdio", NULL) == -1)
94 if ((ibuf = calloc(1, sizeof(*ibuf))) == NULL)
96 imsg_init(ibuf, ctl_sock);
99 /* process user request */
100 switch (res->action) {
105 imsg_compose(ibuf, IMSG_CTL_LOG_VERBOSE, 0, 0, -1,
106 &verbose, sizeof(verbose));
107 puts("logging request sent.");
111 imsg_compose(ibuf, IMSG_CTL_RELOAD, 0, 0, -1, NULL, 0);
112 puts("reload request sent.");
122 * Later we may add commands which requires a response.
125 if ((n = imsg_get(ibuf, &imsg)) == -1)
126 errx(1, "imsg_get error");
130 switch (res->action) {