Skip to content

PHP segfaults if pcntl is built as shared module #9298

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

Closed
hasso opened this issue Aug 11, 2022 · 1 comment
Closed

PHP segfaults if pcntl is built as shared module #9298

hasso opened this issue Aug 11, 2022 · 1 comment

Comments

@hasso
Copy link

hasso commented Aug 11, 2022

Description

The following code:

<?php

declare(strict_types = 1);

function sigalrm()
{
}

while (true) {

    pcntl_signal(SIGALRM, "sigalrm", false);

    $pid = pcntl_fork();
    if ($pid < 0) {
        printf("pcntl_fork() failed\n");
        exit(-1);
    }

    if ($pid == 0) {
        exit(0);
    } else {
        while (true) {
            posix_kill($pid, SIGALRM);
            $wpid = pcntl_wait($st, WNOHANG);
            if ($wpid > 0) {
                break;
            }
        }

        if (pcntl_wifsignaled($st)) {
            $signo = pcntl_wtermsig($st);
            if ($signo != SIGALRM) {
                printf("##### Worker killed by signal %d ####\n", $signo);
                exit(0);
            }
        }

        printf("Worker exited normally\n");
    }

}

Resulted in this output:

##### Worker killed by signal 11 ####

But I expected this output instead:

Worker exited normally
Worker exited normally
Worker exited normally
Worker exited normally
...

The problem only appears if pcntl is built as shared module (--enable-pcntl=shared). There is no problem if pcntl support is built in (--enable-pcntl).

PHP Version

PHP 8.1.9

Operating System

Debian GNU/Linux 11 (bullseye)

@hasso
Copy link
Author

hasso commented Aug 12, 2022

I edited the test code to fix small bug - it could happen before that the code was going to kill a wrong process.

arnaud-lb added a commit that referenced this issue Nov 13, 2022
* PHP-8.1:
  [ci skip] NEWS
  Fix GH-9298: remove all registered signal handlers in pcntl RSHUTDOWN
arnaud-lb added a commit that referenced this issue Nov 13, 2022
* PHP-8.2:
  [ci skip] NEWS
  [ci skip] NEWS
  Fix GH-9298: remove all registered signal handlers in pcntl RSHUTDOWN
TimWolla added a commit to TimWolla/php-src that referenced this issue Nov 15, 2022
* master: (274 commits)
  Cache UTF-8-validity status of strings in GC flags
  Escape the role attribute of namespaced classes (php#9952)
  Fix phpGH-9932: Discards further characters for session name.
  Fix phpGH-9890: OpenSSL legacy providers not available on Windows
  Fix regression test for phpGH-9535 on PHP-8.2+
  Fix memory leak
  Introduce TEST_FPM_EXTENSION_DIR for FPM tests with shared extensions
  [ci skip] NEWS
  Fix phpGH-9535 (unintended behavior change for mb_strcut in PHP 8.1)
  [ci skip] NEWS
  [ci skip] NEWS
  Fix phpGH-9298: remove all registered signal handlers in pcntl RSHUTDOWN
  Fix phpGH-9923: Add the `SIGINFO` constant in pcntl for system supporting it.
  Skip tests if extension or SAPI is not included. (php#9939)
  Remove unused PHP 8.1 BC layer in JIT (php#9937)
  [skip ci] Skip function JIT in nightly for ASAN
  [skip ci] Backport XFAIL of failing test
  Disable opcache file_cache for observer preloading test
  No more need to cater to mime_magic extension
  [ci skip] Fix phpGH-9918: License information for xxHash is not included in README.REDIST.BINS file
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants
@hasso @cmb69 and others