]> err.no Git - systemd/commitdiff
move code to its own files
authorKay Sievers <kay.sievers@suse.de>
Fri, 22 Jul 2005 16:35:58 +0000 (12:35 -0400)
committerKay Sievers <kay.sievers@suse.de>
Fri, 22 Jul 2005 16:35:58 +0000 (12:35 -0400)
Signed-off-by: Kay Sievers <kay.sievers@suse.de>
25 files changed:
Makefile
extras/usb_id/Makefile
udev.c
udev.h
udev.spec
udev_add.c
udev_config.c
udev_db.c
udev_db.h
udev_device.c [new file with mode: 0644]
udev_event.c [new file with mode: 0644]
udev_remove.c
udev_rules.c
udev_rules.h
udev_rules_parse.c
udev_utils.c
udev_utils.h
udevcontrol.c
udevd.h
udeveventrecorder.c
udevinfo.c
udevinitsend.c
udevsend.c
udevstart.c
udevtest.c

index b740838ace3009a07bcb38202f1e99ca3c34ba9b..881ef85ad60000a883f82cc5896f8ac6aa07e1b0 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -115,34 +115,36 @@ CFLAGS            += -D_GNU_SOURCE
 OPTFLAGS := $(call cc-supports, -Os, -O2)
 
 HEADERS = \
-       udev.h                  \
-       udev_utils.h            \
-       udev_rules.h            \
-       udev_version.h          \
-       udev_db.h               \
-       udev_sysfs.h            \
-       logging.h               \
-       udev_libc_wrapper.h     \
-       udev_selinux.h          \
+       udev.h                          \
+       udev_utils.h                    \
+       udev_rules.h                    \
+       udev_version.h                  \
+       udev_db.h                       \
+       udev_sysfs.h                    \
+       logging.h                       \
+       udev_libc_wrapper.h             \
+       udev_selinux.h                  \
        list.h
 
 SYSFS_OBJS = \
-       libsysfs/sysfs_class.o  \
-       libsysfs/sysfs_device.o \
-       libsysfs/sysfs_dir.o    \
-       libsysfs/sysfs_driver.o \
-       libsysfs/sysfs_utils.o  \
+       libsysfs/sysfs_class.o          \
+       libsysfs/sysfs_device.o         \
+       libsysfs/sysfs_dir.o            \
+       libsysfs/sysfs_driver.o         \
+       libsysfs/sysfs_utils.o          \
        libsysfs/dlist.o
 
 UDEV_OBJS = \
-       udev_utils.o            \
-       udev_config.o           \
-       udev_add.o              \
-       udev_remove.o           \
-       udev_sysfs.o            \
-       udev_db.o               \
-       udev_rules.o            \
-       udev_rules_parse.o      \
+       udev_utils.o                    \
+       udev_event.o                    \
+       udev_device.o                   \
+       udev_config.o                   \
+       udev_add.o                      \
+       udev_remove.o                   \
+       udev_sysfs.o                    \
+       udev_db.o                       \
+       udev_rules.o                    \
+       udev_rules_parse.o              \
        udev_libc_wrapper.o
 
 OBJS = \
@@ -151,7 +153,7 @@ OBJS = \
 
 SYSFS = $(PWD)/libsysfs/sysfs.a
 
-CFLAGS +=      -I$(PWD)/libsysfs/sysfs \
+CFLAGS +=      -I$(PWD)/libsysfs/sysfs \
                -I$(PWD)/libsysfs
 
 ifeq ($(strip $(USE_LOG)),true)
index 4324f95c764ac6527fc2fd56872513cdb95f914c..e319a4fee8886ebe253cf8b18bc4355be5b642a7 100644 (file)
@@ -28,7 +28,7 @@ INSTALL_PROGRAM = ${INSTALL}
 INSTALL_DATA  = ${INSTALL} -m 644
 INSTALL_SCRIPT = ${INSTALL_PROGRAM}
 
-override CFLAGS+=-D_FILE_OFFSET_BITS=64
+CFLAGS+=-D_FILE_OFFSET_BITS=64
 
 OBJS = $(PROG).o $(VOLUME_ID_OBJS) ../../udev.a ../../libsysfs/sysfs.a
 HEADERS =
