gpm
gpm copied to clipboard
startup.c:129 if daemon(0,0) fails, the error message is wrong.
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.)
No strong opinion from my side, please send a PR to change it
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.
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.
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.