Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: Freaky/checkrestart
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.5.0
Choose a base ref
...
head repository: Freaky/checkrestart
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 7 commits
  • 2 files changed
  • 1 contributor

Commits on Apr 20, 2020

  1. I am not paid by the line

    Freaky committed Apr 20, 2020
    Copy the full SHA
    040edfe View commit details
  2. Silence warning

    Freaky committed Apr 20, 2020
    Copy the full SHA
    25b8580 View commit details
  3. Copy the full SHA
    91214f3 View commit details

Commits on Apr 21, 2020

  1. Add a parse_uint()

    I like how the unsigned conversion functions still accept signed inputs.
    Sure, -42 is *totally* within the range of an unsigned int.
    Freaky committed Apr 21, 2020
    Copy the full SHA
    5e83cb3 View commit details

Commits on Jan 21, 2022

  1. Copy the full SHA
    798aa70 View commit details
  2. Copy the full SHA
    c6de4c3 View commit details

Commits on Mar 20, 2022

  1. Correct -u logic

    Freaky committed Mar 20, 2022
    Copy the full SHA
    89df67d View commit details
Showing with 26 additions and 35 deletions.
  1. +4 −0 checkrestart.1
  2. +22 −35 checkrestart.c
4 changes: 4 additions & 0 deletions checkrestart.1
Original file line number Diff line number Diff line change
@@ -108,6 +108,10 @@ in the author's
.Nm pkg-cruft
Ruby script.
.Pp
A similar tool is also available in
.Fx
ports as sysutils/lsop.
.Pp
An unrelated but similar
.Nm
command is also available as an
57 changes: 22 additions & 35 deletions checkrestart.c
Original file line number Diff line number Diff line change
@@ -40,28 +40,23 @@ usage(void)
{
xo_error("usage: %s [--libxo] [-bHw] [-j jail] [-u [user]] [proc ...]\n", getprogname());
xo_finish();
exit(EXIT_FAILURE);
}

static bool
parse_int(const char *str, int *value)
{
char *end;

*value = strtoimax(str, &end, 10);
return (*str != '\0' && *end == '\0');
exit(EX_USAGE);
}

static int
gettermwidth(void)
{
struct winsize ws = { .ws_row = 0 };
const char *err;
char *colenv;
int cols;

colenv = getenv("COLUMNS");
if (colenv != NULL && parse_int(colenv, &cols) && cols > 0) {
return (cols);
if (colenv != NULL) {
cols = strtonum(colenv, 1, 512, &err);
if (err == NULL) {
return (cols);
}
}

if (ioctl(STDOUT_FILENO, TIOCGWINSZ, (char *)&ws) != -1 ||
@@ -133,7 +128,6 @@ static void
needsrestart(const struct kinfo_proc *proc, const enum Reason reason, const char *args)
{
char fmtbuf[sizeof("{:arguments/%.4294967295s}\n")];
const char *why;
int col, width;

if (needheader) {
@@ -150,14 +144,7 @@ needsrestart(const struct kinfo_proc *proc, const enum Reason reason, const char
col += xo_emit("{e:uid/%d/%d}", proc->ki_uid);
col += xo_emit("{w:user/%-12.12s/%s}", user_getname(proc->ki_uid));
col += xo_emit("{w:command/%-12.12s/%s}", proc->ki_comm);

if (reason == MissingExe) {
why = "bin";
} else {
why = ".so";
}

col += xo_emit("{w:why/%-3s/%s}", why);
col += xo_emit("{w:why/%-3s/%s}", reason == MissingExe ? "bin" : ".so");

if (termwidth && xo_get_style(NULL) == XO_STYLE_TEXT) {
width = MAX(termwidth - col, (int)sizeof("ARGUMENTS") - 1);
@@ -229,17 +216,18 @@ main(int argc, char *argv[])
{
struct kinfo_proc *p;
struct procstat *prstat;
const char *err;
unsigned int cnt, i;
int ch, rc, filterc;
pid_t pid;

rc = EXIT_FAILURE;
rc = EX_TEMPFAIL; // most likely we just didn't find anything
termwidth = gettermwidth();

xo_set_flags(NULL, XOF_WARN | XOF_COLUMNS);
argc = xo_parse_args(argc, argv);
if (argc < 0) {
return (EXIT_FAILURE);
return (EX_USAGE);
}

while ((ch = getopt(argc, argv, "bHj:u:w")) != -1) {
@@ -252,21 +240,19 @@ main(int argc, char *argv[])
break;
case 'j':
jflag = true;
if (parse_int(optarg, &filter_jid)) {
if (filter_jid < 0) {
usage();
}
} else {
filter_jid = strtonum(optarg, 0, INT_MAX, &err);
if (err != NULL) {
filter_jid = jail_getid(optarg);
if (filter_jid == -1) {
xo_errx(EXIT_FAILURE, "jail \"%s\" not found", optarg);
xo_errx(EX_NOHOST, "jail \"%s\" not found", optarg);
}
}
break;
case 'u':
uflag = true;
if (!parse_int(optarg, &filter_uid) && !user_getuid(optarg, &filter_uid)) {
xo_errx(EXIT_FAILURE, "user \"%s\" not found", optarg);
filter_uid = strtonum(optarg, 0, UID_MAX, &err);
if (err != NULL && !user_getuid(optarg, &filter_uid)) {
xo_errx(EX_NOUSER, "user \"%s\" not found", optarg);
}
break;
case 'w':
@@ -282,7 +268,7 @@ main(int argc, char *argv[])

prstat = procstat_open_sysctl();
if (prstat == NULL) {
xo_errx(EXIT_FAILURE, "procstat_open()");
xo_errx(EX_OSERR, "procstat_open()");
}

p = procstat_getprocs(prstat, KERN_PROC_PROC, 0, &cnt);
@@ -296,7 +282,8 @@ main(int argc, char *argv[])
for (i = 0; i < cnt; i++) {
if (argc) {
for (filterc = 0; filterc < argc; filterc++) {
if (!parse_int(argv[filterc], &pid)) {
pid = strtonum(argv[filterc], INT_MIN, INT_MAX, &err);
if (err != NULL) {
pid = 0;
} else if (pid == 0) {
usage();
@@ -307,13 +294,13 @@ main(int argc, char *argv[])
(pid < 0 && p[i].ki_pgid == abs(pid)) ||
(pid == 0 && strcmp(argv[filterc], p[i].ki_comm) == 0)
) {
rc = EXIT_SUCCESS;
rc = EX_OK;
checkrestart(prstat, &p[i]);
break;
}
}
} else {
rc = EXIT_SUCCESS;
rc = EX_OK;
checkrestart(prstat, &p[i]);
}
}