X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=udevruler.c;h=a065591cd18bd6b3a6f36e5083b67f3516c7c94a;hp=b66940e944e08eeab2c559166832428624a56620;hb=f2bd44417bf2c6c99037b430f3f97cfd65a21f76;hpb=b608ade8e4b3df1f2e798dd460ce8ff4e70eb3d9 diff --git a/udevruler.c b/udevruler.c index b66940e94..a065591cd 100644 --- a/udevruler.c +++ b/udevruler.c @@ -77,12 +77,12 @@ struct device { char devpath[DEVPATH_SIZE]; int config_line; char config_file[NAME_SIZE]; - time_t config_time; + long config_uptime; int added; }; -LIST_HEAD(device_list); -int device_count; +static LIST_HEAD(device_list); +static int device_count; /* callback for database dump */ static int add_record(char *path, struct udevice *udev) @@ -106,7 +106,7 @@ static int add_record(char *path, struct udevice *udev) strfieldcpy(dev->devpath, path); dev->config_line = udev->config_line; strfieldcpy(dev->config_file, udev->config_file); - dev->config_time = udev->config_time; + dev->config_uptime = udev->config_uptime; dev->added = 0; /* sort in lexical order */ @@ -149,8 +149,8 @@ struct attribute { char key[NAME_SIZE]; }; -LIST_HEAD(attribute_list); -int attribute_count; +static LIST_HEAD(attribute_list); +static int attribute_count; static int add_attribute(const char *key, int level) { @@ -222,6 +222,7 @@ static int add_all_attributes(const char *path, int level) } } + sysfs_close_directory(sysfs_dir); return 0; } @@ -229,7 +230,6 @@ static int get_all_attributes(char *path) { struct sysfs_class_device *class_dev; struct sysfs_class_device *class_dev_parent; - struct sysfs_attribute *attr; struct sysfs_device *sysfs_dev; struct sysfs_device *sysfs_dev_parent; char key[NAME_SIZE]; @@ -246,16 +246,6 @@ static int get_all_attributes(char *path) return -1; } - /* read the 'dev' file for major/minor*/ - attr = sysfs_get_classdev_attr(class_dev, "dev"); - if (attr == NULL) { - dbg("couldn't get the \"dev\" file"); - retval = -1; - goto exit; - } - - sysfs_close_attribute(attr); - /* open sysfs class device directory and get all attributes */ if (add_all_attributes(class_dev->path, level) != 0) { dbg("couldn't open class device directory"); @@ -266,11 +256,10 @@ static int get_all_attributes(char *path) /* get the device link (if parent exists look here) */ class_dev_parent = sysfs_get_classdev_parent(class_dev); - if (class_dev_parent != NULL) { - //sysfs_close_class_device(class_dev); - class_dev = class_dev_parent; - } - sysfs_dev = sysfs_get_classdev_device(class_dev); + if (class_dev_parent != NULL) + sysfs_dev = sysfs_get_classdev_device(class_dev_parent); + else + sysfs_dev = sysfs_get_classdev_device(class_dev); /* look the device chain upwards */ while (sysfs_dev != NULL) { @@ -290,13 +279,11 @@ static int get_all_attributes(char *path) if (sysfs_dev_parent == NULL) break; - //sysfs_close_device(sysfs_dev); sysfs_dev = sysfs_dev_parent; } - sysfs_close_device(sysfs_dev); exit: - //sysfs_close_class_device(class_dev); + sysfs_close_class_device(class_dev); return retval; } @@ -308,7 +295,7 @@ int main(int argc, char *argv[]) { char roottext[81]; char path[NAME_SIZE]; struct device *dev; - time_t time_last; + long time_last; int count_last; newtInit(); @@ -332,13 +319,13 @@ int main(int argc, char *argv[]) { /* look for last discovered device */ time_last = 0; list_for_each_entry(dev, &device_list, list) - if (dev->config_time > time_last) - time_last = dev->config_time; + if (dev->config_uptime > time_last) + time_last = dev->config_uptime; /* skip if more than 16 recent devices */ count_last = 0; list_for_each_entry(dev, &device_list, list) { - if (dev->config_time < time_last - 10) + if (dev->config_uptime < time_last - 10) continue; count_last++; } @@ -347,7 +334,7 @@ int main(int argc, char *argv[]) { if (count_last < 16) { newtListboxAppendEntry(lbox, "--- last dicovered ---", NULL); list_for_each_entry(dev, &device_list, list) { - if (dev->config_time < time_last - 10) + if (dev->config_uptime < time_last - 10) continue; dbg("%s %i", dev->name, dev->config_line); @@ -403,7 +390,7 @@ int main(int argc, char *argv[]) { int i; int numitems; struct attribute **selattr; - char text_rule[80]; + char text_rule[255]; answer = newtRunForm(form); if (answer == quit)