ps: make "ps -o BAD" emit list of good -o params
authorDenys Vlasenko <vda.linux@googlemail.com>
Sat, 22 May 2010 22:34:42 +0000 (00:34 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Sat, 22 May 2010 22:34:42 +0000 (00:34 +0200)
also make ps help more informative

function                                             old     new   delta
find_out_spec                                         58     103     +45
packed_usage                                       27039   27079     +40

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
include/usage.h
procps/ps.c

index 8f695f8b83d28dfdc1b0a5b05a144f618f32b464..d53b867310879e078a14a4d509e66397df487658 100644 (file)
 #if ENABLE_DESKTOP
 
 #define ps_trivial_usage \
-       ""
+       "[-o COL1,COL2=HEADER]" IF_FEATURE_SHOW_THREADS(" [-T]")
 #define ps_full_usage "\n\n" \
-       "Report process status\n" \
+       "Show list of processes\n" \
      "\nOptions:" \
-     "\n       -o col1,col2=header     Select columns for display" \
+     "\n       -o COL1,COL2=HEADER     Select columns for display" \
        IF_FEATURE_SHOW_THREADS( \
      "\n       -T                      Show threads" \
        )
 #define ps_trivial_usage \
        ""
 #define ps_full_usage "\n\n" \
-       "Report process status\n" \
+       "Show list of processes\n" \
        USAGE_PS \
        IF_SELINUX( \
      "\n       -Z      Show selinux context" \
index c3b20086611c47e70a5f4050ed48dedb0bed969a..a3220a92607c9a12f70d9fa854fc77f40e0222f8 100644 (file)
@@ -232,7 +232,6 @@ static void func_tty(char *buf, int size, const procps_status_t *ps)
                snprintf(buf, size+1, "%u,%u", ps->tty_major, ps->tty_minor);
 }
 
-
 #if ENABLE_FEATURE_PS_ADDITIONAL_COLUMNS
 
 static void func_rgroup(char *buf, int size, const procps_status_t *ps)
@@ -250,9 +249,10 @@ static void func_nice(char *buf, int size, const procps_status_t *ps)
        sprintf(buf, "%*d", size, ps->niceness);
 }
 
-#endif /* FEATURE_PS_ADDITIONAL_COLUMNS */
+#endif
 
 #if ENABLE_FEATURE_PS_TIME
+
 static void func_etime(char *buf, int size, const procps_status_t *ps)
 {
        /* elapsed time [[dd-]hh:]mm:ss; here only mm:ss */
@@ -278,6 +278,7 @@ static void func_time(char *buf, int size, const procps_status_t *ps)
        mm /= 60;
        snprintf(buf, size+1, "%3lu:%02u", mm, ss);
 }
+
 #endif
 
 #if ENABLE_SELINUX
@@ -337,11 +338,24 @@ static ps_out_t* new_out_t(void)
 static const ps_out_t* find_out_spec(const char *name)
 {
        unsigned i;
+#if ENABLE_DESKTOP
+       char buf[ARRAY_SIZE(out_spec)*7 + 1];
+       char *p = buf;
+#endif
+
        for (i = 0; i < ARRAY_SIZE(out_spec); i++) {
-               if (!strncmp(name, out_spec[i].name6, 6))
+               if (strncmp(name, out_spec[i].name6, 6) == 0)
                        return &out_spec[i];
+#if ENABLE_DESKTOP
+               p += sprintf(p, "%.6s,", out_spec[i].name6);
+#endif
        }
-       bb_error_msg_and_die("bad -o argument '%s'", name);
+#if ENABLE_DESKTOP
+       p[-1] = '\0';
+       bb_error_msg_and_die("bad -o argument '%s', supported arguments: %s", name, buf);
+#else
+       bb_error_msg_and_die("bad -o argument '%s'");
+#endif
 }
 
 static void parse_o(char* opt)