Removed objective-c from runtool source so it can be built with

newer (not from Apple) versions of gcc.
This commit is contained in:
Dan Sumorok 2013-05-25 10:48:15 -04:00
parent 531b1d7df4
commit c939be2d2d
3 changed files with 45 additions and 15 deletions

View File

@ -40,28 +40,56 @@
#include <Carbon/Carbon.h>
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;
}

View File

@ -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

View File

@ -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);