*/
+#include <sys/wait.h>
+
#include <iostream>
#include <snapper/AppUtil.h>
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;
}
}
<varlistentry>
<term><option>--command</option> <replaceable>command</replaceable></term>
<listitem>
- <para>Create a pre and post snapshot and run command in between.</para>
+ <para>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.</para>
</listitem>
</varlistentry>
<varlistentry>