papertrail / remote_syslog2

To install, see "Releases" tab. Self-contained daemon for reading local files and emitting remote syslog (without using local syslogd).
http://help.papertrailapp.com/
MIT License
637 stars 158 forks source link

New daemonize to eliminate cgo #207

Closed markdascher closed 2 years ago

markdascher commented 7 years ago

Changed Daemonize() to use an new daemonize() implementation that doesn't rely on cgo at all. This ought to make it easier to build for more operating systems, such as FreeBSD (see #156).

The new daemonize() completes steps 5-9 and 11 (and 14-15 to some extent) from this list. These steps all come "for free" with various options to os.StartProcess(). The missing steps would either need the syscall package or weren't clearly needed.

Compared to VividCortex/godaemon, the only real difference is that there's no syscall.Umask(0), which is step 10 from the list above. It's also used differently:

if !isDaemonized() {
    // put any one-time init here, not repeated in children
    err = daemonize([]*os.File{newStdin, newStdout, newStderr, ...})
    if err != nil {
        os.Exit(1)
    }
}
// continue here

Probably best to compare old vs. new side-by-side, since the diff is hard to follow.

Wouldn't necessarily be opposed to adding more (e.g. syscall.Umask(0)), but this seems like a good starting point.