home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.aix
- Path: sparky!uunet!wupost!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!usenet.ins.cwru.edu!news.ysu.edu!do-not-reply-to-path
- From: doug@cc.ysu.edu (Doug Sewell)
- Subject: ptys and getpwnam()
- Message-ID: <1992Jul30.141015.27287@news.ysu.edu>
- Sender: news@news.ysu.edu (Usenet News Admin)
- Nntp-Posting-Host: unix1
- Organization: Youngstown State University
- X-Newsreader: Tin 1.1 PL4
- Date: Thu, 30 Jul 1992 14:10:15 GMT
- Lines: 68
-
- I'm running aix 3.1.5, and am having strange problem with pty-creating
- applications (script, screen, etc) - getpwnam() isn't always returning
- the correct user entry.
-
- For example, if I run the sample program below, I get correct output:
-
- "getpwnam() returned 101 doug Doug Sewell,Computer Center"
-
- but if I run it inside 'script', I get
-
- "getpwnam() returned 294 fred Fred Ullom,Computer Center"
-
- If inside script, I do a 'who am I', it shows me on pts/2. If I
- do a 'last -30 | grep pts/2', I see that the last person to log
- on via pts/2 is fred.
-
- The pts that I'm telneted to before I run 'script' is pts/3, for
- what that's worth.
-
- Is this a bug ??? Has it been fixed ??? Is there a workaround ?
-
- Here's my test program (called 'tinbug.c', since it first showed up
- as a problem in the 'tin' newsreader):
-
- #! /bin/sh
- # This is a shell archive. Remove anything before this line,
- # then unpack it by saving it in a file and typing "sh file".
- #
- # Wrapped by doug on Thu Jul 30 10:08:40 EDT 1992
- # Contents: tinbug.c
-
- echo x - tinbug.c
- sed 's/^@//' > "tinbug.c" <<'@//E*O*F tinbug.c//'
- #include <stdio.h>
- #include <pwd.h>
- main(argc,argv)
- int argc;
- char *argv[];
- {
- extern char *getlogin();
- char *p;
- extern struct passwd *getpwnam();
- extern struct passwd *getpwuid();
- struct passwd *myentry;
-
- myentry = (struct passwd *) 0;
-
- if (((p = getlogin()) != (char *) 0) && strlen(p)) {
- @ myentry = getpwnam(p);
- @ printf("getpwnam() returned %d %s %s\n",
- @ myentry->pw_uid, myentry->pw_name, myentry->pw_gecos);
- @ }
- else {
- @ myentry = getpwuid(getuid());
- @ printf("getpwuid(getuid()) returned %d %s %s\n",
- @ myentry->pw_uid, myentry->pw_name, myentry->pw_gecos);
- @ }
- return 0;
- }
- @//E*O*F tinbug.c//
- chmod u=rw,g=r,o= tinbug.c
-
- exit 0
- --
- Doug Sewell, Tech Support, Computer Center, Youngstown State University
- doug@cc.ysu.edu doug@ysub.bitnet <internet>!cc.ysu.edu!doug
- "Recession: your friend loses his job. Depression: you lose your job.
- Recovery: Bush loses his job" - Bill Davidsen
-