after

Echo a string after process dies
git clone _git@git.zakaria.org/after.git
Log | Files | Refs | README | LICENSE

commit 269f02273a492d248ced4b4613a5a83fb78e7c62
parent 4cc602ddaff83a0993058190cbf22d6975506551
Author: zk <58356365+e-zk@users.noreply.github.com>
Date:   Tue,  5 Jan 2021 23:23:11 +1000

merge PR #3 from netzbasis/forUpstream

* only print string if process was running in the first place.
* add pledge safetybelts
Diffstat:
Mafter.c | 14++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/after.c b/after.c @@ -74,6 +74,7 @@ main(int argc, char *argv[]) { int i, ch, entries; int pid = 0; + int found = 0; char *pname = NULL, *cmd = NULL; char errbuf[_POSIX2_LINE_MAX]; @@ -82,6 +83,9 @@ main(int argc, char *argv[]) verbose = 0; + if (pledge("stdio ps", NULL) == -1) + err(1, "pledge"); + // argument parsing... while((ch = getopt(argc, argv, "e:hn:p:v")) != -1) switch(ch) { @@ -131,13 +135,19 @@ main(int argc, char *argv[]) pname_is_in(pname, kinfo, entries) == 0 : pid_is_in(pid, kinfo, entries) == 0 ) { + found = 1; kinfo = get_proc_list(kd, &entries); debug_print("waiting..."); sleep(1); } - debug_print("process not in process list (died?)."); - printf("%s\n", cmd); + if (found) { + debug_print("process died."); + printf("%s\n", cmd); + } else { + debug_print("process not in process list."); + exit(1); + } return 0; }