2 3baa2617 2022-02-16 op * Copyright (c) 2022 Omar Polo <op@openbsd.org>
4 3baa2617 2022-02-16 op * Permission to use, copy, modify, and distribute this software for any
5 3baa2617 2022-02-16 op * purpose with or without fee is hereby granted, provided that the above
6 3baa2617 2022-02-16 op * copyright notice and this permission notice appear in all copies.
8 3baa2617 2022-02-16 op * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 3baa2617 2022-02-16 op * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 3baa2617 2022-02-16 op * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 3baa2617 2022-02-16 op * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 3baa2617 2022-02-16 op * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 3baa2617 2022-02-16 op * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 3baa2617 2022-02-16 op * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 3baa2617 2022-02-16 op #include <sys/types.h>
18 3baa2617 2022-02-16 op #include <sys/socket.h>
19 3baa2617 2022-02-16 op #include <sys/queue.h>
20 3baa2617 2022-02-16 op #include <sys/uio.h>
21 3baa2617 2022-02-16 op #include <sys/un.h>
23 3baa2617 2022-02-16 op #include <errno.h>
24 3baa2617 2022-02-16 op #include <event.h>
25 3baa2617 2022-02-16 op #include <limits.h>
26 3baa2617 2022-02-16 op #include <sndio.h>
27 3baa2617 2022-02-16 op #include <stdio.h>
28 3baa2617 2022-02-16 op #include <stdlib.h>
29 3baa2617 2022-02-16 op #include <stdint.h>
30 3baa2617 2022-02-16 op #include <string.h>
31 3baa2617 2022-02-16 op #include <syslog.h>
32 3baa2617 2022-02-16 op #include <unistd.h>
33 3baa2617 2022-02-16 op #include <imsg.h>
35 3baa2617 2022-02-16 op #include "amused.h"
36 3baa2617 2022-02-16 op #include "log.h"
37 bb3f279f 2022-02-16 op #include "playlist.h"
38 3baa2617 2022-02-16 op #include "xmalloc.h"
40 3baa2617 2022-02-16 op static struct imsgbuf *ibuf;
42 3baa2617 2022-02-16 op int ctl_noarg(struct parse_result *, int, char **);
43 3baa2617 2022-02-16 op int ctl_add(struct parse_result *, int, char **);
44 8e916714 2022-02-17 op int ctl_show(struct parse_result *, int, char **);
45 14be015f 2022-02-17 op int ctl_load(struct parse_result *, int, char **);
46 a913de21 2022-02-17 op int ctl_jump(struct parse_result *, int, char **);
47 310ef57c 2022-02-19 op int ctl_repeat(struct parse_result *, int, char **);
49 3baa2617 2022-02-16 op struct ctl_command ctl_commands[] = {
50 3baa2617 2022-02-16 op { "play", PLAY, ctl_noarg, "" },
51 3baa2617 2022-02-16 op { "pause", PAUSE, ctl_noarg, "" },
52 3baa2617 2022-02-16 op { "toggle", TOGGLE, ctl_noarg, "" },
53 3baa2617 2022-02-16 op { "stop", STOP, ctl_noarg, "" },
54 3baa2617 2022-02-16 op { "restart", RESTART, ctl_noarg, "" },
55 3baa2617 2022-02-16 op { "add", ADD, ctl_add, "files...", 1 },
56 3baa2617 2022-02-16 op { "flush", FLUSH, ctl_noarg, "" },
57 714abf92 2022-02-19 op { "show", SHOW, ctl_show, "[-p]" },
58 bb3f279f 2022-02-16 op { "status", STATUS, ctl_noarg, "" },
59 af27e631 2022-02-17 op { "next", NEXT, ctl_noarg, "" },
60 af27e631 2022-02-17 op { "prev", PREV, ctl_noarg, "" },
61 14be015f 2022-02-17 op { "load", LOAD, ctl_load, "[file]", 1 },
62 a913de21 2022-02-17 op { "jump", JUMP, ctl_jump, "pattern" },
63 310ef57c 2022-02-19 op { "repeat", REPEAT, ctl_repeat, "one|all on|off" },
70 3baa2617 2022-02-16 op fprintf(stderr, "usage: %s [-dv] [-s socket]\n", getprogname());
71 3baa2617 2022-02-16 op fprintf(stderr, "%s version %s\n", getprogname(), AMUSED_VERSION);
75 3baa2617 2022-02-16 op static __dead void
76 3baa2617 2022-02-16 op ctl_usage(struct ctl_command *ctl)
78 3baa2617 2022-02-16 op fprintf(stderr, "usage: %s [-v] [-s socket] %s %s\n", getprogname(),
79 3baa2617 2022-02-16 op ctl->name, ctl->usage);
84 3baa2617 2022-02-16 op parse(int argc, char **argv)
86 3baa2617 2022-02-16 op struct ctl_command *ctl = NULL;
87 3baa2617 2022-02-16 op struct parse_result res;
88 3baa2617 2022-02-16 op int i, status;
90 3baa2617 2022-02-16 op memset(&res, 0, sizeof(res));
92 3baa2617 2022-02-16 op for (i = 0; ctl_commands[i].name != NULL; ++i) {
93 3baa2617 2022-02-16 op if (strncmp(ctl_commands[i].name, argv[0], strlen(argv[0]))
95 3baa2617 2022-02-16 op if (ctl != NULL) {
96 3baa2617 2022-02-16 op fprintf(stderr,
97 3baa2617 2022-02-16 op "ambiguous argument: %s\n", argv[0]);
100 3baa2617 2022-02-16 op ctl = &ctl_commands[i];
104 3baa2617 2022-02-16 op if (ctl == NULL) {
105 3baa2617 2022-02-16 op fprintf(stderr, "unknown argument: %s\n", argv[0]);
109 3baa2617 2022-02-16 op res.action = ctl->action;
110 3baa2617 2022-02-16 op res.ctl = ctl;
112 3baa2617 2022-02-16 op if (!ctl->has_pledge) {
113 3baa2617 2022-02-16 op /* pledge(2) default if command doesn't have its own */
114 3baa2617 2022-02-16 op if (pledge("stdio", NULL) == -1)
115 3baa2617 2022-02-16 op fatal("pledge");
118 3baa2617 2022-02-16 op status = ctl->main(&res, argc, argv);
119 3baa2617 2022-02-16 op close(ibuf->fd);
121 3baa2617 2022-02-16 op return status;
125 3baa2617 2022-02-16 op enqueue_tracks(char **files)
127 3baa2617 2022-02-16 op char res[PATH_MAX];
130 3baa2617 2022-02-16 op for (; *files != NULL; ++files) {
131 3baa2617 2022-02-16 op memset(&res, 0, sizeof(res));
132 3baa2617 2022-02-16 op if (realpath(*files, res) == NULL) {
133 3baa2617 2022-02-16 op log_warn("realpath %s", *files);
137 3baa2617 2022-02-16 op imsg_compose(ibuf, IMSG_CTL_ADD, 0, 0, -1,
138 3baa2617 2022-02-16 op res, sizeof(res));
142 3baa2617 2022-02-16 op return enq == 0;
146 a913de21 2022-02-17 op jump_req(const char *arg)
148 a913de21 2022-02-17 op char path[PATH_MAX];
150 a913de21 2022-02-17 op memset(path, 0, sizeof(path));
151 a913de21 2022-02-17 op strlcpy(path, arg, sizeof(path));
152 a913de21 2022-02-17 op imsg_compose(ibuf, IMSG_CTL_JUMP, 0, 0, -1, path, sizeof(path));
157 8ff9231f 2022-02-16 op print_error_message(const char *prfx, struct imsg *imsg)
159 8ff9231f 2022-02-16 op size_t datalen;
162 8ff9231f 2022-02-16 op datalen = IMSG_DATA_SIZE(*imsg);
163 8ff9231f 2022-02-16 op if ((msg = calloc(1, datalen)) == NULL)
164 8ff9231f 2022-02-16 op fatal("calloc %zu", datalen);
165 8ff9231f 2022-02-16 op memcpy(msg, imsg->data, datalen);
166 8ff9231f 2022-02-16 op if (datalen == 0 || msg[datalen-1] != '\0')
167 8ff9231f 2022-02-16 op fatalx("malformed error message");
169 8ff9231f 2022-02-16 op log_warnx("%s: %s", prfx, msg);
174 8ff9231f 2022-02-16 op show_add(struct imsg *imsg, int *ret, char ***files)
176 8ff9231f 2022-02-16 op if (**files == NULL) {
177 8ff9231f 2022-02-16 op log_warnx("received more replies than file sent");
182 8ff9231f 2022-02-16 op if (imsg->hdr.type == IMSG_CTL_ERR)
183 8ff9231f 2022-02-16 op print_error_message(**files, imsg);
184 8ff9231f 2022-02-16 op else if (imsg->hdr.type == IMSG_CTL_ADD)
185 8ff9231f 2022-02-16 op log_debug("enqueued %s", **files);
187 8ff9231f 2022-02-16 op fatalx("got invalid message %d", imsg->hdr.type);
190 8ff9231f 2022-02-16 op return (**files) == NULL;
194 8e916714 2022-02-17 op show_complete(struct parse_result *res, struct imsg *imsg, int *ret)
196 63dd8e70 2022-02-17 op struct player_status s;
197 3baa2617 2022-02-16 op size_t datalen;
199 8ff9231f 2022-02-16 op if (imsg->hdr.type == IMSG_CTL_ERR) {
200 8ff9231f 2022-02-16 op print_error_message("show failed", imsg);
205 3baa2617 2022-02-16 op datalen = IMSG_DATA_SIZE(*imsg);
206 3baa2617 2022-02-16 op if (datalen == 0)
209 63dd8e70 2022-02-17 op if (datalen != sizeof(s))
210 3baa2617 2022-02-16 op fatalx("%s: data size mismatch", __func__);
211 63dd8e70 2022-02-17 op memcpy(&s, imsg->data, sizeof(s));
212 63dd8e70 2022-02-17 op if (s.path[sizeof(s.path)-1] != '\0')
213 3baa2617 2022-02-16 op fatalx("%s: data corrupted?", __func__);
215 8e916714 2022-02-17 op if (res->pretty)
216 8e916714 2022-02-17 op printf("%c ", s.status == STATE_PLAYING ? '>' : ' ');
217 8e916714 2022-02-17 op printf("%s\n", s.path);
222 bb3f279f 2022-02-16 op show_status(struct imsg *imsg, int *ret)
224 bb3f279f 2022-02-16 op struct player_status s;
225 bb3f279f 2022-02-16 op size_t datalen;
227 bb3f279f 2022-02-16 op if (imsg->hdr.type == IMSG_CTL_ERR) {
228 bb3f279f 2022-02-16 op print_error_message("show failed", imsg);
233 bb3f279f 2022-02-16 op if (imsg->hdr.type != IMSG_CTL_STATUS)
234 bb3f279f 2022-02-16 op fatalx("%s: got wrong reply", __func__);
236 bb3f279f 2022-02-16 op datalen = IMSG_DATA_SIZE(*imsg);
237 bb3f279f 2022-02-16 op if (datalen != sizeof(s))
238 bb3f279f 2022-02-16 op fatalx("%s: data size mismatch", __func__);
239 bb3f279f 2022-02-16 op memcpy(&s, imsg->data, sizeof(s));
240 bb3f279f 2022-02-16 op if (s.path[sizeof(s.path)-1] != '\0')
241 bb3f279f 2022-02-16 op fatalx("%s: data corrupted?", __func__);
243 bb3f279f 2022-02-16 op switch (s.status) {
244 bb3f279f 2022-02-16 op case STATE_STOPPED:
245 bb3f279f 2022-02-16 op printf("stopped ");
247 bb3f279f 2022-02-16 op case STATE_PLAYING:
248 bb3f279f 2022-02-16 op printf("playing ");
250 bb3f279f 2022-02-16 op case STATE_PAUSED:
251 bb3f279f 2022-02-16 op printf("paused ");
254 bb3f279f 2022-02-16 op printf("unknown ");
258 bb3f279f 2022-02-16 op printf("%s\n", s.path);
259 44398779 2022-02-19 op printf("repeat one %s -- repeat all %s\n",
260 44398779 2022-02-19 op s.rp.repeat_one ? "on" : "off",
261 44398779 2022-02-19 op s.rp.repeat_all ? "on" : "off");
266 7a427ecd 2022-02-17 op show_load(struct parse_result *res, struct imsg *imsg, int *ret)
269 7a427ecd 2022-02-17 op const char *file;
270 7a427ecd 2022-02-17 op char *line = NULL;
271 7a427ecd 2022-02-17 op char path[PATH_MAX];
272 7a427ecd 2022-02-17 op size_t linesize = 0;
273 7a427ecd 2022-02-17 op ssize_t linelen;
276 7a427ecd 2022-02-17 op if (imsg->hdr.type == IMSG_CTL_ERR) {
277 7a427ecd 2022-02-17 op print_error_message("load failed", imsg);
282 7a427ecd 2022-02-17 op if (imsg->hdr.type == IMSG_CTL_ADD)
285 7a427ecd 2022-02-17 op if (imsg->hdr.type == IMSG_CTL_COMMIT)
288 7a427ecd 2022-02-17 op if (imsg->hdr.type != IMSG_CTL_BEGIN)
289 7a427ecd 2022-02-17 op fatalx("got unexpected message %d", imsg->hdr.type);
291 ec1fb0c7 2022-02-17 op if (res->file == NULL)
293 ec1fb0c7 2022-02-17 op else if ((f = fopen(res->file, "r")) == NULL) {
294 ec1fb0c7 2022-02-17 op log_warn("can't open %s", res->file);
299 ec1fb0c7 2022-02-17 op while ((linelen = getline(&line, &linesize, f)) != -1) {
300 7a427ecd 2022-02-17 op if (linelen == 0)
302 7a427ecd 2022-02-17 op line[linelen-1] = '\0';
304 7a427ecd 2022-02-17 op if (file[0] == '>' && file[1] == ' ')
306 7a427ecd 2022-02-17 op if (file[0] == ' ' && file[1] == ' ')
309 7a427ecd 2022-02-17 op memset(&path, 0, sizeof(path));
310 7a427ecd 2022-02-17 op if (realpath(file, path) == NULL) {
311 7a427ecd 2022-02-17 op log_warn("realpath %s", file);
316 7a427ecd 2022-02-17 op imsg_compose(ibuf, IMSG_CTL_ADD, 0, 0, -1,
317 7a427ecd 2022-02-17 op path, sizeof(path));
321 ec1fb0c7 2022-02-17 op if (ferror(f))
322 7a427ecd 2022-02-17 op fatal("getline");
330 7a427ecd 2022-02-17 op imsg_compose(ibuf, IMSG_CTL_COMMIT, 0, 0, -1,
332 7a427ecd 2022-02-17 op imsg_flush(ibuf);
337 3baa2617 2022-02-16 op ctlaction(struct parse_result *res)
339 3baa2617 2022-02-16 op struct imsg imsg;
341 3baa2617 2022-02-16 op int ret = 0, done = 1;
342 8ff9231f 2022-02-16 op char **files;
344 3baa2617 2022-02-16 op switch (res->action) {
347 3baa2617 2022-02-16 op imsg_compose(ibuf, IMSG_CTL_PLAY, 0, 0, -1, NULL, 0);
348 146307bd 2022-02-17 op imsg_compose(ibuf, IMSG_CTL_STATUS, 0, 0, -1, NULL, 0);
351 3baa2617 2022-02-16 op imsg_compose(ibuf, IMSG_CTL_PAUSE, 0, 0, -1, NULL, 0);
355 3baa2617 2022-02-16 op imsg_compose(ibuf, IMSG_CTL_TOGGLE_PLAY, 0, 0, -1, NULL, 0);
356 146307bd 2022-02-17 op imsg_compose(ibuf, IMSG_CTL_STATUS, 0, 0, -1, NULL, 0);
359 3baa2617 2022-02-16 op imsg_compose(ibuf, IMSG_CTL_STOP, 0, 0, -1, NULL, 0);
361 3baa2617 2022-02-16 op case RESTART:
363 3baa2617 2022-02-16 op imsg_compose(ibuf, IMSG_CTL_RESTART, 0, 0, -1, NULL, 0);
364 146307bd 2022-02-17 op imsg_compose(ibuf, IMSG_CTL_STATUS, 0, 0, -1, NULL, 0);
368 8ff9231f 2022-02-16 op files = res->files;
369 3baa2617 2022-02-16 op ret = enqueue_tracks(res->files);
372 3baa2617 2022-02-16 op imsg_compose(ibuf, IMSG_CTL_FLUSH, 0, 0, -1, NULL, 0);
376 3baa2617 2022-02-16 op imsg_compose(ibuf, IMSG_CTL_SHOW, 0, 0, -1, NULL, 0);
380 bb3f279f 2022-02-16 op imsg_compose(ibuf, IMSG_CTL_STATUS, 0, 0, -1, NULL, 0);
384 af27e631 2022-02-17 op imsg_compose(ibuf, IMSG_CTL_NEXT, 0, 0, -1, NULL, 0);
385 146307bd 2022-02-17 op imsg_compose(ibuf, IMSG_CTL_STATUS, 0, 0, -1, NULL, 0);
389 af27e631 2022-02-17 op imsg_compose(ibuf, IMSG_CTL_PREV, 0, 0, -1, NULL, 0);
390 146307bd 2022-02-17 op imsg_compose(ibuf, IMSG_CTL_STATUS, 0, 0, -1, NULL, 0);
394 7a427ecd 2022-02-17 op imsg_compose(ibuf, IMSG_CTL_BEGIN, 0, 0, -1, NULL, 0);
398 a913de21 2022-02-17 op ret = jump_req(res->file);
401 310ef57c 2022-02-19 op imsg_compose(ibuf, IMSG_CTL_REPEAT, 0, 0, -1,
402 310ef57c 2022-02-19 op &res->rep, sizeof(res->rep));
405 3baa2617 2022-02-16 op /* action not expected */
406 3baa2617 2022-02-16 op fatalx("invalid action %u", res->action);
410 3baa2617 2022-02-16 op if (ret != 0)
413 3baa2617 2022-02-16 op imsg_flush(ibuf);
415 3baa2617 2022-02-16 op while (!done) {
416 3baa2617 2022-02-16 op if ((n = imsg_read(ibuf)) == -1 && errno != EAGAIN)
417 3baa2617 2022-02-16 op fatalx("imsg_read error");
419 3baa2617 2022-02-16 op fatalx("pipe closed");
421 3baa2617 2022-02-16 op while (!done) {
422 3baa2617 2022-02-16 op if ((n = imsg_get(ibuf, &imsg)) == -1)
423 3baa2617 2022-02-16 op fatalx("imsg_get error");
427 3baa2617 2022-02-16 op switch (res->action) {
429 8ff9231f 2022-02-16 op done = show_add(&imsg, &ret, &files);
432 8e916714 2022-02-17 op done = show_complete(res, &imsg, &ret);
436 146307bd 2022-02-17 op case RESTART:
441 bb3f279f 2022-02-16 op done = show_status(&imsg, &ret);
444 7a427ecd 2022-02-17 op done = show_load(res, &imsg, &ret);
451 3baa2617 2022-02-16 op imsg_free(&imsg);
460 3baa2617 2022-02-16 op ctl_noarg(struct parse_result *res, int argc, char **argv)
462 3baa2617 2022-02-16 op if (argc != 1)
463 3baa2617 2022-02-16 op ctl_usage(res->ctl);
464 3baa2617 2022-02-16 op return ctlaction(res);
468 3baa2617 2022-02-16 op ctl_add(struct parse_result *res, int argc, char **argv)
470 3baa2617 2022-02-16 op if (argc < 2)
471 3baa2617 2022-02-16 op ctl_usage(res->ctl);
472 3baa2617 2022-02-16 op res->files = argv+1;
474 14be015f 2022-02-17 op if (pledge("stdio rpath", NULL) == -1)
475 14be015f 2022-02-17 op fatal("pledge");
477 3baa2617 2022-02-16 op return ctlaction(res);
481 8e916714 2022-02-17 op ctl_show(struct parse_result *res, int argc, char **argv)
485 8e916714 2022-02-17 op while ((ch = getopt(argc, argv, "p")) != -1) {
486 8e916714 2022-02-17 op switch (ch) {
488 8e916714 2022-02-17 op res->pretty = 1;
491 8e916714 2022-02-17 op ctl_usage(res->ctl);
495 8e916714 2022-02-17 op return ctlaction(res);
499 14be015f 2022-02-17 op ctl_load(struct parse_result *res, int argc, char **argv)
501 14be015f 2022-02-17 op if (argc < 2)
502 ec1fb0c7 2022-02-17 op res->file = NULL;
503 ec1fb0c7 2022-02-17 op else if (argc == 2)
504 ec1fb0c7 2022-02-17 op res->file = argv[1];
506 14be015f 2022-02-17 op ctl_usage(res->ctl);
508 14be015f 2022-02-17 op if (pledge("stdio rpath", NULL) == -1)
509 14be015f 2022-02-17 op fatal("pledge");
511 7a427ecd 2022-02-17 op return ctlaction(res);
515 a913de21 2022-02-17 op ctl_jump(struct parse_result *res, int argc, char **argv)
519 a913de21 2022-02-17 op while ((ch = getopt(argc, argv, "")) != -1)
520 a913de21 2022-02-17 op ctl_usage(res->ctl);
521 a913de21 2022-02-17 op argc -= optind;
522 a913de21 2022-02-17 op argv += optind;
524 a913de21 2022-02-17 op if (argc != 1)
525 a913de21 2022-02-17 op ctl_usage(res->ctl);
527 a913de21 2022-02-17 op res->file = argv[0];
528 310ef57c 2022-02-19 op return ctlaction(res);
532 310ef57c 2022-02-19 op ctl_repeat(struct parse_result *res, int argc, char **argv)
536 310ef57c 2022-02-19 op while ((ch = getopt(argc, argv, "")) != -1)
537 310ef57c 2022-02-19 op ctl_usage(res->ctl);
538 310ef57c 2022-02-19 op argc -= optind;
539 310ef57c 2022-02-19 op argv += optind;
541 310ef57c 2022-02-19 op if (argc != 2)
542 310ef57c 2022-02-19 op ctl_usage(res->ctl);
544 310ef57c 2022-02-19 op if (!strcmp(argv[1], "on"))
546 310ef57c 2022-02-19 op else if (!strcmp(argv[1], "off"))
549 310ef57c 2022-02-19 op ctl_usage(res->ctl);
551 310ef57c 2022-02-19 op res->rep.repeat_one = -1;
552 310ef57c 2022-02-19 op res->rep.repeat_all = -1;
553 310ef57c 2022-02-19 op if (!strcmp(argv[0], "one"))
554 310ef57c 2022-02-19 op res->rep.repeat_one = b;
555 310ef57c 2022-02-19 op else if (!strcmp(argv[0], "all"))
556 310ef57c 2022-02-19 op res->rep.repeat_all = b;
558 310ef57c 2022-02-19 op ctl_usage(res->ctl);
560 a913de21 2022-02-17 op return ctlaction(res);
564 fea541a8 2022-02-16 op sockconn(void)
566 fea541a8 2022-02-16 op struct sockaddr_un sun;
567 fea541a8 2022-02-16 op int sock, saved_errno;
569 fea541a8 2022-02-16 op if ((sock = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
570 3baa2617 2022-02-16 op fatal("socket");
572 3baa2617 2022-02-16 op memset(&sun, 0, sizeof(sun));
573 3baa2617 2022-02-16 op sun.sun_family = AF_UNIX;
574 3baa2617 2022-02-16 op strlcpy(sun.sun_path, csock, sizeof(sun.sun_path));
575 fea541a8 2022-02-16 op if (connect(sock, (struct sockaddr *)&sun, sizeof(sun)) == -1) {
576 fea541a8 2022-02-16 op saved_errno = errno;
578 fea541a8 2022-02-16 op errno = saved_errno;
586 fea541a8 2022-02-16 op ctl(int argc, char **argv)
588 fea541a8 2022-02-16 op int ctl_sock, i = 0;
590 fea541a8 2022-02-16 op log_init(1, LOG_DAEMON);
591 fea541a8 2022-02-16 op log_setverbose(verbose);
594 fea541a8 2022-02-16 op struct timespec ts = { 0, 50000000 }; /* 0.05 seconds */
596 fea541a8 2022-02-16 op if ((ctl_sock = sockconn()) != -1)
598 fea541a8 2022-02-16 op if (errno != ENOENT && errno != ECONNREFUSED)
599 fea541a8 2022-02-16 op fatal("connect %s", csock);
602 fea541a8 2022-02-16 op spawn_daemon();
604 fea541a8 2022-02-16 op nanosleep(&ts, NULL);
605 fea541a8 2022-02-16 op } while (++i < 20);
607 fea541a8 2022-02-16 op if (ctl_sock == -1)
608 fea541a8 2022-02-16 op fatalx("failed to connect to the daemon");
610 3baa2617 2022-02-16 op ibuf = xmalloc(sizeof(*ibuf));
611 3baa2617 2022-02-16 op imsg_init(ibuf, ctl_sock);
613 3baa2617 2022-02-16 op optreset = 1;
616 3baa2617 2022-02-16 op exit(parse(argc, argv));