Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ProcessTerminationResult, for better alignment with POSIX #244

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Commits on Mar 15, 2023

  1. Add ProcessTerminationResult, for better alignment with POSIX

    POSIX issue 7, 2018 edition, section 3.303 "Process Termination" states
    the following:
    
    > There are two kinds of process termination:
    >
    > 1. Normal termination occurs by a return from main(), when requested
    >    with the exit(), _exit(), or _Exit() functions; or when the last
    >    thread in the process terminates by returning from its start
    >    function, by calling the pthread_exit() function, or through
    >    cancellation.
    >
    > 2. Abnormal termination occurs when requested by the abort() function
    >    or when some signals are received.
    
    Both these cases can be detected by parent processes separately.
    Unfortunately, REv2 currently doesn't allow this, as we only provide an
    exit code. Implementations such as Buildbarn tend to set the exit code
    for abnormal termination to 128+signum, meaning that if a segmentation
    fault occurs, an action terminates with exit code 139. This tends to be
    fairly confusing for non-expert users.
    
    The goal of this change is to make all of this less confusing. It adds a
    new message type named ProcessTerminationResult, which contains the
    termination result in a more structured way. It can now either be an
    exit code or a signal number. If it turns out that other operating
    systems provide even more ways, we can add additional `oneof` cases.
    
    For the exit code in case of normal termination I decided to use an
    int64 instead of int32. The reason being that POSIX allows you to get
    the full exit code back, using APIs like waitid(). On ILP64 systems, the
    exit code may thus be 64 bits.
    
    For the signal in case of abnormal termination I decided to use a
    string. The reason being that signal numbers are not covered by POSIX.
    Everybody always assumes that 9 is SIGKILL, but POSIX only documents
    this as a convention for the command line flags of the `kill` utility.
    Not the the actual `SIG*` constants. Adding an enumeration would also be
    unwise, as operating systems are free to add their own signals that are
    not covered by POSIX (e.g., SIGINFO on BSD).
    
    Fixes: bazelbuild#240
    EdSchouten committed Mar 15, 2023
    Configuration menu
    Copy the full SHA
    19fd68b View commit details
    Browse the repository at this point in the history