|
20 | 20 | */ |
21 | 21 | #include "postgres.h" |
22 | 22 |
|
23 | | -#include <pwd.h> |
24 | 23 | #include <unistd.h> |
25 | 24 |
|
26 | 25 | #if defined(__alpha) && defined(__osf__) /* no __alpha__ ? */ |
@@ -49,7 +48,6 @@ const char *progname; |
49 | 48 | static void startup_hacks(const char *progname); |
50 | 49 | static void help(const char *progname); |
51 | 50 | static void check_root(const char *progname); |
52 | | -static char *get_current_username(const char *progname); |
53 | 51 |
|
54 | 52 |
|
55 | 53 | /* |
@@ -191,7 +189,7 @@ main(int argc, char *argv[]) |
191 | 189 | else if (argc > 1 && strcmp(argv[1], "--single") == 0) |
192 | 190 | PostgresMain(argc, argv, |
193 | 191 | NULL, /* no dbname */ |
194 | | - get_current_username(progname)); /* does not return */ |
| 192 | + strdup(get_user_name_or_exit(progname))); /* does not return */ |
195 | 193 | else |
196 | 194 | PostmasterMain(argc, argv); /* does not return */ |
197 | 195 | abort(); /* should not get here */ |
@@ -372,36 +370,3 @@ check_root(const char *progname) |
372 | 370 | } |
373 | 371 | #endif /* WIN32 */ |
374 | 372 | } |
375 | | - |
376 | | - |
377 | | - |
378 | | -static char * |
379 | | -get_current_username(const char *progname) |
380 | | -{ |
381 | | -#ifndef WIN32 |
382 | | - struct passwd *pw; |
383 | | - |
384 | | - pw = getpwuid(geteuid()); |
385 | | - if (pw == NULL) |
386 | | - { |
387 | | - write_stderr("%s: invalid effective UID: %d\n", |
388 | | - progname, (int) geteuid()); |
389 | | - exit(1); |
390 | | - } |
391 | | - /* Allocate new memory because later getpwuid() calls can overwrite it. */ |
392 | | - return strdup(pw->pw_name); |
393 | | -#else |
394 | | - unsigned long namesize = 256 /* UNLEN */ + 1; |
395 | | - char *name; |
396 | | - |
397 | | - name = malloc(namesize); |
398 | | - if (!GetUserName(name, &namesize)) |
399 | | - { |
400 | | - write_stderr("%s: could not determine user name (GetUserName failed)\n", |
401 | | - progname); |
402 | | - exit(1); |
403 | | - } |
404 | | - |
405 | | - return name; |
406 | | -#endif |
407 | | -} |
0 commit comments