~ubuntu-branches/debian/sid/umockdev/sid

« back to all changes in this revision

Viewing changes to src/umockdev-record.vala

  • Committer: Package Import Robot
  • Author(s): Martin Pitt
  • Date: 2014-09-01 12:03:28 UTC
  • mfrom: (1.1.28)
  • Revision ID: package-import@ubuntu.com-20140901120328-8h1fjou6oe2j5gao
Tags: 0.8.6-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
165
165
}
166
166
 
167
167
static void
 
168
print_device_attributes(string devpath, string subdir)
 
169
{
 
170
    Dir d;
 
171
    var attr_dir = Path.build_filename(devpath, subdir);
 
172
    try {
 
173
        d = Dir.open(attr_dir);
 
174
    } catch (Error e) {
 
175
        if (subdir == "") {
 
176
            exit_error("Cannot open directory %s: %s", attr_dir, e.message);
 
177
        } else {
 
178
            // we ignore this on subdirs, some might be transient or
 
179
            // inaccessible
 
180
            debug("Cannot open directory %s: %s", attr_dir, e.message);
 
181
        }
 
182
        return;
 
183
    }
 
184
 
 
185
    var attributes = new List<string>();
 
186
    string entry;
 
187
    // filter out the uninteresting attributes, sort the others
 
188
    while ((entry = d.read_name()) != null)
 
189
        if (entry != "subsystem" && entry != "firmware_node" && entry != "uevent")
 
190
            attributes.append(entry);
 
191
        else {
 
192
            // don't look into subdirs which are devices by themselves
 
193
            if (subdir != "")
 
194
                return;
 
195
        }
 
196
    attributes.sort(strcmp);
 
197
 
 
198
    foreach (var attr in attributes) {
 
199
        string attr_path = Path.build_filename(attr_dir, attr);
 
200
        string attr_name = Path.build_filename(subdir, attr);
 
201
        if (FileUtils.test(attr_path, FileTest.IS_SYMLINK)) {
 
202
            try {
 
203
                stdout.printf("L: %s=%s\n", attr_name, FileUtils.read_link(attr_path));
 
204
            } catch (Error e) {
 
205
                exit_error("Cannot read link %s: %s", attr_path, e.message);
 
206
            }
 
207
        } else if (FileUtils.test(attr_path, FileTest.IS_REGULAR)) {
 
208
            uint8[] contents;
 
209
            try {
 
210
                FileUtils.get_data(attr_path, out contents);
 
211
                write_attr(attr_name, contents);
 
212
            } catch (FileError e) {} // some attributes are EACCES, or "no such device", etc.
 
213
        } else if (FileUtils.test(attr_path, FileTest.IS_DIR)) {
 
214
            print_device_attributes(devpath, attr);
 
215
        }
 
216
    }
 
217
}
 
218
 
 
219
static void
168
220
record_device(string dev)
169
221
{
170
222
    debug("recording device %s", dev);
208
260
    }
209
261
 
210
262
    // now append all attributes
211
 
    Dir d;
212
 
    try {
213
 
        d = Dir.open(dev);
214
 
    } catch (Error e) {
215
 
        exit_error("Cannot open directory %s: %s", dev, e.message);
216
 
        return; /* not reached, just to avoid warnings */
217
 
    }
218
 
    var attributes = new List<string>();
219
 
    string entry;
220
 
    // filter out the uninteresting attributes, sort the others
221
 
    while ((entry = d.read_name()) != null)
222
 
        if (entry != "subsystem" && entry != "firmware_node" && entry != "uevent")
223
 
            attributes.append(entry);
224
 
    attributes.sort(strcmp);
225
 
 
226
 
    foreach (var attr in attributes) {
227
 
        string attr_path = Path.build_filename(dev, attr);
228
 
        // only look at files or symlinks
229
 
        if (FileUtils.test(attr_path, FileTest.IS_SYMLINK)) {
230
 
            try {
231
 
                stdout.printf("L: %s=%s\n", attr, FileUtils.read_link(attr_path));
232
 
            } catch (Error e) {
233
 
                exit_error("Cannot read link %s: %s", attr, e.message);
234
 
            }
235
 
        } else if (FileUtils.test(attr_path, FileTest.IS_REGULAR)) {
236
 
            uint8[] contents;
237
 
            try {
238
 
                FileUtils.get_data(attr_path, out contents);
239
 
                write_attr(attr, contents);
240
 
            } catch (FileError e) {} // some attributes are EACCES, or "no such device", etc.
241
 
        }
242
 
    }
243
 
 
 
263
    print_device_attributes(dev, "");
244
264
    stdout.putc('\n');
245
265
}
246
266