+ int ret;
+ char *config_file;
+ struct stat statbuf;
+ char *old_logfile_arg = NULL;
+ int old_daemon_given = 0;
+
+ if (conf.config_file_given)
+ config_file = dss_strdup(conf.config_file_arg);
+ else {
+ char *home = get_homedir();
+ config_file = make_message("%s/.dssrc", home);
+ free(home);
+ }
+ if (override) { /* SIGHUP */
+ if (conf.logfile_given)
+ old_logfile_arg = dss_strdup(conf.logfile_arg);
+ old_daemon_given = conf.daemon_given;
+ }
+
+ ret = stat(config_file, &statbuf);
+ if (ret && 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 (!ret) {
+ struct cmdline_parser_params params = {
+ .override = override,
+ .initialize = 0,
+ .check_required = 1,
+ .check_ambiguity = 0
+ };
+ cmdline_parser_config_file(config_file, &conf, ¶ms);
+ }
+ ret = check_config();
+ if (ret < 0)
+ goto out;
+ if (override) {
+ /* 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;
+ }
+ }
+ if (conf.logfile_given) {
+ logfile = open_log(conf.logfile_arg);
+ log_welcome(conf.loglevel_arg);
+ }
+ DSS_EMERG_LOG("loglevel: %d\n", conf.loglevel_arg);
+// cmdline_parser_dump(logfile? logfile : stdout, &conf);
+ ret = dss_chdir(conf.dest_dir_arg);
+out:
+ free(config_file);
+ if (ret >= 0)
+ return;
+ DSS_EMERG_LOG("%s\n", dss_strerror(-ret));
+ exit(EXIT_FAILURE);
+}
+
+static void handle_sighup(void)
+{
+ DSS_NOTICE_LOG("SIGHUP\n");
+ parse_config_file(1);
+}
+
+static void handle_signal(void)
+{
+ int sig, ret = next_signal();
+
+ if (ret <= 0)
+ goto out;
+ sig = ret;
+ switch (sig) {
+ case SIGINT:
+ case SIGTERM:
+ restart_rsync_process();
+ kill_process(rsync_pid);
+ kill_process(rm_pid);
+ exit(EXIT_FAILURE);
+ case SIGHUP:
+ handle_sighup();
+ ret = 1;
+ break;
+ case SIGCHLD:
+ ret = handle_sigchld();
+ break;
+ }
+out:
+ if (ret < 0)
+ DSS_ERROR_LOG("%s\n", dss_strerror(-ret));