Skip to content
This repository
Browse code

Fix DEVNAME property with older libudev versions

The kernel sets the DEVNAME property without the /dev prefix in the uevent
attribute. Mirror that behaviour so that device names are correct with older
libudev versions as well.
  • Loading branch information...
commit a223c3fdbaaf1f9bb3ea8824b45af0a2f7320034 1 parent f3a42df
Martin Pitt authored

Showing 2 changed files with 17 additions and 4 deletions. Show diff stats Hide diff stats

  1. +1 0  NEWS
  2. +16 4 src/umockdev.vala
1  NEWS
@@ -4,6 +4,7 @@
4 4 - preload: Print proper error message instead of assertion when trying to load
5 5 an empty or invalid ioctl record. (issue #8)
6 6 - umockdev-run: Fix --help output to not mention the child program twice.
  7 +- Fix DEVNAME property with older libudev versions.
7 8
8 9 0.2.1 (2013-02-21)
9 10 ------------------
20 src/umockdev.vala
@@ -122,6 +122,13 @@ public class Testbed: GLib.Object {
122 122 {
123 123 var uevent_path = Path.build_filename(this.root_dir, devpath, "uevent");
124 124 string props = "";
  125 + string real_value;
  126 +
  127 + /* the kernel sets DEVNAME without prefix */
  128 + if (name == "DEVNAME" && value.has_prefix("/dev/"))
  129 + real_value = value.substring(5);
  130 + else
  131 + real_value = value;
125 132
126 133 /* read current properties from the uevent file; if name is already set,
127 134 * replace its value with the new one */
@@ -135,7 +142,7 @@ public class Testbed: GLib.Object {
135 142 while ((line = inp.read_line(out len)) != null) {
136 143 if (line.has_prefix(prefix)) {
137 144 existing = true;
138   - props += prefix + value + "\n";
  145 + props += prefix + real_value + "\n";
139 146 } else {
140 147 props += line + "\n";
141 148 }
@@ -144,7 +151,7 @@ public class Testbed: GLib.Object {
144 151
145 152 /* if property name does not yet exist, append it */
146 153 if (!existing)
147   - props += prefix + value + "\n";
  154 + props += prefix + real_value + "\n";
148 155
149 156 /* write it back */
150 157 FileUtils.set_data(uevent_path, props.data);
@@ -252,8 +259,13 @@ public class Testbed: GLib.Object {
252 259
253 260 /* properties; they go into the "uevent" sysfs attribute */
254 261 string props = "";
255   - for (int i = 0; i < properties.length - 1; i += 2)
256   - props += properties[i] + "=" + properties[i+1] + "\n";
  262 + for (int i = 0; i < properties.length - 1; i += 2) {
  263 + /* the kernel sets DEVNAME without prefix */
  264 + if (properties[i] == "DEVNAME" && properties[i+1].has_prefix("/dev/"))
  265 + props += "DEVNAME=" + properties[i+1].substring(5) + "\n";
  266 + else
  267 + props += properties[i] + "=" + properties[i+1] + "\n";
  268 + }
257 269 if (properties.length % 2 != 0)
258 270 warning("add_devicev: Ignoring property key '%s' without value", properties[properties.length-1]);
259 271 this.set_attribute(dev_path, "uevent", props);

0 comments on commit a223c3f

Please sign in to comment.
Something went wrong with that request. Please try again.