From 747cd67fa150e549280274de72627b2801bc0a1e Mon Sep 17 00:00:00 2001 From: Tristan Matthews <tristan.matthews@savoirfairelinux.com> Date: Mon, 16 Jul 2012 17:01:42 -0400 Subject: [PATCH] * #13587: daemon: don't overwrite argv[0] This breaks various system tools' (i.e. pidof, netstat) ability to correctly identify the sflphoned process --- daemon/src/main.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/daemon/src/main.cpp b/daemon/src/main.cpp index 0a6bbe7208..54a7b9b1c7 100644 --- a/daemon/src/main.cpp +++ b/daemon/src/main.cpp @@ -137,7 +137,14 @@ int main(int argc, char *argv []) signal(SIGHUP, signal_handler); signal(SIGTERM, signal_handler); - fileutils::set_program_dir(argv[0]); + // make a copy as we don't want to modify argv[0], copy it to a vector to + // guarantee that memory is correctly managed/exception safe + std::string programName(argv[0]); + std::vector<char> writable(programName.size() + 1); + std::copy(programName.begin(), programName.end(), writable.begin()); + + fileutils::set_program_dir(&*writable.begin()); + print_title(); if (parse_args(argc, argv)) return 0; -- GitLab