]> git.tuebingen.mpg.de Git - dss.git/blobdiff - dss.c
Restart the rsync process if it returned with exit code 13.
[dss.git] / dss.c
diff --git a/dss.c b/dss.c
index b27bdf6604d14f44dfa34d402e1c22f6e37055ae..af1326fd5ad4d7262814d85f3dbdb203c9736fb8 100644 (file)
--- a/dss.c
+++ b/dss.c
@@ -498,6 +498,13 @@ static int handle_rsync_exit(int status)
                goto out;
        }
        es = WEXITSTATUS(status);
+       if (es == 13) { /* Errors with program diagnostics */
+               DSS_WARNING_LOG("rsync process %d returned %d -- restarting\n",
+                       (int)rsync_pid, es);
+               snapshot_creation_status = SCS_RSYNC_NEEDS_RESTART;
+               ret = 1;
+               goto out;
+       }
        if (es != 0 && es != 23 && es != 24) {
                DSS_ERROR_LOG("rsync process %d returned %d\n", (int)rsync_pid, es);
                ret = -E_BAD_EXIT_CODE;
@@ -726,6 +733,9 @@ static void create_rsync_argv(char ***argv, int64_t *num)
 static void free_rsync_argv(char **argv)
 {
        int i;
+
+       if (!argv)
+               return;
        for (i = 0; argv[i]; i++)
                free(argv[i]);
        free(argv);
@@ -751,11 +761,11 @@ static int select_loop(void)
        int ret;
        /* check every 60 seconds for free disk space */
        struct timeval tv;
+       char **rsync_argv = NULL;
 
        for (;;) {
                fd_set rfds;
                int low_disk_space;
-               char **rsync_argv;
                struct timeval now, *tvp;
 
                if (rm_pid)
@@ -801,10 +811,15 @@ static int select_loop(void)
                        continue;
                case SCS_PRE_HOOK_RUNNING:
                        continue;
+               case SCS_RSYNC_NEEDS_RESTART:
+                       ret = create_snapshot(rsync_argv);
+                       if (ret < 0)
+                               goto out;
+                       continue;
                case SCS_PRE_HOOK_SUCCESS:
+                       free_rsync_argv(rsync_argv);
                        create_rsync_argv(&rsync_argv, &current_snapshot_creation_time);
                        ret = create_snapshot(rsync_argv);
-                       free_rsync_argv(rsync_argv);
                        if (ret < 0)
                                goto out;
                        continue;
@@ -826,16 +841,13 @@ out:
 static void exit_hook(int exit_code)
 {
        int fds[3] = {0, 0, 0};
-       char *cmd;
+       char *argv[] = {conf.exit_hook_arg, dss_strerror(-exit_code), NULL};
        pid_t pid;
 
        if (!conf.exit_hook_given)
                return;
-       cmd = make_message("%s %s", conf.exit_hook_arg,
-               dss_strerror(-exit_code));
-       DSS_NOTICE_LOG("executing %s\n", cmd);
-       dss_exec_cmdline_pid(&pid, cmd, fds);
-       free(cmd);
+       DSS_NOTICE_LOG("executing %s %s\n", argv[0], argv[1]);
+       dss_exec(&pid, conf.exit_hook_arg, argv, fds);
 }
 
 static int com_run(void)