Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 662446 - sys-apps/portage: commands like emerge should call kill(os.getpid(), signum) when killed by signal
Summary: sys-apps/portage: commands like emerge should call kill(os.getpid(), signum) ...
Status: RESOLVED FIXED
Alias: None
Product: Portage Development
Classification: Unclassified
Component: Core (show other bugs)
Hardware: All All
: Normal normal (vote)
Assignee: Portage team
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 910332
  Show dependency tree
 
Reported: 2018-07-30 00:04 UTC by Zac Medico
Modified: 2023-07-14 14:57 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Zac Medico gentoo-dev 2018-07-30 00:04:14 UTC
In https://www.cons.org/cracauer/sigint.html it explains that the correct way to handle a termination signal is:

> void sigint_handler(int sig)
> {
> 	[do some cleanup]
> 	signal(SIGINT, SIG_DFL);
> 	kill(getpid(), SIGINT);
> }
However, the above approach would prevent python context manager __exit__ routines from being called because SIG_DFL causes the interpreter to exit immediately. Therefore, something like this should be used instead:

> class TermSig(Exception):
>     def __init__(self, signum, *args, **kwargs):
>         super(TermSig, self).__init__(*args, **kwargs)
>         self.signum = signum
> 
> 
> def sig_handler(signum, frame):
>     raise TermSig(signum)
> 
> 
> def main():
>     return os.EX_OK
> 
> 
> if __name__ = '__main__':
>     signal.signal(signal.SIGINT, sig_handler)
>     signal.signal(signal.SIGTERM, sig_handler)
>     signal.signal(signal.SIGHUP, sig_handler)
>     try:
>         sys.exit(main())
>     except TermSig as e:
>         signal.signal(signum, signal.SIG_DFL)
>         os.kill(os.getpid(), e.signum)
Comment 1 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2023-07-14 10:41:17 UTC
I think this got fixed by bug 887817.