aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-06-26 01:55:45 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2009-06-26 01:55:45 +0200
commitd30b89c7eee19f395af0335b66822989c770437e (patch)
tree0695091ac035d39d6ba57e316474126fe8872347
parent2f86ca135069e457bb16ab9e062a10e0775717a6 (diff)
downloadbusybox-w32-d30b89c7eee19f395af0335b66822989c770437e.tar.gz
busybox-w32-d30b89c7eee19f395af0335b66822989c770437e.tar.bz2
busybox-w32-d30b89c7eee19f395af0335b66822989c770437e.zip
updates for supporting Linux kernel build and initrd utilities
cpio: --verbose, --quiet, --to-stdout test: make 64-bit math enable-able for hush too dnsdomainname: alias to hostname -d hostname: support --fqdn, --domain, --file Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--archival/cpio.c23
-rw-r--r--coreutils/Config.in2
-rw-r--r--include/applets.h1
-rw-r--r--include/usage.h3
-rw-r--r--networking/hostname.c121
5 files changed, 115 insertions, 35 deletions
diff --git a/archival/cpio.c b/archival/cpio.c
index a6484e5c0..5b4135f66 100644
--- a/archival/cpio.c
+++ b/archival/cpio.c
@@ -88,9 +88,17 @@ enum {
88 CPIO_OPT_PRESERVE_MTIME = (1 << 6), 88 CPIO_OPT_PRESERVE_MTIME = (1 << 6),
89 CPIO_OPT_DEREF = (1 << 7), 89 CPIO_OPT_DEREF = (1 << 7),
90 CPIO_OPT_FILE = (1 << 8), 90 CPIO_OPT_FILE = (1 << 8),
91 CPIO_OPT_CREATE = (1 << 9) * ENABLE_FEATURE_CPIO_O, 91 OPTBIT_FILE = 8,
92 CPIO_OPT_FORMAT = (1 << 10) * ENABLE_FEATURE_CPIO_O, 92 IF_FEATURE_CPIO_O(OPTBIT_CREATE ,)
93 CPIO_OPT_PASSTHROUGH = (1 << 11) * ENABLE_FEATURE_CPIO_P, 93 IF_FEATURE_CPIO_O(OPTBIT_FORMAT ,)
94 IF_FEATURE_CPIO_P(OPTBIT_PASSTHROUGH,)
95 IF_LONG_OPTS( OPTBIT_QUIET ,)
96 IF_LONG_OPTS( OPTBIT_2STDOUT ,)
97 CPIO_OPT_CREATE = IF_FEATURE_CPIO_O((1 << OPTBIT_CREATE )) + 0,
98 CPIO_OPT_FORMAT = IF_FEATURE_CPIO_O((1 << OPTBIT_FORMAT )) + 0,
99 CPIO_OPT_PASSTHROUGH = IF_FEATURE_CPIO_P((1 << OPTBIT_PASSTHROUGH)) + 0,
100 CPIO_OPT_QUIET = IF_LONG_OPTS( (1 << OPTBIT_QUIET )) + 0,
101 CPIO_OPT_2STDOUT = IF_LONG_OPTS( (1 << OPTBIT_2STDOUT )) + 0,
94}; 102};
95 103
96#define OPTION_STR "it0uvdmLF:" 104#define OPTION_STR "it0uvdmLF:"
@@ -284,6 +292,9 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
284 "pass-through\0" No_argument "p" 292 "pass-through\0" No_argument "p"
285#endif 293#endif
286#endif 294#endif
295 "verbose\0" No_argument "v"
296 "quiet\0" No_argument "\xff"
297 "to-stdout\0" No_argument "\xfe"
287 ; 298 ;
288#endif 299#endif
289 300
@@ -372,6 +383,8 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
372 } 383 }
373 if (opt & CPIO_OPT_EXTRACT) { 384 if (opt & CPIO_OPT_EXTRACT) {
374 archive_handle->action_data = data_extract_all; 385 archive_handle->action_data = data_extract_all;
386 if (opt & CPIO_OPT_2STDOUT)
387 archive_handle->action_data = data_extract_to_stdout;
375 } 388 }
376 if (opt & CPIO_OPT_UNCONDITIONAL) { 389 if (opt & CPIO_OPT_UNCONDITIONAL) {
377 archive_handle->ah_flags |= ARCHIVE_EXTRACT_UNCONDITIONAL; 390 archive_handle->ah_flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
@@ -406,7 +419,9 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
406 while (get_header_cpio(archive_handle) == EXIT_SUCCESS) 419 while (get_header_cpio(archive_handle) == EXIT_SUCCESS)
407 continue; 420 continue;
408 421
409 if (archive_handle->ah_priv[2] != (void*) ~(ptrdiff_t)0) 422 if (archive_handle->ah_priv[2] != (void*) ~(ptrdiff_t)0
423 && !(opt & CPIO_OPT_QUIET)
424 )
410 printf("%lu blocks\n", (unsigned long)(ptrdiff_t)(archive_handle->ah_priv[2])); 425 printf("%lu blocks\n", (unsigned long)(ptrdiff_t)(archive_handle->ah_priv[2]));
411 426
412 return EXIT_SUCCESS; 427 return EXIT_SUCCESS;
diff --git a/coreutils/Config.in b/coreutils/Config.in
index f9db0671d..1bc047c9a 100644
--- a/coreutils/Config.in
+++ b/coreutils/Config.in
@@ -667,7 +667,7 @@ config TEST
667config FEATURE_TEST_64 667config FEATURE_TEST_64
668 bool "Extend test to 64 bit" 668 bool "Extend test to 64 bit"
669 default n 669 default n
670 depends on TEST || ASH_BUILTIN_TEST 670 depends on TEST || ASH_BUILTIN_TEST || HUSH
671 help 671 help
672 Enable 64-bit support in test. 672 Enable 64-bit support in test.
673 673
diff --git a/include/applets.h b/include/applets.h
index 929616016..905bab393 100644
--- a/include/applets.h
+++ b/include/applets.h
@@ -127,6 +127,7 @@ IF_DIFF(APPLET(diff, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
127IF_DIRNAME(APPLET_NOFORK(dirname, dirname, _BB_DIR_USR_BIN, _BB_SUID_NEVER, dirname)) 127IF_DIRNAME(APPLET_NOFORK(dirname, dirname, _BB_DIR_USR_BIN, _BB_SUID_NEVER, dirname))
128IF_DMESG(APPLET(dmesg, _BB_DIR_BIN, _BB_SUID_NEVER)) 128IF_DMESG(APPLET(dmesg, _BB_DIR_BIN, _BB_SUID_NEVER))
129IF_DNSD(APPLET(dnsd, _BB_DIR_USR_SBIN, _BB_SUID_ALWAYS)) 129IF_DNSD(APPLET(dnsd, _BB_DIR_USR_SBIN, _BB_SUID_ALWAYS))
130IF_HOSTNAME(APPLET_ODDNAME(dnsdomainname, hostname, _BB_DIR_BIN, _BB_SUID_NEVER, dnsdomainname))
130IF_DOS2UNIX(APPLET(dos2unix, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) 131IF_DOS2UNIX(APPLET(dos2unix, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
131IF_DPKG(APPLET(dpkg, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) 132IF_DPKG(APPLET(dpkg, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
132IF_DPKG_DEB(APPLET_ODDNAME(dpkg-deb, dpkg_deb, _BB_DIR_USR_BIN, _BB_SUID_NEVER, dpkg_deb)) 133IF_DPKG_DEB(APPLET_ODDNAME(dpkg-deb, dpkg_deb, _BB_DIR_USR_BIN, _BB_SUID_NEVER, dpkg_deb))
diff --git a/include/usage.h b/include/usage.h
index 91bc01ee4..f65406254 100644
--- a/include/usage.h
+++ b/include/usage.h
@@ -1675,6 +1675,9 @@
1675 "$ hostname\n" \ 1675 "$ hostname\n" \
1676 "sage\n" 1676 "sage\n"
1677 1677
1678#define dnsdomainname_trivial_usage NOUSAGE_STR
1679#define dnsdomainname_full_usage ""
1680
1678#define httpd_trivial_usage \ 1681#define httpd_trivial_usage \
1679 "[-ifv[v]]" \ 1682 "[-ifv[v]]" \
1680 " [-c CONFFILE]" \ 1683 " [-c CONFFILE]" \
diff --git a/networking/hostname.c b/networking/hostname.c
index 48e70db91..7a120fa2c 100644
--- a/networking/hostname.c
+++ b/networking/hostname.c
@@ -4,20 +4,17 @@
4 * 4 *
5 * Copyright (C) 1999 by Randolph Chung <tausq@debian.org> 5 * Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
6 * 6 *
7 * adjusted by Erik Andersen <andersen@codepoet.org> to remove 7 * Adjusted by Erik Andersen <andersen@codepoet.org> to remove
8 * use of long options and GNU getopt. Improved the usage info. 8 * use of long options and GNU getopt. Improved the usage info.
9 * 9 *
10 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
11 *
12 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 10 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
13 */ 11 */
14
15#include "libbb.h" 12#include "libbb.h"
16 13
17static void do_sethostname(char *s, int isfile) 14static void do_sethostname(char *s, int isfile)
18{ 15{
19 if (!s) 16// if (!s)
20 return; 17// return;
21 if (isfile) { 18 if (isfile) {
22 parser_t *parser = config_open2(s, xfopen_for_read); 19 parser_t *parser = config_open2(s, xfopen_for_read);
23 while (config_read(parser, &s, 1, 1, "# \t", PARSE_NORMAL & ~PARSE_GREEDY)) { 20 while (config_read(parser, &s, 1, 1, "# \t", PARSE_NORMAL & ~PARSE_GREEDY)) {
@@ -25,15 +22,65 @@ static void do_sethostname(char *s, int isfile)
25 } 22 }
26 if (ENABLE_FEATURE_CLEAN_UP) 23 if (ENABLE_FEATURE_CLEAN_UP)
27 config_close(parser); 24 config_close(parser);
28 } else if (sethostname(s, strlen(s)) < 0) { 25 } else if (sethostname(s, strlen(s))) {
29 if (errno == EPERM) 26// if (errno == EPERM)
30 bb_error_msg_and_die(bb_msg_perm_denied_are_you_root); 27// bb_error_msg_and_die(bb_msg_perm_denied_are_you_root);
31 bb_perror_msg_and_die("sethostname"); 28 bb_perror_msg_and_die("sethostname");
32 } 29 }
33} 30}
34 31
32/* Manpage circa 2009:
33 *
34 * hostname [-v] [-a] [--alias] [-d] [--domain] [-f] [--fqdn] [--long]
35 * [-i] [--ip-address] [-s] [--short] [-y] [--yp] [--nis]
36 *
37 * hostname [-v] [-F filename] [--file filename] / [hostname]
38 *
39 * domainname [-v] [-F filename] [--file filename] / [name]
40 * { bbox: not supported }
41 *
42 * nodename [-v] [-F filename] [--file filename] / [name]
43 * { bbox: not supported }
44 *
45 * dnsdomainname [-v]
46 * { bbox: supported: Linux kernel build needs this }
47 * nisdomainname [-v]
48 * { bbox: not supported }
49 * ypdomainname [-v]
50 * { bbox: not supported }
51 *
52 * -a, --alias
53 * Display the alias name of the host (if used).
54 * { bbox: not supported }
55 * -d, --domain
56 * Display the name of the DNS domain. Don't use the command
57 * domainname to get the DNS domain name because it will show the
58 * NIS domain name and not the DNS domain name. Use dnsdomainname
59 * instead.
60 * -f, --fqdn, --long
61 * Display the FQDN (Fully Qualified Domain Name). A FQDN consists
62 * of a short host name and the DNS domain name. Unless you are
63 * using bind or NIS for host lookups you can change the FQDN and
64 * the DNS domain name (which is part of the FQDN) in the
65 * /etc/hosts file.
66 * -i, --ip-address
67 * Display the IP address(es) of the host.
68 * -s, --short
69 * Display the short host name. This is the host name cut at the
70 * first dot.
71 * -v, --verbose
72 * Be verbose and tell what's going on.
73 * { bbox: supported but ignored }
74 * -y, --yp, --nis
75 * Display the NIS domain name. If a parameter is given (or --file
76 * name ) then root can also set a new NIS domain.
77 * { bbox: not supported }
78 * -F, --file filename
79 * Read the host name from the specified file. Comments (lines
80 * starting with a `#') are ignored.
81 */
35int hostname_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 82int hostname_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
36int hostname_main(int argc, char **argv) 83int hostname_main(int argc UNUSED_PARAM, char **argv)
37{ 84{
38 enum { 85 enum {
39 OPT_d = 0x1, 86 OPT_d = 0x1,
@@ -44,49 +91,63 @@ int hostname_main(int argc, char **argv)
44 OPT_dfis = 0xf, 91 OPT_dfis = 0xf,
45 }; 92 };
46 93
94 unsigned opts;
47 char *buf; 95 char *buf;
48 char *hostname_str; 96 char *hostname_str;
49 97
50 if (argc < 1) 98#if ENABLE_LONG_OPTS
51 bb_show_usage(); 99 applet_long_options =
100 "domain\0" No_argument "d"
101 "fqdn\0" No_argument "f"
102 //Enable if seen in active use in some distro:
103 // "long\0" No_argument "f"
104 // "ip-address\0" No_argument "i"
105 // "short\0" No_argument "s"
106 // "verbose\0" No_argument "v"
107 "file\0" No_argument "F"
108 ;
52 109
53 getopt32(argv, "dfisF:", &hostname_str); 110#endif
111 /* dnsdomainname from net-tools 1.60, hostname 1.100 (2001-04-14),
112 * supports hostname's options too (not just -v as manpage says) */
113 opts = getopt32(argv, "dfisF:v", &hostname_str);
54 argv += optind; 114 argv += optind;
55 buf = safe_gethostname(); 115 buf = safe_gethostname();
116 if (applet_name[0] == 'd') /* dnsdomainname? */
117 opts = OPT_d;
56 118
57 /* Output in desired format */ 119 if (opts & OPT_dfis) {
58 if (option_mask32 & OPT_dfis) { 120 /* Cases when we need full hostname (or its part) */
59 struct hostent *hp; 121 struct hostent *hp;
60 char *p; 122 char *p;
123
61 hp = xgethostbyname(buf); 124 hp = xgethostbyname(buf);
62 p = strchr(hp->h_name, '.'); 125 p = strchrnul(hp->h_name, '.');
63 if (option_mask32 & OPT_f) { 126 if (opts & OPT_f) {
64 puts(hp->h_name); 127 puts(hp->h_name);
65 } else if (option_mask32 & OPT_s) { 128 } else if (opts & OPT_s) {
66 if (p) 129 *p = '\0';
67 *p = '\0';
68 puts(hp->h_name); 130 puts(hp->h_name);
69 } else if (option_mask32 & OPT_d) { 131 } else if (opts & OPT_d) {
70 if (p) 132 if (*p)
71 puts(p + 1); 133 puts(p + 1);
72 } else if (option_mask32 & OPT_i) { 134 } else /*if (opts & OPT_i)*/ {
73 while (hp->h_addr_list[0]) { 135 while (hp->h_addr_list[0]) {
74 printf("%s ", inet_ntoa(*(struct in_addr *) (*hp->h_addr_list++))); 136 printf("%s ", inet_ntoa(*(struct in_addr *) (*hp->h_addr_list++)));
75 } 137 }
76 bb_putchar('\n'); 138 bb_putchar('\n');
77 } 139 }
78 } 140 } else if (opts & OPT_F) {
79 /* Set the hostname */ 141 /* Set the hostname */
80 else if (option_mask32 & OPT_F) {
81 do_sethostname(hostname_str, 1); 142 do_sethostname(hostname_str, 1);
82 } else if (argv[0]) { 143 } else if (argv[0]) {
144 /* Set the hostname */
83 do_sethostname(argv[0], 0); 145 do_sethostname(argv[0], 0);
84 } 146 } else {
85 /* Or if all else fails, 147 /* Just print the current hostname */
86 * just print the current hostname */
87 else {
88 puts(buf); 148 puts(buf);
89 } 149 }
150
90 if (ENABLE_FEATURE_CLEAN_UP) 151 if (ENABLE_FEATURE_CLEAN_UP)
91 free(buf); 152 free(buf);
92 return EXIT_SUCCESS; 153 return EXIT_SUCCESS;