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

Raise a signal on the current process #9093

Closed
mk12 opened this issue Jan 11, 2021 · 2 comments
Closed

Raise a signal on the current process #9093

mk12 opened this issue Jan 11, 2021 · 2 comments
Labels
permissions related to --allow-* flags public API related to "Deno" namespace in JS runtime Relates to code in the runtime crate suggestion suggestions for new features (yet to be agreed)

Comments

@mk12
Copy link

mk12 commented Jan 11, 2021

A common pattern with signals like SIGHUP, SIGINT, and SIGTERM is to perform some cleanup and then invoke the default handler. For example, in C:

static void signal_handler(int signum) {
    do_cleanup();
    signal(signum, SIG_DFL);
    raise(signum);
}

This is different from calling exit yourself. For one thing, exit is not async-signal-safe, so you'd actually need to call _exit or abort. But more importantly, the parent process (e.g. the shell) can tell from wait if a child was killed by a signal or exited normally. So even if you mimic the exit code:

await Deno.signal(sig);
Deno.exit(128 + sig);

it will not be the same as invoking the default handler.

You can call Deno.kill(Deno.pid, sig), but this requires the very broad permission --allow-run. It would be better if there was a Deno.raise(sig) function that did not require any permission.

@lucacasonato
Copy link
Member

lucacasonato commented Jan 13, 2021

Is there a node equivalent for this? We could consider not requiring the --allow-run permission for killing the current pid.

@lucacasonato lucacasonato added runtime Relates to code in the runtime crate suggestion suggestions for new features (yet to be agreed) public API related to "Deno" namespace in JS permissions related to --allow-* flags labels Jan 17, 2021
@lucacasonato
Copy link
Member

Duplicate of #8299.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
permissions related to --allow-* flags public API related to "Deno" namespace in JS runtime Relates to code in the runtime crate suggestion suggestions for new features (yet to be agreed)
Projects
None yet
Development

No branches or pull requests

2 participants