udevruler.c revision bbbe503ec1a5623a5a8abd003f46fdd8c3581054
/*
* udevruler.c - simple udev-rule composer
*
* Reads the udev-db to get all currently known devices and
* scans the sysfs device chain for the choosen device to select attributes
* to compose a rule for the udev.rules file to uniquely name this device.
*
* Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
*
* under the terms of the GNU General Public License as published by the
* Free Software Foundation version 2 of the License.
*
* 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 this program; if not, write to the Free Software Foundation, Inc.,
* 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#include <newt.h>
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <ctype.h>
#include <time.h>
#include <unistd.h>
#include "udev.h"
#include "udev_lib.h"
#include "udev_version.h"
#include "udevdb.h"
#include "logging.h"
#include "list.h"
#ifdef LOG
unsigned char logname[LOGNAME_SIZE];
{
if (!udev_log)
return;
}
#endif
static char *dev_blacklist[] = {
"tty",
"pty",
"zero",
"null",
"kmsg",
"rtc",
"timer",
"full",
"kmem",
"mem",
"random",
"urandom",
"console",
"port",
""
};
struct device {
char devpath[DEVPATH_SIZE];
int config_line;
char config_file[NAME_SIZE];
long config_uptime;
int added;
};
static LIST_HEAD(device_list);
static int device_count;
/* callback for database dump */
{
int i = 0;
while (dev_blacklist[i][0] != '\0') {
goto exit;
i++;
}
printf("error malloc\n");
exit(2);
}
/* sort in lexical order */
break;
}
}
device_count++;
exit:
return 0;
}
/* get all devices from udev database */
static int get_all_devices(void)
{
int retval;
device_count = 0;
retval = udevdb_open_ro();
if (retval != 0) {
printf("unable to open udev database\n");
exit(1);
}
udevdb_exit();
return 0;
}
struct attribute {
int level;
};
static LIST_HEAD(attribute_list);
static int attribute_count;
{
printf("error malloc\n");
exit(2);
}
return 0;
}
{
struct dlist *attributes;
struct sysfs_attribute *attr;
struct sysfs_directory *sysfs_dir;
int len;
int retval = 0;
return -1;
if (attributes == NULL) {
retval = -1;
return 0;
}
if (len == 0)
continue;
/* skip very long attributes */
if (len > 40)
continue;
/* remove trailing newline */
len--;
}
/* skip nonprintable values */
while (len) {
break;
len--;
}
if (len == 0) {
}
}
return 0;
}
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;
int retval = 0;
int level = 0;
attribute_count = 0;
/* get the class dev */
dbg("couldn't get the class device");
return -1;
}
dbg("couldn't get the \"dev\" file");
retval = -1;
goto exit;
}
/* open sysfs class device directory and get all attributes */
dbg("couldn't open class device directory");
retval = -1;
goto exit;
}
level++;
/* get the device link (if parent exists look here) */
if (class_dev_parent != NULL) {
//sysfs_close_class_device(class_dev);
}
/* look the device chain upwards */
/* open sysfs device directory and print all attributes */
}
level++;
if (sysfs_dev_parent == NULL)
break;
//sysfs_close_device(sysfs_dev);
}
exit:
//sysfs_close_class_device(class_dev);
return retval;
}
char roottext[81];
long time_last;
int count_last;
newtInit();
newtCls();
"This program lets you select a device currently present "
"on the system and you may choose the attributes to uniquely "
"name the device with a udev rule.\n"
"No configuration will be changed, it just prints the rule "
"to place in a udev.rules configuration file. The \"%k\" in the "
"NAME key of the printed rule may be replaced by the name the "
"node should have.");
init_logging("udevruler");
/* look for last discovered device */
time_last = 0;
/* skip if more than 16 recent devices */
count_last = 0;
continue;
count_last++;
}
/* add devices up to 10 seconds older than the last one */
if (count_last < 16) {
continue;
}
}
/* add devices not catched by a rule */
continue;
if (dev->config_line != 0)
continue;
}
/* add remaining devices */
continue;
}
newtPushHelpLine(" <Tab>/<Alt-Tab> between elements | Use <Enter> to select a device");
snprintf(roottext, sizeof(roottext), "simple udev rule composer, version %s, (c) 2004 can't sleep team", UDEV_VERSION);
newtDrawRootText(0, 0, roottext);
while (1) {
int i;
int numitems;
char text_rule[80];
break;
continue;
if (dev->config_line > 0)
"The device is handled by a rule in the file '%s', line %i.",
else
newtGridWrappedWindow(grid3, "Select one ore more attributes within one section with the space bar");
while (1) {
char rule[255];
int onelevel;
int skipped;
break;
continue;
rule[0] = '\0';
onelevel = -1;
skipped = 0;
for (i = 0; i < numitems; i++) {
continue;
if (onelevel != -1) {
skipped = 1;
continue;
}
} else {
}
}
if (skipped) {
continue;
}
} else {
if (rule[0] == '\0')
continue;
}
}
}
newtFinished();
return 0;
}