From a64fcc3988f75cb4fc2388013c245e5e884bb96f Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Fri, 4 Feb 2022 02:15:56 +0100 Subject: tools: Print meaningful error messages when service startup fails --- tools/idevicebackup.c | 14 ++++++++------ tools/idevicebackup2.c | 2 +- tools/idevicecrashreport.c | 9 +++++++-- tools/idevicediagnostics.c | 9 +++++++-- tools/idevicenotificationproxy.c | 2 +- tools/ideviceprovision.c | 7 ++++--- tools/idevicescreenshot.c | 6 +++--- tools/idevicesetlocation.c | 5 +++-- 8 files changed, 34 insertions(+), 20 deletions(-) (limited to 'tools') diff --git a/tools/idevicebackup.c b/tools/idevicebackup.c index 42f020d..1759f50 100644 --- a/tools/idevicebackup.c +++ b/tools/idevicebackup.c @@ -598,15 +598,15 @@ static void do_post_notification(const char *notification) } } - lockdownd_start_service(client, NP_SERVICE_NAME, &service); - if (service && service->port) { + lockdownd_error_t ldret = lockdownd_start_service(client, NP_SERVICE_NAME, &service); + if (ldret == LOCKDOWN_E_SUCCESS) { np_client_new(device, service, &np); if (np) { np_post_notification(np, notification); np_client_free(np); } } else { - printf("Could not start %s\n", NP_SERVICE_NAME); + printf("Could not start %s: %s\n", NP_SERVICE_NAME, lockdownd_strerror(ldret)); } if (service) { @@ -826,7 +826,7 @@ int main(int argc, char *argv[]) }; np_observe_notifications(np, noties); } else { - printf("ERROR: Could not start service %s.\n", NP_SERVICE_NAME); + printf("ERROR: Could not start service %s: %s\n", NP_SERVICE_NAME, lockdownd_strerror(ldret)); } afc_client_t afc = NULL; @@ -834,9 +834,11 @@ int main(int argc, char *argv[]) /* start AFC, we need this for the lock file */ service->port = 0; service->ssl_enabled = 0; - ldret = lockdownd_start_service(client, "com.apple.afc", &service); + ldret = lockdownd_start_service(client, AFC_SERVICE_NAME, &service); if ((ldret == LOCKDOWN_E_SUCCESS) && service->port) { afc_client_new(device, service, &afc); + } else { + printf("ERROR: Could not start service %s: %s\n", AFC_SERVICE_NAME, lockdownd_strerror(ldret)); } } @@ -1588,7 +1590,7 @@ files_out: if (manifest_path) free(manifest_path); } else { - printf("ERROR: Could not start service %s.\n", MOBILEBACKUP_SERVICE_NAME); + printf("ERROR: Could not start service %s: %s\n", MOBILEBACKUP_SERVICE_NAME, lockdownd_strerror(ldret)); lockdownd_client_free(client); client = NULL; } diff --git a/tools/idevicebackup2.c b/tools/idevicebackup2.c index eff05ee..b024721 100644 --- a/tools/idevicebackup2.c +++ b/tools/idevicebackup2.c @@ -639,7 +639,7 @@ static void do_post_notification(idevice_t device, const char *notification) } lockdownd_error_t ldret = lockdownd_start_service(lockdown, NP_SERVICE_NAME, &service); - if (service && service->port) { + if (ldret == LOCKDOWN_E_SUCCESS) { np_client_new(device, service, &np); if (np) { np_post_notification(np, notification); diff --git a/tools/idevicecrashreport.c b/tools/idevicecrashreport.c index 4d3b686..7df8dd9 100644 --- a/tools/idevicecrashreport.c +++ b/tools/idevicecrashreport.c @@ -47,6 +47,9 @@ #define S_IFSOCK S_IFREG #endif +#define CRASH_REPORT_MOVER_SERVICE "com.apple.crashreportmover" +#define CRASH_REPORT_COPY_MOBILE_SERVICE "com.apple.crashreportcopymobile" + const char* target_directory = NULL; static int extract_raw_crash_reports = 0; static int keep_crash_reports = 0; @@ -422,8 +425,9 @@ int main(int argc, char* argv[]) /* start crash log mover service */ lockdownd_service_descriptor_t service = NULL; - lockdownd_error = lockdownd_start_service(lockdownd, "com.apple.crashreportmover", &service); + lockdownd_error = lockdownd_start_service(lockdownd, CRASH_REPORT_MOVER_SERVICE, &service); if (lockdownd_error != LOCKDOWN_E_SUCCESS) { + fprintf(stderr, "ERROR: Could not start service %s: %s\n", CRASH_REPORT_MOVER_SERVICE, lockdownd_strerror(lockdownd_error)); lockdownd_client_free(lockdownd); idevice_free(device); return -1; @@ -465,8 +469,9 @@ int main(int argc, char* argv[]) return -1; } - lockdownd_error = lockdownd_start_service(lockdownd, "com.apple.crashreportcopymobile", &service); + lockdownd_error = lockdownd_start_service(lockdownd, CRASH_REPORT_COPY_MOBILE_SERVICE, &service); if (lockdownd_error != LOCKDOWN_E_SUCCESS) { + fprintf(stderr, "ERROR: Could not start service %s: %s\n", CRASH_REPORT_COPY_MOBILE_SERVICE, lockdownd_strerror(lockdownd_error)); lockdownd_client_free(lockdownd); idevice_free(device); return -1; diff --git a/tools/idevicediagnostics.c b/tools/idevicediagnostics.c index 0e3e66e..66ed589 100644 --- a/tools/idevicediagnostics.c +++ b/tools/idevicediagnostics.c @@ -213,13 +213,18 @@ int main(int argc, char **argv) /* attempt to use newer diagnostics service available on iOS 5 and later */ ret = lockdownd_start_service(lockdown_client, "com.apple.mobile.diagnostics_relay", &service); - if (ret != LOCKDOWN_E_SUCCESS) { + if (ret == LOCKDOWN_E_INVALID_SERVICE) { /* attempt to use older diagnostics service */ ret = lockdownd_start_service(lockdown_client, "com.apple.iosdiagnostics.relay", &service); } - lockdownd_client_free(lockdown_client); + if (ret != LOCKDOWN_E_SUCCESS) { + idevice_free(device); + printf("ERROR: Could not start diagnostics relay service: %s\n", lockdownd_strerror(ret)); + goto cleanup; + } + result = EXIT_FAILURE; if ((ret == LOCKDOWN_E_SUCCESS) && service && (service->port > 0)) { diff --git a/tools/idevicenotificationproxy.c b/tools/idevicenotificationproxy.c index cfc9260..00bcba8 100644 --- a/tools/idevicenotificationproxy.c +++ b/tools/idevicenotificationproxy.c @@ -250,7 +250,7 @@ int main(int argc, char *argv[]) } } } else { - printf("Could not start notification_proxy service on device.\n"); + printf("ERROR: Could not start service %s: %s\n", NP_SERVICE_NAME, lockdownd_strerror(ret)); } if (service) { diff --git a/tools/ideviceprovision.c b/tools/ideviceprovision.c index 36c69b0..1dee899 100644 --- a/tools/ideviceprovision.c +++ b/tools/ideviceprovision.c @@ -481,8 +481,9 @@ int main(int argc, char *argv[]) } int product_version = ((product_version_major & 0xFF) << 16) | ((product_version_minor & 0xFF) << 8) | (product_version_patch & 0xFF); - if (LOCKDOWN_E_SUCCESS != lockdownd_start_service(client, "com.apple.misagent", &service)) { - fprintf(stderr, "Could not start service \"com.apple.misagent\"\n"); + lockdownd_error_t lerr = lockdownd_start_service(client, MISAGENT_SERVICE_NAME, &service); + if (lerr != LOCKDOWN_E_SUCCESS) { + fprintf(stderr, "Could not start service %s: %s\n", MISAGENT_SERVICE_NAME, lockdownd_strerror(lerr)); lockdownd_client_free(client); idevice_free(device); return -1; @@ -492,7 +493,7 @@ int main(int argc, char *argv[]) misagent_client_t mis = NULL; if (misagent_client_new(device, service, &mis) != MISAGENT_E_SUCCESS) { - fprintf(stderr, "Could not connect to \"com.apple.misagent\" on device\n"); + fprintf(stderr, "Could not connect to %s on device\n", MISAGENT_SERVICE_NAME); if (service) lockdownd_service_descriptor_free(service); lockdownd_client_free(client); diff --git a/tools/idevicescreenshot.c b/tools/idevicescreenshot.c index 62bb4a3..9b1ffa3 100644 --- a/tools/idevicescreenshot.c +++ b/tools/idevicescreenshot.c @@ -110,9 +110,9 @@ int main(int argc, char **argv) return -1; } - lockdownd_start_service(lckd, "com.apple.mobile.screenshotr", &service); + lockdownd_error_t lerr = lockdownd_start_service(lckd, SCREENSHOTR_SERVICE_NAME, &service); lockdownd_client_free(lckd); - if (service && service->port > 0) { + if (lerr == LOCKDOWN_E_SUCCESS) { if (screenshotr_client_new(device, service, &shotr) != SCREENSHOTR_E_SUCCESS) { printf("Could not connect to screenshotr!\n"); } else { @@ -142,7 +142,7 @@ int main(int argc, char **argv) screenshotr_client_free(shotr); } } else { - printf("Could not start screenshotr service! Remember that you have to mount the Developer disk image on your device if you want to use the screenshotr service.\n"); + printf("Could not start screenshotr service: %s\nRemember that you have to mount the Developer disk image on your device if you want to use the screenshotr service.\n", lockdownd_strerror(lerr)); } if (service) diff --git a/tools/idevicesetlocation.c b/tools/idevicesetlocation.c index 412b47c..6237a1a 100644 --- a/tools/idevicesetlocation.c +++ b/tools/idevicesetlocation.c @@ -141,10 +141,11 @@ int main(int argc, char **argv) lockdownd_client_new_with_handshake(device, &lockdown, TOOL_NAME); lockdownd_service_descriptor_t svc = NULL; - if (lockdownd_start_service(lockdown, DT_SIMULATELOCATION_SERVICE, &svc) != LOCKDOWN_E_SUCCESS) { + lockdownd_error_t lerr = lockdownd_start_service(lockdown, DT_SIMULATELOCATION_SERVICE, &svc); + if (lerr != LOCKDOWN_E_SUCCESS) { lockdownd_client_free(lockdown); idevice_free(device); - printf("ERROR: Could not start the simulatelocation service. Make sure a developer disk image is mounted!\n"); + printf("ERROR: Could not start the simulatelocation service: %s\nMake sure a developer disk image is mounted!\n", lockdownd_strerror(lerr)); return -1; } lockdownd_client_free(lockdown); -- cgit v1.1-32-gdbae