]> git.tuebingen.mpg.de Git - dss.git/blobdiff - dss.c
find_orphaned_snapshot(): Improve log message.
[dss.git] / dss.c
diff --git a/dss.c b/dss.c
index d0dab0dc3f688254163d9d138069a48dd77ccd5b..22a350a478bb9d48c67dca9487e15145bb11c8fe 100644 (file)
--- a/dss.c
+++ b/dss.c
@@ -295,6 +295,7 @@ static int send_signal(int sig)
                dss_msg("%d\n", (int)pid);
                return 0;
        }
+       DSS_NOTICE_LOG(("sending signal %d to pid %d\n", sig, (int)pid));
        ret = kill(pid, sig);
        if (ret < 0)
                return -ERRNO_TO_DSS_ERROR(errno);
@@ -515,7 +516,7 @@ static struct snapshot *find_orphaned_snapshot(struct snapshot_list *sl)
        struct snapshot *s;
        int i;
 
-       DSS_DEBUG_LOG(("looking for orphaned snapshots\n"));
+       DSS_DEBUG_LOG(("looking for old incomplete snapshots\n"));
        FOR_EACH_SNAPSHOT(s, i, sl) {
                if (snapshot_is_being_created(s))
                        continue;
@@ -729,6 +730,7 @@ static int try_to_free_disk_space(void)
        if (!low_disk_space)
                goto out;
        DSS_WARNING_LOG(("disk space low and nothing obvious to remove\n"));
+       why = "oldest";
        victim = find_oldest_removable_snapshot(&sl);
        if (victim)
                goto remove;
@@ -1055,9 +1057,15 @@ static int handle_sigchld(void)
 
 static int change_to_dest_dir(void)
 {
+       int ret;
        const char *dd = OPT_STRING_VAL(DSS, DEST_DIR);
+
        DSS_INFO_LOG(("changing cwd to %s\n", dd));
-       return dss_chdir(dd);
+       if (chdir(dd) >= 0)
+               return 1;
+       ret = -ERRNO_TO_DSS_ERROR(errno);
+       DSS_ERROR_LOG(("could not change cwd to %s\n", dd));
+       return ret;
 }
 
 static int check_config(const struct lls_command *cmd)
@@ -1341,6 +1349,7 @@ static void create_rsync_argv(char ***argv, int64_t *num)
        char *logname;
        int i = 0, j, N = OPT_GIVEN(DSS, RSYNC_OPTION);
        struct snapshot_list sl;
+       static bool seeded;
 
        dss_get_snapshot_list(&sl);
        assert(!name_of_reference_snapshot);
@@ -1351,6 +1360,14 @@ static void create_rsync_argv(char ***argv, int64_t *num)
        (*argv)[i++] = dss_strdup("rsync");
        (*argv)[i++] = dss_strdup("-a");
        (*argv)[i++] = dss_strdup("--delete");
+       if (!seeded) {
+               srandom((unsigned)time(NULL)); /* no need to be fancy here */
+               seeded = true;
+       }
+       if (1000 * (random() / (RAND_MAX + 1.0)) < OPT_UINT32_VAL(DSS, CHECKSUM)) {
+               DSS_NOTICE_LOG(("adding --checksum to rsync options\n"));
+               (*argv)[i++] = dss_strdup("--checksum");
+       }
        for (j = 0; j < N; j++)
                (*argv)[i++] = dss_strdup(lls_string_val(j,
                        OPT_RESULT(DSS, RSYNC_OPTION)));
@@ -1510,14 +1527,23 @@ static void lock_dss_or_die(void)
 
 static int com_run(void)
 {
-       int ret;
+       int ret, fd = -1;
+       char *config_file;
+       pid_t pid;
 
        if (OPT_GIVEN(DSS, DRY_RUN)) {
                DSS_ERROR_LOG(("dry run not supported by this command\n"));
                return -E_SYNTAX;
        }
+       config_file = get_config_file_name();
+       ret = get_dss_pid(config_file, &pid);
+       free(config_file);
+       if (ret >= 0) {
+               DSS_ERROR_LOG(("pid %d\n", (int)pid));
+               return -E_ALREADY_RUNNING;
+       }
        if (OPT_GIVEN(RUN, DAEMON)) {
-               daemon_init();
+               fd = daemon_init();
                daemonized = true;
                logfile = open_log(OPT_STRING_VAL(RUN, LOGFILE));
        }
@@ -1526,6 +1552,16 @@ static int com_run(void)
        ret = install_sighandler(SIGHUP);
        if (ret < 0)
                return ret;
+       if (fd >= 0) {
+               ret = write(fd, "\0", 1);
+               if (ret != 1) {
+                       DSS_ERROR_LOG(("write to daemon pipe returned %d\n",
+                               ret));
+                       if (ret < 0)
+                               return -ERRNO_TO_DSS_ERROR(errno);
+                       return -E_BUG;
+               }
+       }
        ret = select_loop();
        if (ret >= 0) /* impossible */
                ret = -E_BUG;
@@ -1662,6 +1698,13 @@ static int com_ls(void)
 }
 EXPORT_CMD_HANDLER(ls);
 
+static int com_configtest(void)
+{
+       printf("Syntax Ok\n");
+       return 0;
+}
+EXPORT_CMD_HANDLER(configtest);
+
 static int setup_signal_handling(void)
 {
        int ret;
@@ -1703,7 +1746,7 @@ static void show_subcommand_summary(void)
        for (i = 1; (cmd = lls_cmd(i, dss_suite)); i++) {
                const char *name = lls_command_name(cmd);
                const char *purpose = lls_purpose(cmd);
-               printf("%-10s%s\n", name, purpose);
+               printf("%-11s%s\n", name, purpose);
        }
        exit(EXIT_SUCCESS);
 }