Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Register
  • Sign in
  • G GLib
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 851
    • Issues 851
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 49
    • Merge requests 49
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Releases
  • Packages and registries
    • Packages and registries
    • Container Registry
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • GNOMEGNOME
  • GLib
  • Merge requests
  • !1967

Distinguish more clearly between wait status and exit status

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Simon McVittie requested to merge wip/wait-status into main Feb 25, 2021
  • Overview 8
  • Commits 3
  • Pipelines 4
  • Changes 13
  • subprocess test: Check wait status correctly

    Confusingly, g_spawn_check_exit_status() takes a wait status, not an exit status, so passing g_subprocess_get_exit_status() to it is incorrect (although both encodings happen to use 0 to encode success and a nonzero value to encode failure, so in practice this probably had the desired effect).

  • Distinguish more clearly between wait status and exit status

    On Unix platforms, wait() and friends yield an integer that encodes how the process exited. Confusingly, this is usually not the same as the integer passed to exit() or returned from main(): conceptually it's an integer encoding of this tagged union:

      enum { EXITED, SIGNALLED, ... } tag;
      union {
          int exit_status;         /* if EXITED */
          struct {
              int terminating_signal;
              bool core_dumped;
          } terminating_signal;    /* if SIGNALLED */
          ...
      } detail;

    Meanwhile, on Windows, wait statuses and exit statuses are interchangeable.

    I find that it's clearer what is going on if we are consistent about referring to the result of wait() as a "wait status", and the value passed to exit() as an "exit status".

    GSubprocess already gets this right: g_subprocess_get_status() returns the wait status, while g_subprocess_get_exit_status() genuinely returns the exit status. However, the GSpawn family of APIs has tended to conflate the two.

    Confusingly, g_spawn_check_exit_status() has always checked a wait status, and it would not be correct to pass an exit status to it; so let's deprecate it in favour of g_spawn_check_wait_status(), which does the same thing that g_spawn_check_exit_status() always did. Code that needs backwards-compatibility with older GLib can use:

      #if !GLIB_CHECK_VERSION(2, 69, 0)
      #define g_spawn_check_wait_status(x) (g_spawn_check_exit_status (x))
      #endif
  • spawn: Clarify the most common non-exit reason for process termination

    A reader might think "how would a process terminate without an exit status?", or equivalently, "what harm would it do if I assume every termination has an exit status?" without this reminder that termination with a signal is also reasonably common.

Edited Jun 14, 2021 by Simon McVittie
Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: wip/wait-status