Skip to content

utils: use || instead of | in waitpid_ignore_stopped - #2192

Merged
giuseppe merged 1 commit into
containers:mainfrom
eriksjolund:use-logical-or
Aug 15, 2026
Merged

utils: use || instead of | in waitpid_ignore_stopped#2192
giuseppe merged 1 commit into
containers:mainfrom
eriksjolund:use-logical-or

Conversation

@eriksjolund

Copy link
Copy Markdown
Contributor

Claude Opus 5 helped finding the bug and writing this PR.

utils: use || instead of | in waitpid_ignore_stopped

What

One-line change in src/libcrun/utils.h:

-  } while (WIFSTOPPED (s) | WIFCONTINUED (s));
+  } while (WIFSTOPPED (s) || WIFCONTINUED (s));

Why

WIFSTOPPED() and WIFCONTINUED() are boolean predicates, but POSIX only requires
them to evaluate to a non-zero value for a matching status — not to exactly 1.
Combining them with | relies on a normalization the standard does not guarantee.

This is in the same spirit as 910eb16 ("utils: normalize S_ISDIR() result to 0 or 1").

Is this a bug fix?

No — and I would rather say so plainly than oversell it. Both glibc and musl expand
these macros to a comparison, so they already yield 0 or 1 and the loop behaves
correctly on every platform crun supports. Both operands are also side-effect-free,
so nothing changes from restoring short-circuit evaluation. Treat this as a
readability and robustness cleanup.

Testing

  • No behavioral change is expected; the generated code is expected to be identical
    on glibc and musl.
  • Builds cleanly with -Wall -Wextra.
  • The existing integration tests exercise this path heavily — waitpid_ignore_stopped()
    has 12 call sites across container.c, linux.c, seccomp.c, net_device.c
    and utils.c, covering container teardown, exec, and the seccomp notify helper.

WIFSTOPPED() and WIFCONTINUED() are boolean predicates, but POSIX only
specifies that they evaluate to a non-zero value for a matching status,
not that they evaluate to exactly 1.  Combining them with the bitwise OR
operator therefore relies on a property the standard does not guarantee.

glibc and musl both happen to expand these macros to a comparison, so
the current code works there, but the logical OR operator expresses the
intent directly and does not depend on the values being normalized.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Signed-off-by: Erik Sjölund <erik.sjolund@gmail.com>
@packit-as-a-service

Copy link
Copy Markdown

Ephemeral COPR build failed. @containers/packit-build please check.

@giuseppe giuseppe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@giuseppe
giuseppe merged commit 3425c83 into containers:main Aug 15, 2026
45 of 47 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants