chiark / gitweb /
accelerometer: display short options too
[elogind.git] / src / udev / accelerometer / accelerometer.c
index 32adf277777dcdb38a54295fdcc4a55afb1de12f..9c13d978705f7cf09c2504df87f35d889938e3bd 100644 (file)
 #define LONG(x) ((x)/BITS_PER_LONG)
 #define test_bit(bit, array)    ((array[LONG(bit)] >> OFF(bit)) & 1)
 
-static int debug = 0;
-
-_printf_(6,0)
-static void log_fn(struct udev *udev, int priority,
-                   const char *file, int line, const char *fn,
-                   const char *format, va_list args)
-{
-        if (debug) {
-                fprintf(stderr, "%s: ", fn);
-                vfprintf(stderr, format, args);
-        } else {
-                vsyslog(priority, format, args);
-        }
-}
-
 typedef enum {
         ORIENTATION_UNDEFINED,
         ORIENTATION_NORMAL,
@@ -213,8 +198,8 @@ static void test_orientation(struct udev *udev,
 static void help(void)
 {
         printf("Usage: accelerometer [options] <device path>\n"
-               "  --debug         debug to stderr\n"
-               "  --help          print this help text\n\n");
+               "  -d,--debug         debug to stderr\n"
+               "  -h,--help          print this help text\n\n");
 }
 
 int main (int argc, char** argv)
@@ -233,26 +218,26 @@ int main (int argc, char** argv)
         struct udev_enumerate *enumerate;
         struct udev_list_entry *list_entry;
 
+        log_parse_environment();
+        log_open();
+
         udev = udev_new();
         if (udev == NULL)
                 return 1;
 
-        log_open();
-        udev_set_log_fn(udev, log_fn);
-
         /* CLI argument parsing */
         while (1) {
                 int option;
 
-                option = getopt_long(argc, argv, "dxh", options, NULL);
+                option = getopt_long(argc, argv, "dh", options, NULL);
                 if (option == -1)
                         break;
 
                 switch (option) {
                 case 'd':
-                        debug = 1;
+                        log_set_target(LOG_TARGET_CONSOLE);
                         log_set_max_level(LOG_DEBUG);
-                        udev_set_log_priority(udev, LOG_DEBUG);
+                        log_open();
                         break;
                 case 'h':
                         help();