Skip to content

Commit

Permalink
mach_error message only if we really have an error
Browse files Browse the repository at this point in the history
  • Loading branch information
albertz committed Sep 17, 2011
1 parent 87f491f commit 66c5b41
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
5 changes: 4 additions & 1 deletion mach_inject/mach_inject.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ void* fixedUpImageFromImage (
ptrdiff_t fixUpOffset);
#endif /* __i386__ */

#include <mach/MACH_ERROR.h>
#define MACH_ERROR(msg, err) { if(err != err_none) mach_error(msg, err); }

/*******************************************************************************
*
* Interface
Expand Down Expand Up @@ -76,7 +79,7 @@ mach_inject(
if( !err ) {
err = task_for_pid( mach_task_self(), targetProcess, &remoteTask );
#if defined(__i386__) || defined(__x86_64__)
mach_error("mach_inject failing..", err);
MACH_ERROR("mach_inject failing..", err);
if (err == 5) fprintf(stderr, "Could not access task for pid %d. You probably need to add user to procmod group\n", targetProcess);
#endif
}
Expand Down
15 changes: 9 additions & 6 deletions mach_inject_bundle_stub/load_bundle.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
#include <mach-o/dyld.h>
#include <dlfcn.h>

#include <mach/MACH_ERROR.h>
#define MACH_ERROR(msg, err) { if(err != err_none) mach_error(msg, err); }

mach_error_t
load_bundle_package(
const char *bundlePackageFileSystemRepresentation )
Expand All @@ -20,7 +23,7 @@ load_bundle_package(
assert( strlen( bundlePackageFileSystemRepresentation ) );

mach_error_t err = err_none;
mach_error("mach error on bundle load", err);
MACH_ERROR("mach error on bundle load", err);

// Morph the FSR into a URL.
CFURLRef bundlePackageURL = NULL;
Expand All @@ -33,7 +36,7 @@ load_bundle_package(
if( bundlePackageURL == NULL )
err = err_load_bundle_url_from_path;
}
mach_error("mach error on bundle load", err);
MACH_ERROR("mach error on bundle load", err);

// Create bundle.
CFBundleRef bundle = NULL;
Expand All @@ -42,7 +45,7 @@ load_bundle_package(
if( bundle == NULL )
err = err_load_bundle_create_bundle;
}
mach_error("mach error on bundle load", err);
MACH_ERROR("mach error on bundle load", err);

// Discover the bundle's executable file.
CFURLRef bundleExecutableURL = NULL;
Expand All @@ -52,7 +55,7 @@ load_bundle_package(
if( bundleExecutableURL == NULL )
err = err_load_bundle_package_executable_url;
}
mach_error("mach error on bundle load", err);
MACH_ERROR("mach error on bundle load", err);

// Morph the executable's URL into an FSR.
char bundleExecutableFileSystemRepresentation[PATH_MAX];
Expand All @@ -67,7 +70,7 @@ load_bundle_package(
err = err_load_bundle_path_from_url;
}
}
mach_error("mach error on bundle load", err);
MACH_ERROR("mach error on bundle load", err);

// Do the real work.
if( !err ) {
Expand All @@ -83,7 +86,7 @@ load_bundle_package(
if( bundlePackageURL )
CFRelease( bundlePackageURL );

mach_error("mach error on bundle load", err);
MACH_ERROR("mach error on bundle load", err);
return err;
}

Expand Down

0 comments on commit 66c5b41

Please sign in to comment.