[systemd-devel] Getting EOF on FD#1 stdout (a service using socat)
Christian Seiler
christian at iwakd.de
Mon Jul 27 04:12:04 PDT 2015
Am 2015-07-27 12:31, schrieb John Lane:
> I have a problem with what I thought would be a simple service unit:
>
> # /etc/systemd/system/socat.service
> [Service]
> ExecStart=/usr/bin/socat UDP-RECV:4321 STDOUT
>
> The expected outcome is that "/usr/bin/socat UDP-RECV:4321 STDOUT" is
> started with its standard output connected to the journal.
>
> However, the service terminates immediately without error. I've
> looked
> into it and notice that socat is getting an EOF on FD#1, its standard
> output, and it then terminates:
>
> N starting data transfer loop with FDs [5,5] and [1,1]
> N socket 2 (fd 1) is at EOF
> I close(5)
> N exiting with status 0
>
> The command-line given in "ExecStart" works as expected if given on a
> command-line.
systemd opens sockets that connect the stdout/stderr of a service to
journald, but those sockets are unidirectional. This means that one
cannot read from those file descriptors. But socat by default uses
a bidirectional mode, and because it gets EOF when trying to read
STDOUT, it will immediately terminate.
Use the -u option to make socat work unidirectionally, then it should
work:
ExecStart=/usr/bin/socat -u UDP-RECV:4321 STDOUT
(See the man page of socat for further details.)
If you try it on the command line, the terminal you are using can in
fact be opened for writing, so it will not get an EOF there (but you
can use Ctrl+D when calling it manually to simulate that condition).
Christian
More information about the systemd-devel
mailing list