Bug 82732

Summary: rootless X doesn't start if stderr redirected
Product: xorg Reporter: Olivier Brunel (jjacky) <jjk>
Component: Server/GeneralAssignee: Xorg Project Team <xorg-team>
Status: RESOLVED MOVED QA Contact: Xorg Project Team <xorg-team>
Severity: normal    
Priority: medium CC: karol.blazewicz
Version: unspecified   
Hardware: Other   
OS: Linux (All)   
i915 platform: i915 features:

Description Olivier Brunel (jjacky) 2014-08-17 14:45:39 UTC
Trying to start a rootless X while redirecting stderr will fail:
 (EE) xf86OpenConsole: VT_ACTIVATE failed: Operation not permitted

Looking into this, it turns out this is because X failed to see that the current
tty was the vt we're starting on and to auto-enable KeepTty, which led to the
mentionned permission error.

The issue comes from the following, in hw/xfree86/os-support/linux/lnx_init.c +130:

/* Some of stdin / stdout / stderr maybe redirected to a file */
for (i = STDIN_FILENO; i <= STDERR_FILENO; i++) {
    ret = fstat(i, &st);
    if (ret == 0 && S_ISCHR(st.st_mode) && major(st.st_rdev) == 4) {
        current_vt = minor(st.st_rdev);

Specifically, I believe in os/osinit.c both stdin and stdout were closed, so the
fstat() calls here for 0 and 1 aren't about stdin/stdout but other things (0
seems to be the Xorg log file, and 1 a socket), which leaves only stderr to give
valid/expected results.
And obviously, redirecting it to a file will cause the issue.

(Note that as a simple workaround, one can use the -keeptty option.)
Comment 1 GitLab Migration User 2018-12-13 22:30:33 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/xorg/xserver/issues/461.

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.