Skip to content

Commit

Permalink
Make opening/closing container conditional
Browse files Browse the repository at this point in the history
  • Loading branch information
Freaky committed Mar 21, 2020
1 parent d30057d commit 1d69e11
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions checkrestart.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,27 +234,26 @@ main(int argc, char *argv[])
xo_errx(EXIT_FAILURE, "procstat_open()");
}

xo_set_version(CHECKRESTART_XO_VERSION);
xo_open_container(CHECKRESTART_XO_CONTAINER);
xo_open_list(CHECKRESTART_XO_PROCESS);

p = procstat_getprocs(prstat, KERN_PROC_PROC, 0, &cnt);
if (p == NULL) {
xo_warn("procstat_getprocs()");
} else {
xo_set_version(CHECKRESTART_XO_VERSION);
xo_open_container(CHECKRESTART_XO_CONTAINER);
xo_open_list(CHECKRESTART_XO_PROCESS);

for (i = 0; i < cnt; i++) {
if (argc) {
for (filterc = 0; filterc < argc; filterc++) {

if (!parse_int(argv[filterc], &pid)) {
pid = 0;
} else if (pid == 0) {
usage();
}

if (
(pid < 0 && p[i].ki_pgid == abs(pid)) ||
(pid > 0 && p[i].ki_pid == pid) ||
(pid < 0 && p[i].ki_pgid == abs(pid)) ||
(pid == 0 && strcmp(argv[filterc], p[i].ki_comm) == 0)
) {
rc = EXIT_SUCCESS;
Expand All @@ -268,11 +267,11 @@ main(int argc, char *argv[])
}
}

xo_close_list(CHECKRESTART_XO_PROCESS);
xo_close_container(CHECKRESTART_XO_CONTAINER);

procstat_freeprocs(prstat, p);
}

xo_close_list(CHECKRESTART_XO_PROCESS);
xo_close_container(CHECKRESTART_XO_CONTAINER);
xo_finish();

procstat_close(prstat);
Expand Down

0 comments on commit 1d69e11

Please sign in to comment.