Fix rsync exit handling in create mode.
[dss.git] / dss.c
diff --git a/dss.c b/dss.c
index 95c4c03ab1c3467aa33507b35f7e57cc81d4aea9..0bc891373bd7e6096063ebc45aa953582433d68c 100644 (file)
--- a/dss.c
+++ b/dss.c
@@ -606,9 +606,18 @@ static int try_to_free_disk_space(void)
                if (next_snapshot_is_due())
                        return 0;
        }
+       /*
+        * Idle and --keep_redundant not given, or low disk space. Look at
+        * existing snapshots.
+        */
        dss_get_snapshot_list(&sl);
        ret = 0;
-       if (!low_disk_space && sl.num_snapshots <= 1)
+       /*
+        * Don't remove anything if there is free space and we have fewer
+        * snapshots than configured, plus one. This way there is always one
+        * snapshot that can be recycled.
+        */
+       if (!low_disk_space && sl.num_snapshots <= 1 << conf.num_intervals_arg)
                goto out;
        why = "outdated";
        victim = find_outdated_snapshot(&sl);
@@ -618,13 +627,13 @@ static int try_to_free_disk_space(void)
        victim = find_redundant_snapshot(&sl);
        if (victim)
                goto remove;
-       /* try harder only if disk space is low */
-       if (!low_disk_space)
-               goto out;
        why = "orphaned";
        victim = find_orphaned_snapshot(&sl);
        if (victim)
                goto remove;
+       /* try harder only if disk space is low */
+       if (!low_disk_space)
+               goto out;
        DSS_WARNING_LOG(("disk space low and nothing obvious to remove\n"));
        victim = find_oldest_removable_snapshot(&sl);
        if (victim)
@@ -853,6 +862,10 @@ static int handle_rsync_exit(int status)
        if (es != 0 && es != 24) {
                DSS_WARNING_LOG(("rsync exit code %d, error count %d\n",
                        es, ++num_consecutive_rsync_errors));
+               if (conf.create_given) {
+                       ret = -E_BAD_EXIT_CODE;
+                       goto out;
+               }
                if (num_consecutive_rsync_errors > conf.max_rsync_errors_arg) {
                        ret = -E_TOO_MANY_RSYNC_ERRORS;
                        snapshot_creation_status = HS_READY;
@@ -1480,12 +1493,6 @@ static int setup_signal_handling(void)
        return install_sighandler(SIGCHLD);
 }
 
-/**
- * The main function of dss.
- *
- * \param argc Usual argument count.
- * \param argv Usual argument vector.
- */
 int main(int argc, char **argv)
 {
        int ret;
@@ -1524,6 +1531,7 @@ int main(int argc, char **argv)
        if (ret < 0)
                goto out;
        ret = call_command_handler();
+       signal_shutdown();
 out:
        if (ret < 0)
                DSS_EMERG_LOG(("%s\n", dss_strerror(-ret)));