diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-02-11 16:19:28 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-02-11 16:19:28 +0000 |
commit | 6ca0444420223c224162674902d4f6e4e093962d (patch) | |
tree | c13da1537be3327e041fac86d9fdce68de70298a /sysklogd/syslogd.c | |
parent | 136f42f503cb3e9588e62332d043e92b7475ec4e (diff) | |
download | busybox-w32-6ca0444420223c224162674902d4f6e4e093962d.tar.gz busybox-w32-6ca0444420223c224162674902d4f6e4e093962d.tar.bz2 busybox-w32-6ca0444420223c224162674902d4f6e4e093962d.zip |
syslogd: fix "readpath bug" by using readlink instead
libbb: rename xgetcwd and xreadlink
Diffstat (limited to 'sysklogd/syslogd.c')
-rw-r--r-- | sysklogd/syslogd.c | 41 |
1 files changed, 24 insertions, 17 deletions
diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c index 97ddf09b5..53290f1cc 100644 --- a/sysklogd/syslogd.c +++ b/sysklogd/syslogd.c | |||
@@ -24,9 +24,6 @@ | |||
24 | 24 | ||
25 | #define DEBUG 0 | 25 | #define DEBUG 0 |
26 | 26 | ||
27 | /* Path to the unix socket */ | ||
28 | static const char *dev_log_name; | ||
29 | |||
30 | /* Path for the file where all log messages are written */ | 27 | /* Path for the file where all log messages are written */ |
31 | static const char *logFilePath = "/var/log/messages"; | 28 | static const char *logFilePath = "/var/log/messages"; |
32 | static int logFD = -1; | 29 | static int logFD = -1; |
@@ -446,7 +443,6 @@ static void quit_signal(int sig) | |||
446 | { | 443 | { |
447 | timestamp_and_log(LOG_SYSLOG | LOG_INFO, (char*)"syslogd exiting", 0); | 444 | timestamp_and_log(LOG_SYSLOG | LOG_INFO, (char*)"syslogd exiting", 0); |
448 | puts("syslogd exiting"); | 445 | puts("syslogd exiting"); |
449 | unlink(dev_log_name); | ||
450 | if (ENABLE_FEATURE_IPC_SYSLOG) | 446 | if (ENABLE_FEATURE_IPC_SYSLOG) |
451 | ipcsyslog_cleanup(); | 447 | ipcsyslog_cleanup(); |
452 | exit(1); | 448 | exit(1); |
@@ -464,9 +460,9 @@ static void do_syslogd(void) ATTRIBUTE_NORETURN; | |||
464 | static void do_syslogd(void) | 460 | static void do_syslogd(void) |
465 | { | 461 | { |
466 | struct sockaddr_un sunx; | 462 | struct sockaddr_un sunx; |
467 | socklen_t addr_len; | ||
468 | int sock_fd; | 463 | int sock_fd; |
469 | fd_set fds; | 464 | fd_set fds; |
465 | char *dev_log_name; | ||
470 | 466 | ||
471 | /* Set up signal handlers */ | 467 | /* Set up signal handlers */ |
472 | signal(SIGINT, quit_signal); | 468 | signal(SIGINT, quit_signal); |
@@ -480,22 +476,33 @@ static void do_syslogd(void) | |||
480 | signal(SIGALRM, do_mark); | 476 | signal(SIGALRM, do_mark); |
481 | alarm(markInterval); | 477 | alarm(markInterval); |
482 | 478 | ||
483 | dev_log_name = xmalloc_realpath(_PATH_LOG); | ||
484 | if (!dev_log_name) | ||
485 | dev_log_name = _PATH_LOG; | ||
486 | |||
487 | /* Unlink old /dev/log (or object it points to) */ | ||
488 | unlink(dev_log_name); | ||
489 | |||
490 | memset(&sunx, 0, sizeof(sunx)); | 479 | memset(&sunx, 0, sizeof(sunx)); |
491 | sunx.sun_family = AF_UNIX; | 480 | sunx.sun_family = AF_UNIX; |
492 | strncpy(sunx.sun_path, dev_log_name, sizeof(sunx.sun_path)); | 481 | strcpy(sunx.sun_path, "/dev/log"); |
482 | |||
483 | /* Unlink old /dev/log or object it points to. */ | ||
484 | /* (if it exists, bind will fail) */ | ||
485 | logmode = LOGMODE_NONE; | ||
486 | dev_log_name = xmalloc_readlink_or_warn("/dev/log"); | ||
487 | logmode = LOGMODE_STDIO; | ||
488 | if (dev_log_name) { | ||
489 | int fd = xopen(".", O_NONBLOCK); | ||
490 | xchdir("/dev"); | ||
491 | /* we do not check whether this is a link also */ | ||
492 | unlink(dev_log_name); | ||
493 | fchdir(fd); | ||
494 | close(fd); | ||
495 | safe_strncpy(sunx.sun_path, dev_log_name, sizeof(sunx.sun_path)); | ||
496 | free(dev_log_name); | ||
497 | } else { | ||
498 | unlink("/dev/log"); | ||
499 | } | ||
500 | |||
493 | sock_fd = xsocket(AF_UNIX, SOCK_DGRAM, 0); | 501 | sock_fd = xsocket(AF_UNIX, SOCK_DGRAM, 0); |
494 | addr_len = sizeof(sunx.sun_family) + strlen(sunx.sun_path); | 502 | xbind(sock_fd, (struct sockaddr *) &sunx, sizeof(sunx)); |
495 | xbind(sock_fd, (struct sockaddr *) &sunx, addr_len); | ||
496 | 503 | ||
497 | if (chmod(dev_log_name, 0666) < 0) { | 504 | if (chmod("/dev/log", 0666) < 0) { |
498 | bb_perror_msg_and_die("cannot set permission on %s", dev_log_name); | 505 | bb_perror_msg_and_die("cannot set permission on /dev/log"); |
499 | } | 506 | } |
500 | if (ENABLE_FEATURE_IPC_SYSLOG && (option_mask32 & OPT_circularlog)) { | 507 | if (ENABLE_FEATURE_IPC_SYSLOG && (option_mask32 & OPT_circularlog)) { |
501 | ipcsyslog_init(); | 508 | ipcsyslog_init(); |