[SOLVED] What happens to stdin and stdout when you're in X
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
1) vim/view trying to use stderr as the terminal when it doesn't have a terminal on stdin/out is just wrong.
2) fluxbox is leaving itself suceptible to SIGTTIN/SIGTTOU by not starting barbarella in its own process group.
3) Ditto barbarella itself (which you've now fixed).
4) Finally, I wonder whether startx/xinitrc should arguably be closing stdin/out and pointing stderr at $HOME/.xsession-errors much like xdm does.
I have to say, I'm not a fan of the various xinitrc and especially /usr/bin/startfluxbox on Slackware (I don't know whether they're just the stock upstream implementations.
everything started by fvwm (xload/xclock/xkbleds/firefox/xterm) are all in their own process group, so fvwm wouldn't be susceptible to this issue. You'll also notice that they have no controlling TTY.
In short, UNIX processes are susceptible to getting bad signals unless they take defensive action, and fluxbox didn't. X was working fine, it was just that the window manager got suspended.
If it's fluxbox that stopped, that explains the behaviour of both keyboard and mouse. Moving the mouse cursor around is the job of X and that worked fine. Clicks were probably being picked up too, but they had no effect because they couldn't be localised to a window (or to the taskbar). That's the job of the window manager. And the keyboard worked for switching consoles but not for typing into an xterm.
I wonder if this extract from startx is relevant:
Code:
# When starting the defaultserver start X on the current tty to avoid
# the startx session being seen as inactive:
# "https://bugzilla.redhat.com/show_bug.cgi?id=806491"
if [ -x /usr/lib/systemd/systemd -o -x /lib/systemd/systemd ]; then
tty=$(tty)
if expr match "$tty" '^/dev/tty[0-9]\+$' > /dev/null; then
tty_num=$(echo "$tty" | grep -oE '[0-9]+$')
vtarg="vt$tty_num"
fi
fi
If that's really what's causing the problem, then I think the Slackware team ought to know about it.
No, I don't believe that section is anything to do with it.
You've found an extreme edge case here. In order to hit the problem, fluxbox had to fail to setpgid(), your program had to fail to setpgid() and your program had to try and run a tty based program without a tty.
I don't believe that's something you can expect a distro maintainer to come up with a solution for.
'startx' is really ugly, there's no getting around that. Slackware's xinitrc's and Xsession setup isn't ideal either. I've discussed improvements in the past but Pat didn't want to make changes owing to resource constraints (amongst other considerations), which is not entirely unreasonable.
Perhaps you'd be better off getting in touch with the fluxbox devs and suggesting they setpgid(0,0) before spawning any external processes in order to make it a little more resilient.
Perhaps you'd be better off getting in touch with the fluxbox devs and suggesting they setpgid(0,0) before spawning any external processes in order to make it a little more resilient.
How exactly do I do that? I don't know the correct protocol for these things. Should I email one of the project developers or would that be a bit cheeky. After all, if I hadn't made two mistakes in a row, this would never have surfaced.
I've certainly emailed people before. As long as you're respectful in your email it's generally received well, but obviously it's going to depend on the personality of the individual you're contacting.
http://fluxbox.org/help/ has a number of contact methods, but if you're uncomfortable with contacting them or if you think it's such a minor issue you don't think it's worth the effort you could just let it sit. No one would blame you and you're unlikely to hit the same issue again.
When a process in a background job tries to read from its controlling terminal, the process group is usually sent a SIGTTIN signal. This normally causes all of the processes in that group to stop (unless they handle the signal and don’t stop themselves). However, if the reading process is ignoring or blocking this signal, then read fails with an EIO error instead.
So it seems that the SIGTTIN is sent to the whole process group, not just the offending program. If barbarella and the program that it launches belong to the same group as fluxbox, then fluxbox stops too.
I still don't understand the difference between process groups and sessions. I mean, I get that process groups are smaller and are contained within sessions, but I don't understand why there are these two levels. In what circumstances would you create a new process group as distinct from a new session (or the reverse)?
That man page is too much oriented to the command line. For example, it identifies process groups with groups of programs that are launched together as a pipeline. But this thread so far suggests that graphical programs don't usually create new process groups or new sessions when they fork off new processes. Why not? And when would they (apart from fixing a bug like we just did)?
As I understand it, the session leader is for things like the shell process itself, then each command or pipeline that you start from that shell is run as a separate process group within that session. It's the session leader who then manages which process/process group is foreground/background and which gets the terminal input/output at any given time.
Now, for non tty based processes which are outside of a shell and that don't have a controlling terminal, or the need for job control, then I guess sessions are less meaningful, but I suppose one might want to group a bunch of related processes into a session to keep them all together even though there's no job control to speak of that would require it.
Now I understand it a little clear than I did at the start of this discussion I believe that in this particular case (a GUI application launcher) its correct to start a new process group and not a new session.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.