After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 350501 - handle sigterm, sigquit, etc. gracefully
handle sigterm, sigquit, etc. gracefully
Status: RESOLVED FIXED
Product: Pan
Classification: Other
Component: general
unspecified
Other All
: Normal enhancement
: 1.0
Assigned To: Charles Kerr
Pan QA Team
: 120763 352668 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2006-08-08 21:47 UTC by Søren Boll Overgaard
Modified: 2007-01-23 00:44 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
first draft (1.81 KB, patch)
2006-08-09 02:52 UTC, Charles Kerr
none Details | Review

Description Søren Boll Overgaard 2006-08-08 21:47:55 UTC
Hello,

A Debian user suggested the following at http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=272959:

--- 8< ---

This might be a bit over the top but it's something that's bugged me
about pan. It won't write metadata about which messages were read until
the program is closed. Therefore, if I turn off the machine by pressing
the power button (and letting ACPI handle the shutdown gracefully), pan
will be forcibly closed and it will have forgotten all of those read
messages. I do this often, and it would be nice to have this feature.

--- 8< ---

From what I can tell after experimenting with the betas, this still applies.
While I usually shut down pan cleanly, I agree with the submitter that this sort of feature would be quite useful.

I have only made a few greps of the source to check this, but it seems to me that a simple signal handler for a few of the more important signals (SIGQUIT, SIGTERM leaps to mind) ensuring that data is written to disk would go a long way? If that is already handled, please disregard my suggestion.
Comment 1 Charles Kerr 2006-08-09 01:18:20 UTC
primer on handling SIGINT/SIGQUIT:

http://www.cons.org/cracauer/sigint.html

Looks like the handler could just call g_main_loop_exit in pan.cc
and existing code would handle everything else...
Comment 2 Charles Kerr 2006-08-09 02:52:28 UTC
Created attachment 70521 [details] [review]
first draft

Søren, how does this patch look to you?  Is it really this simple? :)
Comment 3 Christophe Lambin 2006-08-09 06:18:01 UTC
*** Bug 120763 has been marked as a duplicate of this bug. ***
Comment 4 Søren Boll Overgaard 2006-08-09 08:09:12 UTC
The patch looks good to me, although I am not exactly sure how the gtk event loop likes being interrupted and then resumed. According to the signal man page, some weirdness may occur if certain system calls are being executed at the time of the signal.

I will give the patch a spin later tonight, or sometime tomorrow if the wifes guests decide to stick around too long.
Comment 5 Søren Boll Overgaard 2006-08-13 18:45:39 UTC
Having now finally gotten around to testing the patch, it works as expected.

However, you should probably trap SIGTERM as well as SIGQUIT and SIGINT, since that is what gets sent by default if the process is killed by means of "kill".

Thanks for providing the patch.
Comment 6 Charles Kerr 2006-08-13 22:14:34 UTC
Oops, I saw this comment after rolling the 0.108 binary.
I'll leave this ticket open and get SIGTERM next release.
Comment 7 Charles Kerr 2006-08-15 14:51:57 UTC
Doing a little more digging, IMO 0.108 is doing the wrong thing for
sigquit and sigterm too.

SIGHUP   Modem carrier has dropped
SIGINT   User changed his mind (Control-C)
SIGQUIT  User wants core image (Control-\)
SIGTERM  General software termination signal

So SIGINT and SIGTERM should probably be handled the same way,
with an orderly shutdown.

SIGQUIT should dump core immediately, which is the default handling,
so we shouldn't be handling it at all.

#120763 suggests that SIGHUP be handled like SIGTERM.
Comment 8 Bevis King 2006-08-15 15:10:21 UTC
If I can just chip in my 2 cents here....  the way I'd read it, SIGHUP can result in a "Are You Sure?" dialog, so could SIGINT although a CONTROL-C tends to indicate the user is really wanting a termination; whereas SIGTERM is a more generic "this host is going down, tidy up as best you can" and should not result in any kind of user dialog.

Hope that helps...

Regards, Bevis.
Comment 9 Charles Kerr 2006-08-15 16:19:22 UTC
looking around a little more, I found this on xchat-discuss, which 
says SIGHUP should be handled with a non-interactive, orderly shutdown:

http://mail.nl.linux.org/xchat-discuss/2002-04/msg00130.html

> > Hello,
> >   I've added a signal handler for SIGHUP to X-Chat. It causes the logfiles
> > to be closed and then reopen (usefull for log rotation).
> > Now, how do I get it in the official X-Chat source?
> > I've attached the patch (its pretty small) and if anyone wishes for a shell
> > script to rotate the logs, just mail me.
> 
> Hmm, this is a bad idea. SIGHUP normal means, the user is logged of.

Only for processes which are children of a login shell. The normal
meaning for daemons is "reread your config files and reopen your
logfiles".

> To close the logfiles is a good idea (i dont know, if xchat does it
> already).
> But catching the SIGHUP and preventing xchat from exit will most times
> cause the effect, that the Xserver is gone away and xchat will
> crash.

What exactly do you think happens when it fails to handle SIGHUP?

Crashing due to an unhandled signal isn't much different from crashing
due to the X server connection being terminated. Actually gtk will
probably handle the latter cleanly and tidy up (not that xchat needs
much tidying).
Comment 10 Charles Kerr 2006-08-15 22:18:35 UTC
I'm thinking of using this in 0.109:

#ifndef G_OS_WIN32
  void sighandler (int signum)
  {
    std::cerr << "shutting down pan." << std::endl;
    signal (signum, SIG_DFL);
    gtk_main_quit ();
  }
#endif // G_OS_WIN32

  void register_shutdown_signals ()
  {
#ifndef G_OS_WIN32
    signal (SIGHUP, sighandler);
    signal (SIGINT, sighandler);
    signal (SIGTERM, sighandler);
#endif // G_OS_WIN32
  }
Comment 11 Charles Kerr 2006-08-18 16:04:14 UTC
This draft fix is included in 0.109.
Comment 12 Charles Kerr 2007-01-23 00:44:16 UTC
*** Bug 352668 has been marked as a duplicate of this bug. ***