diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-02-26 02:23:58 +0300 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-02-26 02:23:58 +0300 |
commit | 6f1713f216fef686a68db5ee02232bc67e525c7d (patch) | |
tree | 256adc75a88723a4b247c32e692d721d65243a82 /sysklogd/syslogd.c | |
parent | 394eebed6656dfc2e56a79500b602023000ac415 (diff) |
*: intrduce and use safe_gethostname. By Tito <farmatito AT tiscali.it>
safe_gethostname - 48 +48
glob3 35 37 +2
timestamp_and_log 314 315 +1
udhcp_send_kernel_packet 234 231 -3
scan_tree 275 271 -4
passwd_main 1074 1070 -4
print_login_prompt 68 58 -10
obscure 392 377 -15
syslogd_main 882 866 -16
print_login_issue 516 478 -38
hostname_main 278 223 -55
parse_and_put_prompt 825 756 -69
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 2/9 up/down: 51/-214) Total: -163 bytes
text data bss dec hex filename
798791 728 7484 807003 c505b busybox_old
798631 728 7484 806843 c4fbb busybox_unstripped
Diffstat (limited to 'sysklogd/syslogd.c')
-rw-r--r-- | sysklogd/syslogd.c | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c index 0dc69d8cc..0d004bc27 100644 --- a/sysklogd/syslogd.c +++ b/sysklogd/syslogd.c @@ -97,8 +97,8 @@ struct globals { struct shbuf_ds *shbuf; #endif time_t last_log_time; - /* localhost's name */ - char localHostName[64]; + /* localhost's name. We print only first 64 chars */ + char *hostname; /* We recv into recvbuf... */ char recvbuf[MAX_READ]; @@ -416,7 +416,7 @@ static void timestamp_and_log(int pri, char *msg, int len) else { char res[20]; parse_fac_prio_20(pri, res); - sprintf(G.printbuf, "%s %s %s %s\n", timestamp, G.localHostName, res, msg); + sprintf(G.printbuf, "%s %.64s %s %s\n", timestamp, G.hostname, res, msg); } /* Log message locally (to file or shared mem) */ @@ -647,11 +647,8 @@ int syslogd_main(int argc, char **argv) option_mask32 |= OPT_locallog; /* Store away localhost's name before the fork */ - /* "It is unspecified whether the truncated hostname - * will be null-terminated". We give it (size - 1), - * thus last byte will be NUL no matter what. */ - gethostname(G.localHostName, sizeof(G.localHostName) - 1); - *strchrnul(G.localHostName, '.') = '\0'; + G.hostname = safe_gethostname(); + *strchrnul(G.hostname, '.') = '\0'; if (!(option_mask32 & OPT_nofork)) { bb_daemonize_or_rexec(DAEMON_CHDIR_ROOT, argv); |