Bug 260349

Summary: Failure to save current playlist on session shutdown
Product: [Applications] amarok Reporter: Ben Cooksley <bcooksley>
Component: generalAssignee: Amarok Developers <amarok-bugs-dist>
Status: RESOLVED FIXED    
Severity: normal    
Priority: HI    
Version: 2.4-GIT   
Target Milestone: 2.4.0   
Platform: Compiled Sources   
OS: Linux   
Latest Commit: Version Fixed In: 2.4
Sentry Crash Report:

Description Ben Cooksley 2010-12-17 09:51:27 UTC
Version:           unspecified (using Devel) 
OS:                Linux

Amarok fails to save the current playlist successfully on logout, whilst successfully saving it when it is manually Quit. The unsaved playlist is completely lost.

Reproducible: Didn't try
Comment 1 Sergey Ivanov 2011-01-02 18:43:33 UTC
commit d1536e41e8faddac3a07329744abba7b22d2dd74
branch master
Author: Sergey Ivanov <123kash@gmail.com>
Date:   Sun Jan 2 20:42:55 2011 +0300

    Make amarok save current playlist in case of forced application termination (
    logout, Ctr+C in console, etc).
    BUG: 260349

diff --git a/src/main.cpp b/src/main.cpp
index 2e1e43c..a1f64d9 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -23,12 +23,13 @@
 #include <KCmdLineArgs>
 #include <KDebug>
 
+#include <csignal>
+
 //#define AMAROK_USE_DRKONQI
 
 extern AMAROK_EXPORT class KAboutData aboutData; //defined in App.cpp
 extern AMAROK_EXPORT class OcsData ocsData;
 
-
 int main( int argc, char *argv[] )
 {
     //Authors
@@ -256,6 +257,12 @@ int main( int argc, char *argv[] )
         return 0;
     }
 
+    // Rewrite default SIGINT and SIGTERM handlers
+    // to make amarok save current playlists during forced
+    // application termination (logout, Ctr+C in console etc.)
+    signal( SIGINT, &QCoreApplication::exit );
+    signal( SIGTERM, &QCoreApplication::exit );
+
     App app;
     app.setUniqueInstance( startFlag == KUniqueApplication::NonUniqueInstance );
     return app.exec();