diff --git a/udev.c b/udev.c
index 6e0f7f1d0c535389c0ff56b1c2cbdc35213f1667..4096b8b3485bdf53dd439bc80e5f0fa506c36160 100644 (file)
--- a/udev.c
+++ b/udev.c
@@ -1,10 +1,8 @@
 /*
  * udev.c
  *
- * Userspace devfs
- *
- * Copyright (C) 2003,2004 Greg Kroah-Hartman <greg@kroah.com>
- * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
+ * Copyright (C) 2003-2004 Greg Kroah-Hartman <greg@kroah.com>
+ * Copyright (C) 2004-2005 Kay Sievers <kay.sievers@vrfy.org>
  *
  *     This program is free software; you can redistribute it and/or modify it
  *     under the terms of the GNU General Public License as published by the
@@ -69,8 +67,6 @@ int main(int argc, char *argv[], char *envp[])
 {
        struct udevice udev;
        struct udev_rules rules;
-       char path[PATH_SIZE];
-       const char *error;
        const char *action;
        const char *devpath;
        const char *subsystem;
@@ -121,98 +117,9 @@ int main(int argc, char *argv[], char *envp[])
        udev_init_device(&udev, devpath, subsystem, action);
        udev_rules_init(&rules, 0);
 
-       if (udev.type == DEV_BLOCK || udev.type == DEV_CLASS || udev.type == DEV_NET) {
-               /* handle device node */
-               if (strcmp(action, "add") == 0) {
-                       struct sysfs_class_device *class_dev;
-
-                       /* wait for sysfs of /sys/class /sys/block */
-                       dbg("node add");
-                       snprintf(path, sizeof(path), "%s%s", sysfs_path, udev.devpath);
-                       path[sizeof(path)-1] = '\0';
-                       class_dev = wait_class_device_open(path);
-                       if (class_dev == NULL) {
-                               dbg("open class device failed");
-                               goto run;
-                       }
-                       dbg("opened class_dev->name='%s'", class_dev->name);
-                       wait_for_class_device(class_dev, &error);
-
-                       /* get major/minor */
-                       if (udev.type == DEV_BLOCK || udev.type == DEV_CLASS)
-                               udev.devt = get_devt(class_dev);
-
-                       if (udev.type == DEV_NET || udev.devt) {
-                               /* name device */
-                               udev_rules_get_name(&rules, &udev, class_dev);
-                               if (udev.ignore_device) {
-                                       info("device event will be ignored");
-                                       sysfs_close_class_device(class_dev);
-                                       goto cleanup;
-                               }
-                               if (udev.name[0] == '\0') {
-                                       info("device node creation supressed");
-                                       sysfs_close_class_device(class_dev);
-                                       goto cleanup;
-                               }
-                               /* create node, store in db */
-                               retval = udev_add_device(&udev, class_dev);
-                       } else {
-                               dbg("no dev-file found");
-                               udev_rules_get_run(&rules, &udev, class_dev, NULL);
-                               if (udev.ignore_device) {
-                                       info("device event will be ignored");
-                                       sysfs_close_class_device(class_dev);
-                                       goto cleanup;
-                               }
-                       }
-                       sysfs_close_class_device(class_dev);
-               } else if (strcmp(action, "remove") == 0) {
-                       dbg("node remove");
-                       udev_rules_get_run(&rules, &udev, NULL, NULL);
-                       if (udev.ignore_device) {
-                               dbg("device event will be ignored");
-                               goto cleanup;
-                       }
-
-                       /* get name from db, remove db-entry, delete node */
-                       retval = udev_remove_device(&udev);
-               }
-
-               /* export name of device node or netif */
-               if (udev.devname[0] != '\0')
-                       setenv("DEVNAME", udev.devname, 1);
-       } else if (udev.type == DEV_DEVICE && strcmp(action, "add") == 0) {
-               struct sysfs_device *devices_dev;
-
-               /* wait for sysfs of /sys/devices/ */
-               dbg("devices add");
-               snprintf(path, sizeof(path), "%s%s", sysfs_path, devpath);
-               path[sizeof(path)-1] = '\0';
-               devices_dev = wait_devices_device_open(path);
-               if (!devices_dev) {
-                       dbg("devices device unavailable (probably remove has beaten us)");
-                       goto run;
-               }
-               dbg("devices device opened '%s'", path);
-               wait_for_devices_device(devices_dev, &error);
-               udev_rules_get_run(&rules, &udev, NULL, devices_dev);
-               sysfs_close_device(devices_dev);
-               if (udev.ignore_device) {
-                       info("device event will be ignored");
-                       goto cleanup;
-               }
-       } else {
-               dbg("default handling");
-               udev_rules_get_run(&rules, &udev, NULL, NULL);
-               if (udev.ignore_device) {
-                       info("device event will be ignored");
-                       goto cleanup;
-               }
-       }
+       retval = udev_process_event(&rules, &udev);
 
