X-Git-Url: http://git.tuebingen.mpg.de/?p=dss.git;a=blobdiff_plain;f=dss.c;h=793e9194b1c695fb89d50d3fae5f63703dceeccd;hp=bf30f893fa36fb9749d00ab706311709a9d4a42f;hb=55c90e8e1d56bc2aec456067cdd1789d09f97d74;hpb=17eea857c175123d68e7dffc28134befa4c0aa5f diff --git a/dss.c b/dss.c index bf30f89..793e919 100644 --- a/dss.c +++ b/dss.c @@ -33,6 +33,7 @@ #include "df.h" #include "time.h" #include "snap.h" +#include "ipc.h" /** Command line and config file options. */ static struct gengetopt_args_info conf; @@ -170,7 +171,10 @@ static void dump_dss_config(const char *msg) COMMAND(ls) \ COMMAND(create) \ COMMAND(prune) \ - COMMAND(run) + COMMAND(run) \ + COMMAND(kill) \ + COMMAND(reload) \ + #define COMMAND(x) static int com_ ##x(void); COMMANDS #undef COMMAND @@ -238,6 +242,35 @@ static char *get_config_file_name(void) return config_file; } +static int send_signal(int sig) +{ + pid_t pid; + char *config_file = get_config_file_name(); + int ret = get_dss_pid(config_file, &pid); + + free(config_file); + if (ret < 0) + return ret; + if (conf.dry_run_given) { + dss_msg("%d\n", (int)pid); + return 0; + } + ret = kill(pid, sig); + if (ret < 0) + return -ERRNO_TO_DSS_ERROR(errno); + return 1; +} + +static int com_kill(void) +{ + return send_signal(SIGTERM); +} + +static int com_reload(void) +{ + return send_signal(SIGHUP); +} + static void dss_get_snapshot_list(struct snapshot_list *sl) { get_snapshot_list(sl, conf.unit_interval_arg, conf.num_intervals_arg); @@ -1259,10 +1292,23 @@ static void exit_hook(int exit_code) dss_exec(&pid, conf.exit_hook_arg, argv, fds); } +static void lock_dss_or_die(void) +{ + char *config_file = get_config_file_name(); + int ret = lock_dss(config_file); + + free(config_file); + if (ret < 0) { + DSS_EMERG_LOG("failed to lock: %s\n", dss_strerror(-ret)); + exit(EXIT_FAILURE); + } +} + static int com_run(void) { int ret; + lock_dss_or_die(); if (conf.dry_run_given) { DSS_ERROR_LOG("dry_run not supported by this command\n"); return -E_SYNTAX; @@ -1285,6 +1331,7 @@ static int com_prune(void) struct disk_space ds; const char *why; + lock_dss_or_die(); ret = get_disk_space(".", &ds); if (ret < 0) return ret; @@ -1344,6 +1391,7 @@ static int com_create(void) int ret, status; char **rsync_argv; + lock_dss_or_die(); if (conf.dry_run_given) { int i; char *msg = NULL;