merged with version 1.5.0

Updated for devices that use japanese
Updated the version to 1.5.1
This commit is contained in:
senthil 2015-04-11 14:18:54 -04:00
parent 3e8a897fbc
commit 02c23792ee

View File

@ -16,7 +16,7 @@
#include <netinet/tcp.h> #include <netinet/tcp.h>
#include "MobileDevice.h" #include "MobileDevice.h"
#define APP_VERSION "1.3.7" #define APP_VERSION "1.5.1"
#define PREP_CMDS_PATH "/tmp/fruitstrap-lldb-prep-cmds-" #define PREP_CMDS_PATH "/tmp/fruitstrap-lldb-prep-cmds-"
#define LLDB_SHELL "lldb -s " PREP_CMDS_PATH #define LLDB_SHELL "lldb -s " PREP_CMDS_PATH
/* /*
@ -61,6 +61,7 @@ const char* lldb_prep_noninteractive_cmds = "\
*/ */
#define LLDB_FRUITSTRAP_MODULE CFSTR("\ #define LLDB_FRUITSTRAP_MODULE CFSTR("\
import lldb\n\ import lldb\n\
import os\n\
import sys\n\ import sys\n\
import shlex\n\ import shlex\n\
\n\ \n\
@ -90,13 +91,14 @@ def connect_command(debugger, command, result, internal_dict):\n\
\n\ \n\
def run_command(debugger, command, result, internal_dict):\n\ def run_command(debugger, command, result, internal_dict):\n\
device_app = internal_dict['fruitstrap_device_app']\n\ device_app = internal_dict['fruitstrap_device_app']\n\
args = command.split('--',1)\n\
error = lldb.SBError()\n\ error = lldb.SBError()\n\
lldb.target.modules[0].SetPlatformFileSpec(lldb.SBFileSpec(device_app))\n\ lldb.target.modules[0].SetPlatformFileSpec(lldb.SBFileSpec(device_app))\n\
lldb.target.Launch(lldb.SBLaunchInfo(shlex.split('{args}')), error)\n\ lldb.target.Launch(lldb.SBLaunchInfo(shlex.split(args[1] and args[1] or '{args}')), error)\n\
lockedstr = ': Locked'\n\ lockedstr = ': Locked'\n\
if lockedstr in str(error):\n\ if lockedstr in str(error):\n\
print('\\nDevice Locked\\n')\n\ print('\\nDevice Locked\\n')\n\
sys.exit({exitcode_error})\n\ os._exit(254)\n\
else:\n\ else:\n\
print(str(error))\n\ print(str(error))\n\
\n\ \n\
@ -106,12 +108,16 @@ def safequit_command(debugger, command, result, internal_dict):\n\
listener.StartListeningForEvents(process.GetBroadcaster(), lldb.SBProcess.eBroadcastBitStateChanged | lldb.SBProcess.eBroadcastBitSTDOUT | lldb.SBProcess.eBroadcastBitSTDERR)\n\ listener.StartListeningForEvents(process.GetBroadcaster(), lldb.SBProcess.eBroadcastBitStateChanged | lldb.SBProcess.eBroadcastBitSTDOUT | lldb.SBProcess.eBroadcastBitSTDERR)\n\
event = lldb.SBEvent()\n\ event = lldb.SBEvent()\n\
while True:\n\ while True:\n\
if listener.WaitForEvent(1, event):\n\ if listener.WaitForEvent(1, event) and lldb.SBProcess.EventIsProcessEvent(event):\n\
state = process.GetStateFromEvent(event)\n\ state = lldb.SBProcess.GetStateFromEvent(event)\n\
else:\n\ else:\n\
state = lldb.eStateInvalid\n\ state = process.GetState()\n\
process.Detach()\n\ \n\
sys.exit(0)\n\ if state == lldb.eStateRunning:\n\
process.Detach()\n\
os._exit(0)\n\
elif state > lldb.eStateRunning:\n\
os._exit(state)\n\
\n\ \n\
def autoexit_command(debugger, command, result, internal_dict):\n\ def autoexit_command(debugger, command, result, internal_dict):\n\
process = lldb.target.process\n\ process = lldb.target.process\n\
@ -119,10 +125,16 @@ def autoexit_command(debugger, command, result, internal_dict):\n\
listener.StartListeningForEvents(process.GetBroadcaster(), lldb.SBProcess.eBroadcastBitStateChanged | lldb.SBProcess.eBroadcastBitSTDOUT | lldb.SBProcess.eBroadcastBitSTDERR)\n\ listener.StartListeningForEvents(process.GetBroadcaster(), lldb.SBProcess.eBroadcastBitStateChanged | lldb.SBProcess.eBroadcastBitSTDOUT | lldb.SBProcess.eBroadcastBitSTDERR)\n\
event = lldb.SBEvent()\n\ event = lldb.SBEvent()\n\
while True:\n\ while True:\n\
if listener.WaitForEvent(1, event):\n\ if listener.WaitForEvent(1, event) and lldb.SBProcess.EventIsProcessEvent(event):\n\
state = process.GetStateFromEvent(event)\n\ state = lldb.SBProcess.GetStateFromEvent(event)\n\
else:\n\ else:\n\
state = lldb.eStateInvalid\n\ state = process.GetState()\n\
\n\
if state == lldb.eStateExited:\n\
os._exit(process.GetExitStatus())\n\
elif state == lldb.eStateStopped:\n\
debugger.HandleCommand('bt')\n\
os._exit({exitcode_app_crash})\n\
\n\ \n\
stdout = process.GetSTDOUT(1024)\n\ stdout = process.GetSTDOUT(1024)\n\
while stdout:\n\ while stdout:\n\
@ -133,14 +145,6 @@ def autoexit_command(debugger, command, result, internal_dict):\n\
while stderr:\n\ while stderr:\n\
sys.stdout.write(stderr)\n\ sys.stdout.write(stderr)\n\
stderr = process.GetSTDERR(1024)\n\ stderr = process.GetSTDERR(1024)\n\
\n\
if lldb.SBProcess.EventIsProcessEvent(event):\n\
if state == lldb.eStateExited:\n\
sys.exit(process.GetExitStatus())\n\
if state == lldb.eStateStopped:\n\
debugger.HandleCommand('frame select')\n\
debugger.HandleCommand('bt')\n\
sys.exit({exitcode_app_crash})\n\
") ")
typedef struct am_device * AMDeviceRef; typedef struct am_device * AMDeviceRef;
@ -164,7 +168,7 @@ char *device_id = NULL;
char *args = NULL; char *args = NULL;
char *list_root = NULL; char *list_root = NULL;
int timeout = 0; int timeout = 0;
int port = 12345; int port = 0; // 0 means "dynamically assigned"
CFStringRef last_path = NULL; CFStringRef last_path = NULL;
service_conn_t gdbfd; service_conn_t gdbfd;
pid_t parent = 0; pid_t parent = 0;
@ -176,8 +180,26 @@ AMDeviceRef best_device_match = NULL;
// Error codes we report on different failures, so scripts can distinguish between user app exit // Error codes we report on different failures, so scripts can distinguish between user app exit
// codes and our exit codes. For non app errors we use codes in reserved 128-255 range. // codes and our exit codes. For non app errors we use codes in reserved 128-255 range.
const int exitcode_error = SIGTERM; const int exitcode_error = 253;
const int exitcode_app_crash = SIGABRT; const int exitcode_app_crash = 254;
void fprintCFSTR(FILE* console, CFStringRef formatString, ...) {
CFStringRef resultString;
CFDataRef data;
va_list argList;
va_start(argList, formatString);
resultString = CFStringCreateWithFormatAndArguments(NULL, NULL,
formatString, argList);
va_end(argList);
data = CFStringCreateExternalRepresentation(NULL, resultString,
kCFStringEncodingUTF8, '?');
if (data != NULL) {
fprintf (console, "%.*s\n\n", (int)CFDataGetLength(data),
CFDataGetBytePtr(data));
CFRelease(data);
}
CFRelease(resultString);
}
Boolean path_exists(CFTypeRef path) { Boolean path_exists(CFTypeRef path) {
if (CFGetTypeID(path) == CFStringGetTypeID()) { if (CFGetTypeID(path) == CFStringGetTypeID()) {
@ -319,13 +341,11 @@ CFStringRef copy_xcode_path_for(CFStringRef subPath, CFStringRef search) {
const CFStringRef get_device_hardware_name(const AMDeviceRef device) { const CFStringRef get_device_hardware_name(const AMDeviceRef device) {
CFStringRef model = AMDeviceCopyValue(device, 0, CFSTR("HardwareModel")); CFStringRef model = AMDeviceCopyValue(device, 0, CFSTR("HardwareModel"));
if (model == NULL) if (model == NULL) {
{ return CFSTR("Unknown Device");
return CFSTR("Unknown Device");
} }
//printf("Device model: %s\n", CFStringGetCStringPtr(model, CFStringGetSystemEncoding()));
//iPod Touch // iPod Touch
GET_FRIENDLY_MODEL_NAME(model, "N45AP", "iPod Touch") GET_FRIENDLY_MODEL_NAME(model, "N45AP", "iPod Touch")
GET_FRIENDLY_MODEL_NAME(model, "N72AP", "iPod Touch 2G") GET_FRIENDLY_MODEL_NAME(model, "N72AP", "iPod Touch 2G")
@ -411,18 +431,10 @@ CFStringRef get_device_full_name(const AMDeviceRef device) {
if (verbose) if (verbose)
{ {
char *devName = MYCFStringCopyUTF8String(device_name); if (device_name != NULL)
printf("Device Name:[%s]\n",devName); fprintCFSTR(stdout, CFSTR("Device Name:[%@]\n"), device_name);
CFShow(device_name); if (model_name != NULL)
printf("\n"); fprintCFSTR(stdout, CFSTR("Model Name:[%@]\n"), model_name);
free(devName);
char *mdlName = MYCFStringCopyUTF8String(model_name);
printf("Model Name:[%s]\n",mdlName);
printf("MM: [%s]\n",CFStringGetCStringPtr(model_name, kCFStringEncodingUTF8));
CFShow(model_name);
printf("\n");
free(mdlName);
} }
if(device_name != NULL && model_name != NULL) if(device_name != NULL && model_name != NULL)
@ -705,8 +717,6 @@ void write_lldb_prep_cmds(AMDeviceRef device, CFURLRef disk_app_url) {
CFMutableStringRef pmodule = CFStringCreateMutableCopy(NULL, 0, LLDB_FRUITSTRAP_MODULE); CFMutableStringRef pmodule = CFStringCreateMutableCopy(NULL, 0, LLDB_FRUITSTRAP_MODULE);
CFRange rangeLLDB = { 0, CFStringGetLength(pmodule) }; CFRange rangeLLDB = { 0, CFStringGetLength(pmodule) };
CFStringRef exitcode_error_str = CFStringCreateWithFormat(NULL, NULL, CFSTR("%d"), exitcode_error);
CFStringFindAndReplace(pmodule, CFSTR("{exitcode_error}"), exitcode_error_str, rangeLLDB, 0);
CFStringRef exitcode_app_crash_str = CFStringCreateWithFormat(NULL, NULL, CFSTR("%d"), exitcode_app_crash); CFStringRef exitcode_app_crash_str = CFStringCreateWithFormat(NULL, NULL, CFSTR("%d"), exitcode_app_crash);
CFStringFindAndReplace(pmodule, CFSTR("{exitcode_app_crash}"), exitcode_app_crash_str, rangeLLDB, 0); CFStringFindAndReplace(pmodule, CFSTR("{exitcode_app_crash}"), exitcode_app_crash_str, rangeLLDB, 0);
rangeLLDB.length = CFStringGetLength(pmodule); rangeLLDB.length = CFStringGetLength(pmodule);
@ -826,27 +836,9 @@ server_callback (CFSocketRef s, CFSocketCallBackType callbackType, CFDataRef add
int res; int res;
if (CFDataGetLength (data) == 0) { if (CFDataGetLength (data) == 0) {
// FIXME: Close the socket // close the socket on which we've got end-of-file, the server_socket.
//shutdown (CFSocketGetNative (lldb_socket), SHUT_RDWR); CFSocketInvalidate(s);
//close (CFSocketGetNative (lldb_socket)); CFRelease(s);
CFSocketInvalidate(lldb_socket);
CFSocketInvalidate(server_socket);
int mypid = getpid();
assert((child != 0) && (child != mypid)); //child should not be here
if ((parent != 0) && (parent == mypid) && (child != 0))
{
if (verbose)
{
printf("Got an empty packet hence killing child (%d) tree\n", child);
}
kill_ptree(child, SIGHUP);
}
if (justlaunch)
//when in justlaunch at times, we get an empty packet at the end.
//Assume everything is ok
exit(0);
else
exit(exitcode_error);
return; return;
} }
res = write (CFSocketGetNative (lldb_socket), CFDataGetBytePtr (data), CFDataGetLength (data)); res = write (CFSocketGetNative (lldb_socket), CFDataGetBytePtr (data), CFDataGetLength (data));
@ -856,8 +848,12 @@ void lldb_callback(CFSocketRef s, CFSocketCallBackType callbackType, CFDataRef a
{ {
//printf ("lldb: %s\n", CFDataGetBytePtr (data)); //printf ("lldb: %s\n", CFDataGetBytePtr (data));
if (CFDataGetLength (data) == 0) if (CFDataGetLength (data) == 0) {
// close the socket on which we've got end-of-file, the lldb_socket.
CFSocketInvalidate(s);
CFRelease(s);
return; return;
}
write (gdbfd, CFDataGetBytePtr (data), CFDataGetLength (data)); write (gdbfd, CFDataGetBytePtr (data), CFDataGetLength (data));
} }
@ -868,21 +864,20 @@ void fdvendor_callback(CFSocketRef s, CFSocketCallBackType callbackType, CFDataR
//PRINT ("callback!\n"); //PRINT ("callback!\n");
lldb_socket = CFSocketCreateWithNative(NULL, socket, kCFSocketDataCallBack, &lldb_callback, NULL); lldb_socket = CFSocketCreateWithNative(NULL, socket, kCFSocketDataCallBack, &lldb_callback, NULL);
int flag = 1;
int res = setsockopt(socket, IPPROTO_TCP, TCP_NODELAY, (char *) &flag, sizeof(flag));
assert(res == 0);
CFRunLoopAddSource(CFRunLoopGetMain(), CFSocketCreateRunLoopSource(NULL, lldb_socket, 0), kCFRunLoopCommonModes); CFRunLoopAddSource(CFRunLoopGetMain(), CFSocketCreateRunLoopSource(NULL, lldb_socket, 0), kCFRunLoopCommonModes);
CFSocketInvalidate(s);
CFRelease(s);
} }
void start_remote_debug_server(AMDeviceRef device) { void start_remote_debug_server(AMDeviceRef device) {
char buf [256];
int res, err, i;
char msg [256];
int chsum, len;
struct stat s;
socklen_t buflen;
struct sockaddr name;
int namelen;
assert(AMDeviceStartService(device, CFSTR("com.apple.debugserver"), &gdbfd, NULL) == 0); int res = AMDeviceStartService(device, CFSTR("com.apple.debugserver"), &gdbfd, NULL);
assert (gdbfd); assert(res == 0);
assert(gdbfd > 0);
/* /*
* The debugserver connection is through a fd handle, while lldb requires a host/port to connect, so create an intermediate * The debugserver connection is through a fd handle, while lldb requires a host/port to connect, so create an intermediate
@ -896,20 +891,24 @@ void start_remote_debug_server(AMDeviceRef device) {
addr4.sin_len = sizeof(addr4); addr4.sin_len = sizeof(addr4);
addr4.sin_family = AF_INET; addr4.sin_family = AF_INET;
addr4.sin_port = htons(port); addr4.sin_port = htons(port);
addr4.sin_addr.s_addr = htonl(INADDR_ANY); addr4.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
CFSocketRef fdvendor = CFSocketCreate(NULL, PF_INET, 0, 0, kCFSocketAcceptCallBack, &fdvendor_callback, NULL); CFSocketRef fdvendor = CFSocketCreate(NULL, PF_INET, 0, 0, kCFSocketAcceptCallBack, &fdvendor_callback, NULL);
int yes = 1; if (port) {
setsockopt(CFSocketGetNative(fdvendor), SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)); int yes = 1;
int flag = 1; setsockopt(CFSocketGetNative(fdvendor), SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes));
res = setsockopt(CFSocketGetNative(fdvendor), IPPROTO_TCP, TCP_NODELAY, (char *) &flag, sizeof(int)); }
assert (res == 0);
CFDataRef address_data = CFDataCreate(NULL, (const UInt8 *)&addr4, sizeof(addr4)); CFDataRef address_data = CFDataCreate(NULL, (const UInt8 *)&addr4, sizeof(addr4));
CFSocketSetAddress(fdvendor, address_data); CFSocketSetAddress(fdvendor, address_data);
CFRelease(address_data); CFRelease(address_data);
socklen_t addrlen = sizeof(addr4);
res = getsockname(CFSocketGetNative(fdvendor),(struct sockaddr *)&addr4,&addrlen);
assert(res == 0);
port = ntohs(addr4.sin_port);
CFRunLoopAddSource(CFRunLoopGetMain(), CFSocketCreateRunLoopSource(NULL, fdvendor, 0), kCFRunLoopCommonModes); CFRunLoopAddSource(CFRunLoopGetMain(), CFSocketCreateRunLoopSource(NULL, fdvendor, 0), kCFRunLoopCommonModes);
} }
@ -995,11 +994,11 @@ void setup_lldb(AMDeviceRef device, CFURLRef url) {
if(AMDeviceGetInterfaceType(device) == 2) if(AMDeviceGetInterfaceType(device) == 2)
{ {
printf("Cannot debug %s over %s.\n", CFStringGetCStringPtr(device_full_name, CFStringGetSystemEncoding()), CFStringGetCStringPtr(device_interface_name, CFStringGetSystemEncoding())); fprintCFSTR(stdout, CFSTR("Cannot debug %@ over %@.\n"), device_full_name, device_interface_name);
exit(0); exit(0);
} }
printf("Starting debug of %s connected through %s...\n", CFStringGetCStringPtr(device_full_name, CFStringGetSystemEncoding()), CFStringGetCStringPtr(device_interface_name, CFStringGetSystemEncoding())); fprintCFSTR(stdout, CFSTR("Starting debug of %@ connected through %@...\n"), device_full_name, device_interface_name);
mount_developer_image(device); // put debugserver on the device mount_developer_image(device); // put debugserver on the device
start_remote_debug_server(device); // start debugserver start_remote_debug_server(device); // start debugserver
@ -1283,6 +1282,40 @@ void list_files(AMDeviceRef device)
} }
} }
int app_exists(AMDeviceRef device)
{
if (bundle_id == NULL) {
printf("Bundle id is not specified\n");
return false;
}
AMDeviceConnect(device);
assert(AMDeviceIsPaired(device));
assert(AMDeviceValidatePairing(device) == 0);
assert(AMDeviceStartSession(device) == 0);
CFStringRef cf_bundle_id = CFStringCreateWithCString(NULL, bundle_id, kCFStringEncodingASCII);
NSArray *a = [NSArray arrayWithObjects:@"CFBundleIdentifier", nil];
NSDictionary *optionsDict = [NSDictionary dictionaryWithObject:a forKey:@"ReturnAttributes"];
CFDictionaryRef options = (CFDictionaryRef)optionsDict;
CFDictionaryRef result = nil;
afc_error_t resultStatus = AMDeviceLookupApplications(device, options, &result);
assert(resultStatus == 0);
CFDictionaryRef app_dict = CFDictionaryGetValue(result, cf_bundle_id);
int appExists = (app_dict == NULL) ? -1 : 0;
CFRelease(cf_bundle_id);
assert(AMDeviceStopSession(device) == 0);
assert(AMDeviceDisconnect(device) == 0);
return appExists;
}
void copy_file_callback(afc_connection* afc_conn_p, const char *name,int file) void copy_file_callback(afc_connection* afc_conn_p, const char *name,int file)
{ {
const char *local_name=name; const char *local_name=name;
@ -1440,7 +1473,8 @@ void handle_device(AMDeviceRef device) {
device_interface_name = get_device_interface_name(device); device_interface_name = get_device_interface_name(device);
if (detect_only) { if (detect_only) {
printf("[....] Found %s connected through %s.\n", CFStringGetCStringPtr(device_full_name, CFStringGetSystemEncoding()), CFStringGetCStringPtr(device_interface_name, CFStringGetSystemEncoding())); fprintCFSTR(stdout, CFSTR("[....] Found %@ connected through %@.\n"), device_full_name, device_interface_name);
//printf("[....] Found %s connected through %s.\n", CFStringGetCStringPtr(device_full_name, CFStringGetSystemEncoding()), CFStringGetCStringPtr(device_interface_name, CFStringGetSystemEncoding()));
found_device = true; found_device = true;
return; return;
} }
@ -1448,7 +1482,7 @@ void handle_device(AMDeviceRef device) {
if(strcmp(device_id, CFStringGetCStringPtr(found_device_id, CFStringGetSystemEncoding())) == 0) { if(strcmp(device_id, CFStringGetCStringPtr(found_device_id, CFStringGetSystemEncoding())) == 0) {
found_device = true; found_device = true;
} else { } else {
printf("Skipping %s.\n", CFStringGetCStringPtr(device_full_name, CFStringGetSystemEncoding())); fprintCFSTR(stdout, CFSTR("Skipping %@.\n"), device_full_name);
return; return;
} }
} else { } else {
@ -1456,7 +1490,7 @@ void handle_device(AMDeviceRef device) {
found_device = true; found_device = true;
} }
printf("[....] Using %s (%s).\n", CFStringGetCStringPtr(device_full_name, CFStringGetSystemEncoding()), CFStringGetCStringPtr(found_device_id, CFStringGetSystemEncoding())); fprintCFSTR(stdout, CFSTR("[....] Using %@ (%@).\n"), device_full_name, found_device_id);
if (command_only) { if (command_only) {
if (strcmp("list", command) == 0) { if (strcmp("list", command) == 0) {
@ -1465,6 +1499,8 @@ void handle_device(AMDeviceRef device) {
upload_file(device); upload_file(device);
} else if (strcmp("download", command) == 0) { } else if (strcmp("download", command) == 0) {
download_tree(device); download_tree(device);
} else if (strcmp("exists", command) == 0) {
exit(app_exists(device));
} }
exit(0); exit(0);
} }
@ -1503,7 +1539,7 @@ void handle_device(AMDeviceRef device) {
if(install) { if(install) {
printf("------ Install phase ------\n"); printf("------ Install phase ------\n");
printf("[ 0%%] Found %s connected through %s, beginning install\n", CFStringGetCStringPtr(device_full_name, CFStringGetSystemEncoding()), CFStringGetCStringPtr(device_interface_name, CFStringGetSystemEncoding())); fprintCFSTR(stdout, CFSTR("[ 0%%] Found %@ connected through %@, beginning install\n"), device_full_name, device_interface_name);
AMDeviceConnect(device); AMDeviceConnect(device);
assert(AMDeviceIsPaired(device)); assert(AMDeviceIsPaired(device));
@ -1638,14 +1674,15 @@ void usage(const char* app) {
" -L, --justlaunch just launch the app and exit lldb\n" " -L, --justlaunch just launch the app and exit lldb\n"
" -v, --verbose enable verbose output\n" " -v, --verbose enable verbose output\n"
" -m, --noinstall directly start debugging without app install (-d not required)\n" " -m, --noinstall directly start debugging without app install (-d not required)\n"
" -p, --port <number> port used for device, default: 12345 \n" " -p, --port <number> port used for device, default: dynamic\n"
" -r, --uninstall uninstall the app before install (do not use with -m; app cache and data are cleared) \n" " -r, --uninstall uninstall the app before install (do not use with -m; app cache and data are cleared) \n"
" -1, --bundle_id <bundle id> specify bundle id for list and upload\n" " -1, --bundle_id <bundle id> specify bundle id for list and upload\n"
" -l, --list list files\n" " -l, --list list files\n"
" -o, --upload <file> upload file\n" " -o, --upload <file> upload file\n"
" -w, --download download app tree\n" " -w, --download download app tree\n"
" -2, --to <target pathname> use together with up/download file/tree. specify target\n" " -2, --to <target pathname> use together with up/download file/tree. specify target\n"
" -V, --version print the executable version \n", " -V, --version print the executable version \n"
" -e, --exists check if the app with given bundle_id is installed or not \n",
app); app);
} }
@ -1675,11 +1712,12 @@ int main(int argc, char *argv[]) {
{ "upload", required_argument, NULL, 'o'}, { "upload", required_argument, NULL, 'o'},
{ "download", optional_argument, NULL, 'w'}, { "download", optional_argument, NULL, 'w'},
{ "to", required_argument, NULL, '2'}, { "to", required_argument, NULL, '2'},
{ "exists", no_argument, NULL, 'e'},
{ NULL, 0, NULL, 0 }, { NULL, 0, NULL, 0 },
}; };
char ch; char ch;
while ((ch = getopt_long(argc, argv, "VmcdvunrILi:b:a:t:g:x:p:1:2:o:l::w::", longopts, NULL)) != -1) while ((ch = getopt_long(argc, argv, "VmcdvunrILei:b:a:t:g:x:p:1:2:o:l::w::", longopts, NULL)) != -1)
{ {
switch (ch) { switch (ch) {
case 'm': case 'm':
@ -1716,7 +1754,6 @@ int main(int argc, char *argv[]) {
case 'L': case 'L':
interactive = false; interactive = false;
justlaunch = true; justlaunch = true;
debug = 1;
break; break;
case 'c': case 'c':
detect_only = true; detect_only = true;
@ -1724,7 +1761,7 @@ int main(int argc, char *argv[]) {
break; break;
case 'V': case 'V':
show_version(); show_version();
return exitcode_error; return 0;
case 'p': case 'p':
port = atoi(optarg); port = atoi(optarg);
break; break;
@ -1752,6 +1789,10 @@ int main(int argc, char *argv[]) {
command = "download"; command = "download";
list_root = optarg; list_root = optarg;
break; break;
case 'e':
command_only = true;
command = "exists";
break;
default: default:
usage(argv[0]); usage(argv[0]);
return exitcode_error; return exitcode_error;
@ -1792,4 +1833,3 @@ int main(int argc, char *argv[]) {
AMDeviceNotificationSubscribe(&device_callback, 0, 0, NULL, &notify); AMDeviceNotificationSubscribe(&device_callback, 0, 0, NULL, &notify);
CFRunLoopRun(); CFRunLoopRun();
} }