aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-09-07 16:20:03 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-09-07 16:20:03 +0000
commita9801658ee4b7f5717d145818428452f864e1015 (patch)
treef85bbdf6cb572751dee639feb9896cad3503b924
parentb750dec40a4bf013f98658b46925117d9d1d4811 (diff)
downloadbusybox-w32-a9801658ee4b7f5717d145818428452f864e1015.tar.gz
busybox-w32-a9801658ee4b7f5717d145818428452f864e1015.tar.bz2
busybox-w32-a9801658ee4b7f5717d145818428452f864e1015.zip
getty, sulogin: convert to using bb_msg for syslog output
-rw-r--r--coreutils/nohup.c2
-rw-r--r--include/libbb.h2
-rw-r--r--libbb/error_msg_and_die.c4
-rw-r--r--libbb/fflush_stdout_and_exit.c2
-rw-r--r--libbb/herror_msg_and_die.c2
-rw-r--r--libbb/perror_msg_and_die.c2
-rw-r--r--libbb/verror_msg.c5
-rw-r--r--libbb/vinfo_msg.c2
-rw-r--r--libbb/warn_ignoring_args.c2
-rw-r--r--libbb/xfuncs.c3
-rw-r--r--loginutils/getty.c144
-rw-r--r--loginutils/login.c2
-rw-r--r--loginutils/su.c6
-rw-r--r--loginutils/sulogin.c32
14 files changed, 96 insertions, 114 deletions
diff --git a/coreutils/nohup.c b/coreutils/nohup.c
index 86d788683..5dd90adcc 100644
--- a/coreutils/nohup.c
+++ b/coreutils/nohup.c
@@ -47,7 +47,7 @@ int nohup_main(int argc, char *argv[])
47 if (temp) fdprintf(2,"Writing to %s\n", home ? home : nohupout); 47 if (temp) fdprintf(2,"Writing to %s\n", home ? home : nohupout);
48 dup2(temp ? 1 : nullfd, 2); 48 dup2(temp ? 1 : nullfd, 2);
49 close(nullfd); 49 close(nullfd);
50 signal (SIGHUP, SIG_IGN); 50 signal(SIGHUP, SIG_IGN);
51 51
52 // Exec our new program. 52 // Exec our new program.
53 53
diff --git a/include/libbb.h b/include/libbb.h
index c6a9ae577..6bea048a3 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -118,7 +118,9 @@ enum {
118 LOGMODE_SYSLOG = 1<<1, 118 LOGMODE_SYSLOG = 1<<1,
119 LOGMODE_BOTH = LOGMODE_SYSLOG + LOGMODE_STDIO, 119 LOGMODE_BOTH = LOGMODE_SYSLOG + LOGMODE_STDIO,
120}; 120};
121extern const char *msg_eol;
121extern int logmode; 122extern int logmode;
123extern int die_sleep;
122 124
123extern void bb_show_usage(void) ATTRIBUTE_NORETURN ATTRIBUTE_EXTERNALLY_VISIBLE; 125extern void bb_show_usage(void) ATTRIBUTE_NORETURN ATTRIBUTE_EXTERNALLY_VISIBLE;
124extern void bb_error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))); 126extern void bb_error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2)));
diff --git a/libbb/error_msg_and_die.c b/libbb/error_msg_and_die.c
index f25a1da32..29a260bde 100644
--- a/libbb/error_msg_and_die.c
+++ b/libbb/error_msg_and_die.c
@@ -13,6 +13,8 @@
13#include <stdlib.h> 13#include <stdlib.h>
14#include "libbb.h" 14#include "libbb.h"
15 15
16int die_sleep;
17
16void bb_error_msg_and_die(const char *s, ...) 18void bb_error_msg_and_die(const char *s, ...)
17{ 19{
18 va_list p; 20 va_list p;
@@ -20,5 +22,7 @@ void bb_error_msg_and_die(const char *s, ...)
20 va_start(p, s); 22 va_start(p, s);
21 bb_verror_msg(s, p, NULL); 23 bb_verror_msg(s, p, NULL);
22 va_end(p); 24 va_end(p);
25 if (die_sleep)
26 sleep(die_sleep);
23 exit(bb_default_error_retval); 27 exit(bb_default_error_retval);
24} 28}
diff --git a/libbb/fflush_stdout_and_exit.c b/libbb/fflush_stdout_and_exit.c
index 7e8152dd6..245f50864 100644
--- a/libbb/fflush_stdout_and_exit.c
+++ b/libbb/fflush_stdout_and_exit.c
@@ -20,5 +20,7 @@ void bb_fflush_stdout_and_exit(int retval)
20 if (fflush(stdout)) { 20 if (fflush(stdout)) {
21 retval = bb_default_error_retval; 21 retval = bb_default_error_retval;
22 } 22 }
23 if (die_sleep)
24 sleep(die_sleep);
23 exit(retval); 25 exit(retval);
24} 26}
diff --git a/libbb/herror_msg_and_die.c b/libbb/herror_msg_and_die.c
index 285b195ef..f115c8e0a 100644
--- a/libbb/herror_msg_and_die.c
+++ b/libbb/herror_msg_and_die.c
@@ -19,5 +19,7 @@ void bb_herror_msg_and_die(const char *s, ...)
19 va_start(p, s); 19 va_start(p, s);
20 bb_vherror_msg(s, p); 20 bb_vherror_msg(s, p);
21 va_end(p); 21 va_end(p);
22 if (die_sleep)
23 sleep(die_sleep);
22 exit(bb_default_error_retval); 24 exit(bb_default_error_retval);
23} 25}
diff --git a/libbb/perror_msg_and_die.c b/libbb/perror_msg_and_die.c
index 5b0464077..c1cfb956f 100644
--- a/libbb/perror_msg_and_die.c
+++ b/libbb/perror_msg_and_die.c
@@ -20,5 +20,7 @@ void bb_perror_msg_and_die(const char *s, ...)
20 va_start(p, s); 20 va_start(p, s);
21 bb_vperror_msg(s, p); 21 bb_vperror_msg(s, p);
22 va_end(p); 22 va_end(p);
23 if (die_sleep)
24 sleep(die_sleep);
23 exit(bb_default_error_retval); 25 exit(bb_default_error_retval);
24} 26}
diff --git a/libbb/verror_msg.c b/libbb/verror_msg.c
index d55da73ff..988a7a293 100644
--- a/libbb/verror_msg.c
+++ b/libbb/verror_msg.c
@@ -15,6 +15,7 @@
15#include "libbb.h" 15#include "libbb.h"
16 16
17int logmode = LOGMODE_STDIO; 17int logmode = LOGMODE_STDIO;
18const char *msg_eol = "\n";
18 19
19void bb_verror_msg(const char *s, va_list p, const char* strerr) 20void bb_verror_msg(const char *s, va_list p, const char* strerr)
20{ 21{
@@ -28,9 +29,9 @@ void bb_verror_msg(const char *s, va_list p, const char* strerr)
28 fprintf(stderr, "%s: ", bb_applet_name); 29 fprintf(stderr, "%s: ", bb_applet_name);
29 vfprintf(stderr, s, p); 30 vfprintf(stderr, s, p);
30 if (!strerr) 31 if (!strerr)
31 fputc('\n', stderr); 32 fputs(msg_eol, stderr);
32 else 33 else
33 fprintf(stderr, ": %s\n", strerr); 34 fprintf(stderr, ": %s%s", strerr, msg_eol);
34 } 35 }
35 if (ENABLE_FEATURE_SYSLOG && (logmode & LOGMODE_SYSLOG)) { 36 if (ENABLE_FEATURE_SYSLOG && (logmode & LOGMODE_SYSLOG)) {
36 if (!strerr) 37 if (!strerr)
diff --git a/libbb/vinfo_msg.c b/libbb/vinfo_msg.c
index 82fbda221..613b013cd 100644
--- a/libbb/vinfo_msg.c
+++ b/libbb/vinfo_msg.c
@@ -22,7 +22,7 @@ void bb_vinfo_msg(const char *s, va_list p)
22 va_copy(p2, p); 22 va_copy(p2, p);
23 if (logmode & LOGMODE_STDIO) { 23 if (logmode & LOGMODE_STDIO) {
24 vprintf(s, p); 24 vprintf(s, p);
25 putchar('\n'); 25 fputs(msg_eol, stdout);
26 } 26 }
27 if (ENABLE_FEATURE_SYSLOG && (logmode & LOGMODE_SYSLOG)) 27 if (ENABLE_FEATURE_SYSLOG && (logmode & LOGMODE_SYSLOG))
28 vsyslog(LOG_INFO, s, p2); 28 vsyslog(LOG_INFO, s, p2);
diff --git a/libbb/warn_ignoring_args.c b/libbb/warn_ignoring_args.c
index af82a6b5b..6405ff826 100644
--- a/libbb/warn_ignoring_args.c
+++ b/libbb/warn_ignoring_args.c
@@ -12,6 +12,6 @@
12void bb_warn_ignoring_args(int n) 12void bb_warn_ignoring_args(int n)
13{ 13{
14 if (n) { 14 if (n) {
15 bb_perror_msg("ignoring all arguments"); 15 bb_error_msg("ignoring all arguments");
16 } 16 }
17} 17}
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c
index 435379de2..4bb05f248 100644
--- a/libbb/xfuncs.c
+++ b/libbb/xfuncs.c
@@ -408,7 +408,8 @@ char *xasprintf(const char *format, ...)
408void xprint_and_close_file(FILE *file) 408void xprint_and_close_file(FILE *file)
409{ 409{
410 // copyfd outputs error messages for us. 410 // copyfd outputs error messages for us.
411 if (bb_copyfd_eof(fileno(file), 1) == -1) exit(bb_default_error_retval); 411 if (bb_copyfd_eof(fileno(file), 1) == -1)
412 exit(bb_default_error_retval);
412 413
413 fclose(file); 414 fclose(file);
414} 415}
diff --git a/loginutils/getty.c b/loginutils/getty.c
index 3da7c560a..71f6b2458 100644
--- a/loginutils/getty.c
+++ b/loginutils/getty.c
@@ -223,51 +223,6 @@ FILE *dbf;
223#endif 223#endif
224 224
225 225
226/*
227 * output error messages
228 */
229static void error(const char *fmt, ...) ATTRIBUTE_NORETURN;
230static void error(const char *fmt, ...)
231{
232 va_list va_alist;
233 char buf[256];
234
235#ifdef CONFIG_SYSLOGD
236 va_start(va_alist, fmt);
237 vsnprintf(buf, sizeof(buf), fmt, va_alist);
238 openlog(bb_applet_name, 0, LOG_AUTH);
239 syslog(LOG_ERR, "%s", buf);
240 closelog();
241#else
242 int fd;
243 size_t l;
244
245 snprintf(buf, sizeof(buf), "%s: ", bb_applet_name);
246 l = strlen(buf);
247 va_start(va_alist, fmt);
248 vsnprintf(buf + l, sizeof(buf) - l, fmt, va_alist);
249 l = strlen(buf);
250 /* truncate if need */
251 if((l + 3) > sizeof(buf))
252 l = sizeof(buf) - 3;
253 /* add \r\n always */
254 buf[l++] = '\r';
255 buf[l++] = '\n';
256 buf[l] = 0;
257 if ((fd = open("/dev/console", 1)) >= 0) {
258 write(fd, buf, l);
259 close(fd);
260 }
261#endif
262
263 va_end(va_alist);
264
265 (void) sleep((unsigned) 10); /* be kind to init(8) */
266 exit(1);
267}
268
269
270
271/* bcode - convert speed string to speed code; return 0 on failure */ 226/* bcode - convert speed string to speed code; return 0 on failure */
272static int bcode(const char *s) 227static int bcode(const char *s)
273{ 228{
@@ -291,15 +246,15 @@ static void parse_speeds(struct options *op, char *arg)
291 debug("entered parse_speeds\n"); 246 debug("entered parse_speeds\n");
292 for (cp = strtok(arg, ","); cp != 0; cp = strtok((char *) 0, ",")) { 247 for (cp = strtok(arg, ","); cp != 0; cp = strtok((char *) 0, ",")) {
293 if ((op->speeds[op->numspeed++] = bcode(cp)) <= 0) 248 if ((op->speeds[op->numspeed++] = bcode(cp)) <= 0)
294 error("bad speed: %s", cp); 249 bb_error_msg_and_die("bad speed: %s", cp);
295 if (op->numspeed > MAX_SPEED) 250 if (op->numspeed > MAX_SPEED)
296 error("too many alternate speeds"); 251 bb_error_msg_and_die("too many alternate speeds");
297 } 252 }
298 debug("exiting parsespeeds\n"); 253 debug("exiting parsespeeds\n");
299} 254}
300 255
301 256
302/* parse-args - parse command-line arguments */ 257/* parse_args - parse command-line arguments */
303static void parse_args(int argc, char **argv, struct options *op) 258static void parse_args(int argc, char **argv, struct options *op)
304{ 259{
305 char *ts; 260 char *ts;
@@ -327,7 +282,7 @@ static void parse_args(int argc, char **argv, struct options *op)
327 op->flags ^= F_ISSUE; /* revert flag show /etc/issue */ 282 op->flags ^= F_ISSUE; /* revert flag show /etc/issue */
328 if(op->flags & F_TIMEOUT) { 283 if(op->flags & F_TIMEOUT) {
329 if ((op->timeout = atoi(ts)) <= 0) 284 if ((op->timeout = atoi(ts)) <= 0)
330 error("bad timeout value: %s", ts); 285 bb_error_msg_and_die("bad timeout value: %s", ts);
331 } 286 }
332 debug("after getopt loop\n"); 287 debug("after getopt loop\n");
333 if (argc < optind + 2) /* check parameter count */ 288 if (argc < optind + 2) /* check parameter count */
@@ -350,6 +305,12 @@ static void parse_args(int argc, char **argv, struct options *op)
350 debug("exiting parseargs\n"); 305 debug("exiting parseargs\n");
351} 306}
352 307
308static void xdup2(int srcfd, int dstfd, const char *tty)
309{
310 if(dup2(srcfd, dstfd) == -1)
311 bb_perror_msg_and_die("%s: dup", tty);
312}
313
353/* open_tty - set up tty as standard { input, output, error } */ 314/* open_tty - set up tty as standard { input, output, error } */
354static void open_tty(char *tty, struct termio *tp, int local) 315static void open_tty(char *tty, struct termio *tp, int local)
355{ 316{
@@ -363,37 +324,34 @@ static void open_tty(char *tty, struct termio *tp, int local)
363 324
364 /* Sanity checks... */ 325 /* Sanity checks... */
365 326
366 if (chdir("/dev")) 327 xchdir("/dev");
367 error("/dev: chdir() failed: %m");
368 chdir_to_root = 1; 328 chdir_to_root = 1;
369 if (stat(tty, &st) < 0) 329 xstat(tty, &st);
370 error("/dev/%s: %m", tty);
371 if ((st.st_mode & S_IFMT) != S_IFCHR) 330 if ((st.st_mode & S_IFMT) != S_IFCHR)
372 error("/dev/%s: not a character device", tty); 331 bb_error_msg_and_die("%s: not a character device", tty);
373 332
374 /* Open the tty as standard input. */ 333 /* Open the tty as standard input. */
375 334
376 close(0);
377 debug("open(2)\n"); 335 debug("open(2)\n");
378 fd = open(tty, O_RDWR | O_NONBLOCK, 0); 336 fd = xopen(tty, O_RDWR | O_NONBLOCK);
379 if (fd != 0) 337 if(fd) {
380 error("/dev/%s: cannot open as standard input: %m", tty); 338 xdup2(fd, 0, tty);
339 close(fd);
340 }
381 } else { 341 } else {
382
383 /* 342 /*
384 * Standard input should already be connected to an open port. Make 343 * Standard input should already be connected to an open port. Make
385 * sure it is open for read/write. 344 * sure it is open for read/write.
386 */ 345 */
387 346
388 if ((fcntl(0, F_GETFL, 0) & O_RDWR) != O_RDWR) 347 if ((fcntl(0, F_GETFL, 0) & O_RDWR) != O_RDWR)
389 error("%s: not open for read/write", tty); 348 bb_error_msg_and_die("%s: not open for read/write", tty);
390 } 349 }
391 350
392 /* Replace current standard output/error fd's with new ones */ 351 /* Replace current standard output/error fd's with new ones */
393 debug("duping\n"); 352 debug("duping\n");
394 if (dup2(STDIN_FILENO, STDOUT_FILENO) == -1 || 353 xdup2(0, 1, tty);
395 dup2(STDIN_FILENO, STDERR_FILENO) == -1) 354 xdup2(0, 2, tty);
396 error("%s: dup problem: %m", tty); /* we have a problem */
397 355
398 /* 356 /*
399 * The following ioctl will fail if stdin is not a tty, but also when 357 * The following ioctl will fail if stdin is not a tty, but also when
@@ -405,7 +363,7 @@ static void open_tty(char *tty, struct termio *tp, int local)
405 */ 363 */
406 364
407 if (ioctl(0, TCGETA, tp) < 0) 365 if (ioctl(0, TCGETA, tp) < 0)
408 error("%s: ioctl: %m", tty); 366 bb_perror_msg_and_die("%s: ioctl(TCGETA)", tty);
409 367
410 /* 368 /*
411 * It seems to be a terminal. Set proper protections and ownership. Mode 369 * It seems to be a terminal. Set proper protections and ownership. Mode
@@ -428,10 +386,8 @@ static void open_tty(char *tty, struct termio *tp, int local)
428 if (!strncmp(tty, "tty", 3) && isdigit(tty[3])) { 386 if (!strncmp(tty, "tty", 3) && isdigit(tty[3])) {
429 char *vcs, *vcsa; 387 char *vcs, *vcsa;
430 388
431 if (!(vcs = strdup(tty))) 389 vcs = xstrdup(tty);
432 error("Can't malloc for vcs"); 390 vcsa = xmalloc(strlen(tty) + 2);
433 if (!(vcsa = malloc(strlen(tty) + 2)))
434 error("Can't malloc for vcsa");
435 strcpy(vcs, "vcs"); 391 strcpy(vcs, "vcs");
436 strcpy(vcs + 3, tty + 3); 392 strcpy(vcs + 3, tty + 3);
437 strcpy(vcsa, "vcsa"); 393 strcpy(vcsa, "vcsa");
@@ -451,8 +407,8 @@ static void open_tty(char *tty, struct termio *tp, int local)
451 (void) chown(tty, 0, 0); /* root, sys */ 407 (void) chown(tty, 0, 0); /* root, sys */
452 (void) chmod(tty, 0622); /* crw--w--w- */ 408 (void) chmod(tty, 0622); /* crw--w--w- */
453#endif 409#endif
454 if(chdir_to_root && chdir("/")) 410 if (chdir_to_root)
455 error("chdir to / failed: %m"); 411 xchdir("/");
456} 412}
457 413
458/* termio_init - initialize termio settings */ 414/* termio_init - initialize termio settings */
@@ -634,7 +590,7 @@ static char *get_logname(struct options *op, struct chardata *cp, struct termio
634 if (read(0, &c, 1) < 1) { 590 if (read(0, &c, 1) < 1) {
635 if (errno == EINTR || errno == EIO) 591 if (errno == EINTR || errno == EIO)
636 exit(0); 592 exit(0);
637 error("%s: read: %m", op->tty); 593 bb_perror_msg_and_die("%s: read", op->tty);
638 } 594 }
639 /* Do BREAK handling elsewhere. */ 595 /* Do BREAK handling elsewhere. */
640 596
@@ -681,7 +637,7 @@ static char *get_logname(struct options *op, struct chardata *cp, struct termio
681 if (!isascii(ascval) || !isprint(ascval)) { 637 if (!isascii(ascval) || !isprint(ascval)) {
682 /* ignore garbage characters */ ; 638 /* ignore garbage characters */ ;
683 } else if (bp - logname >= sizeof(logname) - 1) { 639 } else if (bp - logname >= sizeof(logname) - 1) {
684 error("%s: input overrun", op->tty); 640 bb_error_msg_and_die("%s: input overrun", op->tty);
685 } else { 641 } else {
686 (void) write(1, &c, 1); /* echo the character */ 642 (void) write(1, &c, 1); /* echo the character */
687 *bp++ = ascval; /* and store it */ 643 *bp++ = ascval; /* and store it */
@@ -759,7 +715,7 @@ static void termio_final(struct options *op, struct termio *tp, struct chardata
759 /* Finally, make the new settings effective */ 715 /* Finally, make the new settings effective */
760 716
761 if (ioctl(0, TCSETA, tp) < 0) 717 if (ioctl(0, TCSETA, tp) < 0)
762 error("%s: ioctl: TCSETA: %m", op->tty); 718 bb_perror_msg_and_die("%s: ioctl(TCSETA)", op->tty);
763} 719}
764 720
765 721
@@ -828,6 +784,7 @@ static void update_utmp(char *line)
828#undef logname 784#undef logname
829int getty_main(int argc, char **argv) 785int getty_main(int argc, char **argv)
830{ 786{
787 int nullfd;
831 char *logname = NULL; /* login name, given to /bin/login */ 788 char *logname = NULL; /* login name, given to /bin/login */
832 struct chardata chardata; /* set by get_logname() */ 789 struct chardata chardata; /* set by get_logname() */
833 struct termio termio; /* terminal mode bits */ 790 struct termio termio; /* terminal mode bits */
@@ -845,6 +802,29 @@ int getty_main(int argc, char **argv)
845 0, /* no baud rates known yet */ 802 0, /* no baud rates known yet */
846 }; 803 };
847 804
805 /* Already too late because of theoretical
806 * possibility of getty --help somehow triggered
807 * inadvertently before we reach this. Oh well. */
808 close(0);
809 close(1);
810 close(2);
811#ifdef __linux__
812 setsid();
813#endif
814 /* We want special flavor of error_msg_and_die */
815 die_sleep = 10;
816 msg_eol = "\r\n";
817 /* Was "/dev/console". Why should we spam *system console*
818 * if there is a problem with getty on /dev/ttyS15?... */
819 nullfd = xopen(bb_dev_null, O_RDWR);
820 dup2(nullfd, 0);
821 dup2(nullfd, 1);
822 dup2(nullfd, 2);
823 if(nullfd > 2)
824 close(nullfd);
825 openlog(bb_applet_name, LOG_PID, LOG_AUTH);
826 logmode = LOGMODE_BOTH;
827
848#ifdef DEBUGGING 828#ifdef DEBUGGING
849 dbf = xfopen(DEBUGTERM, "w"); 829 dbf = xfopen(DEBUGTERM, "w");
850 830
@@ -859,18 +839,11 @@ int getty_main(int argc, char **argv)
859#endif 839#endif
860 840
861 /* Parse command-line arguments. */ 841 /* Parse command-line arguments. */
862
863 parse_args(argc, argv, &options); 842 parse_args(argc, argv, &options);
864 843
865#ifdef __linux__ 844#ifdef SYSV_STYLE
866 setsid();
867#endif
868
869 /* Update the utmp file. */
870
871
872#ifdef SYSV_STYLE
873#ifdef CONFIG_FEATURE_UTMP 845#ifdef CONFIG_FEATURE_UTMP
846 /* Update the utmp file. */
874 update_utmp(options.tty); 847 update_utmp(options.tty);
875#endif 848#endif
876#endif 849#endif
@@ -931,8 +904,9 @@ int getty_main(int argc, char **argv)
931 /* Read the login name. */ 904 /* Read the login name. */
932 debug("reading login name\n"); 905 debug("reading login name\n");
933 /* while ((logname = get_logname(&options, &chardata, &termio)) == 0) */ 906 /* while ((logname = get_logname(&options, &chardata, &termio)) == 0) */
934 while ((logname = get_logname(&options, &chardata, &termio)) == 907 logname = get_logname(&options, &chardata, &termio);
935 NULL) next_speed(&termio, &options); 908 while (logname == NULL)
909 next_speed(&termio, &options);
936 } 910 }
937 911
938 /* Disable timer. */ 912 /* Disable timer. */
@@ -951,6 +925,6 @@ int getty_main(int argc, char **argv)
951 /* Let the login program take care of password validation. */ 925 /* Let the login program take care of password validation. */
952 926
953 (void) execl(options.login, options.login, "--", logname, (char *) 0); 927 (void) execl(options.login, options.login, "--", logname, (char *) 0);
954 error("%s: can't exec %s: %m", options.tty, options.login); 928 bb_error_msg_and_die("%s: can't exec %s", options.tty, options.login);
955} 929}
956 930
diff --git a/loginutils/login.c b/loginutils/login.c
index f3c7e70f4..5b4edd8de 100644
--- a/loginutils/login.c
+++ b/loginutils/login.c
@@ -444,7 +444,7 @@ static void checkutmp(int picky)
444 } 444 }
445 if (strncmp(line, "/dev/", 5) == 0) 445 if (strncmp(line, "/dev/", 5) == 0)
446 line += 5; 446 line += 5;
447 memset((void *) &utent, 0, sizeof utent); 447 memset(&utent, 0, sizeof utent);
448 utent.ut_type = LOGIN_PROCESS; 448 utent.ut_type = LOGIN_PROCESS;
449 utent.ut_pid = pid; 449 utent.ut_pid = pid;
450 strncpy(utent.ut_line, line, sizeof utent.ut_line); 450 strncpy(utent.ut_line, line, sizeof utent.ut_line);
diff --git a/loginutils/su.c b/loginutils/su.c
index 6410e748f..2e0aed6b1 100644
--- a/loginutils/su.c
+++ b/loginutils/su.c
@@ -8,7 +8,7 @@
8#include "busybox.h" 8#include "busybox.h"
9#include <syslog.h> 9#include <syslog.h>
10 10
11int su_main ( int argc, char **argv ) 11int su_main(int argc, char **argv)
12{ 12{
13 unsigned long flags; 13 unsigned long flags;
14 char *opt_shell = 0; 14 char *opt_shell = 0;
@@ -27,7 +27,7 @@ int su_main ( int argc, char **argv )
27 if (optind < argc && argv[optind][0] == '-' && argv[optind][1] == 0) { 27 if (optind < argc && argv[optind][0] == '-' && argv[optind][1] == 0) {
28 flags |= SU_OPT_l; 28 flags |= SU_OPT_l;
29 ++optind; 29 ++optind;
30 } 30 }
31 31
32 /* get user if specified */ 32 /* get user if specified */
33 if (optind < argc) opt_username = argv [optind++]; 33 if (optind < argc) opt_username = argv [optind++];
@@ -81,7 +81,7 @@ int su_main ( int argc, char **argv )
81 81
82 change_identity(pw); 82 change_identity(pw);
83 setup_environment(opt_shell, flags & SU_OPT_l, !(flags & SU_OPT_mp), pw); 83 setup_environment(opt_shell, flags & SU_OPT_l, !(flags & SU_OPT_mp), pw);
84 USE_SELINUX(set_current_security_context(NULL);) 84 USE_SELINUX(set_current_security_context(NULL);)
85 85
86 /* Never returns */ 86 /* Never returns */
87 run_shell(opt_shell, flags & SU_OPT_l, opt_command, (const char**)opt_args); 87 run_shell(opt_shell, flags & SU_OPT_l, opt_command, (const char**)opt_args);
diff --git a/loginutils/sulogin.c b/loginutils/sulogin.c
index 1c49d324d..763a9913a 100644
--- a/loginutils/sulogin.c
+++ b/loginutils/sulogin.c
@@ -65,7 +65,8 @@ int sulogin_main(int argc, char **argv)
65 struct spwd *spwd = NULL; 65 struct spwd *spwd = NULL;
66#endif 66#endif
67 67
68 openlog("sulogin", LOG_PID | LOG_CONS | LOG_NOWAIT, LOG_AUTH); 68 openlog("sulogin", LOG_PID | LOG_NOWAIT, LOG_AUTH);
69 logmode = LOGMODE_BOTH;
69 if (argc > 1) { 70 if (argc > 1) {
70 if (strncmp(argv[1], "-t", 2) == 0) { 71 if (strncmp(argv[1], "-t", 2) == 0) {
71 if (argv[1][2] == '\0') { /* -t NN */ 72 if (argv[1][2] == '\0') { /* -t NN */
@@ -92,28 +93,24 @@ int sulogin_main(int argc, char **argv)
92 dup(0); 93 dup(0);
93 dup(0); 94 dup(0);
94 } else { 95 } else {
95 syslog(LOG_WARNING, "cannot open %s\n", device); 96 /* Well, it will go only to syslog :) */
96 exit(EXIT_FAILURE); 97 bb_perror_msg_and_die("Cannot open %s", device);
97 } 98 }
98 } 99 }
99 } 100 }
100 if (access(bb_path_passwd_file, 0) == -1) {
101 syslog(LOG_WARNING, "No password file\n");
102 bb_error_msg_and_die("No password file");
103 }
104 if (!isatty(0) || !isatty(1) || !isatty(2)) { 101 if (!isatty(0) || !isatty(1) || !isatty(2)) {
105 exit(EXIT_FAILURE); 102 exit(EXIT_FAILURE);
106 } 103 }
107 104 if (access(bb_path_passwd_file, 0) == -1) {
105 bb_error_msg_and_die("No password file");
106 }
108 107
109 /* Clear out anything dangerous from the environment */ 108 /* Clear out anything dangerous from the environment */
110 for (p = forbid; *p; p++) 109 for (p = forbid; *p; p++)
111 unsetenv(*p); 110 unsetenv(*p);
112 111
113
114 signal(SIGALRM, catchalarm); 112 signal(SIGALRM, catchalarm);
115 if (!(pwd = getpwnam(name))) { 113 if (!(pwd = getpwnam(name))) {
116 syslog(LOG_WARNING, "No password entry for `root'");
117 bb_error_msg_and_die("No password entry for `root'"); 114 bb_error_msg_and_die("No password entry for `root'");
118 } 115 }
119 pwent = *pwd; 116 pwent = *pwd;
@@ -131,9 +128,10 @@ int sulogin_main(int argc, char **argv)
131 while (1) { 128 while (1) {
132 cp = bb_askpass(timeout, SULOGIN_PROMPT); 129 cp = bb_askpass(timeout, SULOGIN_PROMPT);
133 if (!cp || !*cp) { 130 if (!cp || !*cp) {
134 puts("\n"); 131 puts("\n"); /* Why only on error path? */
135 fflush(stdout); 132 fflush(stdout);
136 syslog(LOG_INFO, "Normal startup\n"); 133 /* Why only to syslog? */
134 syslog(LOG_INFO, "Normal startup");
137 exit(EXIT_SUCCESS); 135 exit(EXIT_SUCCESS);
138 } else { 136 } else {
139 safe_strncpy(pass, cp, sizeof(pass)); 137 safe_strncpy(pass, cp, sizeof(pass));
@@ -143,15 +141,11 @@ int sulogin_main(int argc, char **argv)
143 break; 141 break;
144 } 142 }
145 bb_do_delay(FAIL_DELAY); 143 bb_do_delay(FAIL_DELAY);
146 puts("Login incorrect"); 144 bb_error_msg("Incorrect root password");
147 fflush(stdout);
148 syslog(LOG_WARNING, "Incorrect root password\n");
149 } 145 }
150 memset(pass, 0, strlen(pass)); 146 memset(pass, 0, strlen(pass));
151 signal(SIGALRM, SIG_DFL); 147 signal(SIGALRM, SIG_DFL);
152 puts("Entering System Maintenance Mode\n"); 148 bb_info_msg("Entering System Maintenance Mode");
153 fflush(stdout);
154 syslog(LOG_INFO, "System Maintenance Mode\n");
155 149
156#if ENABLE_SELINUX 150#if ENABLE_SELINUX
157 renew_current_security_context(); 151 renew_current_security_context();
@@ -159,5 +153,5 @@ int sulogin_main(int argc, char **argv)
159 153
160 run_shell(pwent.pw_shell, 1, 0, 0); 154 run_shell(pwent.pw_shell, 1, 0, 0);
161 155
162 return (0); 156 return 0;
163} 157}