commit 042bb1b698c0ef4dd6dfb2923197031cd6f5b468
parent e9d14c1f997bea3068913cf242c50108b8cd3e36
Author: e-zk <58356365+e-zk@users.noreply.github.com>
Date: Mon, 7 Dec 2020 16:12:18 +1000
show usage if no echo string is given
Diffstat:
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/after.c b/after.c
@@ -48,7 +48,8 @@ pname_is_in(char *pname, struct kinfo_proc **kinfo, int entries)
}
struct kinfo_proc **
-get_proc_list(kvm_t *kd, int *entries) {
+get_proc_list(kvm_t *kd, int *entries)
+{
int i;
struct kinfo_proc *kp, **kinfo;
@@ -98,6 +99,7 @@ main(int argc, char *argv[])
usage();
exit(1);
}
+
argc -= optind;
argv += optind;
@@ -107,6 +109,12 @@ main(int argc, char *argv[])
exit(1);
}
+ // show usage if no output string is given
+ if (cmd == NULL) {
+ usage();
+ exit(1);
+ }
+
// initialise virtual memory access
kd = kvm_openfiles(NULL, NULL, NULL, KVM_NO_FILES, errbuf);
@@ -116,7 +124,7 @@ main(int argc, char *argv[])
// get initial process list
kinfo = get_proc_list(kd, &entries);
- // if a process name is given
+ // if a process name is given use that, otherwise use pid
if (pname != NULL) {
while(pname_is_in(pname, kinfo, entries) == 0) {
kinfo = get_proc_list(kd, &entries);
@@ -135,7 +143,7 @@ main(int argc, char *argv[])
}
if (verbose == 1)
- fprintf(stderr, "%s: process not in process list.\n", prog_name);
+ fprintf(stderr, "%s: process not in process list (died?).\n", prog_name);
printf("%s\n", cmd);