return -E_BUG;
}
+/* also checks if . is a mountpoint, if --mountpoint was given */
static int change_to_dest_dir(void)
{
+ int ret;
const char *dd = OPT_STRING_VAL(DSS, DEST_DIR);
+ struct stat dot, dotdot;
+
DSS_INFO_LOG(("changing cwd to %s\n", dd));
- return dss_chdir(dd);
+ if (chdir(dd) < 0) {
+ ret = -ERRNO_TO_DSS_ERROR(errno);
+ DSS_ERROR_LOG(("could not change cwd to %s\n", dd));
+ return ret;
+ }
+ if (!OPT_GIVEN(DSS, MOUNTPOINT))
+ return 0;
+ if (stat(".", &dot) < 0) {
+ ret = -ERRNO_TO_DSS_ERROR(errno);
+ DSS_ERROR_LOG(("could not stat .\n"));
+ return ret;
+ }
+ if (stat("..", &dotdot) < 0) {
+ ret = -ERRNO_TO_DSS_ERROR(errno);
+ DSS_ERROR_LOG(("could not stat ..\n"));
+ return ret;
+ }
+ if (dot.st_dev == dotdot.st_dev && dot.st_ino != dotdot.st_ino) {
+ DSS_ERROR_LOG(("mountpoint check failed for %s\n", dd));
+ return -E_MOUNTPOINT;
+ }
+ return 1;
}
static int check_config(const struct lls_command *cmd)
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);
(*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)));
static int com_run(void)
{
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)) {
fd = daemon_init();
daemonized = true;