diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-02-25 23:23:58 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-02-25 23:23:58 +0000 |
commit | 6f1713f216fef686a68db5ee02232bc67e525c7d (patch) | |
tree | 256adc75a88723a4b247c32e692d721d65243a82 /networking | |
parent | 394eebed6656dfc2e56a79500b602023000ac415 (diff) | |
download | busybox-w32-6f1713f216fef686a68db5ee02232bc67e525c7d.tar.gz busybox-w32-6f1713f216fef686a68db5ee02232bc67e525c7d.tar.bz2 busybox-w32-6f1713f216fef686a68db5ee02232bc67e525c7d.zip |
*: 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 'networking')
-rw-r--r-- | networking/hostname.c | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/networking/hostname.c b/networking/hostname.c index 2c224bef9..93cbc961f 100644 --- a/networking/hostname.c +++ b/networking/hostname.c | |||
@@ -24,8 +24,7 @@ static void do_sethostname(char *s, int isfile) | |||
24 | if (sethostname(s, strlen(s)) < 0) { | 24 | if (sethostname(s, strlen(s)) < 0) { |
25 | if (errno == EPERM) | 25 | if (errno == EPERM) |
26 | bb_error_msg_and_die(bb_msg_perm_denied_are_you_root); | 26 | bb_error_msg_and_die(bb_msg_perm_denied_are_you_root); |
27 | else | 27 | bb_perror_msg_and_die("sethostname"); |
28 | bb_perror_msg_and_die("sethostname"); | ||
29 | } | 28 | } |
30 | } else { | 29 | } else { |
31 | f = xfopen(s, "r"); | 30 | f = xfopen(s, "r"); |
@@ -54,27 +53,27 @@ int hostname_main(int argc, char **argv) | |||
54 | OPT_dfis = 0xf, | 53 | OPT_dfis = 0xf, |
55 | }; | 54 | }; |
56 | 55 | ||
57 | char buf[256]; | 56 | char *buf; |
58 | char *hostname_str; | 57 | char *hostname_str; |
59 | 58 | ||
60 | if (argc < 1) | 59 | if (argc < 1) |
61 | bb_show_usage(); | 60 | bb_show_usage(); |
62 | 61 | ||
63 | getopt32(argv, "dfisF:", &hostname_str); | 62 | getopt32(argv, "dfisF:", &hostname_str); |
63 | argv += optind; | ||
64 | buf = safe_gethostname(); | ||
64 | 65 | ||
65 | /* Output in desired format */ | 66 | /* Output in desired format */ |
66 | if (option_mask32 & OPT_dfis) { | 67 | if (option_mask32 & OPT_dfis) { |
67 | struct hostent *hp; | 68 | struct hostent *hp; |
68 | char *p; | 69 | char *p; |
69 | gethostname(buf, sizeof(buf)); | ||
70 | hp = xgethostbyname(buf); | 70 | hp = xgethostbyname(buf); |
71 | p = strchr(hp->h_name, '.'); | 71 | p = strchr(hp->h_name, '.'); |
72 | if (option_mask32 & OPT_f) { | 72 | if (option_mask32 & OPT_f) { |
73 | puts(hp->h_name); | 73 | puts(hp->h_name); |
74 | } else if (option_mask32 & OPT_s) { | 74 | } else if (option_mask32 & OPT_s) { |
75 | if (p != NULL) { | 75 | if (p) |
76 | *p = '\0'; | 76 | *p = '\0'; |
77 | } | ||
78 | puts(hp->h_name); | 77 | puts(hp->h_name); |
79 | } else if (option_mask32 & OPT_d) { | 78 | } else if (option_mask32 & OPT_d) { |
80 | if (p) | 79 | if (p) |
@@ -89,14 +88,15 @@ int hostname_main(int argc, char **argv) | |||
89 | /* Set the hostname */ | 88 | /* Set the hostname */ |
90 | else if (option_mask32 & OPT_F) { | 89 | else if (option_mask32 & OPT_F) { |
91 | do_sethostname(hostname_str, 1); | 90 | do_sethostname(hostname_str, 1); |
92 | } else if (optind < argc) { | 91 | } else if (argv[0]) { |
93 | do_sethostname(argv[optind], 0); | 92 | do_sethostname(argv[0], 0); |
94 | } | 93 | } |
95 | /* Or if all else fails, | 94 | /* Or if all else fails, |
96 | * just print the current hostname */ | 95 | * just print the current hostname */ |
97 | else { | 96 | else { |
98 | gethostname(buf, sizeof(buf)); | ||
99 | puts(buf); | 97 | puts(buf); |
100 | } | 98 | } |
99 | if (ENABLE_FEATURE_CLEAN_UP) | ||
100 | free(buf); | ||
101 | return 0; | 101 | return 0; |
102 | } | 102 | } |