X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=remote.cc;h=a279751ffbd73f010e5d65220fa4b2ae8b2e619f;hb=09533a1615813c343e1244275531f933d9b48ddf;hp=1e77333aa0eadcd1c1143ea6a887d417b0b28b11;hpb=dfb3bcd8cbcc6aa8737deddd332884e23d0e4b22;p=cumulus.git diff --git a/remote.cc b/remote.cc index 1e77333..a279751 100644 --- a/remote.cc +++ b/remote.cc @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -144,7 +145,31 @@ void RemoteStore::transfer_thread() // Transfer the file fprintf(stderr, "Start transfer: %s\n", file->remote_path.c_str()); - // TODO + 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()); + } + } fprintf(stderr, "Finish transfer: %s\n", file->remote_path.c_str()); delete file;