Lines Matching refs:fd
59 control_queue_free(struct fd_list *fd) in control_queue_free() argument
63 while ((fdp = TAILQ_FIRST(&fd->queue))) { in control_queue_free()
64 TAILQ_REMOVE(&fd->queue, fdp, next); in control_queue_free()
71 while ((fdp = TAILQ_FIRST(&fd->free_queue))) { in control_queue_free()
72 TAILQ_REMOVE(&fd->free_queue, fdp, next); in control_queue_free()
81 control_free(struct fd_list *fd) in control_free() argument
85 if (fd->ctx->ps_control_client == fd) in control_free()
86 fd->ctx->ps_control_client = NULL; in control_free()
89 eloop_event_delete(fd->ctx->eloop, fd->fd); in control_free()
90 close(fd->fd); in control_free()
91 TAILQ_REMOVE(&fd->ctx->control_fds, fd, next); in control_free()
92 control_queue_free(fd); in control_free()
93 free(fd); in control_free()
97 control_hangup(struct fd_list *fd) in control_hangup() argument
101 if (IN_PRIVSEP(fd->ctx)) { in control_hangup()
102 if (ps_ctl_sendeof(fd) == -1) in control_hangup()
106 control_free(fd); in control_hangup()
110 control_handle_read(struct fd_list *fd) in control_handle_read() argument
115 bytes = read(fd->fd, buffer, sizeof(buffer) - 1); in control_handle_read()
119 control_hangup(fd); in control_handle_read()
124 if (IN_PRIVSEP(fd->ctx)) { in control_handle_read()
127 fd->flags |= FD_SENDLEN; in control_handle_read()
128 err = ps_ctl_handleargs(fd, buffer, (size_t)bytes); in control_handle_read()
129 fd->flags &= ~FD_SENDLEN; in control_handle_read()
135 ps_ctl_sendargs(fd, buffer, (size_t)bytes) == -1) { in control_handle_read()
137 control_free(fd); in control_handle_read()
144 control_recvdata(fd, buffer, (size_t)bytes); in control_handle_read()
149 control_handle_write(struct fd_list *fd) in control_handle_write() argument
155 data = TAILQ_FIRST(&fd->queue); in control_handle_write()
169 if (writev(fd->fd, iov, iov_len) == -1) { in control_handle_write()
174 control_hangup(fd); in control_handle_write()
178 TAILQ_REMOVE(&fd->queue, data, next); in control_handle_write()
180 TAILQ_INSERT_TAIL(&fd->free_queue, data, next); in control_handle_write()
187 if (TAILQ_FIRST(&fd->queue) != NULL) in control_handle_write()
191 if (IN_PRIVSEP_SE(fd->ctx) && !(fd->flags & FD_LISTEN)) { in control_handle_write()
192 if (ps_ctl_sendeof(fd) == -1) in control_handle_write()
198 if (eloop_event_add(fd->ctx->eloop, fd->fd, ELE_READ, in control_handle_write()
199 control_handle_data, fd) == -1) in control_handle_write()
207 struct fd_list *fd = arg; in control_handle_data() local
213 if (control_handle_write(fd) == -1) in control_handle_data()
217 if (control_handle_read(fd) == -1) in control_handle_data()
221 control_hangup(fd); in control_handle_data()
225 control_recvdata(struct fd_list *fd, char *data, size_t len) in control_recvdata() argument
269 if (dhcpcd_handleargs(fd->ctx, fd, argc, argvp) == -1) { in control_recvdata()
272 control_free(fd); in control_recvdata()
280 control_new(struct dhcpcd_ctx *ctx, int fd, unsigned int flags) in control_new() argument
289 l->fd = fd; in control_new()
306 int fd, flags; in control_handle1() local
312 if ((fd = accept(lfd, (struct sockaddr *)&run, &len)) == -1) in control_handle1()
314 if ((flags = fcntl(fd, F_GETFD, 0)) == -1 || in control_handle1()
315 fcntl(fd, F_SETFD, flags | FD_CLOEXEC) == -1) in control_handle1()
317 if ((flags = fcntl(fd, F_GETFL, 0)) == -1 || in control_handle1()
318 fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1) in control_handle1()
328 l = control_new(ctx, fd, fd_flags); in control_handle1()
332 if (eloop_event_add(ctx->eloop, l->fd, ELE_READ, in control_handle1()
339 if (fd != -1) in control_handle1()
340 close(fd); in control_handle1()
390 int fd; in make_sock() local
392 if ((fd = xsocket(AF_UNIX, SOCK_STREAM | SOCK_CXNB, 0)) == -1) in make_sock()
397 return fd; in make_sock()
408 int fd; in control_start1() local
411 fd = make_sock(&sa, ifname, family, (fmode & S_UNPRIV) == S_UNPRIV); in control_start1()
412 if (fd == -1) in control_start1()
417 if (bind(fd, (struct sockaddr *)&sa, len) == -1 || in control_start1()
421 listen(fd, sizeof(ctx->control_fds)) == -1) in control_start1()
423 close(fd); in control_start1()
429 if (IN_PRIVSEP(ctx) && ps_rights_limit_fd_fctnl(fd) == -1) { in control_start1()
430 close(fd); in control_start1()
442 return fd; in control_start1()
448 int fd; in control_start() local
461 if ((fd = control_start1(ctx, ifname, family, S_PRIV)) == -1) in control_start()
464 ctx->control_fd = fd; in control_start()
465 if (eloop_event_add(ctx->eloop, fd, ELE_READ, in control_start()
469 if ((fd = control_start1(ctx, ifname, family, S_UNPRIV)) != -1) { in control_start()
470 ctx->control_unpriv_fd = fd; in control_start()
471 if (eloop_event_add(ctx->eloop, fd, ELE_READ, in control_start()
542 int fd; in control_open() local
544 if ((fd = make_sock(&sa, ifname, family, unpriv)) != -1) { in control_open()
548 if (connect(fd, (struct sockaddr *)&sa, len) == -1) { in control_open()
549 close(fd); in control_open()
550 fd = -1; in control_open()
553 return fd; in control_open()
581 control_queue(struct fd_list *fd, void *data, size_t data_len) in control_queue() argument
595 TAILQ_FOREACH(df, &fd->free_queue, next) { in control_queue()
603 TAILQ_REMOVE(&fd->free_queue, d, next); in control_queue()
626 d->data_flags = fd->flags & FD_SENDLEN; in control_queue()
628 TAILQ_INSERT_TAIL(&fd->queue, d, next); in control_queue()
630 if (fd->flags & FD_LISTEN) in control_queue()
632 return eloop_event_add(fd->ctx->eloop, fd->fd, events, in control_queue()
633 control_handle_data, fd); in control_queue()