Project

General

Profile

Feature #13677

pwait -v should decode wait status

Added by Rich Lowe 24 days ago. Updated 2 days ago.

Status:
New
Priority:
Normal
Assignee:
Category:
cmd - userland programs
Start date:
Due date:
% Done:

0%

Estimated time:
Difficulty:
Bite-size
Tags:
Gerrit CR:

Description

At present, pwait -v just prints the return from wait as a hex integer, it'd be nice if it decoded it.


Files

pwait_screenshot.PNG (8.26 KB) pwait_screenshot.PNG Ryan England, 2021-04-16 02:01 AM
#1

Updated by Ryan England 4 days ago

Rich, I have modified the code to return and integer as opposed to hex. Is this what you meant by decode?

Test: Echo terminal PID, pwait -v PID, close terminal. See screenshot for output.

#2

Updated by Ryan England 4 days ago

  • Assignee set to Ryan England
#3

Updated by Joshua M. Clulow 4 days ago

I suspect Rich probably meant that in addition to printing the numeric value, we could print a string that describes what it means symbolically. For reference, there are a number of macros documented in the wait.h manual page that allow for decoding the status. e.g., you might do something like:

static void
maybe_comma(custr_t *)
{
    if (custr_len(cu) != 0) {
        if (custr_append(cu, ", ") != 0) {
            err(1, "custr_append");
        }
    }
}

static custr_t *
describe_status(int status)
{
    custr_t *cu;

    if (custr_alloc(&cu) != 0) {
        err(1, "custr_alloc");
    }

    if (WIFEXITED(status)) {
        maybe_comma(cu);
        if (custr_append_printf(cu, "exited with status %d",
            WEXITSTATUS(status)) != 0) {
            err(1, "custr_append_printf");
        }
    }

    if (WIFSIGNALED(status)) {
        maybe_comma(cu);
        if (custr_append_printf(cu, "terminated by signal %d",
            WTERMSIG(status)) != 0) {
            err(1, "custr_append_printf");
        }

        if (WCOREDUMP(status)) {
            maybe_comma(cu);
            if (custr_append(cu, "dumped core")) {
                err(1, "custr_append_printf");
            }
        }
    }

    return (cu);
}

Note that this is an incomplete sketch. You might also consider translating the signal numbers into names as well, say, for WTERMSIG and WSTOPSIG.

#4

Updated by Andy Fiddaman 4 days ago

When I recently tried to get pwait to show anything other than zero, I was unsuccessful.
Have you had any success there?

#5

Updated by Ryan England 3 days ago

Andy Fiddaman wrote in #note-4:

When I recently tried to get pwait to show anything other than zero, I was unsuccessful.
Have you had any success there?

Andy, I have NOT been able to get pwait to return anything other than zero either.

#6

Updated by Rich Lowe 2 days ago

I had seen other values at least once, but I'm struggling to get it now. I guess maybe we should change it to "should work"?
And yes, decoded in the sense that Joshua sketched out. Sorry for being so terse.

Also available in: Atom PDF