Skip to content

Check if stdin is a tty#23

Merged
teddych merged 1 commit intoteddych:masterfrom
Fuddl1:check-tty
Jan 9, 2026
Merged

Check if stdin is a tty#23
teddych merged 1 commit intoteddych:masterfrom
Fuddl1:check-tty

Conversation

@Fuddl1
Copy link
Contributor

@Fuddl1 Fuddl1 commented Jan 9, 2026

When stdin links to /dev/null, which is the case for systemd service units, select() returns immediately. That causes the loop to endlessly read() 0 bytes and eats up 100% of a processor core.

isatty() checks if railcontrol has a "real" stdin available. If that is not the case, do not select() and read() stdin but use the 1s delay as for silent mode and avoid spinning at 100%.

When stdin links to /dev/null, which is the case for systemd service
units, select() returns immediately. That causes the loop to endlessly
read() 0 bytes and eats up 100% of a processor core.

isatty() checks if railcontrol has a "real" stdin available. If that is not the
case, do not select() and read() stdin but use the 1s delay as for
silent mode.
@teddych teddych merged commit b6e12dd into teddych:master Jan 9, 2026
@Fuddl1 Fuddl1 deleted the check-tty branch January 9, 2026 09:48
@ekohl
Copy link
Contributor

ekohl commented Jan 9, 2026

Thanks! I think I also ran into this yesterday in doing testing.

which is the case for systemd service units

I was going to look at writing a systemd service unit in the context of #19 but it sounds like you already have one. Would you mind sharing it?

And from your icon I'm guessing you're looking at packaging for Debian so #24 may also interest you.

@Fuddl1
Copy link
Contributor Author

Fuddl1 commented Jan 9, 2026

I was going to look at writing a systemd service unit in the context of #19 but it sounds like you already have one. Would you mind sharing it?
Not at all, help yourself: https://salsa.debian.org/fuddl/railcontrol/-/tree/76a19aea37da5d54b7cdeab92ac3510482b20789/debian

You may also be interested in the workaround for #22 by setting WorkingDirectory= for the service to the directory that stores the database.

If you wonder why railcontrol gets restarted on regular exit code, you'll find my rationale in line 29 following in https://salsa.debian.org/fuddl/railcontrol/-/blob/76a19aea37da5d54b7cdeab92ac3510482b20789/debian/README.Debian :)

And from your icon I'm guessing you're looking at packaging for Debian so #24 may also interest you.
I managed to get the FHS part solved by a simple but ugly patch, see https://salsa.debian.org/fuddl/railcontrol/-/blob/76a19aea37da5d54b7cdeab92ac3510482b20789/debian/patches/fix-paths.patch

What I'm looking forward to is using cmake and I'm glad Teddy has already merged your efforts on that topic 👍

@ekohl
Copy link
Contributor

ekohl commented Jan 9, 2026

You may also be interested in the workaround for #22 by setting WorkingDirectory= for the service to the directory that stores the database.

Oh, good tip! I can take a look because I've also been running into this with testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants