Linux 4.14 systemd 如何把自定义服务的日志log默认输出到debug口ttyLP0?

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Linux 4.14 systemd 如何把自定义服务的日志log默认输出到debug口ttyLP0?

3,229 次查看
475143463
Contributor III

如题,如何把自定义服务的日志log默认输出到debug口ttyLP0?

即,CPU启动后,自定义服务的日志log(printf输出)直接输出到debug口上。

测试service(位置:/lib/systemd/system):

root@imx8qxpmek:~# cat /lib/systemd/system/printftest.service
[Unit]
Description=printftest
After=rc-local.service
After=syslog.target network.target

[Service]
#Type=forking
RemainAfterExit=yes
ExecStart=/opt/test/testsh
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
User=root

[Install]
WantedBy=multi-user.target

测试脚本testsh

#!/bin/sh

echo "printf test"

cd /opt/test
./printftest

 

printftest源码:

#include <stdint.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include <fcntl.h>
#include <time.h>
#include <sys/ioctl.h>
#include <linux/ioctl.h>
#include <sys/stat.h>
#include <linux/types.h>

void main(void)
{
while(1)
{
printf("printf test\n");
sleep(1);
}
}

0 项奖励
0 回复数