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) ...
Alias: None
Product: Portage Development
Classification: Unclassified
Component: Core (show other bugs)
Hardware: All All
: Normal normal (vote)
Assignee: Portage team
Depends on:
Reported: 2018-07-30 00:04 UTC by Zac Medico
Modified: 2018-07-30 00:04 UTC (History)
0 users

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


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 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)