From c939be2d2d8a8b34133d55f54d80f2e5a43a7e18 Mon Sep 17 00:00:00 2001 From: Dan Sumorok Date: Sat, 25 May 2013 10:48:15 -0400 Subject: [PATCH] Removed objective-c from runtool source so it can be built with newer (not from Apple) versions of gcc. --- .../src/MacOSX/{runtool.m => runtool.c} | 54 ++++++++++++++----- BasiliskII/src/Unix/configure.ac | 2 +- BasiliskII/src/Unix/ether_unix.cpp | 4 +- 3 files changed, 45 insertions(+), 15 deletions(-) rename BasiliskII/src/MacOSX/{runtool.m => runtool.c} (68%) diff --git a/BasiliskII/src/MacOSX/runtool.m b/BasiliskII/src/MacOSX/runtool.c similarity index 68% rename from BasiliskII/src/MacOSX/runtool.m rename to BasiliskII/src/MacOSX/runtool.c index b866599c..691a2765 100644 --- a/BasiliskII/src/MacOSX/runtool.m +++ b/BasiliskII/src/MacOSX/runtool.c @@ -40,28 +40,56 @@ #include -FILE * run_tool(const char *ifName); +FILE * run_tool(const char *if_name, const char *tool_name); -FILE * run_tool(const char *ifName) +FILE * run_tool(const char *if_name, const char *tool_name) { OSStatus auth_status; - FILE *fp; + FILE *fp = NULL; char *args[] = {"etherslavetool", NULL, NULL}; int ret; - const char *path; + char path_buffer[256]; AuthorizationFlags auth_flags; AuthorizationRef auth_ref; AuthorizationItem auth_items[1]; AuthorizationRights auth_rights; + CFBundleRef bundle_ref; + CFURLRef url_ref; + CFStringRef path_str; + CFStringRef tool_name_str; - path = [[[NSBundle mainBundle] - pathForResource:@"etherslavetool" ofType: nil] UTF8String]; - - if (path == NULL) { + bundle_ref = CFBundleGetMainBundle(); + if(bundle_ref == NULL) { return NULL; } - args[1] = (char *)ifName; + tool_name_str = CFStringCreateWithCString(NULL, tool_name, + kCFStringEncodingUTF8); + + url_ref = CFBundleCopyResourceURL(bundle_ref, tool_name_str, + NULL, NULL); + + if(url_ref == NULL) { + return NULL; + } + + path_str = CFURLCopyFileSystemPath(url_ref, kCFURLPOSIXPathStyle); + CFRelease(url_ref); + + if(path_str == NULL) { + return NULL; + } + + CFIndex index = CFStringGetLength(path_str); + if(!CFStringGetCString(path_str, path_buffer, sizeof(path_buffer), + kCFStringEncodingUTF8)) { + CFRelease(path_str); + return NULL; + } + CFRelease(path_str); + + args[0] = (char *)tool_name; + args[1] = (char *)if_name; auth_flags = kAuthorizationFlagExtendRights | kAuthorizationFlagInteractionAllowed | @@ -81,18 +109,20 @@ FILE * run_tool(const char *ifName) &auth_ref); if (auth_status != errAuthorizationSuccess) { - fprintf(stderr, "%s: AuthorizationCreate() failed.\n", __func__); + fprintf(stderr, "%s: AuthorizationCreate() failed.\n", + __func__); return NULL; } auth_status = AuthorizationExecuteWithPrivileges(auth_ref, - path, + path_buffer, kAuthorizationFlagDefaults, args + 1, &fp); if (auth_status != errAuthorizationSuccess) { - fprintf(stderr, "%s: AuthorizationExecWithPrivileges() failed.\n", __func__); + fprintf(stderr, "%s: AuthorizationExecWithPrivileges() failed.\n", + __func__); return NULL; } diff --git a/BasiliskII/src/Unix/configure.ac b/BasiliskII/src/Unix/configure.ac index e0608635..e4d862d5 100644 --- a/BasiliskII/src/Unix/configure.ac +++ b/BasiliskII/src/Unix/configure.ac @@ -736,7 +736,7 @@ if [[ "x$WANT_MACOSX_SOUND" = "xyes" ]]; then fi if [[ "x$WANT_MACOSX_ETHERSLAVE" = "xyes" ]]; then - EXTRASYSSRCS="$EXTRASYSSRCS ../MacOSX/runtool.m" + EXTRASYSSRCS="$EXTRASYSSRCS ../MacOSX/runtool.c" LIBS="$LIBS -framework Security" AC_DEFINE(ENABLE_MACOSX_ETHERSLAVE, 1, [Define if supporting "etherslave" network device.]) fi diff --git a/BasiliskII/src/Unix/ether_unix.cpp b/BasiliskII/src/Unix/ether_unix.cpp index 2c030c7b..55c19426 100644 --- a/BasiliskII/src/Unix/ether_unix.cpp +++ b/BasiliskII/src/Unix/ether_unix.cpp @@ -106,7 +106,7 @@ enum { #ifdef ENABLE_MACOSX_ETHERSLAVE extern "C" { - extern FILE * run_tool(const char *if_name); + extern FILE * run_tool(const char *if_name, const char *tool_name); } #endif @@ -1168,7 +1168,7 @@ static bool open_ether_slave(const char *if_name) return false; } - fp = run_tool(if_name); + fp = run_tool(if_name, "etherslavetool"); if (fp == NULL) { snprintf(str, sizeof(str), "Unable to run ether slave helper tool."); WarningAlert(str);