Skip to content

Conversation

@ThePrez
Copy link
Member

@ThePrez ThePrez commented May 20, 2022

@ThePrez ThePrez requested review from abmusse and kadler May 20, 2022 18:33
@ThePrez
Copy link
Member Author

ThePrez commented May 20, 2022

I guess I could have just taken the current BSD implementation:
https://github.com/openssh/openssh-portable/blob/master/openbsd-compat/daemon.c
:/

@ThePrez
Copy link
Member Author

ThePrez commented Nov 2, 2022

@kadler / @abmusse , any review comments?

Comment on lines +48 to +53
for (int i = 0; i <= 2; ++i)
{
if (-1 == dup2(devnull, i))
{
return -1;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't need to be a loop.

Also, I'm not sure how error handling should lwork here. The man page says

If an error occurs, daemon() returns -1 and sets errno to any of the errors specified for the fork(2) and setsid(2).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICT, the only error that really could occur here is EINTR which we could handle better anyway. EBADF and EMFILE should never happen.

#include <fcntl.h>

// Modeled after doc at https://man7.org/linux/man-pages/man3/daemon.3.html
static int libutil_daemon(int nochdir, int noclose)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
static int libutil_daemon(int nochdir, int noclose)
int libutil_daemon(int nochdir, int noclose)

If this is a public API it shouldn't be static.

}
}
return 0;
} No newline at end of file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing newline

Comment on lines +27 to +31
int devnull = open("/dev/null", O_RDWR);
if (-1 == devnull)
{
return -1;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be moved inside the noclose block below. It also needs to be closed after the dup2 calls.

cp perfstat/libiperf.h $(DESTDIR)$(PREFIX)/include/libiperf.h

util/libutil.o: util/getopt_long.o util/pty.o util/mkdtemp.o util/backtrace.o util/bsd-flock.o util/asprintf.o util/progname.o util/err.o util/isatty.o
util/libutil.o: util/getopt_long.o util/pty.o util/mkdtemp.o util/backtrace.o util/bsd-flock.o util/asprintf.o util/progname.o util/err.o util/isatty.o util/daemon.o
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you manually updated the Makefile. You need to update build.json then re-run autogen.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants