Bug 1212756

Summary: Service cannot write to /dev/stdout
Product: [Fedora] Fedora Reporter: Jaroslav Škarvada <jskarvad>
Component: systemdAssignee: systemd-maint
Status: CLOSED CANTFIX QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 21CC: johannbg, jsynacek, lnykryn, msekleta, s, systemd-maint, zbyszek
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2015-06-17 23:25:16 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
service
none
corresponding unit file none

Description Jaroslav Škarvada 2015-04-17 09:50:18 UTC
Created attachment 1015506 [details]
service

Description of problem:
It seems that systemd service cannot write to /dev/stdout. It can see it, check it for R/W access rights (by access call), but cannot write to it. Reproducer is attached.

Version-Release number of selected component (if applicable):
systemd-216-24.fc21.x86_64

How reproducible:
always

Steps to Reproduce:
1. Install the attached reproducer
2. systemctl start ytest
3. systemctl status ytest

Actual results:
...
unable to open /dev/stdout
...

Expected results:
No error

Additional info:
I came across this problem when making unit file for one daemon. It has option for filename where to log. As I wanted it to log to stdout/journal, I used /dev/stdout. It works correctly if it is run without systemd.

Comment 1 Jaroslav Škarvada 2015-04-17 09:51:10 UTC
Created attachment 1015507 [details]
corresponding unit file

Comment 2 Jaroslav Škarvada 2015-04-17 11:51:11 UTC
Bash:
/dev/stdout -> /proc/self/fd/1 -> /dev/pts/X

Systemd:
/dev/stdout -> /proc/self/fd/1 -> socket:[Y]

Comment 3 Jaroslav Škarvada 2015-04-17 11:55:48 UTC
I cannot find a way how to make glibc "open" call to use STDOUT under systemd. AFAIK open("/dev/stdout", ... has been used for this.

Comment 4 Lennart Poettering 2015-06-17 23:25:16 UTC
Yeah, the kernel does not support opening /proc/self/fd/1 if that is a socket. It only supports that for fifos, ttys, files and a few others.

systemd connects stdout/stderr of all services with the journal, to collect the output. 

In the shell use ">&2" in place of ">/dev/stderr" to echo something to stderr.

Alternatively, use StandardOutput=null to turn of journal collection.

Basically, the idiom >/dev/stderr is not really compatible with many execution contexts.

This is unlikely to change, sorry. I have now added a TODO list item to document this behaviour in the systemd docs for StandardOutput= though.