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
#include "log.h"
-int log_level = LL_FATAL;
+int log_level = LL_WARNING;
int log_syslog = 0;
@@ -66,17 +66,22 @@ void usbmuxd_log(enum loglevel level, const char *fmt, ...)
char *fs;
struct timeval ts;
struct tm *tp;
-
+
gettimeofday(&ts, NULL);
tp = localtime(&ts.tv_sec);
-
+
if(level > log_level)
return;
-
+
fs = malloc(20 + strlen(fmt));
- strftime(fs, 10, "[%H:%M:%S", tp);
- sprintf(fs+9, ".%03d][%d] %s\n", (int)(ts.tv_usec / 1000), level, fmt);
-
+
+ if(log_syslog) {
+ sprintf(fs, "[%d] %s\n", level, fmt);
+ } else {
+ strftime(fs, 10, "[%H:%M:%S", tp);
+ sprintf(fs+9, ".%03d][%d] %s\n", (int)(ts.tv_usec / 1000), level, fmt);
+ }
+
va_start(ap, fmt);
if (log_syslog) {
vsyslog(level_to_syslog_level(level), fs, ap);
@@ -84,6 +89,6 @@ void usbmuxd_log(enum loglevel level, const char *fmt, ...)
vfprintf(stderr, fs, ap);
}
va_end(ap);
-
+
free(fs);
}
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()
printf("usage: usbmuxd [options]\n");
printf("\t-h|--help Print this message.\n");
printf("\t-v|--verbose Be verbose (use twice or more to increase).\n");
- printf("\t-f|--foreground Do not daemonize (implies a verbosity of 4).\n");
+ printf("\t-f|--foreground Do not daemonize (implies one -v).\n");
printf("\t-d|--drop-privileges Drop privileges after startup.\n");
printf("\t-u|--udev Run in udev operation mode.\n");
printf("\t-x|--exit Tell a running instance to exit.\n");
@@ -310,9 +310,10 @@ int main(int argc, char *argv[])
argv += optind;
if (!foreground) {
+ verbose += LL_WARNING;
log_enable_syslog();
} else {
- verbose += LL_INFO;
+ verbose += LL_NOTICE;
}
/* set log level to specified verbosity */
@@ -336,20 +337,22 @@ int main(int argc, char *argv[])
if (lock.l_pid && !kill(lock.l_pid, 0)) {
usbmuxd_log(LL_NOTICE, "sending signal %d to instance with pid %d", exit_signal, lock.l_pid);
if (kill(lock.l_pid, exit_signal) < 0) {
- usbmuxd_log(LL_ERROR, "Error: could not deliver signal %d to pid %d", exit_signal, lock.l_pid);
+ usbmuxd_log(LL_FATAL, "Error: could not deliver signal %d to pid %d", exit_signal, lock.l_pid);
}
res = 0;
goto terminate;
} else {
- usbmuxd_log(LL_ERROR, "Error: could not determine pid of the other running instance!");
+ usbmuxd_log(LL_ERROR, "Could not determine pid of the other running instance!");
res = -1;
goto terminate;
}
} else {
- usbmuxd_log(LL_NOTICE,
- "another instance is already running (pid %d). exiting.", lock.l_pid);
if (!opt_udev) {
+ usbmuxd_log(LL_ERROR, "Another instance is already running (pid %d). exiting.", lock.l_pid);
res = -1;
+ } else {
+ usbmuxd_log(LL_NOTICE, "Another instance is already running (pid %d). exiting.", lock.l_pid);
+ res = 0;
}
goto terminate;
}
@@ -357,7 +360,7 @@ int main(int argc, char *argv[])
}
if (opt_exit) {
- usbmuxd_log(LL_NOTICE, "no running instance found, none killed. exiting.");
+ usbmuxd_log(LL_NOTICE, "No running instance found, none killed. exiting.");
goto terminate;
}
@@ -392,7 +395,7 @@ int main(int argc, char *argv[])
lock.l_start = 0;
lock.l_len = 0;
if (fcntl(fileno(lfd), F_SETLK, &lock) == -1) {
- usbmuxd_log(LL_ERROR, "ERROR: lockfile locking failed!");
+ usbmuxd_log(LL_FATAL, "Lockfile locking failed!");
log_disable_syslog();
exit(EXIT_FAILURE);
}
@@ -428,9 +431,9 @@ int main(int argc, char *argv[])
usb_shutdown();
device_shutdown();
client_shutdown();
-terminate:
usbmuxd_log(LL_NOTICE, "Shutdown complete");
+terminate:
log_disable_syslog();
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)
usbmuxd_log(LL_ERROR, "TX transfer timed out for device %d-%d", dev->bus, dev->address);
break;
case LIBUSB_TRANSFER_CANCELLED:
- usbmuxd_log(LL_ERROR, "TX transfer cancelled for device %d-%d", dev->bus, dev->address);
+ usbmuxd_log(LL_DEBUG, "Device %d-%d TX transfer cancelled", dev->bus, dev->address);
break;
case LIBUSB_TRANSFER_STALL:
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)
usbmuxd_log(LL_ERROR, "RX transfer timed out for device %d-%d", dev->bus, dev->address);
break;
case LIBUSB_TRANSFER_CANCELLED:
- usbmuxd_log(LL_ERROR, "RX transfer cancelled for device %d-%d", dev->bus, dev->address);
+ usbmuxd_log(LL_DEBUG, "Device %d-%d RX transfer cancelled", dev->bus, dev->address);
break;
case LIBUSB_TRANSFER_STALL:
usbmuxd_log(LL_ERROR, "RX transfer stalled for device %d-%d", dev->bus, dev->address);