chiark / gitweb /
trivial cleanups
[elogind.git] / extras / usb_id / usb_id.c
index 4679f94fde9b62ad8ee5671f04b69922dc2789c7..3a7a0ffd496cb61130e85ff504fc9535d2ab8134 100644 (file)
@@ -3,12 +3,20 @@
  *
  * Copyright (c) 2005 SUSE Linux Products GmbH, Germany
  *
- * Author:
- *     Hannes Reinecke <hare@suse.de>
+ * Author: Hannes Reinecke <hare@suse.de>
  *
- *     This program is free software; you can redistribute it and/or modify it
- *     under the terms of the GNU General Public License as published by the
- *     Free Software Foundation version 2 of the License.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 #include <stdio.h>
@@ -21,7 +29,8 @@
 #include <errno.h>
 #include <getopt.h>
 
-#include "../../udev/udev.h"
+#include "libudev.h"
+#include "libudev-private.h"
 
 int debug;
 
@@ -455,8 +464,6 @@ int main(int argc, char **argv)
        };
        struct udev *udev;
        struct udev_device *dev = NULL;
-       char syspath[UTIL_PATH_SIZE];
-       const char *devpath;
        static int export;
        int retval = 0;
 
@@ -464,7 +471,7 @@ int main(int argc, char **argv)
        if (udev == NULL)
                goto exit;
 
-       logging_init("usb_id");
+       udev_log_init("usb_id");
        udev_set_log_fn(udev, log_fn);
 
        while (1) {
@@ -491,29 +498,35 @@ int main(int argc, char **argv)
                        export = 1;
                        break;
                case 'h':
-                       printf("Usage: usb_id [--usb-info] [--num-info] [--export] [--help] <devpath>\n"
+                       printf("Usage: usb_id [--usb-info] [--num-info] [--export] [--help] [<devpath>]\n"
                               "  --usb-info  use usb strings instead\n"
                               "  --num-info  use numerical values\n"
                               "  --export    print values as environment keys\n"
                               "  --help      print this help text\n\n");
-               default:
-                       retval = 1;
                        goto exit;
                }
        }
 
-       devpath = argv[optind];
-       if (devpath == NULL) {
-               fprintf(stderr, "No device specified\n");
-               retval = 1;
-               goto exit;
-       }
-
-       util_strscpyl(syspath, sizeof(syspath), udev_get_sys_path(udev), devpath, NULL);
-       dev = udev_device_new_from_syspath(udev, syspath);
+       dev = udev_device_new_from_environment(udev);
        if (dev == NULL) {
-               err(udev, "unable to access '%s'\n", devpath);
-               return 1;
+               char syspath[UTIL_PATH_SIZE];
+               const char *devpath;
+
+               devpath = argv[optind];
+               if (devpath == NULL) {
+                       fprintf(stderr, "missing device\n");
+                       retval = 1;
+                       goto exit;
+               }
+
+               util_strscpyl(syspath, sizeof(syspath), udev_get_sys_path(udev), devpath, NULL);
+               dev = udev_device_new_from_syspath(udev, syspath);
+               if (dev == NULL) {
+                       err(udev, "unable to access '%s'\n", devpath);
+                       retval = 1;
+                       goto exit;
+                       return 1;
+               }
        }
 
        retval = usb_id(dev);
@@ -558,6 +571,6 @@ int main(int argc, char **argv)
 exit:
        udev_device_unref(dev);
        udev_unref(udev);
-       logging_close();
+       udev_log_close();
        return retval;
 }