2

演示问题的简化示例是

#include <stdio.h>

int main(void)
{
    printf("foo\n");
    fflush(stdout);
    getchar();
    return 0;
}

(虽然它不是特定于编程语言的——我发现问题的原始应用程序是在 Go 中)。

如果它已编译并由以下单元运行:

[Unit]
Description=description
After=network.target

[Service]
ExecStart=/path/to/binary

[Install]
WantedBy=multi-user.target

然后 onsystemctl restart journald在大多数情况下不会得到foo\n输出,而syslog成功地将其写入/var/log/syslog.

以下是journald服务的输出示例:

May 18 08:30:38 hostname systemd[1]: Stopped servicename
May 18 08:30:38 hostname systemd[1]: Started servicename
May 18 08:30:38 hostname systemd[1]: Stopped servicename
May 18 08:30:38 hostname systemd[1]: Started servicename
May 18 08:30:38 hostname servicename[7701]: foo
May 18 08:30:41 hostname systemd[1]: Stopped servicename
May 18 08:30:41 hostname systemd[1]: Started servicename
May 18 08:30:46 hostname systemd[1]: Stopped servicename
May 18 08:30:46 hostname systemd[1]: Started servicename

然后是相应的部分/var/log/syslog

May 18 08:30:38 hostname systemd[1]: Stopped servicename.
May 18 08:30:38 hostname systemd[1]: Started servicename.
May 18 08:30:38 hostname servicename[7682]: foo
May 18 08:30:38 hostname systemd[1]: Stopped servicename.
May 18 08:30:38 hostname systemd[1]: Started servicename.
May 18 08:30:38 hostname servicename[7701]: foo
May 18 08:30:41 hostname systemd[1]: Stopped servicename.
May 18 08:30:41 hostname systemd[1]: Started servicename.
May 18 08:30:41 hostname servicename[7720]: foo
May 18 08:30:46 hostname systemd[1]: Stopped servicename.
May 18 08:30:46 hostname systemd[1]: Started servicename.
May 18 08:30:46 hostname servicename[7739]: foo

如果有的话,保证journald 收到的方法stdout是什么?

4

1 回答 1

1

tldr,这是一个已知问题。

我在systemd-devel 邮件列表中问了同样的问题,并得到了对报告问题的参考的回复

于 2018-05-18T00:12:53.927 回答