when used in a script no output is needed. The latest version
of pidof supports the -q option to make thinks more easy.

Signed-off-by: walter <[email protected]>
---
I did not manage to have a usage() , can someone add this ?
---
 procps/pidof.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/procps/pidof.c b/procps/pidof.c
index 5595e34..c6ee357 100644
--- a/procps/pidof.c
+++ b/procps/pidof.c
@@ -69,8 +69,10 @@

 enum {
        IF_FEATURE_PIDOF_SINGLE(OPTBIT_SINGLE,)
+                                OPTBIT_QUIET ,
        IF_FEATURE_PIDOF_OMIT(  OPTBIT_OMIT  ,)
        OPT_SINGLE = IF_FEATURE_PIDOF_SINGLE((1<<OPTBIT_SINGLE)) + 0,
+       OPT_QUIET   = (1<<OPTBIT_QUIET  ) + 0,
        OPT_OMIT   = IF_FEATURE_PIDOF_OMIT(  (1<<OPTBIT_OMIT  )) + 0,
 };

@@ -86,6 +88,7 @@ int pidof_main(int argc UNUSED_PARAM, char **argv)
        /* do unconditional option parsing */
        opt = getopt32(argv, ""
                        IF_FEATURE_PIDOF_SINGLE ("s")
+                       "q"
                        IF_FEATURE_PIDOF_OMIT("o:*", &omits));

 #if ENABLE_FEATURE_PIDOF_OMIT
@@ -121,7 +124,7 @@ int pidof_main(int argc UNUSED_PARAM, char **argv)
                                }
                        }
 #endif
-                       printf(" %u" + first, (unsigned)*pl);
+                       if (!(opt & OPT_QUIET)) printf(" %u" + first, 
(unsigned)*pl);
                        first = 0;
                        if (ENABLE_FEATURE_PIDOF_SINGLE && (opt & OPT_SINGLE))
                                break;
@@ -132,7 +135,7 @@ int pidof_main(int argc UNUSED_PARAM, char **argv)
                free(pidList);
                argv++;
        }
-       if (!first)
+       if (!first && !(opt & OPT_QUIET))
                bb_putchar('\n');

 #if ENABLE_FEATURE_PIDOF_OMIT
-- 
2.1.4

_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to