Reporter Logging Improvements
Bug #1933984 reported by
Jason Stephenson
This bug affects 2 people
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Evergreen |
Confirmed
|
Undecided
|
Unassigned | ||
OpenSRF |
Confirmed
|
Undecided
|
Unassigned |
Bug Description
The reporter, clark-kent.pl (aka Clark), currently spews text to stdout/stderr. This is wrong on 2 fronts:
1. When started with the --daemon option those messages get dropped on the floor after the user who started the process logs out, and
2. daemon processes are expected to close stdin, stdout, and stderr and then use syslog to log any messages.
I propose that we follow UNIX/SUSP conventions and do #2 when clark-kent.pl is started as a daemon.
Branch to follow.
Changed in evergreen: | |
status: | New → Confirmed |
Changed in opensrf: | |
assignee: | nobody → Jason Stephenson (jstephenson) |
Changed in evergreen: | |
assignee: | Jason Stephenson (jstephenson) → nobody |
Changed in opensrf: | |
assignee: | Jason Stephenson (jstephenson) → nobody |
milestone: | none → 3.2.2 |
Changed in evergreen: | |
milestone: | none → 3.8-beta |
Changed in evergreen: | |
milestone: | 3.8-beta → 3.next |
Changed in opensrf: | |
milestone: | 3.2.2 → none |
Changed in evergreen: | |
milestone: | 3.next → none |
To post a comment you must log in.
This bug also affects OpenSRF because the daemonize funciton in OpenSRF::Utils does not do everything that it should.
Section 13.3 of Advanced Programming in the Unix Environment, 3rd Edition, lists the requirements for a process to daemonize itself:
1. Call umask to set the file mode creation mask to a known value, usually 0. The inherited file mode creation mask could be set to deny certain permissions. If the daemon process creates files, it may want to set specific permissions. For example, if it creates files with group-read and group-write enabled, a file mode creation mask that turns off either of these permissions would undo its efforts. On the other hand, if the daemon calls library functions that result in files being created, then it might make sense to set the file mode create mask to a more restrictive value (such as 007), since the library functions might not allow the caller to specify the permissions through an explicit argument.
2. Call fork and have the parent exit. This does several things. First, if the daemon was started as a simple shell command, having the parent terminate makes the shell think that the command is done. Second, the child inherits the process group ID of the parent but gets a new process ID, so we’re guaranteed that the child is not a process group leader. This is a prerequisite for the call to setsid that is done next.
3. Call setsid to create a new session. The three steps listed in Section 9.5 occur. The process (a) becomes the leader of a new session, (b) becomes the leader of a new process group, and (c) is disassociated from its controlling terminal.
Under System V–based systems, some people recommend calling fork again at this point, terminating the parent, and continuing the daemon in the child. This guarantees that the daemon is not a session leader, which prevents it from acquiring a controlling terminal under the System V rules (Section 9.6). Alternatively, to avoid acquiring a controlling terminal, be sure to specify O_NOCTTY whenever opening a terminal device.
4. Change the current working directory to the root directory. The current working directory inherited from the parent could be on a mounted file system. Since daemons normally exist until the system is rebooted, if the daemon stays on a mounted file system, that file system cannot be unmounted.
Alternatively, some daemons might change the current working directory to a specific location where they will do all their work. For example, a line printer spooling daemon might change its working directory to its spool directory.
5. Unneeded file descriptors should be closed. This prevents the daemon from holding open any descriptors that it may have inherited from its parent (which could be a shell or some other process). We can use our open_max function (Figure 2.17) or the getrlimit function (Section 7.11) to determine the highest descriptor and close all descriptors up to that value.
6. Some daemons open file descriptors 0, 1, and 2 to /dev/null so that any library routines that try to read from standard input or write to standard output or standard error will have no effect. Since the daemon is not associated with a terminal dev...