chiark / gitweb /
udevinfo: do not replace chars when printing ATTR== matches
[elogind.git] / udevinfo.c
index 3fc40faf143231952f4ae8ac4d57d9346660e542..52d409df88c520a5e6ef844027835269569ff353 100644 (file)
@@ -83,7 +83,6 @@ static void print_all_attributes(const char *devpath, const char *key)
                                continue;
                        }
 
-                       replace_chars(value, ALLOWED_CHARS_INPUT);
                        printf("    %s{%s}==\"%s\"\n", key, dent->d_name, value);
                }
        }
@@ -213,9 +212,6 @@ static int stat_device(const char *name)
        if (stat(name, &statbuf) != 0)
                return -1;
 
-       if (major(statbuf.st_dev) == 0)
-               return -1;
-
        printf("%d %d\n", major(statbuf.st_dev), minor(statbuf.st_dev));
        return 0;
 }
@@ -284,6 +280,7 @@ int udevinfo(int argc, char *argv[], char *envp[])
                                strlcpy(name, &optarg[strlen(udev_root)+1], sizeof(name));
                        else
                                strlcpy(name, optarg, sizeof(name));
+                       remove_trailing_chars(name, '/');
                        dbg("name: %s", name);
                        break;
                case 'p':
@@ -292,6 +289,27 @@ int udevinfo(int argc, char *argv[], char *envp[])
                                strlcpy(path, &optarg[strlen(sysfs_path)], sizeof(path));
                        else
                                strlcpy(path, optarg, sizeof(path));
+                       remove_trailing_chars(path, '/');
+
+                       /* possibly resolve to real devpath */
+                       if (sysfs_resolve_link(path, sizeof(path)) != 0) {
+                               char temp[PATH_SIZE];
+                               char *pos;
+
+                               /* also check if the parent is a link */
+                               strlcpy(temp, path, sizeof(temp));
+                               pos = strrchr(temp, '/');
+                               if (pos != 0) {
+                                       char tail[PATH_SIZE];
+
+                                       strlcpy(tail, pos, sizeof(tail));
+                                       pos[0] = '\0';
+                                       if (sysfs_resolve_link(temp, sizeof(temp)) == 0) {
+                                               strlcpy(path, temp, sizeof(path));
+                                               strlcat(path, tail, sizeof(path));
+                                       }
+                               }
+                       }
                        dbg("path: %s", path);
                        break;
                case 'q':