0

I am trying to automatically collect how long the system took to boot up. The I am working on a cpp code that has been configured as one of the systemd service.

I heard systemd-analyze outputs the boot time information. And the command works if I execute it on the command line.

But when I tried to execute the command from cpp code using popen.

FILE *fp;
fp = popen("systemd-analyze 2>&1", "r");

I get a output message failed to get timestamp properties: transport endpoint is not connected. What does this error mean? and please advise what I can try to fix this issue?

Thank you.

TFuji
  • 1
  • 1
  • Instead of running "systemd-analyze", why don't you just read the information you need directly from the same place it does? (Hint: it's open source, so you can read the code to see where it gets it from) – Jesper Juhl Nov 11 '22 at 18:17
  • Please post the full program. I can't reproduce, work fine for me. What system are you using? What else happens in your program? _How_ do you get the ouptut message? – KamilCuk Nov 11 '22 at 22:12
  • @JesperJuhl Thank you for the comment. That’s good to know. I will go through the code and find how “systems-analyze” is getting the information. – TFuji Nov 14 '22 at 04:59
  • @KamilCuk Thank you for your comment. Sorry, I cannot share the full code. But it is good to know that the command works fine on your system. So there should be a way to make it work on mine too! – TFuji Nov 14 '22 at 05:02
  • `Sorry, I cannot share the full code` Write a new code, that you can share, that reproduces the problem. It's about _minimal_, but full, [MCVE]. Or remove code from your "full code", until you can share it and it reproduces the problem. Still, what system are you using? What else happens in your program? _How_ did you get the output message - there is no `printf` in your code. – KamilCuk Nov 14 '22 at 07:03
  • Hi, I found the problem. The issue was not in my code. The unit file for this systemd service had "DynamicUser" enabled. So it had the permission problem to run the systemd-analyze. – TFuji Nov 16 '22 at 18:55

0 Answers0