Changeset 8219374 for tester.c


Ignore:
Timestamp:
Jul 16, 2011, 12:28:10 AM (10 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master, release-1.8, release-1.9
Children:
f5f6ec0
Parents:
99ac28a
git-author:
David Benjamin <davidben@mit.edu> (07/10/11 19:11:46)
git-committer:
David Benjamin <davidben@mit.edu> (07/16/11 00:28:10)
Message:
Use getpwnam_r instead of getpwnam

It's re-entrant, so that's probably a good thing in case some other
thread calls getpwnam. More relevantly, Solaris has both a standard and
a non-standard version, and perl redefines getpwnam to a getpwnam_r. We
manage to convince Solaris to use the standard form, but perl doesn't
seem to notice and defines the macro wrong.

So just avoid the function altogether. Seems as reasonable of an excuse
to use the ostensibly better (and infinitely less friendly) one as any.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • tester.c

    r396505be r8219374  
    44#undef WINDOW
    55
    6 #include <errno.h>
    76#include <unistd.h>
    8 #include <pwd.h>
    97#include <stdio.h>
    108#include <stdlib.h>
    119#include <string.h>
    12 #include <sys/types.h>
    1310
    1411#undef instr
     
    136133{
    137134  int numfailed=0;
    138   const char *home;
    139   char *s, *path;
    140   struct passwd *pw;
     135  char *s, *path, *home;
    141136
    142137  printf("# BEGIN testing owl_util\n");
     
    274269  g_free(s);
    275270
    276   errno = 0;
    277   home = owl_global_get_homedir(&g);
     271  home = g_strdup(owl_global_get_homedir(&g));
    278272  s = owl_util_makepath("~");
    279273  FAIL_UNLESS("makepath ~", !strcmp(home, s));
     
    285279  g_free(s);
    286280  g_free(path);
    287 
    288   errno = 0;
    289   pw = getpwnam("root");
    290   if (pw) {
    291     home = pw->pw_dir;
    292   } else {
     281  g_free(home);
     282
     283  home = owl_util_homedir_for_user("root");
     284  if (home == NULL) {
    293285    /* Just make some noise so we notice. */
    294     home = "<WHAT>";
    295     fprintf(stderr, "getpwnam: %s", errno ? strerror(errno) : "No such user");
     286    home = g_strdup("<WHAT>");
     287    fprintf(stderr, "owl_util_homedir_for_user failed");
    296288  }
    297289
     
    305297  g_free(s);
    306298  g_free(path);
     299  g_free(home);
    307300
    308301  /* if (numfailed) printf("*** WARNING: failures encountered with owl_util\n"); */
Note: See TracChangeset for help on using the changeset viewer.