ntpd: and real handling for -N, show usage w/o options; trim text
authorDenys Vlasenko <vda.linux@googlemail.com>
Wed, 25 Nov 2009 13:52:47 +0000 (14:52 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Wed, 25 Nov 2009 13:52:47 +0000 (14:52 +0100)
function                                             old     new   delta
ntp_init                                             317     348     +31
bb_msg_you_must_be_root                                -      17     +17
xsocket                                               66      76     +10
changepath                                           195     194      -1
bb_msg_perm_denied_are_you_root                       35      34      -1
send_tree                                            355     353      -2
count_lines                                           74      72      -2
must_be_root                                          17       -     -17
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 2/4 up/down: 58/-23)             Total: 35 bytes
   text   data    bss    dec    hexfilename
 832873    441   7548 840862  cd49ebusybox_old
 832839    441   7548 840828  cd47cbusybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
include/libbb.h
include/usage.h
libbb/messages.c
libbb/xfuncs_printf.c
miscutils/crontab.c
networking/ntpd.c
networking/tcpudp.c
networking/traceroute.c
util-linux/mount.c

index 1194f7eca75e603f04709b0f576d89c14135320c..1f39c95e168325896a7c3ae3d641747fb3d007bc 100644 (file)
@@ -1474,6 +1474,7 @@ extern const char bb_msg_write_error[];
 extern const char bb_msg_unknown[];
 extern const char bb_msg_can_not_create_raw_socket[];
 extern const char bb_msg_perm_denied_are_you_root[];
+extern const char bb_msg_you_must_be_root[];
 extern const char bb_msg_requires_arg[];
 extern const char bb_msg_invalid_arg[];
 extern const char bb_msg_standard_input[];
index 461f5fca1d14a3b74738633cb0ebd5323ca4ebb1..760e8545b20f6944112737c0da6e684cb595071d 100644 (file)
      "\n       -n      Do not daemonize" \
      "\n       -g      Set system time even if offset is > 1000 sec" \
      "\n       -q      Quit after clock is set" \
+/* -N exists for mostly compat reasons, thus Not essential to inform */ \
+/* the user that it exists: user may use nice as well */ \
+/*   "\n       -N      Run at high priority" */ \
      "\n       -l      Run as server on port 123" \
      "\n       -p PEER Obtain time from PEER (may be repeated)" \
 
index 90090283cd85827d2e66d07a9803ad3d321e4b73..1d0e5872058e0ddac7afffcb96d0fb4f65a1e644 100644 (file)
@@ -28,7 +28,8 @@ const char bb_msg_write_error[] ALIGN1 = "write error";
 const char bb_msg_read_error[] ALIGN1 = "read error";
 const char bb_msg_unknown[] ALIGN1 = "(unknown)";
 const char bb_msg_can_not_create_raw_socket[] ALIGN1 = "can't create raw socket";
-const char bb_msg_perm_denied_are_you_root[] ALIGN1 = "permission denied. (are you root?)";
+const char bb_msg_perm_denied_are_you_root[] ALIGN1 = "permission denied (are you root?)";
+const char bb_msg_you_must_be_root[] ALIGN1 = "you must be root";
 const char bb_msg_requires_arg[] ALIGN1 = "%s requires an argument";
 const char bb_msg_invalid_arg[] ALIGN1 = "invalid argument '%s' to '%s'";
 const char bb_msg_standard_input[] ALIGN1 = "standard input";
index 644134a0e01392fd976a03e2dd1815793bd155fe..d362841318d2fb385d1caf5d1cc3cbb2d0c59cd6 100644 (file)
@@ -388,7 +388,7 @@ int FAST_FUNC xsocket(int domain, int type, int protocol)
                if (domain == AF_PACKET) s = "PACKET";
                if (domain == AF_NETLINK) s = "NETLINK";
 IF_FEATURE_IPV6(if (domain == AF_INET6) s = "INET6";)
-               bb_perror_msg_and_die("socket(AF_%s)", s);
+               bb_perror_msg_and_die("socket(AF_%s,%d,%d)", s, type, protocol);
 #else
                bb_perror_msg_and_die("socket");
 #endif
