void proc_close(struct privsep *ps) { unsigned int dst, n; struct privsep_pipes *pp; if (ps == NULL) return; pp = ps->ps_pp; for (dst = 0; dst < PROC_MAX; dst++) { if (ps->ps_ievs[dst] == NULL) continue; for (n = 0; n < ps->ps_instances[dst]; n++) { if (pp->pp_pipes[dst][n] == -1) continue; /* Cancel the fd, close and invalidate the fd */ event_del(&(ps->ps_ievs[dst][n].ev)); imsg_clear(&(ps->ps_ievs[dst][n].ibuf)); close(pp->pp_pipes[dst][n]); pp->pp_pipes[dst][n] = -1; } free(ps->ps_ievs[dst]); } }
void mproc_clear(struct mproc *p) { log_debug("debug: clearing p=%s, fd=%d, pid=%d", p->name, p->imsgbuf.fd, p->pid); event_del(&p->ev); close(p->imsgbuf.fd); imsg_clear(&p->imsgbuf); }
void proc_remove_peer(struct tmuxpeer *peer) { log_debug("remove peer %p", peer); event_del(&peer->event); imsg_clear(&peer->ibuf); close(peer->ibuf.fd); free(peer); }
/* * The purpose of this function is to handle requests sent by the * root privileged process. */ int tnt_dispatch_imsg(struct imsg_data *data) { struct imsg imsg; ssize_t n; int device_fd; struct imsgbuf *ibuf = data->ibuf; n = imsg_read(ibuf); if (n == -1) { log_warnx("loose some imsgs"); imsg_clear(ibuf); return -1; } if (n == 0) { log_warnx("pipe closed"); return -1; } /* Loops through the queue created by imsg_read */ while ((n = imsg_get(ibuf, &imsg)) != 0 && n != -1) { switch (imsg.hdr.type) { case IMSG_CREATE_DEV: device_fd = imsg.fd; log_info("receive IMSG_CREATE_DEV: fd %i", device_fd); server_set_device(data->server, device_fd); /* directly ask to configure the tun device */ imsg_compose(ibuf, IMSG_SET_IP, 0, 0, -1, serv_opts.addr , strlen(serv_opts.addr)); break; default: break; } imsg_free(&imsg); } if (n == -1) { log_warnx("imsg_get"); return -1; } return 0; }
static void control_close(struct ctl_conn *c) { TAILQ_REMOVE(&ctl_conns, c, entry); event_del(&c->iev.ev); close(c->iev.ibuf.fd); imsg_clear(&c->iev.ibuf); free(c); stat_backend->decrement("control.session", 1); if (available_fds(CONTROL_FD_RESERVE)) return; if (!event_pending(&control_state.ev, EV_READ, NULL)) { log_warnx("re-enabling ctl connections"); event_add(&control_state.ev, NULL); } }
void control_close(int fd) { struct ctl_conn *c; if ((c = control_connbyfd(fd)) == NULL) { log_warn("control_close: fd %d: not found", fd); return; } TAILQ_REMOVE(&ctl_conns, c, entry); event_del(&c->iev.ev); imsg_clear(&c->iev.ibuf); close(fd); free(c); if (stat_decrement(STATS_CONTROL_SESSION) < env->sc_maxconn && !event_pending(&control_state.ev, EV_READ, NULL)) { log_warnx("re-enabling ctl connections"); event_add(&control_state.ev, NULL); } }
static int m_priv_iked_imsg(u_int cmd) { struct sockaddr_un sun; int fd = -1, ret = -1; struct imsgbuf ibuf; if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) { log_err("m_priv_iked_imsg: socket"); goto out; } bzero(&sun, sizeof(sun)); sun.sun_family = AF_UNIX; strlcpy(sun.sun_path, IKED_SOCKET, sizeof(sun.sun_path)); if (connect(fd, (struct sockaddr *)&sun, sizeof(sun)) == -1) { log_err("m_priv_iked_imsg: connect"); goto out; } imsg_init(&ibuf, fd); if (imsg_compose(&ibuf, cmd, 0, 0, -1, NULL, 0) == -1) { log_err("m_priv_iked_imsg: compose"); goto err; } if (imsg_flush(&ibuf) == -1) { log_err("m_priv_iked_imsg: flush"); goto err; } ret = 0; err: imsg_clear(&ibuf); out: if (fd != -1) close(fd); return (ret); }
void mdns_close(struct mdns *m) { imsg_clear(&m->ibuf); }