A missing securetty file is not an error.
[oweals/busybox.git] / procps / pidof.c
index 9415827042a98b1c796cef19605faa0f45047d37..169a92007ea3f867ad4aa8a1de0e1de334a89db5 100644 (file)
@@ -3,7 +3,7 @@
  * pidof implementation for busybox
  *
  * Copyright (C) 1999,2000 by Lineo, inc. and Erik Andersen
- * Copyright (C) 1999,2000,2001 by Erik Andersen <andersee@debian.org>
+ * Copyright (C) 1999-2002 by Erik Andersen <andersee@debian.org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 
 extern int pidof_main(int argc, char **argv)
 {
-       int opt;
-
+       int opt, n = 0;
+       int single_flag = 0;
+       int fail = 1;
 
        /* do normal option parsing */
-       while ((opt = getopt(argc, argv, "ne:f:")) > 0) {
+       while ((opt = getopt(argc, argv, "s")) > 0) {
                switch (opt) {
-#if 0
-                       case 'g':
-                               break;
-                       case 'e':
+                       case 's':
+                               single_flag = 1;
                                break;
-#endif
                        default:
                                show_usage();
                }
        }
 
-       /* if we didn't get a process name, then we need to choke and die here */
-       if (argv[optind] == NULL)
-               show_usage();
-
        /* Looks like everything is set to go. */
        while(optind < argc) {
                long* pidList;
 
-               pidList = find_pid_by_name( argv[optind]);
-               if (!pidList || *pidList<=0) {
-                       break;
-               }
-
-               for(; pidList && *pidList!=0; pidList++) {
-                       printf("%ld ", (long)*pidList);
+               pidList = find_pid_by_name(argv[optind]);
+               for(; *pidList > 0; pidList++) {
+                       printf("%s%ld", (n++ ? " " : ""), (long)*pidList);
+                       fail = 0;
+                       if (single_flag)
+                               break;
                }
-               /* Note that we don't bother to free the memory
-                * allocated in find_pid_by_name().  It will be freed
-                * upon exit, so we can save a byte or two */
+               free(pidList);
                optind++;
+
        }
        printf("\n");
 
-       return EXIT_SUCCESS;
+       return fail ? EXIT_FAILURE : EXIT_SUCCESS;
 }