+ if (backup_script != "") {
+ pid_t pid = fork();
+ if (pid < 0) {
+ fprintf(stderr, "Unable to fork for upload script: %m\n");
+ throw IOException("fork: upload script");
+ }
+ if (pid == 0) {
+ string cmd = backup_script;
+ cmd += " " + file->local_path + " " + file->remote_path;
+ execlp("/bin/sh", "/bin/sh", "-c", cmd.c_str(), NULL);
+ throw IOException("exec failed");
+ }
+
+ int status = 0;
+ waitpid(pid, &status, 0);
+ if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
+ fprintf(stderr, "Warning: error code from upload script: %d\n",
+ status);
+ }
+
+ if (unlink(file->local_path.c_str()) < 0) {
+ fprintf(stderr, "Warning: Deleting temporary file %s: %m\n",
+ file->local_path.c_str());
+ }
+ }