aboutsummaryrefslogtreecommitdiff
path: root/coreutils/logname.c
diff options
context:
space:
mode:
Diffstat (limited to 'coreutils/logname.c')
-rw-r--r--coreutils/logname.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/coreutils/logname.c b/coreutils/logname.c
index 743e2291c..aba6ce3c6 100644
--- a/coreutils/logname.c
+++ b/coreutils/logname.c
@@ -20,23 +20,23 @@
20 * a diagnostic message and an error return. 20 * a diagnostic message and an error return.
21 */ 21 */
22 22
23#include <stdio.h>
24#include <stdlib.h>
25#include <unistd.h>
26#include "busybox.h" 23#include "busybox.h"
27 24
25/* This is a NOFORK applet. Be very careful! */
26
28int logname_main(int argc, char ATTRIBUTE_UNUSED **argv); 27int logname_main(int argc, char ATTRIBUTE_UNUSED **argv);
29int logname_main(int argc, char ATTRIBUTE_UNUSED **argv) 28int logname_main(int argc, char ATTRIBUTE_UNUSED **argv)
30{ 29{
31 const char *p; 30 char buf[128];
32 31
33 if (argc > 1) { 32 if (argc > 1) {
34 bb_show_usage(); 33 bb_show_usage();
35 } 34 }
36 35
37 if ((p = getlogin()) != NULL) { 36 /* Using _r function - avoid pulling in static buffer from libc */
38 puts(p); 37 if (getlogin_r(buf, sizeof(buf)) == 0) {
39 fflush_stdout_and_exit(EXIT_SUCCESS); 38 puts(buf);
39 return fflush(stdout);
40 } 40 }
41 41
42 bb_perror_msg_and_die("getlogin"); 42 bb_perror_msg_and_die("getlogin");