-run:
-       if (udev_run && !list_empty(&udev.run_list)) {
+       if (!retval && udev_run && !list_empty(&udev.run_list)) {
                struct name_entry *name_loop;
 
                dbg("executing run list");
@@ -220,7 +127,6 @@ run:
                        execute_program(name_loop->name, udev.subsystem, NULL, 0, NULL);
        }
 
-cleanup:
        udev_cleanup_device(&udev);
 
 exit:
diff --git a/udev.h b/udev.h
index 391dc2c41c06860c55c625979c358cc6601a27ca..66edfd66bffea97fbf7b339eebf2abb613c9b43f 100644 (file)
--- a/udev.h
+++ b/udev.h
@@ -1,8 +1,6 @@
 /*
  * udev.h
  *
- * Userspace devfs
- *
  * Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com>
  * Copyright (C) 2003-2005 Kay Sievers <kay.sievers@vrfy.org>
  *
@@ -40,6 +38,8 @@
 #define DEFAULT_PARTITIONS_COUNT       15
 #define UDEV_ALARM_TIMEOUT             120
 
+struct udev_rules;
+
 enum device_type {
        DEV_UNKNOWN,
        DEV_CLASS,
@@ -82,6 +82,9 @@ struct udevice {
        int test_run;
 };
 
+extern int udev_init_device(struct udevice *udev, const char* devpath, const char *subsystem, const char *action);
+extern void udev_cleanup_device(struct udevice *udev);
+extern int udev_process_event(struct udev_rules *rules, struct udevice *udev);
 extern int udev_add_device(struct udevice *udev, struct sysfs_class_device *class_dev);
 extern int udev_remove_device(struct udevice *udev);
 extern void udev_init_config(void);
index 22d91605293d39918f84598e9e63b3554eea0855..09f95f13173fe4cd9bf1a72d51f1e4c270d337ed 100644 (file)
--- a/udev.spec
+++ b/udev.spec
@@ -27,7 +27,7 @@
 # 1 - build it
 %define volume_id 1
 
-Summary: A userspace implementation of devfs
+Summary: A userspace device manager providing devfs functionality
 Name: udev
 Version: 063
 Release: 1
@@ -41,8 +41,9 @@ BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
 Prereq: /bin/sh, fileutils, hotplug
 
 %description
-udev is a implementation of devfs in userspace using sysfs and
-/sbin/hotplug. It requires a 2.6 kernel to run properly.
+udev is a userspace device manager, using sysfs and uevents
+to provide a devfs-like device directory management and uevent
+dispatching.
 
 %prep
 %setup -q
index e9ae150180f56675bad3d1618e62833060344cd8..9d872bf039474f2be8668e4f7c545a2e7227bf39 100644 (file)
@@ -1,10 +1,8 @@
 /*
  * udev-add.c
  *
- * Userspace devfs
- *
  * Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com>
- *
+ * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
  *
  *     This program is free software; you can redistribute it and/or modify it
  *     under the terms of the GNU General Public License as published by the
index 773ee67f9e1a48abff33430ec7cc8ea95a65063f..c57e36cd8c21ce5115babf3c23780dbd11788255 100644 (file)
@@ -1,10 +1,8 @@
 /*
  * udev_config.c
  *
- * Userspace devfs
- *
  * Copyright (C) 2003,2004 Greg Kroah-Hartman <greg@kroah.com>
- *
+ * Copyright (C) 2004, 2005 Kay Sievers <kay.sievers@vrfy.org>
  *
  *     This program is free software; you can redistribute it and/or modify it
  *     under the terms of the GNU General Public License as published by the
index 6f10b1e58d1318c998f7151caffc43c8d16b33bf..ef0e9a71ae8471131a1b39f2136f43c638e84bf7 100644 (file)
--- a/udev_db.c
+++ b/udev_db.c
@@ -1,8 +1,6 @@
 /*
  * udev_db.c
  *
- * Userspace devfs
- *
  * Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com>
  * Copyright (C) 2004-2005 Kay Sievers <kay.sievers@vrfy.org>
  *
index 94209819443883630bae411f14ac18aa5c832151..b961c871021cc2cda2d3687f20ba114f5596b49e 100644 (file)
--- a/udev_db.h
+++ b/udev_db.h
@@ -1,10 +1,8 @@
 /*
  * udev_db.h
  *
- * Userspace devfs
- *
  * Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com>
- * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
+ * Copyright (C) 2004-2005 Kay Sievers <kay.sievers@vrfy.org>
  *
  *     This program is free software; you can redistribute it and/or modify it
  *     under the terms of the GNU General Public License as published by the
diff --git a/udev_device.c b/udev_device.c
new file mode 100644 (file)
index 0000000..45bb6a2
--- /dev/null
@@ -0,0 +1,121 @@
+/*
+ * udev_utils.c - generic stuff used by udev
+ *
+ * Copyright (C) 2004, 2005 Kay Sievers <kay.sievers@vrfy.org>
+ *
+ *     This program is free software; you can redistribute it and/or modify it
+ *     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 <stdlib.h>
+#include <stdio.h>
+#include <stddef.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <ctype.h>
+#include <dirent.h>
+#include <syslog.h>
+#include <sys/wait.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+#include <sys/utsname.h>
+
+#include "udev_libc_wrapper.h"
+#include "udev.h"
+#include "logging.h"
+#include "udev_utils.h"
+#include "udev_sysfs.h"
+#include "list.h"
+
+
+int udev_init_device(struct udevice *udev, const char* devpath, const char *subsystem, const char *action)
+{
+       char *pos;
+
+       memset(udev, 0x00, sizeof(struct udevice));
+       INIT_LIST_HEAD(&udev->symlink_list);
+       INIT_LIST_HEAD(&udev->run_list);
+       INIT_LIST_HEAD(&udev->env_list);
+
+       if (subsystem)
+               strlcpy(udev->subsystem, subsystem, sizeof(udev->subsystem));
+
+       if (action)
+               strlcpy(udev->action, action, sizeof(udev->action));
+
+       if (devpath) {
+               strlcpy(udev->devpath, devpath, sizeof(udev->devpath));
+               remove_trailing_char(udev->devpath, '/');
+
+               if (strncmp(udev->devpath, "/block/", 7) == 0)
+                       udev->type = DEV_BLOCK;
+               else if (strncmp(udev->devpath, "/class/net/", 11) == 0)
+                       udev->type = DEV_NET;
+               else if (strncmp(udev->devpath, "/class/", 7) == 0)
+                       udev->type = DEV_CLASS;
+               else if (strncmp(udev->devpath, "/devices/", 9) == 0)
+                       udev->type = DEV_DEVICE;
+
+               /* get kernel name */
+               pos = strrchr(udev->devpath, '/');
+               if (pos) {
+                       strlcpy(udev->kernel_name, &pos[1], sizeof(udev->kernel_name));
+                       dbg("kernel_name='%s'", udev->kernel_name);
+
+                       /* Some block devices have '!' in their name, change that to '/' */
+                       pos = udev->kernel_name;
+                       while (pos[0] != '\0') {
+                               if (pos[0] == '!')
+                                       pos[0] = '/';
+                               pos++;
+                       }
+
+                       /* get kernel number */
+                       pos = &udev->kernel_name[strlen(udev->kernel_name)];
+                       while (isdigit(pos[-1]))
+                               pos--;
+                       strlcpy(udev->kernel_number, pos, sizeof(udev->kernel_number));
+                       dbg("kernel_number='%s'", udev->kernel_number);
+               }
+       }
+
+       if (udev->type == DEV_BLOCK || udev->type == DEV_CLASS) {
+               udev->mode = 0660;
+               strcpy(udev->owner, "root");
+               strcpy(udev->group, "root");
+       }
+
+       return 0;
+}
+
+void udev_cleanup_device(struct udevice *udev)
+{
+       struct name_entry *name_loop;
+       struct name_entry *temp_loop;
+
+       list_for_each_entry_safe(name_loop, temp_loop, &udev->symlink_list, node) {
+               list_del(&name_loop->node);
+               free(name_loop);
+       }
+       list_for_each_entry_safe(name_loop, temp_loop, &udev->run_list, node) {
+               list_del(&name_loop->node);
+               free(name_loop);
+       }
+       list_for_each_entry_safe(name_loop, temp_loop, &udev->env_list, node) {
+               list_del(&name_loop->node);
+               free(name_loop);
+       }
+}
diff --git a/udev_event.c b/udev_event.c
new file mode 100644 (file)
index 0000000..8a3ed29
--- /dev/null
@@ -0,0 +1,141 @@
+/*
+ * udev_event.c - udev event process
+ *
+ * Copyright (C) 2004, 2005 Kay Sievers <kay.sievers@vrfy.org>
+ *
+ *     This program is free software; you can redistribute it and/or modify it
+ *     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 <stdlib.h>
+#include <stdio.h>
+#include <stddef.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <ctype.h>
+#include <dirent.h>
+#include <syslog.h>
+#include <sys/wait.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+#include <sys/utsname.h>
+
+#include "udev_libc_wrapper.h"
+#include "udev.h"
+#include "logging.h"
+#include "udev_rules.h"
+#include "udev_utils.h"
+#include "udev_sysfs.h"
+#include "list.h"
+
+
+int udev_process_event(struct udev_rules *rules, struct udevice *udev)
+{
+       int retval;
+       char path[PATH_SIZE];
+       const char *error;
+
+       if (udev->type == DEV_BLOCK || udev->type == DEV_CLASS || udev->type == DEV_NET) {
+               /* handle device node */
+               if (strcmp(udev->action, "add") == 0) {
+                       struct sysfs_class_device *class_dev;
+
+                       /* wait for sysfs of /sys/class /sys/block */
+                       dbg("node add");
+                       snprintf(path, sizeof(path), "%s%s", sysfs_path, udev->devpath);
+                       path[sizeof(path)-1] = '\0';
+                       class_dev = wait_class_device_open(path);
+                       if (class_dev == NULL) {
+                               dbg("open class device failed");
+                               return 0;
+                       }
+                       dbg("opened class_dev->name='%s'", class_dev->name);
+                       wait_for_class_device(class_dev, &error);
+
+                       /* get major/minor */
+                       if (udev->type == DEV_BLOCK || udev->type == DEV_CLASS)
+                               udev->devt = get_devt(class_dev);
+
+                       if (udev->type == DEV_NET || udev->devt) {
+                               /* name device */
+                               udev_rules_get_name(rules, udev, class_dev);
+                               if (udev->ignore_device) {
+                                       info("device event will be ignored");
+                                       sysfs_close_class_device(class_dev);
+                                       return -1;
+                               }
+                               if (udev->name[0] == '\0') {
+                                       info("device node creation supressed");
+                                       sysfs_close_class_device(class_dev);
+                                       return -1;
+                               }
+                               /* create node, store in db */
+                               retval = udev_add_device(udev, class_dev);
+                       } else {
+                               dbg("no dev-file found");
+                               udev_rules_get_run(rules, udev, class_dev, NULL);
+                               if (udev->ignore_device) {
+                                       info("device event will be ignored");
+                                       sysfs_close_class_device(class_dev);
+                                       return -1;
+                               }
+                       }
+                       sysfs_close_class_device(class_dev);
+               } else if (strcmp(udev->action, "remove") == 0) {
+                       dbg("node remove");
+                       udev_rules_get_run(rules, udev, NULL, NULL);
+                       if (udev->ignore_device) {
+                               dbg("device event will be ignored");
+                               return -1;
+                       }
+
+                       /* get name from db, remove db-entry, delete node */
+                       retval = udev_remove_device(udev);
+               }
+
+               /* export name of device node or netif */
+               if (udev->devname[0] != '\0')
+                       setenv("DEVNAME", udev->devname, 1);
+       } else if (udev->type == DEV_DEVICE && strcmp(udev->action, "add") == 0) {
+               struct sysfs_device *devices_dev;
+
+               /* wait for sysfs of /sys/devices/ */
+               dbg("devices add");
+               snprintf(path, sizeof(path), "%s%s", sysfs_path, udev->devpath);
+               path[sizeof(path)-1] = '\0';
+               devices_dev = wait_devices_device_open(path);
+               if (!devices_dev) {
+                       dbg("devices device unavailable (probably remove has beaten us)");
+                       return 0;
+               }
+               dbg("devices device opened '%s'", path);
+               wait_for_devices_device(devices_dev, &error);
+               udev_rules_get_run(rules, udev, NULL, devices_dev);
+               sysfs_close_device(devices_dev);
+               if (udev->ignore_device) {
+                       info("device event will be ignored");
+                       return -1;
+               }
+       } else {
+               dbg("default handling");
+               udev_rules_get_run(rules, udev, NULL, NULL);
+               if (udev->ignore_device) {
+                       info("device event will be ignored");
+                       return -1;
+               }
+       }
+       return 0;
+}
index b9a4384ee06e649b5f41cfaf94be96270e12c617..28885d4710faa15df1dd70f66c440408990b95a6 100644 (file)
@@ -1,10 +1,8 @@
 /*
  * udev-remove.c
  *
- * Userspace devfs
- *
  * Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com>
- *
+ * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
  *
  *     This program is free software; you can redistribute it and/or modify it
  *     under the terms of the GNU General Public License as published by the
index 6cbaa781f64e5c8b84df593e54147289ebbb2f6f..6a485f08afaa00bf5eabf1701726ecc510c68609 100644 (file)
@@ -1,12 +1,9 @@
 /*
  * udev_rules.c
  *
- * Userspace devfs
- *
  * Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com>
  * Copyright (C) 2003-2005 Kay Sievers <kay.sievers@vrfy.org>
  *
- *
  *     This program is free software; you can redistribute it and/or modify it
  *     under the terms of the GNU General Public License as published by the
  *     Free Software Foundation version 2 of the License.
 #include "udev_db.h"
 
 
-/* compare string with pattern (supports * ? [0-9] [!A-Z]) */
-static int strcmp_pattern(const char *p, const char *s)
-{
-       if (s[0] == '\0') {
-               while (p[0] == '*')
-                       p++;
-               return (p[0] != '\0');
-       }
-       switch (p[0]) {
-       case '[':
-               {
-                       int not = 0;
-                       p++;
-                       if (p[0] == '!') {
-                               not = 1;
-                               p++;
-                       }
-                       while ((p[0] != '\0') && (p[0] != ']')) {
-                               int match = 0;
-                               if (p[1] == '-') {
-                                       if ((s[0] >= p[0]) && (s[0] <= p[2]))
-                                               match = 1;
-                                       p += 3;
-                               } else {
-                                       match = (p[0] == s[0]);
-                                       p++;
-                               }
-                               if (match ^ not) {
-                                       while ((p[0] != '\0') && (p[0] != ']'))
-                                               p++;
-                                       if (p[0] == ']')
-                                               return strcmp_pattern(p+1, s+1);
-                               }
-                       }
-               }
-               break;
-       case '*':
-               if (strcmp_pattern(p, s+1))
-                       return strcmp_pattern(p+1, s);
-               return 0;
-       case '\0':
-               if (s[0] == '\0') {
-                       return 0;
-               }
-               break;
-       default:
-               if ((p[0] == s[0]) || (p[0] == '?'))
-                       return strcmp_pattern(p+1, s+1);
-               break;
-       }
-       return 1;
-}
-
 /* extract possible {attr} and move str behind it */
 static char *get_format_attribute(char **str)
 {
index bfcb3f23d5c9dec88042aaa7d5faff9b551ea648..9e3931129f2afa3f3841fb41e50873006138f429 100644 (file)
@@ -1,9 +1,8 @@
 /*
  * udev_rules.h
  *
- * Userspace devfs
- *
- * Copyright (C) 2003,2004 Greg Kroah-Hartman <greg@kroah.com>
+ * Copyright (C) 2003-2004 Greg Kroah-Hartman <greg@kroah.com>
+ * Copyright (C) 2004-2005 Kay Sievers <kay.sievers@vrfy.org>
  *
  *     This program is free software; you can redistribute it and/or modify it
  *     under the terms of the GNU General Public License as published by the
@@ -108,6 +107,9 @@ struct udev_rules {
 extern int udev_rules_init(struct udev_rules *rules, int resolve_names);
 extern void udev_rules_close(struct udev_rules *rules);
 
+extern void udev_apply_format(struct udevice *udev, char *string, size_t maxsize,
+                             struct sysfs_class_device *class_dev, struct sysfs_device *sysfs_device);
+
 extern void udev_rules_iter_init(struct udev_rules *rules);
 extern struct udev_rule *udev_rules_iter_next(struct udev_rules *rules);
 extern struct udev_rule *udev_rules_iter_label(struct udev_rules *rules, const char *label);
index e708f355584ec1f73b7c6db798cbcdac6ef81011..be0757374e216f2e2822e75c955c83a49a7b138f 100644 (file)
@@ -1,12 +1,9 @@
 /*
  * udev_rules_parse.c
  *
- * Userspace devfs
- *
  * Copyright (C) 2003,2004 Greg Kroah-Hartman <greg@kroah.com>
  * Copyright (C) 2003-2005 Kay Sievers <kay.sievers@vrfy.org>
  *
- *
  *     This program is free software; you can redistribute it and/or modify it
  *     under the terms of the GNU General Public License as published by the
  *     Free Software Foundation version 2 of the License.
index 073cde1074f921ef920a44aeddb5aa5fb2189875..2524baf5928664ae2e0968cc752c56a1057e7280 100644 (file)
@@ -1,7 +1,7 @@
 /*
- * udev_lib - generic stuff used by udev
+ * udev_utils.c - generic stuff used by udev
  *
- * Copyright (C) 2004 Kay Sievers <kay@vrfy.org>
+ * Copyright (C) 2004-2005 Kay Sievers <kay.sievers@vrfy.org>
  *
  *     This program is free software; you can redistribute it and/or modify it
  *     under the terms of the GNU General Public License as published by the
 #include "udev_utils.h"
 #include "list.h"
 
-
-int udev_init_device(struct udevice *udev, const char* devpath, const char *subsystem, const char *action)
+/* compare string with pattern (supports * ? [0-9] [!A-Z]) */
+int strcmp_pattern(const char *p, const char *s)
 {
-       char *pos;
-
-       memset(udev, 0x00, sizeof(struct udevice));
-       INIT_LIST_HEAD(&udev->symlink_list);
-       INIT_LIST_HEAD(&udev->run_list);
-       INIT_LIST_HEAD(&udev->env_list);
-
-       if (subsystem)
-               strlcpy(udev->subsystem, subsystem, sizeof(udev->subsystem));
-
-       if (action)
-               strlcpy(udev->action, action, sizeof(udev->action));
-
-       if (devpath) {
-               strlcpy(udev->devpath, devpath, sizeof(udev->devpath));
-               remove_trailing_char(udev->devpath, '/');
-
-               if (strncmp(udev->devpath, "/block/", 7) == 0)
-                       udev->type = DEV_BLOCK;
-               else if (strncmp(udev->devpath, "/class/net/", 11) == 0)
-                       udev->type = DEV_NET;
-               else if (strncmp(udev->devpath, "/class/", 7) == 0)
-                       udev->type = DEV_CLASS;
-               else if (strncmp(udev->devpath, "/devices/", 9) == 0)
-                       udev->type = DEV_DEVICE;
-
-               /* get kernel name */
-               pos = strrchr(udev->devpath, '/');
-               if (pos) {
-                       strlcpy(udev->kernel_name, &pos[1], sizeof(udev->kernel_name));
-                       dbg("kernel_name='%s'", udev->kernel_name);
-
-                       /* Some block devices have '!' in their name, change that to '/' */
-                       pos = udev->kernel_name;
-                       while (pos[0] != '\0') {
-                               if (pos[0] == '!')
-                                       pos[0] = '/';
-                               pos++;
+       if (s[0] == '\0') {
+               while (p[0] == '*')
+                       p++;
+               return (p[0] != '\0');
+       }
+       switch (p[0]) {
+       case '[':
+               {
+                       int not = 0;
+                       p++;
+                       if (p[0] == '!') {
+                               not = 1;
+                               p++;
+                       }
+                       while ((p[0] != '\0') && (p[0] != ']')) {
+                               int match = 0;
+                               if (p[1] == '-') {
+                                       if ((s[0] >= p[0]) && (s[0] <= p[2]))
+                                               match = 1;
+                                       p += 3;
+                               } else {
+                                       match = (p[0] == s[0]);
+                                       p++;
+                               }
+                               if (match ^ not) {
+                                       while ((p[0] != '\0') && (p[0] != ']'))
+                                               p++;
+                                       if (p[0] == ']')
+                                               return strcmp_pattern(p+1, s+1);
+                               }
                        }
-
-                       /* get kernel number */
-                       pos = &udev->kernel_name[strlen(udev->kernel_name)];
-                       while (isdigit(pos[-1]))
-                               pos--;
-                       strlcpy(udev->kernel_number, pos, sizeof(udev->kernel_number));
-                       dbg("kernel_number='%s'", udev->kernel_number);
                }
+               break;
+       case '*':
+               if (strcmp_pattern(p, s+1))
+                       return strcmp_pattern(p+1, s);
+               return 0;
+       case '\0':
+               if (s[0] == '\0') {
+                       return 0;
+               }
+               break;
+       default:
+               if ((p[0] == s[0]) || (p[0] == '?'))
+                       return strcmp_pattern(p+1, s+1);
+               break;
        }
-
-       if (udev->type == DEV_BLOCK || udev->type == DEV_CLASS) {
-               udev->mode = 0660;
-               strcpy(udev->owner, "root");
-               strcpy(udev->group, "root");
-       }
-
-       return 0;
-}
-
-void udev_cleanup_device(struct udevice *udev)
-{
-       struct name_entry *name_loop;
-       struct name_entry *temp_loop;
-
-       list_for_each_entry_safe(name_loop, temp_loop, &udev->symlink_list, node) {
-               list_del(&name_loop->node);
-               free(name_loop);
-       }
-       list_for_each_entry_safe(name_loop, temp_loop, &udev->run_list, node) {
-               list_del(&name_loop->node);
-               free(name_loop);
-       }
-       list_for_each_entry_safe(name_loop, temp_loop, &udev->env_list, node) {
-               list_del(&name_loop->node);
-               free(name_loop);
-       }
+       return 1;
 }
 
 int string_is_true(const char *str)
index 655c764fc8c54711ca727b77de0004697d8bdf40..5f4152df829da95b7b9f0ba65258097f0b93783a 100644 (file)
@@ -1,8 +1,7 @@
 /*
- * udev_lib - generic stuff used by udev
- *
- * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
+ * udev_utils.c - generic stuff used by udev
  *
+ * Copyright (C) 2004-2005 Kay Sievers <kay.sievers@vrfy.org>
  *
  *     This program is free software; you can redistribute it and/or modify it
  *     under the terms of the GNU General Public License as published by the
  *
  */
 
-#ifndef _UDEV_LIB_H_
-#define _UDEV_LIB_H_
+#ifndef _UDEV_COMMON_H_
+#define _UDEV_COMMON_H_
 
 #include "udev.h"
+#include "list.h"
 
 struct name_entry {
        struct list_head node;
        char name[PATH_SIZE];
 };
 
-extern int udev_init_device(struct udevice *udev, const char* devpath, const char *subsystem, const char *action);
-extern void udev_cleanup_device(struct udevice *udev);
-
+extern int strcmp_pattern(const char *p, const char *s);
 extern int kernel_release_satisfactory(unsigned int version, unsigned int patchlevel, unsigned int sublevel);
 extern int create_path(const char *path);
 extern int log_priority(const char *priority);
index f19ae98fba8bbd80cff87254c6d7fc44ff94cfd2..5d8fa77683eeee2455e378ff6f142a9cc7df9efe 100644 (file)
@@ -1,11 +1,8 @@
 /*
  * udevcontrol.c
  *
- * Userspace devfs
- *
  * Copyright (C) 2005 Kay Sievers <kay.sievers@vrfy.org>
  *
- *
  *     This program is free software; you can redistribute it and/or modify it
  *     under the terms of the GNU General Public License as published by the
  *     Free Software Foundation version 2 of the License.
diff --git a/udevd.h b/udevd.h
index c60fb139c074ddbcc7c31921920ec8debf5e76e5..aadae31e576caee5c2cff5e0b6794b3607bce657 100644 (file)
--- a/udevd.h
+++ b/udevd.h
@@ -1,11 +1,8 @@
 /*
  * udevd.h
  *
- * Userspace devfs
- *
  * Copyright (C) 2004 Ling, Xiaofeng <xiaofeng.ling@intel.com>
- * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
- *
+ * Copyright (C) 2004-2005 Kay Sievers <kay.sievers@vrfy.org>
  *
  *     This program is free software; you can redistribute it and/or modify it
  *     under the terms of the GNU General Public License as published by the
index af7ea7c15c3471fb7389db1e57c93f5036fec034..711f467307d34057a30314cebab54df99d2001c9 100644 (file)
@@ -1,9 +1,9 @@
 /*
  * udeveventrecorder.c
  *
- * Userspace devfs
- *
- * Copyright (C) 2004, 2005 Olaf Hering <olh@suse.de>
+ * Copyright (C) 2004-2005 SuSE Linux Products GmbH
+ * Author:
+ *     Olaf Hering <olh@suse.de>
  *
  *     This program is free software; you can redistribute it and/or modify it
  *     under the terms of the GNU General Public License as published by the
index db562eee49d6c581c8bb1e775f56da76484684f5..d2c3e1ab7f334498f759a23f2244fab46f816a7a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * udevinfo - fetches attributes for a device
+ * udevinfo.c - fetches attributes for a device
  *
  * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
  *
index 204e9cecd57af1554eb9d65d58e72d7bb0e296c7..5abf3d4bd33fcd361a1c58f680ae99a31ff8bb72 100644 (file)
@@ -1,9 +1,9 @@
 /*
  * udevinitsend.c
  *
- * Userspace devfs
- *
- * Copyright (C) 2004, 2005 Hannes Reinecke <hare@suse.de>
+ * Copyright (C) 2004, 2005 SuSE Linux Products GmbH
+ * Author:
+ *     Hannes Reinecke <hare@suse.de>
  *
  *     This program is free software; you can redistribute it and/or modify it
  *     under the terms of the GNU General Public License as published by the
index bdc69d0508e4c3ce786e895a65a6d66dd5e5980e..94ab6ff6257699a11eb4474322cd8f27e04d24ea 100644 (file)
@@ -1,12 +1,9 @@
 /*
  * udevsend.c
  *
- * Userspace devfs
- *
  * Copyright (C) 2004 Ling, Xiaofeng <xiaofeng.ling@intel.com>
  * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
  *
- *
  *     This program is free software; you can redistribute it and/or modify it
  *     under the terms of the GNU General Public License as published by the
  *     Free Software Foundation version 2 of the License.
index d9912466ca91f5f5aea9258d0237e7543dab317f..0bcbc3973723d605987c31c44b1d8a1903dd0e5e 100644 (file)
@@ -2,10 +2,12 @@
  * udevstart.c
  *
  * Copyright (C) 2004 Greg Kroah-Hartman <greg@kroah.com>
- * 
+ * Copyright (C) 2004 Kay Sievers <kay@vrfy.org>
+ *
  * Quick and dirty way to populate a /dev with udev if your system
- * does not have access to a shell.  Based originally on a patch to udev 
- * from Harald Hoyer <harald@redhat.com>
+ * does not have access to a shell.  Based originally on a patch
+ * from:
+ *     Harald Hoyer <harald@redhat.com>
  *
  *     This program is free software; you can redistribute it and/or modify it
  *     under the terms of the GNU General Public License as published by the
@@ -41,8 +43,8 @@
 #include "udev.h"
 #include "udev_version.h"
 #include "logging.h"
-#include "udev_rules.h"
 #include "udev_utils.h"
+#include "udev_rules.h"
 #include "list.h"
 
 static const char *udev_run_str;
index 3e17b947153604324d67226805a993530eca5601..4890b6837c3c5e1b058165bc15e0ec246978acdc 100644 (file)
@@ -1,9 +1,7 @@
 /*
  * udevtest.c
  *
- * Userspace devfs
- *
- * Copyright (C) 2003,2004 Greg Kroah-Hartman <greg@kroah.com>
+ * Copyright (C) 2003-2004 Greg Kroah-Hartman <greg@kroah.com>
  *
  *     This program is free software; you can redistribute it and/or modify it
  *     under the terms of the GNU General Public License as published by the