From: Eric Gillespie Date: Thu, 11 Dec 2025 17:58:02 +0000 (-0600) Subject: Report failure of 'create --command' command X-Git-Tag: v0.13.1~55^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1f7972c8893ff190ea5786b35e68e8a0ec1fef55;p=thirdparty%2Fsnapper.git Report failure of 'create --command' command When we can't even run a child process at all (system(3) returns -1), throw runtime_error_with_errno without taking the post snapshot. When the child is killed or exits with non-zero status, report that to stderr and exit(EXIT_FAILURE) . --- diff --git a/client/snapper/cmd-create.cc b/client/snapper/cmd-create.cc index 75f67436..65cbaeec 100644 --- a/client/snapper/cmd-create.cc +++ b/client/snapper/cmd-create.cc @@ -21,6 +21,8 @@ */ +#include + #include #include @@ -193,10 +195,22 @@ namespace snapper case CreateType::PRE_POST: { snapshot1 = snapper->createPreSnapshot(scd, report); - system(command.c_str()); + int const status = system(command.c_str()); + if (status == -1) { + throw runtime_error_with_errno("open 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) { + // TODO(epg): Can we have snapper itself exit with this status? + SN_THROW(Exception(sformat("%s exited %d", command.c_str(), exit_status))); + } + } else { + SN_THROW(Exception(sformat("%s killed with %d", command.c_str(), WTERMSIG(status)))); + } } break; } } diff --git a/doc/snapper.xml.in b/doc/snapper.xml.in index 613e07d0..2b4a793c 100644 --- a/doc/snapper.xml.in +++ b/doc/snapper.xml.in @@ -535,7 +535,10 @@ command - Create a pre and post snapshot and run command in between. + Create a pre and post snapshot and run command in between. If snapper is + unable to execute the command at all, it does not take the post snapshot. If the + command exits with a non-zero exit code, snapper takes the post snapshot and exits 1 + to indicate the failure.