index 67b10f684180fd16516e6237cb5e08af3705644e..044440435be20e2fb007c41461edbdc69f1adc98 100644 (file)
@@ -118,9 +118,9 @@ int crontab_main(int argc UNUSED_PARAM, char **argv)
        argv += optind;
 
        if (sanitize_env_if_suid()) { /* Clears dangerous stuff, sets PATH */
-               /* run by non-root? */
+               /* Run by non-root */
                if (opt_ler & (OPT_u|OPT_c))
-                       bb_error_msg_and_die("only root can use -c or -u");
+                       bb_error_msg_and_die(bb_msg_you_must_be_root);
        }
 
        if (opt_ler & OPT_u) {
index 12e498d48d1b6f3ae2882cf5dbc21492ebfa6d7c..e2c3506ed53fcabf258fa2201dfc5a726ca92720 100644 (file)
@@ -7,7 +7,9 @@
  */
 #include "libbb.h"
 #include <netinet/ip.h> /* For IPTOS_LOWDELAY definition */
-
+#ifndef IPTOS_LOWDELAY
+# define IPTOS_LOWDELAY 0x10
+#endif
 #ifndef IP_PKTINFO
 # error "Sorry, your kernel has to support IP_PKTINFO"
 #endif
@@ -161,10 +163,11 @@ enum {
        OPT_n = (1 << 0),
        OPT_g = (1 << 1),
        OPT_q = (1 << 2),
+       OPT_N = (1 << 3),
        /* Insert new options above this line. */
        /* Non-compat options: */
-       OPT_p = (1 << 3),
-       OPT_l = (1 << 4),
+       OPT_p = (1 << 4),
+       OPT_l = (1 << 5) * ENABLE_FEATURE_NTPD_SERVER,
 };
 
 
@@ -877,16 +880,18 @@ static NOINLINE void ntp_init(char **argv)
        /* tzset(); - why? it's called automatically when needed, no? */
 
        if (getuid())
-               bb_error_msg_and_die("need root privileges");
+               bb_error_msg_and_die(bb_msg_you_must_be_root);
 
        peers = NULL;
        opt_complementary = "dd:p::"; /* d: counter, p: list */
        opts = getopt32(argv,
-                       "ngq" /* compat */
+                       "ngqN" /* compat */
                        "p:"IF_FEATURE_NTPD_SERVER("l") /* NOT compat */
                        "d" /* compat */
-                       "46aAbLNx", /* compat, ignored */
+                       "46aAbLx", /* compat, ignored */
                        &peers, &G.verbose);
+       if (!(opts & (OPT_p|OPT_l)))
+               bb_show_usage();
 #if ENABLE_FEATURE_NTPD_SERVER
        G.listen_fd = -1;
        if (opts & OPT_l) {
@@ -903,6 +908,9 @@ static NOINLINE void ntp_init(char **argv)
                logmode = LOGMODE_NONE;
                bb_daemonize(DAEMON_DEVNULL_STDIO);
        }
+       /* I hesitate to set -20 prio. -15 should be high enough for timekeeping */
+       if (opts & OPT_N)
+               setpriority(PRIO_PROCESS, 0, -15);
 
        /* Set some globals */
        {
index 25b3319ec951c2491e28a5dd9deef8b81a82f8b6..d0db33b79fbef81031b26662449065ee1975aae3 100644 (file)
@@ -239,7 +239,7 @@ int tcpudpsvd_main(int argc UNUSED_PARAM, char **argv)
        client = 0;
        if ((getuid() == 0) && !(opts & OPT_u)) {
                xfunc_exitcode = 100;
-               bb_error_msg_and_die("-U ssluser must be set when running as root");
+               bb_error_msg_and_die(bb_msg_you_must_be_root);
        }
        if (opts & OPT_u)
                if (!uidgid_get(&sslugid, ssluser, 1)) {
index e9f3cc6c95a9947fbb2d10344e56cd77afe445a7..110bdfa76e952329b3e58568da1b433e5f8c0c31 100644 (file)
@@ -835,7 +835,7 @@ common_traceroute_main(int op, char **argv)
                 * probe (e.g., on a multi-homed host).
                 */
                if (getuid() != 0)
-                       bb_error_msg_and_die("you must be root to use -s");
+                       bb_error_msg_and_die(bb_msg_you_must_be_root);
        }
        if (op & OPT_WAITTIME)
                waittime = xatou_range(waittime_str, 1, 24 * 60 * 60);
index 271e691e7fd32004494358071dc768016453cb75..d27d65f80a5e9dd40a7404c9cb0469f91790bd65 100644 (file)
@@ -1801,8 +1801,6 @@ static int match_opt(const char *fs_opt, const char *O_opt)
 
 // Parse options, if necessary parse fstab/mtab, and call singlemount for
 // each directory to be mounted.
-static const char must_be_root[] ALIGN1 = "you must be root";
-
 int mount_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int mount_main(int argc UNUSED_PARAM, char **argv)
 {
@@ -1871,7 +1869,7 @@ int mount_main(int argc UNUSED_PARAM, char **argv)
                // argument when we get it.
                if (argv[1]) {
                        if (nonroot)
-                               bb_error_msg_and_die(must_be_root);
+                               bb_error_msg_and_die(bb_msg_you_must_be_root);
                        mtpair->mnt_fsname = argv[0];
                        mtpair->mnt_dir = argv[1];
                        mtpair->mnt_type = fstype;
@@ -1888,7 +1886,7 @@ int mount_main(int argc UNUSED_PARAM, char **argv)
 
        i = parse_mount_options(cmdopts, NULL); // FIXME: should be "long", not "int"
        if (nonroot && (i & ~MS_SILENT)) // Non-root users cannot specify flags
-               bb_error_msg_and_die(must_be_root);
+               bb_error_msg_and_die(bb_msg_you_must_be_root);
 
        // If we have a shared subtree flag, don't worry about fstab or mtab.
        if (ENABLE_FEATURE_MOUNT_FLAGS
@@ -1947,7 +1945,7 @@ int mount_main(int argc UNUSED_PARAM, char **argv)
                        // No, mount -a won't mount anything,
                        // even user mounts, for mere humans
                        if (nonroot)
-                               bb_error_msg_and_die(must_be_root);
+                               bb_error_msg_and_die(bb_msg_you_must_be_root);
 
                        // Does type match? (NULL matches always)
                        if (!match_fstype(mtcur, fstype))
@@ -2012,7 +2010,7 @@ int mount_main(int argc UNUSED_PARAM, char **argv)
                        // fstab must have "users" or "user"
                        l = parse_mount_options(mtcur->mnt_opts, NULL);
                        if (!(l & MOUNT_USERS))
-                               bb_error_msg_and_die(must_be_root);
+                               bb_error_msg_and_die(bb_msg_you_must_be_root);
                }
 
                // Mount the last thing we found