From: Steinar H. Gunderson Date: Tue, 16 Apr 2013 17:57:51 +0000 (+0200) Subject: Canonicalize paths, so that we do not need to worry about cwd on re-exec. X-Git-Tag: 1.0.0~95 X-Git-Url: https://git.sesse.net/?p=cubemap;a=commitdiff_plain;h=867275636c6b2526f6626e503e8e72a21776370f Canonicalize paths, so that we do not need to worry about cwd on re-exec. --- diff --git a/main.cpp b/main.cpp index b927237..75c36d8 100644 --- a/main.cpp +++ b/main.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -269,8 +270,22 @@ int main(int argc, char **argv) config_filename = argv[optind++]; } + // Canonicalize argv[0] and config_filename. + char argv0_canon[PATH_MAX]; + char config_filename_canon[PATH_MAX]; + + if (realpath(argv[0], argv0_canon) == NULL) { + log_perror("realpath"); + exit(1); + } + if (realpath(config_filename.c_str(), config_filename_canon) == NULL) { + log_perror("realpath"); + exit(1); + } + + // Now parse the configuration file. Config config; - if (!parse_config(config_filename, &config)) { + if (!parse_config(config_filename_canon, &config)) { exit(1); } if (test_config) { @@ -414,10 +429,10 @@ start: sprintf(buf, "%d", state_fd); for ( ;; ) { - execlp(argv[0], argv[0], config_filename.c_str(), "--state", buf, NULL); + execlp(argv0_canon, argv0_canon, config_filename_canon, "--state", buf, NULL); open_logs(config.log_destinations); log_perror("execlp"); - log(ERROR, "re-exec of %s failed. Waiting 0.2 seconds and trying again...", argv[0]); + log(ERROR, "re-exec of %s failed. Waiting 0.2 seconds and trying again...", argv0_canon); shut_down_logging(); usleep(200000); }