]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- coding style 1083/head
authorArvin Schnell <aschnell@suse.de>
Mon, 5 Jan 2026 08:29:47 +0000 (09:29 +0100)
committerArvin Schnell <aschnell@suse.de>
Mon, 5 Jan 2026 08:29:47 +0000 (09:29 +0100)
client/snapper/cmd-create.cc

index 51f9e290a3ee22fa250c12a7d57fbb84405d682b..26e092849d1f0edb0306e2b4d46cf397958fa84a 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) [2011-2015] Novell, Inc.
- * Copyright (c) [2016-2020] SUSE LLC
+ * Copyright (c) [2016-2026] SUSE LLC
  *
  * All Rights Reserved.
  *
@@ -23,7 +23,6 @@
 
 #include <sys/wait.h>
 
-#include <cassert>
 #include <iostream>
 
 #include <client/snapper/cmd.h>
@@ -177,47 +176,58 @@ namespace snapper
 
        switch (type)
        {
-           case CreateType::SINGLE: {
+           case CreateType::SINGLE:
+           {
                snapshot1 = snapper->createSingleSnapshot(parent, scd, report);
                if (print_number)
                    cout << snapshot1->getNum() << endl;
-           } break;
+           }
+           break;
 
-           case CreateType::PRE: {
+           case CreateType::PRE:
+           {
                snapshot1 = snapper->createPreSnapshot(scd, report);
                if (print_number)
                    cout << snapshot1->getNum() << endl;
-           } break;
+           }
+           break;
 
-           case CreateType::POST: {
+           case CreateType::POST:
+           {
                snapshot2 = snapper->createPostSnapshot(snapshot1, scd, report);
                if (print_number)
                    cout << snapshot2->getNum() << endl;
-           } break;
+           }
+           break;
 
-           case CreateType::PRE_POST: {
+           case CreateType::PRE_POST:
+           {
                snapshot1 = snapper->createPreSnapshot(scd, report);
+
                int const status = system(command.c_str());
-               if (status == -1) {
+               if (status == -1)
                    throw runtime_error_with_errno("fork failed", errno);
-               }
+
                snapshot2 = snapper->createPostSnapshot(snapshot1, scd, report);
                if (print_number)
                    cout << snapshot1->getNum() << ".." << snapshot2->getNum() << endl;
+
                if (WIFEXITED(status)) {
                    int const exit_status = WEXITSTATUS(status);
                    if (exit_status != 0) {
                        SN_THROW(CommandException(exit_status));
                    }
                } else if (WIFSIGNALED(status)) {
-                   SN_THROW(Exception(sformat("%s killed with %d", command.c_str(), WTERMSIG(status))));
-               } else {
+                   SN_THROW(Exception(sformat(_("%s killed by signal %d"), command.c_str(), WTERMSIG(status))));
+               } else if (WIFSTOPPED(status)) {
+                   // For system(3), only WIFEXITED or WIFSIGNALED should be possible.
+                   SN_THROW(Exception(sformat(_("%s stopped"), command.c_str())));
+               } else if (WIFCONTINUED(status)) {
                    // For system(3), only WIFEXITED or WIFSIGNALED should be possible.
-                   string error = sformat(_("%s got STOP or CONT signal and may still be running"),
-                                          command.c_str());
-                   SN_THROW(Exception(error));
+                   SN_THROW(Exception(sformat(_("%s continued"), command.c_str())));
                }
-           } break;
+           }
+           break;
        }
     }