Skip to content
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

startup.c:129 if daemon(0,0) fails, the error message is wrong. #28

Open
olahaye74 opened this issue Mar 29, 2018 · 4 comments
Open

startup.c:129 if daemon(0,0) fails, the error message is wrong. #28

olahaye74 opened this issue Mar 29, 2018 · 4 comments

Comments

@olahaye74
Copy link

daemon(0,0) does:

  • fork
  • setsid
  • chdir / (1st arg = 0)
  • redirects standard input, standard output and standard error to /dev/null (2nd arg = 0)

if daemon(0,0) fails, that does not mean that fork failed. I can fail at setsid, chdir or redirections to /dev/null

I got gpm failed errno=37. Doing strace show that fork succeed indeed. The problem was that /dev/null is not a char device and lock failed.
The correct error should be "daemonize failed" not "fork failed"!
(Because of the missleading message I lost time.)

@telmich
Copy link
Owner

telmich commented Mar 29, 2018

No strong opinion from my side, please send a PR to change it

@olahaye74
Copy link
Author

I have no time yet for that now.
Also, I gave a missleading message. I don't know errno in fact, the only real thing is that daemon fails after clone (fork). Looking at daemon source code (https://github.com/lattera/glibc/blob/master/misc/daemon.c), and looking at gpm strace, I see the fork success, the chdir success, the setsid and the open(/dev/null) success, thus it fails checking /dev/null is a char device (my system has a buggy /dev/null which is not a char device for some reason).
strace relevant part:
clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f294c08ca10) = 21398
exit_group(0) = ?
+++ exited with 0 +++
strace: Process 21398 attached
setsid() = 21398
chdir("/") = 0
open("/dev/null", O_RDWR) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
close(3)
=> Then it reports fork failed.

@olahaye74
Copy link
Author

Confirmed, If I do "rm -f /dev/null; mknode /dev/null c 1 3", gpm starts without problem.
It should report /dev/null: BAD DEVICE or something appropriate.

@olahaye74
Copy link
Author

After speaking with glibc dev, it turns out that gpm doesn't handle errno.
daemon() will set errno to ENODEV if /dev/null is not a device.
Thus, the error message should be "daemon() failed: ENODEV" or something similar.

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

No branches or pull requests

2 participants