-
Notifications
You must be signed in to change notification settings - Fork 9
add daemon() implementation #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
I guess I could have just taken the current BSD implementation: |
| for (int i = 0; i <= 2; ++i) | ||
| { | ||
| if (-1 == dup2(devnull, i)) | ||
| { | ||
| return -1; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing newline
| int devnull = open("/dev/null", O_RDWR); | ||
| if (-1 == devnull) | ||
| { | ||
| return -1; | ||
| } |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
Based loosely on the doc at https://man7.org/linux/man-pages/man3/daemon.3.html