#endif
}
-int
+ssize_t
logreadfd(int fd)
{
struct logctx *ctx = &_logctx;
- int len, pri;
+ int pri;
pid_t pid;
char buf[LOGERR_SYSLOGBUF] = { '\0' };
struct iovec iov[] = {
.msg_iov = iov,
.msg_iovlen = sizeof(iov) / sizeof(iov[0])
};
+ ssize_t len;
- len = (int)recvmsg(fd, &msg, MSG_WAITALL);
+ len = recvmsg(fd, &msg, MSG_WAITALL);
if (len == -1 || len == 0)
- return -1;
+ return len;
/* Ensure we received the minimum and at least one character to log */
if ((size_t)len < sizeof(pri) + sizeof(pid) + 1 ||
msg.msg_flags & MSG_TRUNC) {
/* For logging in a chroot using SOCK_SEQPACKET */
int loggetfd(void);
void logsetfd(int);
-int logreadfd(int);
+ssize_t logreadfd(int);
unsigned int loggetopts(void);
void logsetopts(unsigned int);
ssize_t len;
int exit_code = EXIT_FAILURE;
- if (events & ELE_HANGUP) {
- logerrx("%s: hangup", __func__);
+ if (events & ELE_HANGUP)
goto out;
- }
if (events != ELE_READ)
logerrx("%s: unexpected event 0x%04x", __func__, events);
ctx->eloop == NULL)
return 0;
+
/* If we are the root process then remove the pidfile */
- if (ctx->options & DHCPCD_PRIVSEPROOT &&
- !(ctx->options & DHCPCD_TEST))
- {
- if (unlink(ctx->pidfile) == -1)
+ if (ctx->options & DHCPCD_PRIVSEPROOT) {
+ if (!(ctx->options & DHCPCD_TEST) && unlink(ctx->pidfile) == -1)
logerr("%s: unlink: %s", __func__, ctx->pidfile);
+
+ /* drain the log */
+ if (ctx->ps_log_root_fd != -1) {
+ ssize_t loglen;
+
+ do {
+ loglen = logreadfd(ctx->ps_log_root_fd);
+ } while (loglen != 0 && loglen != -1);
+ }
}
/* Only the manager process gets past this point. */