Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why is STDIN open by default for programs running in SystemD?

I have an if-statement at the top of a C main method, which checks if STDIN is open. If it is open, the program prints an error and exits. This is mainly for documentation reasons. I don’t want users of the program to assume passing things to STDIN is supported.

A problem arose when I tried to execute this program as a SystemD daemon, however.

It seems like SystemD programs always have an open STDIN pipe.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Why is this? Can it be avoided?

>Solution :

It’s kinda bad if fd 0 isn’t opened because the next open would result in fd 0 being used. It’s therefore common to have it open, but reading from /dev/null.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading