Bug 236117

Summary: /usr/sbin/daemon should support stdin,stdout,stderr redirect to files other than /dev/null
Product: Base System Reporter: TAO ZHOU <zhoutao>
Component: binAssignee: freebsd-bugs (Nobody) <bugs>
Status: Open ---    
Severity: Affects Some People CC: 0mp, grahamperrin, ihor, pat, ygy
Priority: --- Keywords: feature
Version: 11.2-STABLE   
Hardware: Any   
OS: Any   

Description TAO ZHOU 2019-03-01 01:06:59 UTC
The daemon command has an option `-f`, which, according to the man page, redirects stding,stdout,stderr to /dev/null.

This is fine. But if I cannot redirect stdin, stdout, stderr to different files respectively.

There is a `-o` option, 

```
  -o output_file
             Append output from the daemonized process to output_file.  If the
             file does not exist, it is created with permissions 0600.
```

The problem I am having now is that daemon command was used in some freebsd rc.d scripts without the `-f` option. When I try to restart those services through python subprocess.Popen, it would hang indefinitely. 

The problem can be easily reproduced by 

```
python3 -c 'import subprocess; subprocess.Popen(["/usr/sbin/service", "mytestservice", "onerestart"], stderr=subprocess.PIPE).communicate()'
```

I can add the `-f` option to fix the problem, but `-f` will override the `-o` option, and I end up with no log at all.


I think it would be nice if the daemon command can support redirecting stdin, stdout, stderr separately.
Comment 1 Ihor Antonov 2023-03-06 04:12:30 UTC
I am working on daemon improvements and this feature is planned to be added once transition to kqueue is finished.
Comment 2 Ihor Antonov 2023-04-15 00:45:04 UTC
zhoutao@laocius.org:

You could send logs to syslog, if that works for you.
Check these daemon options:

--syslog       Send output to syslog 
--output-mask  What to send to syslog/file
	       1=stdout, 2=stderr, 3=both


I know this is not ideal. I am thinking about the way to add the feature you request without breaking the current interface and without making it inconsistent/incoherent..