mirror of
https://github.com/sheumann/hush.git
synced 2024-12-22 14:30:31 +00:00
Made exit code SysV compliant. Also added -s (single pid) flag.
This commit is contained in:
parent
236abbfd71
commit
d11edf9809
@ -36,26 +36,20 @@
|
|||||||
extern int pidof_main(int argc, char **argv)
|
extern int pidof_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int opt, n = 0;
|
int opt, n = 0;
|
||||||
|
int single_flag = 0;
|
||||||
|
int fail = 1;
|
||||||
|
|
||||||
/* do normal option parsing */
|
/* do normal option parsing */
|
||||||
while ((opt = getopt(argc, argv, "ne:f:")) > 0) {
|
while ((opt = getopt(argc, argv, "s")) > 0) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
#if 0
|
case 's':
|
||||||
case 'g':
|
single_flag = 1;
|
||||||
break;
|
break;
|
||||||
case 'e':
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
default:
|
default:
|
||||||
show_usage();
|
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. */
|
/* Looks like everything is set to go. */
|
||||||
while(optind < argc) {
|
while(optind < argc) {
|
||||||
long* pidList;
|
long* pidList;
|
||||||
@ -67,6 +61,9 @@ extern int pidof_main(int argc, char **argv)
|
|||||||
|
|
||||||
for(; pidList && *pidList!=0; pidList++) {
|
for(; pidList && *pidList!=0; pidList++) {
|
||||||
printf("%s%ld", (n++ ? " " : ""), (long)*pidList);
|
printf("%s%ld", (n++ ? " " : ""), (long)*pidList);
|
||||||
|
fail = 0;
|
||||||
|
if (single_flag)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
/* Note that we don't bother to free the memory
|
/* Note that we don't bother to free the memory
|
||||||
* allocated in find_pid_by_name(). It will be freed
|
* allocated in find_pid_by_name(). It will be freed
|
||||||
@ -75,5 +72,5 @@ extern int pidof_main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return fail ? EXIT_FAILURE : EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user