denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
93.91k stars 5.22k forks source link

Allow a script to kill itself without run permissions #8299

Open c4spar opened 3 years ago

c4spar commented 3 years ago

If this has already been discussed in another issue I'm sorry, I haven't found one.

I'am working on cliffy and we are trying to improve the sigint handling of the prompt module, if a user hit's ctrl+c. The problem is, deno doesn't trigger the sigint signal automaticly, because we need to enable the raw mode with Deno.setRaw.

Currently, the prompt module just exits if the user hit's ctrl+c by calling Deno.exit. But instead of just exiting the programm, we want to use the Deno.kill method to rise a sigint, so it's possible to run some cleanup operations if the user hit's ctrl+c.

But currently it's not possible to rise a signal without the --allow-run permissions flag. And i don't want the prompt module to depend on the --allow-run flag.

One option to improve this could be to allow a script to kill itself without the --allow-run flag. This could be done by checking the pid of the running script. If the pid passed to Deno.kill matches the pid of the running script, the --allow-run flag is not required.

lino-levan commented 1 year ago

Given https://github.com/denoland/deno/pull/16299 recently got merged, I think this would be a really nice thing to have. No need for an argument check anymore.