summaryrefslogtreecommitdiff
path: root/coreutils/logname.c
diff options
context:
space:
mode:
authorManuel Novoa III <mjn3@codepoet.org>2003-03-19 09:13:01 +0000
committerManuel Novoa III <mjn3@codepoet.org>2003-03-19 09:13:01 +0000
commitcad5364599eb5062d59e0c397ed638ddd61a8d5d (patch)
treea318d0f03aa076c74b576ea45dc543a5669e8e91 /coreutils/logname.c
parente01f9662a5bd5d91be4f6b3941b57fff73cd5af1 (diff)
downloadbusybox-w32-cad5364599eb5062d59e0c397ed638ddd61a8d5d.tar.gz
busybox-w32-cad5364599eb5062d59e0c397ed638ddd61a8d5d.tar.bz2
busybox-w32-cad5364599eb5062d59e0c397ed638ddd61a8d5d.zip
Major coreutils update.
Diffstat (limited to 'coreutils/logname.c')
-rw-r--r--coreutils/logname.c29
1 files changed, 22 insertions, 7 deletions
diff --git a/coreutils/logname.c b/coreutils/logname.c
index 3e10fba6f..9cedff027 100644
--- a/coreutils/logname.c
+++ b/coreutils/logname.c
@@ -20,6 +20,19 @@
20 * 20 *
21 */ 21 */
22 22
23/* BB_AUDIT SUSv3 compliant */
24/* http://www.opengroup.org/onlinepubs/007904975/utilities/logname.html */
25
26/* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org)
27 *
28 * SUSv3 specifies the string used is that returned from getlogin().
29 * The previous implementation used getpwuid() for geteuid(), which
30 * is _not_ the same. Erik apparently made this change almost 3 years
31 * ago to avoid failing when no utmp was available. However, the
32 * correct course of action wrt SUSv3 for a failing getlogin() is
33 * a dianostic message and an error return.
34 */
35
23#include <stdio.h> 36#include <stdio.h>
24#include <stdlib.h> 37#include <stdlib.h>
25#include <unistd.h> 38#include <unistd.h>
@@ -27,14 +40,16 @@
27 40
28extern int logname_main(int argc, char **argv) 41extern int logname_main(int argc, char **argv)
29{ 42{
30 char user[9]; 43 const char *p;
31 44
32 if (argc > 1) 45 if (argc > 1) {
33 show_usage(); 46 bb_show_usage();
47 }
34 48
35 if (my_getpwuid(user, geteuid())) { 49 if ((p = getlogin()) != NULL) {
36 puts(user); 50 puts(p);
37 return EXIT_SUCCESS; 51 bb_fflush_stdout_and_exit(EXIT_SUCCESS);
38 } 52 }
39 error_msg_and_die("no login name"); 53
54 bb_perror_msg_and_die("getlogin");
40} 55}