home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / unix / aix / 8330 < prev    next >
Encoding:
Text File  |  1992-07-30  |  2.4 KB  |  81 lines

  1. Newsgroups: comp.unix.aix
  2. 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
  3. From: doug@cc.ysu.edu (Doug Sewell)
  4. Subject: ptys and getpwnam()
  5. Message-ID: <1992Jul30.141015.27287@news.ysu.edu>
  6. Sender: news@news.ysu.edu (Usenet News Admin)
  7. Nntp-Posting-Host: unix1
  8. Organization: Youngstown State University
  9. X-Newsreader: Tin 1.1 PL4
  10. Date: Thu, 30 Jul 1992 14:10:15 GMT
  11. Lines: 68
  12.  
  13. I'm running aix 3.1.5, and am having strange problem with pty-creating
  14. applications (script, screen, etc) - getpwnam() isn't always returning
  15. the correct user entry.
  16.  
  17. For example, if I run the sample program below, I get correct output:
  18.  
  19. "getpwnam() returned 101 doug Doug Sewell,Computer Center"
  20.  
  21. but if I run it inside 'script', I get
  22.  
  23. "getpwnam() returned 294 fred Fred Ullom,Computer Center"
  24.  
  25. If inside script, I do a 'who am I', it shows me on pts/2.  If I
  26. do a 'last -30 | grep pts/2', I see that the last person to log
  27. on via pts/2 is fred.
  28.  
  29. The pts that I'm telneted to before I run 'script' is pts/3, for
  30. what that's worth.
  31.  
  32. Is this a bug ??? Has it been fixed ???  Is there a workaround ?
  33.  
  34. Here's my test program (called 'tinbug.c', since it first showed up
  35. as a problem in the 'tin' newsreader):
  36.  
  37. #! /bin/sh
  38. # This is a shell archive.  Remove anything before this line,
  39. # then unpack it by saving it in a file and typing "sh file".
  40. #
  41. # Wrapped by doug on Thu Jul 30 10:08:40 EDT 1992
  42. # Contents:  tinbug.c
  43.  
  44. echo x - tinbug.c
  45. sed 's/^@//' > "tinbug.c" <<'@//E*O*F tinbug.c//'
  46. #include <stdio.h>
  47. #include <pwd.h>
  48. main(argc,argv)
  49. int argc;
  50. char *argv[];
  51. {
  52. extern char *getlogin();
  53. char *p;
  54. extern struct passwd *getpwnam();
  55. extern struct passwd *getpwuid();
  56. struct passwd *myentry;
  57.  
  58. myentry = (struct passwd *) 0;
  59.  
  60. if (((p = getlogin()) != (char *) 0) && strlen(p)) {
  61. @    myentry = getpwnam(p);
  62. @    printf("getpwnam() returned %d %s %s\n",
  63. @    myentry->pw_uid, myentry->pw_name, myentry->pw_gecos);
  64. @    }
  65. else {
  66. @    myentry = getpwuid(getuid());
  67. @    printf("getpwuid(getuid()) returned %d %s %s\n",
  68. @    myentry->pw_uid, myentry->pw_name, myentry->pw_gecos);
  69. @    }
  70. return 0;
  71. }
  72. @//E*O*F tinbug.c//
  73. chmod u=rw,g=r,o= tinbug.c
  74.  
  75. exit 0
  76. --
  77. Doug Sewell, Tech Support, Computer Center, Youngstown State University
  78. doug@cc.ysu.edu       doug@ysub.bitnet    <internet>!cc.ysu.edu!doug
  79. "Recession: your friend loses his job.  Depression: you lose your job.
  80. Recovery: Bush loses his job" - Bill Davidsen
  81.