<div dir="ltr">I'm observing it on the ubuntu bionic that comes with systemd 237</div><div class="gmail_extra"><br><div class="gmail_quote">On 19 May 2018 at 07:27, Lennart Poettering <span dir="ltr"><<a href="mailto:lennart@poettering.net" target="_blank">lennart@poettering.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Fr, 18.05.18 09:02, Ivan Kurnosov (<a href="mailto:zerkms@zerkms.ru">zerkms@zerkms.ru</a>) wrote:<br>
<br>
> Hi,<br>
> <br>
> I originally asked this question on the stackoverflow (<br>
> <a href="https://stackoverflow.com/q/50400145/251311" rel="noreferrer" target="_blank">https://stackoverflow.com/q/<wbr>50400145/251311</a>) but I feel I wouldn't get an<br>
> answer there.<br>
> <br>
> The simplified example that demonstrates a problem is<br>
> <br>
> #include <stdio.h><br>
> <br>
> int main(void)<br>
> {<br>
> printf("foo\n");<br>
> fflush(stdout);<br>
> getchar();<br>
> return 0;<br>
> }<br>
> <br>
> (it's not programming language specific though - the original application I<br>
> discovered the problem with is in Go).<br>
> <br>
> If it's compiled and is run by the following unit:<br>
> <br>
> [Unit]<br>
> Description=description<br>
> After=network.target<br>
> <br>
> [Service]<br>
> ExecStart=/path/to/binary<br>
> <br>
> [Install]<br>
> WantedBy=multi-user.target<br>
> <br>
> then on `systemctl restart` `journald` would in most cases not get the<br>
> `foo\n` output, while `syslog` successfully writes it down to the<br>
> `/var/log/syslog`.<br>
> <br>
> Here is the example of the `journald` output for the service:<br>
> <br>
> May 18 08:30:38 hostname systemd[1]: Stopped servicename<br>
> May 18 08:30:38 hostname systemd[1]: Started servicename<br>
> May 18 08:30:38 hostname systemd[1]: Stopped servicename<br>
> May 18 08:30:38 hostname systemd[1]: Started servicename<br>
> May 18 08:30:38 hostname servicename[7701]: foo<br>
> May 18 08:30:41 hostname systemd[1]: Stopped servicename<br>
> May 18 08:30:41 hostname systemd[1]: Started servicename<br>
> May 18 08:30:46 hostname systemd[1]: Stopped servicename<br>
> May 18 08:30:46 hostname systemd[1]: Started servicename<br>
> <br>
> and then the corresponding part of the `/var/log/syslog`:<br>
> <br>
> May 18 08:30:38 hostname systemd[1]: Stopped servicename.<br>
> May 18 08:30:38 hostname systemd[1]: Started servicename.<br>
> May 18 08:30:38 hostname servicename[7682]: foo<br>
> May 18 08:30:38 hostname systemd[1]: Stopped servicename.<br>
> May 18 08:30:38 hostname systemd[1]: Started servicename.<br>
> May 18 08:30:38 hostname servicename[7701]: foo<br>
> May 18 08:30:41 hostname systemd[1]: Stopped servicename.<br>
> May 18 08:30:41 hostname systemd[1]: Started servicename.<br>
> May 18 08:30:41 hostname servicename[7720]: foo<br>
> May 18 08:30:46 hostname systemd[1]: Stopped servicename.<br>
> May 18 08:30:46 hostname systemd[1]: Started servicename.<br>
> May 18 08:30:46 hostname servicename[7739]: foo<br>
> <br>
> What would be a way to **guarantee** journald received the `stdout`, if any?<br>
<br>
</div></div>It is guaranteed that it wil get the data. However, you are probably<br>
running into this:<br>
<br>
<a href="https://github.com/systemd/systemd/issues/2913" rel="noreferrer" target="_blank">https://github.com/systemd/<wbr>systemd/issues/2913</a><br>
<br>
i.e. stuff that is logged right before a process exits might miss the<br>
metadata we need for "-u" to work correctly. The message itself is not<br>
lost though, you should see it if you drop the "-u"...<br>
<br>
The situation is improved a ton with systemd 235 where metadata is<br>
cached in journald if possible, which increases the chance we wil have<br>
the metadata around even if the sending process is already gone. It<br>
fixes most common cases, but there are still some cases around which<br>
aren't covered by that.<br>
<br>
hence, make sure to run 235 (or some release that backported the<br>
caching).<br>
<span class="HOEnZb"><font color="#888888"><br>
Lennart<br>
<br>
-- <br>
Lennart Poettering, Red Hat<br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">With best regards, Ivan Kurnosov</div>
</div>