Path: utzoo!utgpu!watmath!clyde!bellcore!rutgers!mailrus!ames!haven!vrdxhq!vsedev!logan From: logan@vsedev.VSE.COM (James Logan III) Newsgroups: comp.unix.questions Subject: Re: Login shell? Message-ID: <1217@vsedev.VSE.COM> Date: 2 Nov 88 22:55:27 GMT References: <3ed799bc.103e8@hi-csc.UUCP> <13851@mimsy.UUCP> <511@imec.UUCP> <25721@bu-cs.BU.EDU> <10791@ulysses.homer.nj.att.com> Reply-To: logan@vsedev.VSE.COM (James Logan III) Organization: VSE Software Development Lab Lines: 61 In article <10791@ulysses.homer.nj.att.com> ggs@ulysses.homer.nj.att.com (Griff Smith) writes: >In article <25721@bu-cs.BU.EDU>, madd@bu-cs.BU.EDU (Jim Frost) writes: >> In article <314@uplog.se> thomas@uplog.UUCP (Thomas Hameenaho) writes: >| |One way of deciding wether or not the current shell is the login shell >| |is the fact that the name of the login shell is prependended with a '-'. >| ... >> That's not really a good indicator. Instead what I'd do is build the >> process tree (you can use the output from ps or, better, sps if you >> can't build it from the actual process table). Find the first entry in >> the tree for the terminal you want. This will work on any unix >> system, while the naming convention may not. >| ... >> jim frost >> madd@bu-it.bu.edu > >Still not quite right. I usually use an AT&T 630 terminal on a 4.3BSD >system. The login shell for the terminal is not the same as the shell >for the current window, and each window has a separate pty connected to >it. The kludge I use also involves reading the output of ps (ugh): I >scan back through the process tree until I find a parent with a >different uid. The child of that process is almost always the login >shell. For my purposes, this also does the right thing for `su'. >I'd rather have someone support the concept of a session id so we could >avoid this sillyness. What is the purpose? If you just want to find out what if the current shell is indeed the shell spawned by init(1M) (via getty(1M), login(1)), then just write a simple C program like this: -------- #include main() { if (getppid() == getpgrp()) exit(0); exit(1); } ------- Call it something like "is_top" and use it like this in sh(1) or ksh(1): ------- if is_top; then echo "Yes, this is the login shell."; else echo "No, this is not the login shell."; fi; ------- Or just put printf(3C) statements in the C program itself... Unless you have a program that explicitly resets the process group ID, it will be the PID of the login shell (which would be the parent PID when this C program is running). Another more accurate way to do this is to use getutline(3C) to get a utmp structure for your current tty (which won't work with a multiplexed terminal using sxt's...) and check the parent PID against utmp.ut_pid. Let me know if you need more details. I hope this is what you're looking for... -Jim