From 9516887d489a0c0bca9a970fdbb2b3f43c3e5f68 Mon Sep 17 00:00:00 2001 From: Robert Knight Date: Mon, 22 Aug 2011 14:20:26 +0100 Subject: [PATCH] Fix ProcessUtils compilation on Mac * Enable the Security framework * Fix variable names in ProcessUtils::runElevatedMac() --- src/CMakeLists.txt | 8 ++++++++ src/ProcessUtils.cpp | 23 ++++++++++++++--------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4cf9d08..bf7051e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -43,6 +43,14 @@ add_executable(updater main.cpp ) +if(APPLE) + set_target_properties( + updater + PROPERTIES LINK_FLAGS "-framework Security" + ) +endif() + + target_link_libraries(updater updatershared ) diff --git a/src/ProcessUtils.cpp b/src/ProcessUtils.cpp index 824378a..3b351f2 100644 --- a/src/ProcessUtils.cpp +++ b/src/ProcessUtils.cpp @@ -17,6 +17,10 @@ #include #endif +#ifdef PLATFORM_MAC +#include +#endif + int ProcessUtils::runSync(const std::string& executable, const std::list& args) { @@ -163,22 +167,23 @@ void ProcessUtils::runElevatedMac(const std::string& executable, if (status == errAuthorizationSuccess) { - char** args; - args = (char**) malloc(sizeof(char*) * arguments.count() + 1); + char** argv; + argv = (char**) malloc(sizeof(char*) * args.size() + 1); - int i; - for (i = 0; i < arguments.size(); i++) + int i = 0; + for (std::list::const_iterator iter = args.begin(); iter != args.end(); iter++) { - args[i] = strdup(arguments[i].c_str()); + argv[i] = strdup(iter->c_str()); + ++i; } - args[i] = NULL; + argv[i] = NULL; FILE* pipe = NULL; char* tool = strdup(executable.c_str()); status = AuthorizationExecuteWithPrivileges(authorizationRef, tool, - kAuthorizationFlagDefaults, args, &pipe); + kAuthorizationFlagDefaults, argv, &pipe); if (status == errAuthorizationSuccess) { @@ -224,9 +229,9 @@ void ProcessUtils::runElevatedMac(const std::string& executable, // If we want to know more information about what has happened: // http://developer.apple.com/mac/library/documentation/Security/Reference/authorization_ref/Reference/reference.html#//apple_ref/doc/uid/TP30000826-CH4g-CJBEABHG free(tool); - for (i = 0; i < arguments.count(); i++) + for (i = 0; i < args.size(); i++) { - free(args[i]); + free(argv[i]); } } else