Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OMake redirects stdout' and stderr' even for simple commands. #112

Open
cspiel opened this issue May 16, 2018 · 4 comments
Open

OMake redirects stdout' and stderr' even for simple commands. #112

cspiel opened this issue May 16, 2018 · 4 comments

Comments

@cspiel
Copy link
Collaborator

cspiel commented May 16, 2018

For example if you use less(1) to page a file from OMake as in

.PHONY: mirar
mirar:
        less /etc/motd

you loose all of the controlling terminal's capabilities. Also try:

        diff --color=auto old-file new-file

or my favorite, w3m(1), which degenerates to a fancy cat(1)

        w3m index.html

in the rule body instead of less(1).

No shell redirects stdout or stderr for simple commands, not even
osh(1)! Try

osh -c 'less /etc/motd'

to verify that it really works.

I wrote the tiny tool is-a-tty to investigate the situation. The program
inquires the TTY's name (ttyname(3)) and whether the standard file
descriptors are connected to a TTY (isatty(3)). Here are the results:

bash(1):

$ ./is-a-tty
isatty("stdin", 0 => /dev/pts/1)?  true
isatty("stdout", 1 => /dev/pts/1)?  true
isatty("stderr", 2 => /dev/pts/1)?  true

OK - all three descriptors are conneted to a TTY.

$ ./is-a-tty 2> err.out
isatty("stdin", 0 => /dev/pts/1)?  true
isatty("stdout", 1 => /dev/pts/1)?  true
is-a-tty: isatty("stderr"): Inappropriate ioctl for device
is-a-tty: ttyname("stderr"): Inappropriate ioctl for device
isatty("stderr", 2 => <no tty name>)?  false

OK - we redirected stderr to err.out.

osh(1):

% ./is-a-tty
isatty("stdin", 0 => /dev/pts/1)?  true
isatty("stdout", 1 => /dev/pts/1)?  true
isatty("stderr", 2 => /dev/pts/1)?  true

OK - all three descriptors are connected to a TTY.

% ./is-a-tty >& err.out
% cat err.out
isatty("stdin", 0 => /dev/pts/1)?  true
is-a-tty: isatty("stdout"): Inappropriate ioctl for device
is-a-tty: ttyname("stdout"): Inappropriate ioctl for device
isatty("stdout", 1 => <no tty name>)?  false
is-a-tty: isatty("stderr"): Inappropriate ioctl for device
is-a-tty: ttyname("stderr"): Inappropriate ioctl for device
isatty("stderr", 2 => <no tty name>)?  false

OK - >& redirects both stdout and stderr to err.out.

omake(1) with an OMakefile containing

.PHONY: is-a-tty
is-a-tty:
        $(HOME)/src/c/is-a-tty

yields:

$ omake is-a-tty
- build bug-always-redirect-stdout-stderr <is-a-tty>
+ /home/cspiel/src/c/is-a-tty
isatty("stdin", 0 => /dev/pts/0)?  true
is-a-tty: isatty("stdout"): Inappropriate ioctl for device
is-a-tty: ttyname("stdout"): Inappropriate ioctl for device
isatty("stdout", 1 => <no tty name>)?  false
is-a-tty: isatty("stderr"): Inappropriate ioctl for device
is-a-tty: ttyname("stderr"): Inappropriate ioctl for device
isatty("stderr", 2 => <no tty name>)?  false

Not OK - both stdout and stderr are implicitly redirected.

Obviously the redirection only kicks in inside of OMake,
not plain osh(1).

This quirk is most annoying when using any kind of pager in a rule
body, but also disables automatic technicolor error messages from
modern compilers.

@ANogin
Copy link

ANogin commented May 16, 2018

Note that this is required in order to support -S, --output-postpone, --output-only-errors, --output-at-end options.

@cspiel
Copy link
Collaborator Author

cspiel commented May 18, 2018

@ANogin: Thanks Aleksey! I should have drawn that conclusion myself. (* Deep sigh. *)
My prejudices that OMake leaves all commands as written in the OMakefile
went down the drain.

Is there a combination of -S or --output-* options that forbid OMake to
tinker with stdout and stderr? I have not find a suitable combination and
am already gazing at Omake_exec_local.spawn_exn.

@ANogin
Copy link

ANogin commented May 18, 2018

@cspiel: I tried to figure it out when I wrote the previous commit, but even those some parts of the code look like some of the diversion is skipped under --output-normal, it still looks like things get redirected with any combination of --no-S --output-normal --no--output--postpone, etc.

@cspiel
Copy link
Collaborator Author

cspiel commented May 23, 2018

@ANogin: Indeed, the redirections are applied not matter which output option is active. Doh!

Therefore I whipped up a new option that disengages the tees; see #113. I'm not
satisfied with the change yet as it does not output the "usual" information on the active
rule and the executed commands. Please let me know whether you find this extension
useful or detrimental to the design of OMake.

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

No branches or pull requests

2 participants