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

Signal example not working #5338

Open
yzhang71 opened this issue Jan 12, 2025 · 1 comment
Open

Signal example not working #5338

yzhang71 opened this issue Jan 12, 2025 · 1 comment
Assignees

Comments

@yzhang71
Copy link

Hi Wasmer community,

We are attempting to run the signal example provided below using the latest versions of Wasix and Wasmer (Wasmer 5.0.4). However, the example is not functioning as expected; it gets stuck in the while loop and keeps printing 'running...'.

#include <stdio.h>
#include <signal.h>
#include <unistd.h>
 
volatile int run = 1; // set to 0 when SIGINT is caught
 
/*
 * Signal handler function.
 * It is called when a signal is delivered to the process.
 */
void sig_handler(int signo)
{
    // SIGHUP is sent when user closes the terminal
    if (signo == SIGHUP)
    {
        run = 0; // set to 0 to terminate the program
        printf("received SIGHUP\n");
    }
    // SIGINT is sent when user presses Ctrl+C
    if (signo == SIGINT)
    {
        run = 0; // set to 0 to terminate the program
        printf("received SIGINT\n");
    }
}
 
int main(void)
{
    if (signal(SIGINT, sig_handler) == SIG_ERR)
        printf("\ncan't catch SIGINT\n");
    if (signal(SIGHUP, sig_handler) == SIG_ERR)
        printf("\ncan't catch SIGHUP\n");
 
    /*
     * Raise a SIGHUP signal.
     */
    raise(SIGHUP);
 
    // A long long wait so that we can easily issue a signal to this process
    while (run)
    {
        printf("running...\n");
        sleep(1); // sleep for 1 second
    }
 
    return 0;
}

Any insights or suggestions would be greatly appreciated!

@xdoardo
Copy link
Collaborator

xdoardo commented Jan 17, 2025

Hello! Thanks for the report. We will take care of this after a planned refactor of important parts of our implementation of WASIX.

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

No branches or pull requests

3 participants