X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=procps%2Fpidof.c;h=2fe8ecd25b66e952ab7844b5b38dbd3531198ddf;hb=b03be7f5677b86acfe2f64b5a57e1f361e257f6c;hp=5a40288dc95d1ebba2a3e40296d20d589f7df254;hpb=bdfd0d78bc44e73d693510e70087857785b3b521;p=oweals%2Fbusybox.git diff --git a/procps/pidof.c b/procps/pidof.c index 5a40288dc..2fe8ecd25 100644 --- a/procps/pidof.c +++ b/procps/pidof.c @@ -2,8 +2,7 @@ /* * pidof implementation for busybox * - * Copyright (C) 1999,2000 by Lineo, inc. and Erik Andersen - * Copyright (C) 1999,2000,2001 by Erik Andersen + * Copyright (C) 1999-2003 by Erik Andersen * * 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 @@ -35,45 +34,38 @@ 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(); + bb_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) { - pid_t* pidList; + long *pidList; + long *pl; - 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(pl = pidList; *pl > 0; pl++) { + printf("%s%ld", (n++ ? " " : ""), *pl); + 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; }