summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorGravatar Alexey Yakovenko <wakeroid@gmail.com>2010-01-09 21:07:54 +0100
committerGravatar Alexey Yakovenko <wakeroid@gmail.com>2010-01-09 21:07:54 +0100
commitacc8579e1b8c22ed98a49345b1ba8adb4e0f0d98 (patch)
tree2c6a2476e3a93607a8a8f4d767f564c2285c7e41 /main.c
parentf26c90bb66c1aa0d8ec7ddcffada1edf1a12bf92 (diff)
atexit code (disabled)
Diffstat (limited to 'main.c')
-rw-r--r--main.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/main.c b/main.c
index 28e36abe..a9d47812 100644
--- a/main.c
+++ b/main.c
@@ -360,11 +360,22 @@ player_mainloop (void) {
}
}
+static int sigterm_handled = 0;
+
+void
+atexit_handler (void) {
+ if (!sigterm_handled) {
+ fprintf (stderr, "handling atexit.\n");
+ pl_save (defpl);
+ conf_save ();
+ }
+}
+
void
sigterm_handler (int sig) {
- fprintf (stderr, "got sigterm, saving...\n");
- pl_save (defpl);
- conf_save ();
+ fprintf (stderr, "got sigterm.\n");
+ atexit_handler ();
+ sigterm_handled = 1;
fprintf (stderr, "bye.\n");
exit (0);
}
@@ -517,6 +528,8 @@ main (int argc, char *argv[]) {
messagepump_init (); // required to push messages while handling commandline
plug_load_all (); // required to add files to playlist from commandline
+ //atexit (atexit_handler); // doesn't help on X11 server shutdown anyway
+
// execute server commands in local context
int noloadpl = 0;
if (argc > 1) {
@@ -572,6 +585,7 @@ main (int argc, char *argv[]) {
pl_free ();
conf_free ();
messagepump_free ();
+ sigterm_handled = 1;
fprintf (stderr, "hej-hej!\n");
return 0;
}