演示问题的简化示例是
#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
是什么?