This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] Linux/AM5728:systemd (tcgetattr(),printf())问题

Guru**** 2562830 points
Other Parts Discussed in Thread: AM5728

请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/processors-group/processors/f/processors-forum/613543/linux-am5728-systemd-tcgetattr-printf-issue

器件型号:AM5728

工具/软件:Linux

大家好、我们使用"AM5728、PSDK 04_00_00_04"。
目前、我们使用 systemd 来运行我们自动开发的程序。

但是,systemd 操作有一些问题。
我想在这方面获得帮助。

1. init 失败 tcgetattr ()
我们开发的程序应从终端接收键盘输入。
但是,如果使用 systemd 执行,init 将失败,并使用 tcgetattr ()函数。
在 systemd 中使用该函数是否有限制?

如果您直接从控制台运行程序,则它可以正常工作。
直接从终端执行时没有问题。

root@am57xx-evm:/#systemctl start test.service  
=>运行失败。
root@am57xx-EVM:/#./test
=>运行正常。


2. printf()调试消息输出。
当我使用 systemd 运行程序时,不会输出文本(hello world)。
这是我们的示例 systemd 服务。

test.service
========================================================================
[单位]
Description=开始测试 PG

[服务]
type=简单
ExecStart=/etc/init.d/helloworld.sh
StandardOutput=journal+console

[安装]
WantedBy=多用户目标
========================================================================

helloworld.sh
========================================================================
回声"Hello World!!!"
========================================================================

root@am57xx-evm:/#systemctl start test.service  
=>没有显示消息

root@am57xx-EVM://#./helloworld.sh
大家好!!!"

请告诉我如何操作?
直接从终端执行时没有问题。


3.不能使用 init.d 进程?
我们的 init.d 仍然有用。

谢谢你。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    您好!

    如果您使用 systemctl enable 启用服务,然后重新引导主板,会发生什么情况?
    您看到控制台消息了吗?

    此致、
    Yordan
  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    您好、Yordan

    我使用"systemctl enable [serivce]"检查了它、但消息未输出。
    执行了可执行的服务。

    谢谢、
  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    Yordan、您好!
    对于 no.2 printf(),回波问题得到了解决。
    感谢你提供帮助。

    但是,第一个问题仍然是一样的。

    我们的测试代码很简单。

    TestPG.cpp
    int main (空)

     int     m_ConsolePipel[2];
     struct termios m_tio_save;
     printf (“DBG::在%s \n",__function__);

     if ( pipe(m_ConsolePipe)=-1 ) assert(0);
     printf ("DBG::传递控制台管道\n");

     if (tcgetattr (STDIN_FILENO、&m_TIO_SAVE)< 0)断言(0);
     printf ("DBG::传递 tcgetattr\n");
     返回0;

    root@am57xx-evm:#systemctl start test.service

    运行日志消息

    [1257.234172] helloworld.sh[1361]:DBG::在 main 处
    [1257.235295] helloworld.sh[1361]:DBG::Pass ConsolePipe.
    [1257.2395660] helloworld.sh[1361]:/etc/init.d/helloworld.sh:第8行: 1362 Aborted (转储的内核)/bin/TestPG

    转储的内核消息表明它正在访问错误的内存。

    谢谢你

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    您好!
    我解决了这个问题。
    这是变量初始化问题。

    struct termios m_tio_save;
    =>
    struct termios m_tio_save ={};

    谢谢你。
  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    感谢您更新该主题。

    此致、
    Yordan