tools: Make sure to print an error when lockdown connection fails
diff --git a/tools/idevicebackup.c b/tools/idevicebackup.c
index 2159566..c5315d2 100644
--- a/tools/idevicebackup.c
+++ b/tools/idevicebackup.c
@@ -843,7 +843,8 @@
 		}
 	}
 
-	if (LOCKDOWN_E_SUCCESS != lockdownd_client_new_with_handshake(device, &client, "idevicebackup")) {
+	if (LOCKDOWN_E_SUCCESS != (ldret = lockdownd_client_new_with_handshake(device, &client, "idevicebackup"))) {
+		printf("ERROR: Could not connect to lockdownd, error code %d\n", ldret);
 		idevice_free(device);
 		return -1;
 	}
diff --git a/tools/idevicebackup2.c b/tools/idevicebackup2.c
index 0370139..4fde24f 100644
--- a/tools/idevicebackup2.c
+++ b/tools/idevicebackup2.c
@@ -1499,7 +1499,8 @@
 	}
 
 	lockdownd_client_t lockdown = NULL;
-	if (LOCKDOWN_E_SUCCESS != lockdownd_client_new_with_handshake(device, &lockdown, "idevicebackup2")) {
+	if (LOCKDOWN_E_SUCCESS != (ldret = lockdownd_client_new_with_handshake(device, &lockdown, "idevicebackup2"))) {
+		printf("ERROR: Could not connect to lockdownd, error code %d\n", ldret);
 		idevice_free(device);
 		return -1;
 	}
diff --git a/tools/idevicecrashreport.c b/tools/idevicecrashreport.c
index dbed041..de2edb5 100644
--- a/tools/idevicecrashreport.c
+++ b/tools/idevicecrashreport.c
@@ -369,6 +369,7 @@
 
 	lockdownd_error = lockdownd_client_new_with_handshake(device, &lockdownd, "idevicecrashreport");
 	if (lockdownd_error != LOCKDOWN_E_SUCCESS) {
+		fprintf(stderr, "ERROR: Could not connect to lockdownd, error code %d\n", lockdownd_error);
 		idevice_free(device);
 		return -1;
 	}
diff --git a/tools/idevicedate.c b/tools/idevicedate.c
index e14d587..234a8fe 100644
--- a/tools/idevicedate.c
+++ b/tools/idevicedate.c
@@ -56,6 +56,7 @@
 int main(int argc, char *argv[])
 {
 	lockdownd_client_t client = NULL;
+	lockdownd_error_t ldret = LOCKDOWN_E_UNKNOWN_ERROR;
 	idevice_t device = NULL;
 	idevice_error_t ret = IDEVICE_E_UNKNOWN_ERROR;
 	int i;
@@ -137,7 +138,8 @@
 		return -1;
 	}
 
-	if (LOCKDOWN_E_SUCCESS != lockdownd_client_new_with_handshake(device, &client, "idevicedate")) {
+	if (LOCKDOWN_E_SUCCESS != (ldret = lockdownd_client_new_with_handshake(device, &client, "idevicedate"))) {
+		fprintf(stderr, "ERROR: Could not connect to lockdownd, error code %d\n", ldret);
 		result = -1;
 		goto cleanup;
 	}
diff --git a/tools/idevicedebugserverproxy.c b/tools/idevicedebugserverproxy.c
index baf3cd7..9ccb3c3 100644
--- a/tools/idevicedebugserverproxy.c
+++ b/tools/idevicedebugserverproxy.c
@@ -223,6 +223,7 @@
 int main(int argc, char *argv[])
 {
 	lockdownd_client_t lockdown = NULL;
+	lockdownd_error_t ldret = LOCKDOWN_E_UNKNOWN_ERROR;
 	idevice_t device = NULL;
 	idevice_connection_t connection = NULL;
 	idevice_error_t ret = IDEVICE_E_UNKNOWN_ERROR;
@@ -291,8 +292,8 @@
 		goto leave_cleanup;
 	}
 
-	if (LOCKDOWN_E_SUCCESS != lockdownd_client_new_with_handshake(device, &lockdown, "idevicedebugserverproxy")) {
-		fprintf(stderr, "Could not connect to lockdownd. Exiting.\n");
+	if (LOCKDOWN_E_SUCCESS != (ldret = lockdownd_client_new_with_handshake(device, &lockdown, "idevicedebugserverproxy"))) {
+		fprintf(stderr, "ERROR: Could not connect to lockdownd, error code %d\n", ldret);
 		result = EXIT_FAILURE;
 		goto leave_cleanup;
 	}
diff --git a/tools/idevicediagnostics.c b/tools/idevicediagnostics.c
index 216ebf1..491441d 100644
--- a/tools/idevicediagnostics.c
+++ b/tools/idevicediagnostics.c
@@ -173,9 +173,9 @@
 		goto cleanup;
 	}
 
-	if (LOCKDOWN_E_SUCCESS != lockdownd_client_new_with_handshake(device, &lockdown_client, "idevicediagnostics")) {
+	if (LOCKDOWN_E_SUCCESS != (ret = lockdownd_client_new_with_handshake(device, &lockdown_client, "idevicediagnostics"))) {
 		idevice_free(device);
-		printf("Unable to connect to lockdownd.\n");
+		printf("ERROR: Could not connect to lockdownd, error code %d\n", ret);
 		goto cleanup;
 	}
 
diff --git a/tools/ideviceenterrecovery.c b/tools/ideviceenterrecovery.c
index 444d531..2747923 100644
--- a/tools/ideviceenterrecovery.c
+++ b/tools/ideviceenterrecovery.c
@@ -42,6 +42,7 @@
 int main(int argc, char *argv[])
 {
 	lockdownd_client_t client = NULL;
+	lockdownd_error_t ldret = LOCKDOWN_E_UNKNOWN_ERROR;
 	idevice_t device = NULL;
 	idevice_error_t ret = IDEVICE_E_UNKNOWN_ERROR;
 	int i;
@@ -72,7 +73,8 @@
 		return -1;
 	}
 
-	if (LOCKDOWN_E_SUCCESS != lockdownd_client_new(device, &client, "ideviceenterrecovery")) {
+	if (LOCKDOWN_E_SUCCESS != (ldret = lockdownd_client_new(device, &client, "ideviceenterrecovery"))) {
+		printf("ERROR: Could not connect to lockdownd, error code %d\n", ldret);
 		idevice_free(device);
 		return -1;
 	}
diff --git a/tools/ideviceimagemounter.c b/tools/ideviceimagemounter.c
index 29d25d7..9ce25c9 100644
--- a/tools/ideviceimagemounter.c
+++ b/tools/ideviceimagemounter.c
@@ -138,6 +138,7 @@
 {
 	idevice_t device = NULL;
 	lockdownd_client_t lckd = NULL;
+	lockdownd_error_t ldret = LOCKDOWN_E_UNKNOWN_ERROR;
 	mobile_image_mounter_client_t mim = NULL;
 	afc_client_t afc = NULL;
 	lockdownd_service_descriptor_t service = NULL;
@@ -172,8 +173,8 @@
 		return -1;
 	}
 
-	if (LOCKDOWN_E_SUCCESS != lockdownd_client_new_with_handshake(device, &lckd, "ideviceimagemounter")) {
-		printf("ERROR: could not connect to lockdown. Exiting.\n");
+	if (LOCKDOWN_E_SUCCESS != (ldret = lockdownd_client_new_with_handshake(device, &lckd, "ideviceimagemounter"))) {
+		printf("ERROR: Could not connect to lockdown, error code %d.\n", ldret);
 		goto leave;
 	}
 
diff --git a/tools/ideviceinfo.c b/tools/ideviceinfo.c
index 7b3b924..005023a 100644
--- a/tools/ideviceinfo.c
+++ b/tools/ideviceinfo.c
@@ -103,6 +103,7 @@
 int main(int argc, char *argv[])
 {
 	lockdownd_client_t client = NULL;
+	lockdownd_error_t ldret = LOCKDOWN_E_UNKNOWN_ERROR;
 	idevice_t device = NULL;
 	idevice_error_t ret = IDEVICE_E_UNKNOWN_ERROR;
 	int i;
@@ -179,9 +180,10 @@
 		return -1;
 	}
 
-	if (LOCKDOWN_E_SUCCESS != (simple ?
+	if (LOCKDOWN_E_SUCCESS != (ldret = simple ?
 			lockdownd_client_new(device, &client, "ideviceinfo"):
 			lockdownd_client_new_with_handshake(device, &client, "ideviceinfo"))) {
+		fprintf(stderr, "ERROR: Could not connect to lockdownd, error code %d\n", ldret);
 		idevice_free(device);
 		return -1;
 	}
diff --git a/tools/idevicename.c b/tools/idevicename.c
index 7e4c372..c013edc 100644
--- a/tools/idevicename.c
+++ b/tools/idevicename.c
@@ -87,7 +87,7 @@
 	lockdownd_error_t lerr = lockdownd_client_new_with_handshake(device, &lockdown, "idevicename");
 	if (lerr != LOCKDOWN_E_SUCCESS) {
 		idevice_free(device);
-		fprintf(stderr, "ERROR: lockdown connection failed, lockdown error %d\n", lerr);
+		fprintf(stderr, "ERROR: Could not connect to lockdownd, error code %d\n", lerr);
 		return -1;
 	}
 
diff --git a/tools/idevicepair.c b/tools/idevicepair.c
index 872d44a..d02a258 100644
--- a/tools/idevicepair.c
+++ b/tools/idevicepair.c
@@ -226,7 +226,7 @@
 	lerr = lockdownd_client_new(device, &client, "idevicepair");
 	if (lerr != LOCKDOWN_E_SUCCESS) {
 		idevice_free(device);
-		printf("ERROR: lockdownd_client_new failed with error code %d\n", lerr);
+		printf("ERROR: Could not connect to lockdownd, error code %d\n", lerr);
 		return EXIT_FAILURE;
 	}
 
diff --git a/tools/ideviceprovision.c b/tools/ideviceprovision.c
index 82e929d..2e13e8b 100644
--- a/tools/ideviceprovision.c
+++ b/tools/ideviceprovision.c
@@ -244,6 +244,7 @@
 int main(int argc, char *argv[])
 {
 	lockdownd_client_t client = NULL;
+	lockdownd_error_t ldret = LOCKDOWN_E_UNKNOWN_ERROR;
 	lockdownd_service_descriptor_t service = NULL;
 	idevice_t device = NULL;
 	idevice_error_t ret = IDEVICE_E_UNKNOWN_ERROR;
@@ -377,7 +378,8 @@
 		return -1;
 	}
 
-	if (LOCKDOWN_E_SUCCESS != lockdownd_client_new_with_handshake(device, &client, "ideviceprovision")) {
+	if (LOCKDOWN_E_SUCCESS != (ldret = lockdownd_client_new_with_handshake(device, &client, "ideviceprovision"))) {
+		fprintf(stderr, "ERROR: Could not connect to lockdownd, error code %d\n", ldret);
 		idevice_free(device);
 		return -1;
 	}
diff --git a/tools/idevicescreenshot.c b/tools/idevicescreenshot.c
index 486265e..bc3793a 100644
--- a/tools/idevicescreenshot.c
+++ b/tools/idevicescreenshot.c
@@ -35,6 +35,7 @@
 {
 	idevice_t device = NULL;
 	lockdownd_client_t lckd = NULL;
+	lockdownd_error_t ldret = LOCKDOWN_E_UNKNOWN_ERROR;
 	screenshotr_client_t shotr = NULL;
 	lockdownd_service_descriptor_t service = NULL;
 	int result = -1;
@@ -80,9 +81,9 @@
 		return -1;
 	}
 
-	if (LOCKDOWN_E_SUCCESS != lockdownd_client_new_with_handshake(device, &lckd, NULL)) {
+	if (LOCKDOWN_E_SUCCESS != (ldret = lockdownd_client_new_with_handshake(device, &lckd, NULL))) {
 		idevice_free(device);
-		printf("Exiting.\n");
+		printf("ERROR: Could not connect to lockdownd, error code %d\n", ldret);
 		return -1;
 	}