(login) behaviour.

Brandon S. Allbery allbery at ncoast.ORG
Fri May 26 09:25:13 AEST 1989


As quoted from <22200001 at ux1.cso.uiuc.edu> by phil at ux1.cso.uiuc.edu:
+---------------
| (echo hey;login);echo test
| 
| Saw "hey" displayed, and went through login.  "ps ux" shows an extra csh.
| I logged out, and then saw "test" displayed.  So I guess I really got a
| new login shell from the subshell.  Apparently doing (login) all by itself
| doesn't really fork a new process for shell commands such as login and cd,
| but rather does them and then restores everything, such as connected
| directory.
+---------------

Nope.  The shells recognize "login" (and often "newgrp") as special commands,
and automagically maps them to "exec login" (and "exec newgrp").  When you
said "(login)", you said "start a subshell, which should exec /bin/login".
When you exited the resulting "login shell", you got the original shell back.

This can be more than slightly disorienting, by the way:

% who am i
allbery  tty15   May 25 18:25
% date
Thu May 25 19:18:02 EDT 1989
% (login root)
Password: ########
# ^D
% who am i
root     tty15   May 25 19:18
% _

(The above is NOT a typescript; I didn't actually do it.  But I have done so
before, on other systems; I can't do it on ncoast.)  <--"covering my *ss" ;-)

AT&T System V prohibits this, by the way:  since /etc/utmp contains the
login shell's pid, login can determine that it wasn't execed from the login
shell:

% who am i
bsa      tty15   May 25 18:25
% date
Thu May 25 19:18:02 EDT 1989
% (login root)
Login must be execed from the top-level shell.
% who am i
bsa      tty15   May 25 19:18
% _

++Brandon
-- 
Brandon S. Allbery, moderator of comp.sources.misc	     allbery at ncoast.org
uunet!hal.cwru.edu!ncoast!allbery		    ncoast!allbery at hal.cwru.edu
      Send comp.sources.misc submissions to comp-sources-misc@<backbone>
NCoast Public Access UN*X - (216) 781-6201, 300/1200/2400 baud, login: makeuser



More information about the Comp.unix.wizards mailing list