Path: utzoo!attcan!uunet!mcvax!ukc!reading!cf-cm!sme From: sme@computing-maths.cardiff.ac.uk (Simon Elliott) Newsgroups: comp.unix.wizards Subject: Re: script & lock Summary: getlogin only returns NULL when not on tty, even psuedo-tty Message-ID: <596@cf-cm.UUCP> Date: 9 Jan 89 10:16:19 GMT References: <17972@adm.BRL.MIL> Organization: University of Wales College of Cardiff, Cardiff, WALES, UK. Lines: 48 Getlogin returns a pointer to the login name as found in /etc/utmp. /etc/utmp contains a record for each terminal on the system (including pseudo-terminals (ttyp?). The login name part is blank or null until login fills it it. When you run script, your controlling terminal is a pseudo-terminal (eg. /dev/ttyp0). Your login name is not put into /etc/utmp for this pseudo-terminal so the entry is still null. A program run in script is attached to the pseudo terminal so getlogin() returns a pointer to the null string entry from utmp. Getlogin returns the NULL pointer only if it called from a process which is NOT attached to any terminal (even a pseudo one). -------cut here------- #include #include main(ac,av) char *av[]; { char *uname, getlogin(); struct passwd *pwd, getpwnam(), getpwuid(); if ((uname = getlogin()) == NULL) { pwd = getpwuid(getuid()); fprintf(stderr, "uid: %d\n", getuid()); } else { pwd = getpwnam(uname); fprintf(stderr, "uname: *(char *)0x%lx = \"%s\"\n", uname, uname); } if (pwd == NULL) { fprintf(stderr, "%s: cannot locate passwd entry!\007\n", av[0]); exit(1); } } ---------cut here------- Try running this a) from shell prompt; b) under 'script' (uses pseudo-tty); c) using 'at' (detaches from terminal). -- -------------------------------------------------------------------------- Simon Elliott Internet: sme%v1.cm.cf.ac.uk@cunyvm.cuny.edu UWCC Computer Centre JANET: sme@uk.ac.cf.cm.v1 40/41 Park Place UUCP: {backbones}!mcvax!ukc!reading!cf-cm!sme Cardiff, Wales PHONE: +44 222 874300