chiark / gitweb /
bootchart: parse /etc/os-release rather than system-release
[elogind.git] / src / udev / accelerometer / accelerometer.c
index 4c5e47d0b70f9b683fa7db817a7b1ae28176d924..f50db71a761850c7ed06fa10b98173ff158a74e5 100644 (file)
  *   Timo Rongas <ext-timo.2.rongas@nokia.com>
  *   Lihan Guo <lihan.guo@digia.com>
  *
- * 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
+ * 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.
+ * 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 keymap; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #include <stdio.h>
@@ -122,7 +122,7 @@ string_to_orientation (const char *orientation)
         if (orientation == NULL)
                 return ORIENTATION_UNDEFINED;
         for (i = 0; orientations[i] != NULL; i++) {
-                if (strcmp (orientation, orientations[i]) == 0)
+                if (streq (orientation, orientations[i]))
                         return i;
         }
         return ORIENTATION_UNDEFINED;
@@ -205,8 +205,10 @@ static void test_orientation(struct udev *udev,
 
                 r = read(fd, ev, sizeof(struct input_event) * 64);
 
-                if (r < (int) sizeof(struct input_event))
+                if (r < (int) sizeof(struct input_event)) {
+                        close(fd);
                         return;
+                }
 
                 for (i = 0; i < r / (int) sizeof(struct input_event); i++) {
                         if (got_syn == 1) {
@@ -255,7 +257,6 @@ int main (int argc, char** argv)
 
         char devpath[PATH_MAX];
         char *devnode;
-        const char *id_path;
         struct udev_enumerate *enumerate;
         struct udev_list_entry *list_entry;
 
@@ -277,8 +278,8 @@ int main (int argc, char** argv)
                 switch (option) {
                 case 'd':
                         debug = 1;
-                        if (udev_get_log_priority(udev) < LOG_INFO)
-                                udev_set_log_priority(udev, LOG_INFO);
+                        log_set_max_level(LOG_DEBUG);
+                        udev_set_log_priority(udev, LOG_DEBUG);
                         break;
                 case 'h':
                         help();
@@ -294,26 +295,17 @@ int main (int argc, char** argv)
         }
 
         /* get the device */
-        snprintf(devpath, sizeof(devpath), "%s/%s", udev_get_sys_path(udev), argv[optind]);
+        snprintf(devpath, sizeof(devpath), "/sys/%s", argv[optind]);
         dev = udev_device_new_from_syspath(udev, devpath);
         if (dev == NULL) {
                 fprintf(stderr, "unable to access '%s'\n", devpath);
                 return 1;
         }
 
-        id_path = udev_device_get_property_value(dev, "ID_PATH");
-        if (id_path == NULL) {
-                fprintf (stderr, "unable to get property ID_PATH for '%s'", devpath);
-                return 0;
-        }
-
-        /* Get the children devices and find the devnode
-         * FIXME: use udev_enumerate_add_match_children() instead
-         * when it's available */
+        /* Get the children devices and find the devnode */
         devnode = NULL;
         enumerate = udev_enumerate_new(udev);
-        udev_enumerate_add_match_property(enumerate, "ID_PATH", id_path);
-        udev_enumerate_add_match_subsystem(enumerate, "input");
+        udev_enumerate_add_match_parent(enumerate, dev);
         udev_enumerate_scan_devices(enumerate);
         udev_list_entry_foreach(list_entry, udev_enumerate_get_list_entry(enumerate)) {
                 struct udev_device *device;