Discussion:
nohup breaks logname and tty commands
ROTH, MATTHEW G (ATTSI)
2008-02-22 16:06:39 UTC
Permalink
As we are moving from RHEL 4.x to 5.x I noticed that some scripts
started failing.

When I researched this I found that RHEL 4.x used coreutils 5.2.1 and
RHEL 5.x used coreutils 5.97.

In RHEL 4 with coreutils 5.2.1 the following works:

$ /usr/bin/nohup /usr/bin/logname
/usr/bin/nohup: appending output to `nohup.out'

$ cat nohup.out
mroth

In RHEL 5 with coreutils 5.97 the following does not work:

$ /usr/bin/nohup /usr/bin/logname
/usr/bin/nohup: appending output to `nohup.out'

$ cat nohup.out
/usr/bin/logname: no login name


I also checked the nohup in the coreutils 6.9 and it has the same
behavior. The tty command has similar issue, not sure if other commands
are effected as well.

We are able to work around the issues but it creates more
incompatibilities between Linux and the other Unix flavors.

Thanks,


Matthew Roth
AT&T Services, Inc.
1010 Pine Street, Room 8-W-3, Saint Louis, Missouri 63101
(314) 331-9839, ***@att.com
Eric Blake
2008-02-22 16:24:50 UTC
Permalink
According to ROTH, MATTHEW G (ATTSI) on 2/22/2008 9:06 AM:
| As we are moving from RHEL 4.x to 5.x I noticed that some scripts
| started failing.

You may want to consider further upgrades - the latest stable version of
coreutils is 6.10.

| In RHEL 5 with coreutils 5.97 the following does not work:
|
| $ /usr/bin/nohup /usr/bin/logname
| /usr/bin/nohup: appending output to `nohup.out'
|
| $ cat nohup.out
| /usr/bin/logname: no login name

I'm not sure why that is failing for you. It worked just fine for me:
$ logname
eblake
$ nohup logname
nohup: ignoring input and appending output to `nohup.out'
$ cat nohup.out
eblake
$ nohup --version | head -n1
nohup (GNU coreutils) 6.10
$ logname --version | head -n1
logname (GNU coreutils) 6.10

Perhaps an strace would shed some light?

| I also checked the nohup in the coreutils 6.9 and it has the same
| behavior. The tty command has similar issue, not sure if other commands
| are effected as well.

Well, the tty command is SUPPOSED to be affected. POSIX allows nohup to
redirect stdin so as not to hold a tty open indefinitely (the idea of
nohup is to isolate a long-running background process from SIGHUP, and
interactive input doesn't make sense to such a long-running process). So
newer coreutils does just that, meaning 'nohup tty' is testing whether
/dev/null is a tty (it isn't), while older coreutils held the input tty
open and was able to return true.

|
| We are able to work around the issues but it creates more
| incompatibilities between Linux and the other Unix flavors.

You already have to work around the incompatibilities of stdin being
redirected, since POSIX allows, but does not require, that. In other
words, relying on a tty input to survive nohup is inherently non-portable.

- --
Don't work too hard, make some time for fun as well!

Eric Blake ***@byu.net
Andreas Schwab
2008-02-22 16:54:43 UTC
Permalink
Post by Eric Blake
|
| $ /usr/bin/nohup /usr/bin/logname
| /usr/bin/nohup: appending output to `nohup.out'
|
| $ cat nohup.out
| /usr/bin/logname: no login name
$ logname
eblake
$ nohup logname
nohup: ignoring input and appending output to `nohup.out'
$ cat nohup.out
eblake
$ nohup --version | head -n1
nohup (GNU coreutils) 6.10
$ logname --version | head -n1
logname (GNU coreutils) 6.10
Perhaps an strace would shed some light?
That appears to be a bug in glibc in that getlogin uses the terminal
connected to stdin instead of the controlling terminal.

Andreas.
--
Andreas Schwab, SuSE Labs, ***@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
Loading...