summaryrefslogtreecommitdiffhomepage
path: root/networking/hostname.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-02-25 23:23:58 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-02-25 23:23:58 +0000
commit6f1713f216fef686a68db5ee02232bc67e525c7d (patch)
tree256adc75a88723a4b247c32e692d721d65243a82 /networking/hostname.c
parent394eebed6656dfc2e56a79500b602023000ac415 (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 'networking/hostname.c')
-rw-r--r--networking/hostname.c18
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)
if (sethostname(s, strlen(s)) < 0) {
if (errno == EPERM)
bb_error_msg_and_die(bb_msg_perm_denied_are_you_root);
- else
- bb_perror_msg_and_die("sethostname");
+ bb_perror_msg_and_die("sethostname");
}
} else {
f = xfopen(s, "r");
@@ -54,27 +53,27 @@ int hostname_main(int argc, char **argv)
OPT_dfis = 0xf,
};
- char buf[256];
+ char *buf;
char *hostname_str;
if (argc < 1)
bb_show_usage();
getopt32(argv, "dfisF:", &hostname_str);
+ argv += optind;
+ buf = safe_gethostname();
/* Output in desired format */
if (option_mask32 & OPT_dfis) {
struct hostent *hp;
char *p;
- gethostname(buf, sizeof(buf));
hp = xgethostbyname(buf);
p = strchr(hp->h_name, '.');
if (option_mask32 & OPT_f) {
puts(hp->h_name);
} else if (option_mask32 & OPT_s) {
- if (p != NULL) {
+ if (p)
*p = '\0';
- }
puts(hp->h_name);
} else if (option_mask32 & OPT_d) {
if (p)
@@ -89,14 +88,15 @@ int hostname_main(int argc, char **argv)
/* Set the hostname */
else if (option_mask32 & OPT_F) {
do_sethostname(hostname_str, 1);
- } else if (optind < argc) {
- do_sethostname(argv[optind], 0);
+ } else if (argv[0]) {
+ do_sethostname(argv[0], 0);
}
/* Or if all else fails,
* just print the current hostname */
else {
- gethostname(buf, sizeof(buf));
puts(buf);
}
+ if (ENABLE_FEATURE_CLEAN_UP)
+ free(buf);
return 0;
}