]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- improved error handling for systemd services 385/head
authorArvin Schnell <aschnell@suse.de>
Fri, 26 Jan 2018 13:40:09 +0000 (14:40 +0100)
committerArvin Schnell <aschnell@suse.de>
Fri, 26 Jan 2018 13:40:09 +0000 (14:40 +0100)
VERSION
client/systemd-helper.cc
package/snapper.changes

diff --git a/VERSION b/VERSION
index be14282b7fffb9ba95d51c6546ed9816dc8f3ff8..7d8568351b4f8d3809763af69f84d5499ef881d0 100644 (file)
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.5.3
+0.5.4
index b14bbb1c8b8aeb87f84fd0f47e6ede1098b62b35..3638168f57edbfc59bade170ee8742fb26c24b37 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) [2014-2015] Novell, Inc.
- * Copyright (c) 2016 SUSE LLC
+ * Copyright (c) [2016,2018] SUSE LLC
  *
  * All Rights Reserved.
  *
@@ -39,9 +39,36 @@ using namespace snapper;
 using namespace std;
 
 
-void
+// cout and cerr are visible with 'journalctl' and 'systemctl status
+// snapper-<name>.service'.
+
+
+bool
+call_with_error_check(std::function<void()> func)
+{
+    try
+    {
+       func();
+       return true;
+    }
+    catch (const DBus::ErrorException& e)
+    {
+       cerr << error_description(e) << endl;
+       return false;
+    }
+    catch (const DBus::FatalException& e)
+    {
+       cerr << "failure (" << e.what() << ")." << endl;
+       return false;
+    }
+}
+
+
+bool
 timeline(ProxySnappers* snappers, const map<string, string>& userdata)
 {
+    bool ok = true;
+
     map<string, ProxyConfig> configs = snappers->getConfigs();
     for (const map<string, ProxyConfig>::value_type value : configs)
     {
@@ -57,15 +84,25 @@ timeline(ProxySnappers* snappers, const map<string, string>& userdata)
            scd.cleanup = "timeline";
            scd.userdata = userdata;
 
-           snapper->createSingleSnapshot(scd);
+           cout << "running timeline for '" << value.first << "'." << endl;
+
+           if (!call_with_error_check([snapper, scd](){ snapper->createSingleSnapshot(scd); }))
+           {
+               cerr << "timeline for '" << value.first << "' failed." << endl;
+               ok = false;
+           }
        }
     }
+
+    return ok;
 }
 
 
-void
+bool
 cleanup(ProxySnappers* snappers)
 {
+    bool ok = true;
+
     map<string, ProxyConfig> configs = snappers->getConfigs();
     for (const map<string, ProxyConfig>::value_type value : configs)
     {
@@ -76,21 +113,41 @@ cleanup(ProxySnappers* snappers)
        map<string, string>::const_iterator pos1 = raw.find("NUMBER_CLEANUP");
        if (pos1 != raw.end() && pos1->second == "yes")
        {
-           do_cleanup_number(snapper, false);
+           cout << "running number cleanup for '" << value.first << "'." << endl;
+
+           if (!call_with_error_check([snapper](){ do_cleanup_number(snapper, false); }))
+           {
+               cerr << "number cleanup for '" << value.first << "' failed." << endl;
+               ok = false;
+           }
        }
 
        map<string, string>::const_iterator pos2 = raw.find("TIMELINE_CLEANUP");
        if (pos2 != raw.end() && pos2->second == "yes")
        {
-           do_cleanup_timeline(snapper, false);
+           cout << "running timeline cleanup for '" << value.first << "'." << endl;
+
+           if (!call_with_error_check([snapper](){ do_cleanup_timeline(snapper, false); }))
+           {
+               cerr << "timeline cleanup for '" << value.first << "' failed." << endl;
+               ok = false;
+           }
        }
 
        map<string, string>::const_iterator pos3 = raw.find("EMPTY_PRE_POST_CLEANUP");
        if (pos3 != raw.end() && pos3->second == "yes")
        {
-           do_cleanup_empty_pre_post(snapper, false);
+           cout << "running empty-pre-post cleanup for '" << value.first << "'." << endl;
+
+           if (!call_with_error_check([snapper](){ do_cleanup_empty_pre_post(snapper, false); }))
+           {
+               cerr << "empty-pre-post cleanup for " << value.first << " failed." << endl;
+               ok = false;
+           }
        }
     }
+
+    return ok;
 }
 
 
@@ -128,24 +185,24 @@ main(int argc, char** argv)
     if ((opt = opts.find("userdata")) != opts.end())
        userdata = read_userdata(opt->second);
 
-    try
-    {
+    bool ok = true;
+
+    if (!call_with_error_check([do_timeline, do_cleanup, userdata, &ok]() {
+
        ProxySnappers snappers(ProxySnappers::createDbus());
 
        if (do_timeline)
-           timeline(&snappers, userdata);
+           if (!timeline(&snappers, userdata))
+               ok = false;
 
        if (do_cleanup)
-           cleanup(&snappers);
-    }
-    catch (const DBus::ErrorException& e)
-    {
-       cerr << error_description(e) << endl;
-       exit(EXIT_FAILURE);
-    }
-    catch (const DBus::FatalException& e)
+           if (!cleanup(&snappers))
+               ok = false;
+
+    }))
     {
-       cerr << _("Failure") << " (" << e.what() << ")." << endl;
-       exit(EXIT_FAILURE);
+       ok = false;
     }
+
+    exit(ok ? EXIT_SUCCESS : EXIT_FAILURE);
 }
index 306c662556424eabd8eeca530754494c21cad71b..ed7b214380c0a7d29592e6a73e95ea3e1def57c8 100644 (file)
@@ -1,3 +1,10 @@
+-------------------------------------------------------------------
+Fri Jan 26 14:36:20 CET 2018 - aschnell@suse.com
+
+- improved error handling for systemd services
+  (gh#openSUSE/snapper#382)
+- version 0.5.4
+
 -------------------------------------------------------------------
 Wed Jan 10 14:33:11 CET 2018 - aschnell@suse.com
 
@@ -8,7 +15,7 @@ Wed Dec  6 16:49:06 CET 2017 - kukuk@suse.de
 
 - Switched from cron to systemd timers (spec file based
   distributions) (fate#324529)
-- 0.5.3
+- version 0.5.3
 
 -------------------------------------------------------------------
 Thu Nov 23 13:51:45 UTC 2017 - rbrown@suse.com