summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Hector Martin2009-08-19 01:24:48 +0200
committerGravatar Hector Martin2009-08-19 01:24:48 +0200
commitd23a2142685b943c4a944ae28d6658c4f562e79e (patch)
tree090d7a62f88151daf02bdf4b076b4908f81e7b1e
parentf3cc57a74fa9647565a920ce03889084ca28c6b0 (diff)
downloadusbmuxd-d23a2142685b943c4a944ae28d6658c4f562e79e.tar.gz
usbmuxd-d23a2142685b943c4a944ae28d6658c4f562e79e.tar.bz2
Logging fixes, change default loglevel to LL_WARNING
-rw-r--r--usbmuxd/log.c21
-rw-r--r--usbmuxd/main.c21
-rw-r--r--usbmuxd/usb-linux.c4
3 files changed, 27 insertions, 19 deletions
diff --git a/usbmuxd/log.c b/usbmuxd/log.c
index 4f67e85..2ccb3cc 100644
--- a/usbmuxd/log.c
+++ b/usbmuxd/log.c
@@ -32,7 +32,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 32
33#include "log.h" 33#include "log.h"
34 34
35int log_level = LL_FATAL; 35int log_level = LL_WARNING;
36 36
37int log_syslog = 0; 37int log_syslog = 0;
38 38
@@ -66,17 +66,22 @@ void usbmuxd_log(enum loglevel level, const char *fmt, ...)
66 char *fs; 66 char *fs;
67 struct timeval ts; 67 struct timeval ts;
68 struct tm *tp; 68 struct tm *tp;
69 69
70 gettimeofday(&ts, NULL); 70 gettimeofday(&ts, NULL);
71 tp = localtime(&ts.tv_sec); 71 tp = localtime(&ts.tv_sec);
72 72
73 if(level > log_level) 73 if(level > log_level)
74 return; 74 return;
75 75
76 fs = malloc(20 + strlen(fmt)); 76 fs = malloc(20 + strlen(fmt));
77 strftime(fs, 10, "[%H:%M:%S", tp); 77
78 sprintf(fs+9, ".%03d][%d] %s\n", (int)(ts.tv_usec / 1000), level, fmt); 78 if(log_syslog) {
79 79 sprintf(fs, "[%d] %s\n", level, fmt);
80 } else {
81 strftime(fs, 10, "[%H:%M:%S", tp);
82 sprintf(fs+9, ".%03d][%d] %s\n", (int)(ts.tv_usec / 1000), level, fmt);
83 }
84
80 va_start(ap, fmt); 85 va_start(ap, fmt);
81 if (log_syslog) { 86 if (log_syslog) {
82 vsyslog(level_to_syslog_level(level), fs, ap); 87 vsyslog(level_to_syslog_level(level), fs, ap);
@@ -84,6 +89,6 @@ void usbmuxd_log(enum loglevel level, const char *fmt, ...)
84 vfprintf(stderr, fs, ap); 89 vfprintf(stderr, fs, ap);
85 } 90 }
86 va_end(ap); 91 va_end(ap);
87 92
88 free(fs); 93 free(fs);
89} 94}
diff --git a/usbmuxd/main.c b/usbmuxd/main.c
index 579a21f..ec52ce0 100644
--- a/usbmuxd/main.c
+++ b/usbmuxd/main.c
@@ -235,7 +235,7 @@ static void usage()
235 printf("usage: usbmuxd [options]\n"); 235 printf("usage: usbmuxd [options]\n");
236 printf("\t-h|--help Print this message.\n"); 236 printf("\t-h|--help Print this message.\n");
237 printf("\t-v|--verbose Be verbose (use twice or more to increase).\n"); 237 printf("\t-v|--verbose Be verbose (use twice or more to increase).\n");
238 printf("\t-f|--foreground Do not daemonize (implies a verbosity of 4).\n"); 238 printf("\t-f|--foreground Do not daemonize (implies one -v).\n");
239 printf("\t-d|--drop-privileges Drop privileges after startup.\n"); 239 printf("\t-d|--drop-privileges Drop privileges after startup.\n");
240 printf("\t-u|--udev Run in udev operation mode.\n"); 240 printf("\t-u|--udev Run in udev operation mode.\n");
241 printf("\t-x|--exit Tell a running instance to exit.\n"); 241 printf("\t-x|--exit Tell a running instance to exit.\n");
@@ -310,9 +310,10 @@ int main(int argc, char *argv[])
310 argv += optind; 310 argv += optind;
311 311
312 if (!foreground) { 312 if (!foreground) {
313 verbose += LL_WARNING;
313 log_enable_syslog(); 314 log_enable_syslog();
314 } else { 315 } else {
315 verbose += LL_INFO; 316 verbose += LL_NOTICE;
316 } 317 }
317 318
318 /* set log level to specified verbosity */ 319 /* set log level to specified verbosity */
@@ -336,20 +337,22 @@ int main(int argc, char *argv[])
336 if (lock.l_pid && !kill(lock.l_pid, 0)) { 337 if (lock.l_pid && !kill(lock.l_pid, 0)) {
337 usbmuxd_log(LL_NOTICE, "sending signal %d to instance with pid %d", exit_signal, lock.l_pid); 338 usbmuxd_log(LL_NOTICE, "sending signal %d to instance with pid %d", exit_signal, lock.l_pid);
338 if (kill(lock.l_pid, exit_signal) < 0) { 339 if (kill(lock.l_pid, exit_signal) < 0) {
339 usbmuxd_log(LL_ERROR, "Error: could not deliver signal %d to pid %d", exit_signal, lock.l_pid); 340 usbmuxd_log(LL_FATAL, "Error: could not deliver signal %d to pid %d", exit_signal, lock.l_pid);
340 } 341 }
341 res = 0; 342 res = 0;
342 goto terminate; 343 goto terminate;
343 } else { 344 } else {
344 usbmuxd_log(LL_ERROR, "Error: could not determine pid of the other running instance!"); 345 usbmuxd_log(LL_ERROR, "Could not determine pid of the other running instance!");
345 res = -1; 346 res = -1;
346 goto terminate; 347 goto terminate;
347 } 348 }
348 } else { 349 } else {
349 usbmuxd_log(LL_NOTICE,
350 "another instance is already running (pid %d). exiting.", lock.l_pid);
351 if (!opt_udev) { 350 if (!opt_udev) {
351 usbmuxd_log(LL_ERROR, "Another instance is already running (pid %d). exiting.", lock.l_pid);
352 res = -1; 352 res = -1;
353 } else {
354 usbmuxd_log(LL_NOTICE, "Another instance is already running (pid %d). exiting.", lock.l_pid);
355 res = 0;
353 } 356 }
354 goto terminate; 357 goto terminate;
355 } 358 }
@@ -357,7 +360,7 @@ int main(int argc, char *argv[])
357 } 360 }
358 361
359 if (opt_exit) { 362 if (opt_exit) {
360 usbmuxd_log(LL_NOTICE, "no running instance found, none killed. exiting."); 363 usbmuxd_log(LL_NOTICE, "No running instance found, none killed. exiting.");
361 goto terminate; 364 goto terminate;
362 } 365 }
363 366
@@ -392,7 +395,7 @@ int main(int argc, char *argv[])
392 lock.l_start = 0; 395 lock.l_start = 0;
393 lock.l_len = 0; 396 lock.l_len = 0;
394 if (fcntl(fileno(lfd), F_SETLK, &lock) == -1) { 397 if (fcntl(fileno(lfd), F_SETLK, &lock) == -1) {
395 usbmuxd_log(LL_ERROR, "ERROR: lockfile locking failed!"); 398 usbmuxd_log(LL_FATAL, "Lockfile locking failed!");
396 log_disable_syslog(); 399 log_disable_syslog();
397 exit(EXIT_FAILURE); 400 exit(EXIT_FAILURE);
398 } 401 }
@@ -428,9 +431,9 @@ int main(int argc, char *argv[])
428 usb_shutdown(); 431 usb_shutdown();
429 device_shutdown(); 432 device_shutdown();
430 client_shutdown(); 433 client_shutdown();
431terminate:
432 usbmuxd_log(LL_NOTICE, "Shutdown complete"); 434 usbmuxd_log(LL_NOTICE, "Shutdown complete");
433 435
436terminate:
434 log_disable_syslog(); 437 log_disable_syslog();
435 438
436 if(res < 0) 439 if(res < 0)
diff --git a/usbmuxd/usb-linux.c b/usbmuxd/usb-linux.c
index c75764b..a5fc6a0 100644
--- a/usbmuxd/usb-linux.c
+++ b/usbmuxd/usb-linux.c
@@ -103,7 +103,7 @@ static void tx_callback(struct libusb_transfer *xfer)
103 usbmuxd_log(LL_ERROR, "TX transfer timed out for device %d-%d", dev->bus, dev->address); 103 usbmuxd_log(LL_ERROR, "TX transfer timed out for device %d-%d", dev->bus, dev->address);
104 break; 104 break;
105 case LIBUSB_TRANSFER_CANCELLED: 105 case LIBUSB_TRANSFER_CANCELLED:
106 usbmuxd_log(LL_ERROR, "TX transfer cancelled for device %d-%d", dev->bus, dev->address); 106 usbmuxd_log(LL_DEBUG, "Device %d-%d TX transfer cancelled", dev->bus, dev->address);
107 break; 107 break;
108 case LIBUSB_TRANSFER_STALL: 108 case LIBUSB_TRANSFER_STALL:
109 usbmuxd_log(LL_ERROR, "TX transfer stalled for device %d-%d", dev->bus, dev->address); 109 usbmuxd_log(LL_ERROR, "TX transfer stalled for device %d-%d", dev->bus, dev->address);
@@ -174,7 +174,7 @@ static void rx_callback(struct libusb_transfer *xfer)
174 usbmuxd_log(LL_ERROR, "RX transfer timed out for device %d-%d", dev->bus, dev->address); 174 usbmuxd_log(LL_ERROR, "RX transfer timed out for device %d-%d", dev->bus, dev->address);
175 break; 175 break;
176 case LIBUSB_TRANSFER_CANCELLED: 176 case LIBUSB_TRANSFER_CANCELLED:
177 usbmuxd_log(LL_ERROR, "RX transfer cancelled for device %d-%d", dev->bus, dev->address); 177 usbmuxd_log(LL_DEBUG, "Device %d-%d RX transfer cancelled", dev->bus, dev->address);
178 break; 178 break;
179 case LIBUSB_TRANSFER_STALL: 179 case LIBUSB_TRANSFER_STALL:
180 usbmuxd_log(LL_ERROR, "RX transfer stalled for device %d-%d", dev->bus, dev->address); 180 usbmuxd_log(LL_ERROR, "RX transfer stalled for device %d-%d", dev->bus, dev->address);