+
+ if (pid == create_pid) {
+ switch (snapshot_creation_status) {
+ case HS_PRE_RUNNING:
+ ret = handle_pre_create_hook_exit(status);
+ break;
+ case HS_RUNNING:
+ ret = handle_rsync_exit(status);
+ break;
+ case HS_POST_RUNNING:
+ snapshot_creation_status = HS_READY;
+ ret = 1;
+ break;
+ default:
+ DSS_EMERG_LOG(("BUG: create can't die in status %d\n",
+ snapshot_creation_status));
+ return -E_BUG;
+ }
+ create_pid = 0;
+ return ret;
+ }
+ if (pid == remove_pid) {
+ ret = handle_remove_exit(status);
+ if (ret < 0)
+ return ret;
+ return ret;
+ }
+ DSS_EMERG_LOG(("BUG: unknown process %d died\n", (int)pid));
+ return -E_BUG;
+}
+
+static int check_config(void)
+{
+ if (conf.unit_interval_arg <= 0) {
+ DSS_ERROR_LOG(("bad unit interval: %i\n", conf.unit_interval_arg));
+ return -E_INVALID_NUMBER;
+ }
+ DSS_DEBUG_LOG(("unit interval: %i day(s)\n", conf.unit_interval_arg));
+ if (conf.num_intervals_arg <= 0 || conf.num_intervals_arg > 30) {
+ DSS_ERROR_LOG(("bad number of intervals: %i\n",
+ conf.num_intervals_arg));
+ return -E_INVALID_NUMBER;
+ }
+ DSS_DEBUG_LOG(("number of intervals: %i\n", conf.num_intervals_arg));
+ return 1;
+}
+
+/*
+ * Returns < 0 on errors, 0 if no config file is given and > 0 if the config
+ * file was read successfully.
+ */
+static int parse_config_file(bool sighup)
+{
+ int ret, config_file_exists;
+ char *config_file = get_config_file_name();
+ struct stat statbuf;
+ char *old_logfile_arg = NULL;
+ int old_daemon_given = 0;
+
+ if (sighup) {
+ if (conf.logfile_given)
+ old_logfile_arg = dss_strdup(conf.logfile_arg);
+ old_daemon_given = conf.daemon_given;
+ }
+
+ config_file_exists = !stat(config_file, &statbuf);
+ if (!config_file_exists && conf.config_file_given) {
+ ret = -ERRNO_TO_DSS_ERROR(errno);
+ DSS_ERROR_LOG(("failed to stat config file %s\n", config_file));
+ goto out;
+ }
+ if (config_file_exists) {
+ struct cmdline_parser_params params;
+ params.override = sighup;
+ params.initialize = 0;
+ params.check_required = 1;
+ params.check_ambiguity = 0;
+ params.print_errors = 1;
+ if (sighup) { /* invalidate all rsync options */
+ int i;
+
+ for (i = 0; i < conf.rsync_option_given; i++) {
+ free(conf.rsync_option_arg[i]);
+ conf.rsync_option_arg[i] = NULL;
+ }
+ conf.rsync_option_given = 0;
+ }
+ cmdline_parser_config_file(config_file, &conf, ¶ms);
+ }
+ ret = check_config();
+ if (ret < 0)
+ goto out;
+ if (sighup) {
+ /* don't change daemon mode on SIGHUP */
+ conf.daemon_given = old_daemon_given;
+ close_log(logfile);
+ logfile = NULL;
+ if (conf.logfile_given)
+ free(old_logfile_arg);
+ else if (conf.daemon_given) { /* re-use old logfile */
+ conf.logfile_arg = old_logfile_arg;
+ conf.logfile_given = 1;
+ }