commit 50e0da0e7f8e07ab5d5c970ebca132a49b5fdbd8 from: Omar Polo date: Sun Jan 21 12:04:36 2024 UTC rename ibuf arguments to imsgbuf ibuf is just too confusing since there is also the 'struct ibuf'. commit - b7e63abaf97545cf19d25cefee076ec51ffcccda commit + 50e0da0e7f8e07ab5d5c970ebca132a49b5fdbd8 blob - 0a8f16718e31d4a231defd850a2f730ea1c6505e blob + a564ad9a76e0273f9f5f0df79e9d1725d8f655c1 --- amused.c +++ amused.c @@ -59,8 +59,8 @@ main_shutdown(void) int status; /* close pipes. */ - msgbuf_clear(&iev_player->ibuf.w); - close(iev_player->ibuf.fd); + msgbuf_clear(&iev_player->imsgbuf.w); + close(iev_player->imsgbuf.fd); free(iev_player); log_debug("waiting for children to terminate"); @@ -101,27 +101,27 @@ main_dispatch_player(int sig, int event, void *d) { char *errstr; struct imsgev *iev = d; - struct imsgbuf *ibuf = &iev->ibuf; + struct imsgbuf *imsgbuf = &iev->imsgbuf; struct imsg imsg; size_t datalen; ssize_t n; int shut = 0; if (event & POLLIN) { - if ((n = imsg_read(ibuf)) == -1 && errno != EAGAIN) + if ((n = imsg_read(imsgbuf)) == -1 && errno != EAGAIN) fatal("imsg_read error"); if (n == 0) /* Connection closed */ shut = 1; } if (event & POLLOUT) { - if ((n = msgbuf_write(&ibuf->w)) == -1 && errno != EAGAIN) + if ((n = msgbuf_write(&imsgbuf->w)) == -1 && errno != EAGAIN) fatal("msgbuf_write"); if (n == 0) /* Connection closed */ shut = 1; } for (;;) { - if ((n = imsg_get(ibuf, &imsg)) == -1) + if ((n = imsg_get(imsgbuf, &imsg)) == -1) fatal("imsg_get"); if (n == 0) /* No more messages. */ break; @@ -278,10 +278,10 @@ amused_main(void) ev_signal(SIGTERM, main_sig_handler, NULL); iev_player = xmalloc(sizeof(*iev_player)); - imsg_init(&iev_player->ibuf, pipe_main2player[0]); + imsg_init(&iev_player->imsgbuf, pipe_main2player[0]); iev_player->handler = main_dispatch_player; iev_player->events = POLLIN; - ev_add(iev_player->ibuf.fd, iev_player->events, + ev_add(iev_player->imsgbuf.fd, iev_player->events, iev_player->handler, iev_player); if ((control_fd = control_init(csock)) == -1) @@ -369,10 +369,10 @@ void imsg_event_add(struct imsgev *iev) { iev->events = POLLIN; - if (iev->ibuf.w.queued) + if (iev->imsgbuf.w.queued) iev->events |= POLLOUT; - ev_add(iev->ibuf.fd, iev->events, iev->handler, iev); + ev_add(iev->imsgbuf.fd, iev->events, iev->handler, iev); } int @@ -381,7 +381,7 @@ imsg_compose_event(struct imsgev *iev, uint16_t type, { int ret; - if ((ret = imsg_compose(&iev->ibuf, type, peerid, pid, fd, data, + if ((ret = imsg_compose(&iev->imsgbuf, type, peerid, pid, fd, data, datalen)) != -1) imsg_event_add(iev); blob - 7677dd73b3b2ce7b87ee121d2c7763c5c6bc1985 blob + f01bd986e916c4aa0c1f42121392d940f3b912f8 --- amused.h +++ amused.h @@ -59,7 +59,7 @@ enum imsg_type { }; struct imsgev { - struct imsgbuf ibuf; + struct imsgbuf imsgbuf; void (*handler)(int, int, void *); int events; }; blob - 4649124cafa5fb9bb584ecc9292093b3745c17ac blob + 988d2bcd20786c9e57b0a22d5009d482ff7259d8 --- control.c +++ control.c @@ -169,10 +169,10 @@ control_accept(int listenfd, int event, void *bula) return; } - imsg_init(&c->iev.ibuf, connfd); + imsg_init(&c->iev.imsgbuf, connfd); c->iev.handler = control_dispatch_imsg; c->iev.events = POLLIN; - ev_add(c->iev.ibuf.fd, c->iev.events, c->iev.handler, &c->iev); + ev_add(c->iev.imsgbuf.fd, c->iev.events, c->iev.handler, &c->iev); TAILQ_INSERT_TAIL(&ctl_conns, c, entry); } @@ -183,7 +183,7 @@ control_connbyfd(int fd) struct ctl_conn *c; TAILQ_FOREACH(c, &ctl_conns, entry) { - if (c->iev.ibuf.fd == fd) + if (c->iev.imsgbuf.fd == fd) break; } @@ -196,7 +196,7 @@ control_connbypid(pid_t pid) struct ctl_conn *c; TAILQ_FOREACH(c, &ctl_conns, entry) { - if (c->iev.ibuf.pid == pid) + if (c->iev.imsgbuf.pid == pid) break; } @@ -214,16 +214,16 @@ control_close(int fd) } /* abort the transaction if running by this user */ - if (control_state.tx != -1 && c->iev.ibuf.fd == control_state.tx) { + if (control_state.tx != -1 && c->iev.imsgbuf.fd == control_state.tx) { playlist_free(&control_state.play); control_state.tx = -1; } - msgbuf_clear(&c->iev.ibuf.w); + msgbuf_clear(&c->iev.imsgbuf.w); TAILQ_REMOVE(&ctl_conns, c, entry); - ev_del(c->iev.ibuf.fd); - close(c->iev.ibuf.fd); + ev_del(c->iev.imsgbuf.fd); + close(c->iev.imsgbuf.fd); /* Some file descriptors are available again. */ if (ev_timer_pending()) { @@ -271,6 +271,7 @@ void control_dispatch_imsg(int fd, int event, void *bula) { struct ctl_conn *c; + struct imsgbuf *imsgbuf; struct imsg imsg; struct player_mode mode; struct player_seek seek; @@ -281,22 +282,24 @@ control_dispatch_imsg(int fd, int event, void *bula) return; } + imsgbuf = &c->iev.imsgbuf; + if (event & POLLIN) { - if (((n = imsg_read(&c->iev.ibuf)) == -1 && errno != EAGAIN) || + if (((n = imsg_read(imsgbuf)) == -1 && errno != EAGAIN) || n == 0) { control_close(fd); return; } } if (event & POLLOUT) { - if (msgbuf_write(&c->iev.ibuf.w) <= 0 && errno != EAGAIN) { + if (msgbuf_write(&imsgbuf->w) <= 0 && errno != EAGAIN) { control_close(fd); return; } } for (;;) { - if ((n = imsg_get(&c->iev.ibuf, &imsg)) == -1) { + if ((n = imsg_get(imsgbuf, &imsg)) == -1) { control_close(fd); return; } @@ -390,13 +393,13 @@ control_dispatch_imsg(int fd, int event, void *bula) main_senderr(&c->iev, "locked"); break; } - control_state.tx = c->iev.ibuf.fd; + control_state.tx = imsgbuf->fd; imsg_compose_event(&c->iev, IMSG_CTL_BEGIN, 0, 0, -1, NULL, 0); break; case IMSG_CTL_ADD: if (control_state.tx != -1 && - control_state.tx != c->iev.ibuf.fd) { + control_state.tx != imsgbuf->fd) { main_senderr(&c->iev, "locked"); break; } @@ -406,7 +409,7 @@ control_dispatch_imsg(int fd, int event, void *bula) control_notify(imsg.hdr.type); break; case IMSG_CTL_COMMIT: - if (control_state.tx != c->iev.ibuf.fd) { + if (control_state.tx != imsgbuf->fd) { main_senderr(&c->iev, "locked"); break; } blob - 4759384a08cee43cf3afe8c94498f7c5c04d5ddc blob + 465d6a472c51cdb319d512a85f9bb2ee5280c1e7 --- ctl.c +++ ctl.c @@ -36,7 +36,7 @@ #include "playlist.h" #include "xmalloc.h" -static struct imsgbuf *ibuf; +static struct imsgbuf *imsgbuf; char cwd[PATH_MAX]; static int ctl_noarg(struct parse_result *, int, char **); @@ -164,8 +164,8 @@ parse(struct parse_result *res, int argc, char **argv) res->ctl = ctl; status = ctl->main(res, argc, argv); - close(ibuf->fd); - free(ibuf); + close(imsgbuf->fd); + free(imsgbuf); return status; } @@ -196,7 +196,7 @@ load_files(struct parse_result *res, int *ret) } i++; - imsg_compose(ibuf, IMSG_CTL_ADD, 0, 0, -1, + imsg_compose(imsgbuf, IMSG_CTL_ADD, 0, 0, -1, path, sizeof(path)); } @@ -206,9 +206,9 @@ load_files(struct parse_result *res, int *ret) fclose(res->fp); res->fp = NULL; - imsg_compose(ibuf, IMSG_CTL_COMMIT, 0, 0, -1, + imsg_compose(imsgbuf, IMSG_CTL_COMMIT, 0, 0, -1, &curr, sizeof(curr)); - imsg_flush(ibuf); + imsg_flush(imsgbuf); return 0; } @@ -370,26 +370,26 @@ ctlaction(struct parse_result *res) switch (res->action) { case PLAY: - imsg_compose(ibuf, IMSG_CTL_PLAY, 0, 0, -1, NULL, 0); + imsg_compose(imsgbuf, IMSG_CTL_PLAY, 0, 0, -1, NULL, 0); if (verbose) { - imsg_compose(ibuf, IMSG_CTL_STATUS, 0, 0, -1, + imsg_compose(imsgbuf, IMSG_CTL_STATUS, 0, 0, -1, NULL, 0); done = 0; } break; case PAUSE: - imsg_compose(ibuf, IMSG_CTL_PAUSE, 0, 0, -1, NULL, 0); + imsg_compose(imsgbuf, IMSG_CTL_PAUSE, 0, 0, -1, NULL, 0); break; case TOGGLE: - imsg_compose(ibuf, IMSG_CTL_TOGGLE_PLAY, 0, 0, -1, NULL, 0); + imsg_compose(imsgbuf, IMSG_CTL_TOGGLE_PLAY, 0, 0, -1, NULL, 0); if (verbose) { - imsg_compose(ibuf, IMSG_CTL_STATUS, 0, 0, -1, + imsg_compose(imsgbuf, IMSG_CTL_STATUS, 0, 0, -1, NULL, 0); done = 0; } break; case STOP: - imsg_compose(ibuf, IMSG_CTL_STOP, 0, 0, -1, NULL, 0); + imsg_compose(imsgbuf, IMSG_CTL_STOP, 0, 0, -1, NULL, 0); break; case ADD: done = 0; @@ -401,54 +401,54 @@ ctlaction(struct parse_result *res) continue; } - imsg_compose(ibuf, IMSG_CTL_ADD, 0, 0, -1, + imsg_compose(imsgbuf, IMSG_CTL_ADD, 0, 0, -1, path, sizeof(path)); } ret = i == 0; break; case FLUSH: - imsg_compose(ibuf, IMSG_CTL_FLUSH, 0, 0, -1, NULL, 0); + imsg_compose(imsgbuf, IMSG_CTL_FLUSH, 0, 0, -1, NULL, 0); break; case SHOW: done = 0; - imsg_compose(ibuf, IMSG_CTL_SHOW, 0, 0, -1, NULL, 0); + imsg_compose(imsgbuf, IMSG_CTL_SHOW, 0, 0, -1, NULL, 0); break; case STATUS: done = 0; - imsg_compose(ibuf, IMSG_CTL_STATUS, 0, 0, -1, NULL, 0); + imsg_compose(imsgbuf, IMSG_CTL_STATUS, 0, 0, -1, NULL, 0); break; case NEXT: - imsg_compose(ibuf, IMSG_CTL_NEXT, 0, 0, -1, NULL, 0); + imsg_compose(imsgbuf, IMSG_CTL_NEXT, 0, 0, -1, NULL, 0); if (verbose) { - imsg_compose(ibuf, IMSG_CTL_STATUS, 0, 0, -1, + imsg_compose(imsgbuf, IMSG_CTL_STATUS, 0, 0, -1, NULL, 0); done = 0; } break; case PREV: - imsg_compose(ibuf, IMSG_CTL_PREV, 0, 0, -1, NULL, 0); + imsg_compose(imsgbuf, IMSG_CTL_PREV, 0, 0, -1, NULL, 0); if (verbose) { - imsg_compose(ibuf, IMSG_CTL_STATUS, 0, 0, -1, + imsg_compose(imsgbuf, IMSG_CTL_STATUS, 0, 0, -1, NULL, 0); done = 0; } break; case LOAD: done = 0; - imsg_compose(ibuf, IMSG_CTL_BEGIN, 0, 0, -1, NULL, 0); + imsg_compose(imsgbuf, IMSG_CTL_BEGIN, 0, 0, -1, NULL, 0); break; case JUMP: done = 0; memset(path, 0, sizeof(path)); strlcpy(path, res->files[0], sizeof(path)); - imsg_compose(ibuf, IMSG_CTL_JUMP, 0, 0, -1, + imsg_compose(imsgbuf, IMSG_CTL_JUMP, 0, 0, -1, path, sizeof(path)); break; case MODE: done = 0; - imsg_compose(ibuf, IMSG_CTL_MODE, 0, 0, -1, + imsg_compose(imsgbuf, IMSG_CTL_MODE, 0, 0, -1, &res->mode, sizeof(res->mode)); - imsg_compose(ibuf, IMSG_CTL_STATUS, 0, 0, -1, + imsg_compose(imsgbuf, IMSG_CTL_STATUS, 0, 0, -1, &res->mode, sizeof(res->mode)); res->status_format = "mode:oneline"; if (verbose) @@ -456,14 +456,14 @@ ctlaction(struct parse_result *res) break; case MONITOR: done = 0; - imsg_compose(ibuf, IMSG_CTL_MONITOR, 0, 0, -1, + imsg_compose(imsgbuf, IMSG_CTL_MONITOR, 0, 0, -1, NULL, 0); break; case RESTART: memset(&res->seek, 0, sizeof(res->seek)); /* fallthrough */ case SEEK: - imsg_compose(ibuf, IMSG_CTL_SEEK, 0, 0, -1, &res->seek, + imsg_compose(imsgbuf, IMSG_CTL_SEEK, 0, 0, -1, &res->seek, sizeof(res->seek)); break; case NONE: @@ -475,17 +475,17 @@ ctlaction(struct parse_result *res) if (ret != 0) goto end; - imsg_flush(ibuf); + imsg_flush(imsgbuf); i = 0; while (!done) { - if ((n = imsg_read(ibuf)) == -1 && errno != EAGAIN) + if ((n = imsg_read(imsgbuf)) == -1 && errno != EAGAIN) fatalx("imsg_read error"); if (n == 0) fatalx("pipe closed"); while (!done) { - if ((n = imsg_get(ibuf, &imsg)) == -1) + if ((n = imsg_get(imsgbuf, &imsg)) == -1) fatalx("imsg_get error"); if (n == 0) break; @@ -1005,8 +1005,8 @@ ctl(int argc, char **argv) if ((ctl_sock = ctl_connect()) == -1) fatal("can't connect"); - ibuf = xmalloc(sizeof(*ibuf)); - imsg_init(ibuf, ctl_sock); + imsgbuf = xmalloc(sizeof(*imsgbuf)); + imsg_init(imsgbuf, ctl_sock); optreset = 1; optind = 1; blob - 23b3afca0ccc9da9f0275984852e6af657caa03d blob + 856bac10e35258f4711b55437794f4e815427be0 --- player.c +++ player.c @@ -35,7 +35,7 @@ struct pollfd *player_pfds; int player_nfds; -static struct imsgbuf *ibuf; +static struct imsgbuf *imsgbuf; static int nextfd = -1; static int64_t samples; @@ -67,8 +67,8 @@ player_setduration(int64_t d) duration = d; seconds = duration / current_rate; - imsg_compose(ibuf, IMSG_LEN, 0, 0, -1, &seconds, sizeof(seconds)); - imsg_flush(ibuf); + imsg_compose(imsgbuf, IMSG_LEN, 0, 0, -1, &seconds, sizeof(seconds)); + imsg_flush(imsgbuf); } static void @@ -82,8 +82,8 @@ player_onmove(void *arg, int delta) reported = samples; sec = samples / current_rate; - imsg_compose(ibuf, IMSG_POS, 0, 0, -1, &sec, sizeof(sec)); - imsg_flush(ibuf); + imsg_compose(imsgbuf, IMSG_POS, 0, 0, -1, &sec, sizeof(sec)); + imsg_flush(imsgbuf); } } @@ -108,17 +108,17 @@ player_dispatch(int64_t *s, int wait) return IMSG_STOP; again: - if ((n = imsg_get(ibuf, &imsg)) == -1) + if ((n = imsg_get(imsgbuf, &imsg)) == -1) fatal("imsg_get"); if (n == 0) { if (!wait) return -1; - pfd.fd = ibuf->fd; + pfd.fd = imsgbuf->fd; pfd.events = POLLIN; if (poll(&pfd, 1, INFTIM) == -1) fatal("poll"); - if ((n = imsg_read(ibuf)) == -1 && errno != EAGAIN) + if ((n = imsg_read(imsgbuf)) == -1 && errno != EAGAIN) fatal("imsg_read"); if (n == 0) fatalx("pipe closed"); @@ -170,15 +170,15 @@ player_senderr(const char *errstr) if (errstr != NULL) len = strlen(errstr) + 1; - imsg_compose(ibuf, IMSG_ERR, 0, 0, -1, errstr, len); - imsg_flush(ibuf); + imsg_compose(imsgbuf, IMSG_ERR, 0, 0, -1, errstr, len); + imsg_flush(imsgbuf); } static void player_sendeof(void) { - imsg_compose(ibuf, IMSG_EOF, 0, 0, -1, NULL, 0); - imsg_flush(ibuf); + imsg_compose(imsgbuf, IMSG_EOF, 0, 0, -1, NULL, 0); + imsg_flush(imsgbuf); } static int @@ -193,8 +193,8 @@ player_playnext(const char **errstr) /* reset samples and set position to zero */ samples = 0; - imsg_compose(ibuf, IMSG_POS, 0, 0, -1, &samples, sizeof(samples)); - imsg_flush(ibuf); + imsg_compose(imsgbuf, IMSG_POS, 0, 0, -1, &samples, sizeof(samples)); + imsg_flush(imsgbuf); r = read(fd, buf, sizeof(buf)); @@ -319,8 +319,8 @@ player(int debug, int verbose) player_pfds[0].events = POLLIN; player_pfds[0].fd = 3; - ibuf = xmalloc(sizeof(*ibuf)); - imsg_init(ibuf, 3); + imsgbuf = xmalloc(sizeof(*imsgbuf)); + imsg_init(imsgbuf, 3); signal(SIGINT, player_signal_handler); signal(SIGTERM, player_signal_handler); blob - 305f4c7ce15a479e66f1e29ae430c56e1a5bd80f blob + 8e365099a89783bf8a46797ee6c04fe3e0610a28 --- web/web.c +++ web/web.c @@ -60,7 +60,7 @@ #define ICON_PLAY "⏵" static struct clthead clients; -static struct imsgbuf ibuf; +static struct imsgbuf imsgbuf; static struct playlist playlist_tmp; static struct player_status player_status; static uint64_t position, duration; @@ -445,20 +445,20 @@ imsg_dispatch(int fd, int ev, void *d) int r; if (ev & (POLLIN|POLLHUP)) { - if ((n = imsg_read(&ibuf)) == -1 && errno != EAGAIN) + if ((n = imsg_read(&imsgbuf)) == -1 && errno != EAGAIN) fatal("imsg_read"); if (n == 0) fatalx("pipe closed"); } if (ev & POLLOUT) { - if ((n = msgbuf_write(&ibuf.w)) == -1 && errno != EAGAIN) + if ((n = msgbuf_write(&imsgbuf.w)) == -1 && errno != EAGAIN) fatal("msgbuf_write"); if (n == 0) fatalx("pipe closed"); } for (;;) { - if ((n = imsg_get(&ibuf, &imsg)) == -1) + if ((n = imsg_get(&imsgbuf, &imsg)) == -1) fatal("imsg_get"); if (n == 0) break; @@ -475,7 +475,8 @@ imsg_dispatch(int fd, int ev, void *d) case IMSG_CTL_ADD: playlist_free(&playlist_tmp); - imsg_compose(&ibuf, IMSG_CTL_SHOW, 0, 0, -1, NULL, 0); + imsg_compose(&imsgbuf, IMSG_CTL_SHOW, 0, 0, -1, + NULL, 0); break; case IMSG_CTL_MONITOR: @@ -487,18 +488,18 @@ imsg_dispatch(int fd, int ev, void *d) case IMSG_CTL_PAUSE: case IMSG_CTL_STOP: case IMSG_CTL_MODE: - imsg_compose(&ibuf, IMSG_CTL_STATUS, 0, 0, -1, - NULL, 0); + imsg_compose(&imsgbuf, IMSG_CTL_STATUS, 0, 0, + -1, NULL, 0); break; case IMSG_CTL_NEXT: case IMSG_CTL_PREV: case IMSG_CTL_JUMP: case IMSG_CTL_COMMIT: - imsg_compose(&ibuf, IMSG_CTL_SHOW, 0, 0, -1, + imsg_compose(&imsgbuf, IMSG_CTL_SHOW, 0, 0, -1, NULL, 0); - imsg_compose(&ibuf, IMSG_CTL_STATUS, 0, 0, -1, - NULL, 0); + imsg_compose(&imsgbuf, IMSG_CTL_STATUS, 0, 0, + -1, NULL, 0); break; case IMSG_CTL_SEEK: @@ -562,7 +563,7 @@ imsg_dispatch(int fd, int ev, void *d) } ev = POLLIN; - if (ibuf.w.queued) + if (imsgbuf.w.queued) ev |= POLLOUT; ev_add(fd, ev, imsg_dispatch, NULL); } @@ -687,9 +688,9 @@ route_jump(struct client *clt) if (strlcpy(path, field, sizeof(path)) >= sizeof(path)) goto badreq; - imsg_compose(&ibuf, IMSG_CTL_JUMP, 0, 0, -1, + imsg_compose(&imsgbuf, IMSG_CTL_JUMP, 0, 0, -1, path, sizeof(path)); - ev_add(ibuf.w.fd, POLLIN|POLLOUT, imsg_dispatch, NULL); + ev_add(imsgbuf.w.fd, POLLIN|POLLOUT, imsg_dispatch, NULL); break; } @@ -734,8 +735,8 @@ route_controls(struct client *clt) else goto badreq; - imsg_compose(&ibuf, cmd, 0, 0, -1, NULL, 0); - imsg_flush(&ibuf); + imsg_compose(&imsgbuf, cmd, 0, 0, -1, NULL, 0); + imsg_flush(&imsgbuf); break; } @@ -779,8 +780,9 @@ route_mode(struct client *clt) else goto badreq; - imsg_compose(&ibuf, IMSG_CTL_MODE, 0, 0, -1, &pm, sizeof(pm)); - ev_add(ibuf.w.fd, POLLIN|POLLOUT, imsg_dispatch, NULL); + imsg_compose(&imsgbuf, IMSG_CTL_MODE, 0, 0, -1, + &pm, sizeof(pm)); + ev_add(imsgbuf.w.fd, POLLIN|POLLOUT, imsg_dispatch, NULL); break; } @@ -1063,10 +1065,10 @@ main(int argc, char **argv) fatal("ev_init"); amused_sock = dial(sock); - imsg_init(&ibuf, amused_sock); - imsg_compose(&ibuf, IMSG_CTL_SHOW, 0, 0, -1, NULL, 0); - imsg_compose(&ibuf, IMSG_CTL_STATUS, 0, 0, -1, NULL, 0); - imsg_compose(&ibuf, IMSG_CTL_MONITOR, 0, 0, -1, NULL, 0); + imsg_init(&imsgbuf, amused_sock); + imsg_compose(&imsgbuf, IMSG_CTL_SHOW, 0, 0, -1, NULL, 0); + imsg_compose(&imsgbuf, IMSG_CTL_STATUS, 0, 0, -1, NULL, 0); + imsg_compose(&imsgbuf, IMSG_CTL_MONITOR, 0, 0, -1, NULL, 0); ev_add(amused_sock, POLLIN|POLLOUT, imsg_dispatch, NULL); memset(&hints, 0, sizeof(hints));