chiark / gitweb /
[PATCH] DEVPATH for netdev
authorkay.sievers@vrfy.org <kay.sievers@vrfy.org>
Thu, 1 Apr 2004 08:59:58 +0000 (00:59 -0800)
committerGreg KH <gregkh@suse.de>
Wed, 27 Apr 2005 04:35:13 +0000 (21:35 -0700)
Here we change the DEVPATH for netdev's in the environment of the dev.d/
scripts to the name the device is renamed to. The original name doesn't
exist in the kernel after rename.

dev_d.c
udev-add.c
udev-remove.c
udev.h
udev_config.c
udevd.c
udevstart.c

diff --git a/dev_d.c b/dev_d.c
index 0910e4d323e344246b590f93d7a4799355645ff6..483ceb4b1b983f398831a46d8db41aa48f88bd18 100644 (file)
--- a/dev_d.c
+++ b/dev_d.c
@@ -61,7 +61,7 @@ static int run_program(char *name)
  *     subsystem/
  *     default/
  */
-void dev_d_send(struct udevice *dev, char *subsystem)
+void dev_d_send(struct udevice *dev, char *subsystem, char *devpath)
 {
        char dirname[256];
        char devname[NAME_SIZE];
@@ -74,8 +74,8 @@ void dev_d_send(struct udevice *dev, char *subsystem)
                strfieldcat(devname, dev->name);
        } else if (dev->type == 'n') {
                strfieldcpy(devname, dev->name);
+               setenv("DEVPATH", devpath, 1);
        }
-       setenv("DEVNODE", devname, 1); /* FIXME: bad name for netif */
        setenv("DEVNAME", devname, 1);
        dbg("DEVNAME='%s'", devname);
 
index 1f17f50bc3de8a372b6a80d9595518fad05a9e4d..09c2ac6d3efd2634ceb1eacac37791e1409c658d 100644 (file)
@@ -403,7 +403,7 @@ int udev_add_device(char *path, char *subsystem, int fake)
 {
        struct sysfs_class_device *class_dev;
        struct udevice dev;
-       char key[DEVPATH_SIZE];
+       char devpath[DEVPATH_SIZE];
        char *pos;
        int retval;
 
@@ -452,10 +452,11 @@ int udev_add_device(char *path, char *subsystem, int fake)
                        dbg("udevdb_add_dev failed, but we are going to try "
                            "to create the node anyway. But remove might not "
                            "work properly for this device.");
+
+               dev_d_send(&dev, subsystem, path);
                break;
 
        case 'n':
-               strfieldcpy(key, path);
                if (strcmp(dev.name, dev.kernel_name) != 0) {
                        retval = rename_net_if(&dev, fake);
                        if (fake || retval != 0)
@@ -463,20 +464,20 @@ int udev_add_device(char *path, char *subsystem, int fake)
                        /* netif's are keyed with the configured name, cause
                         * the original kernel name sleeps with the fishes
                         */
-                       pos = strrchr(key, '/');
+                       strfieldcpy(devpath, path);
+                       pos = strrchr(devpath, '/');
                        if (pos != NULL) {
                                pos[1] = '\0';
-                               strfieldcat(key, dev.name);
+                               strfieldcat(devpath, dev.name);
                        }
                }
-               if (udevdb_add_dev(key, &dev) != 0)
+               if (udevdb_add_dev(devpath, &dev) != 0)
                        dbg("udevdb_add_dev failed");
+
+               dev_d_send(&dev, subsystem, devpath);
                break;
        }
 
-       /* execute programs in dev.d/ with the name in the environment */
-       dev_d_send(&dev, subsystem);
-
 exit:
        sysfs_close_class_device(class_dev);
 
index c838f15ce3521a6510a128320db658b6afef47a2..27ff5bc0a2e12d38167ba1db43d85ca78ac3ccf0 100644 (file)
@@ -148,7 +148,7 @@ int udev_remove_device(char *path, char *subsystem)
        dbg("name='%s'", dev.name);
 
        dev.type = get_device_type(path, subsystem);
-       dev_d_send(&dev, subsystem);
+       dev_d_send(&dev, subsystem, path);
        udevdb_delete_dev(path);
 
        if (dev.type == 'b' || dev.type == 'c')
diff --git a/udev.h b/udev.h
index 8d13fb5bc34178cbeffaefe918d63a2fdecb00d0..da02e26bbae2a223a2e6cc078d20050ffbcfc4ba 100644 (file)
--- a/udev.h
+++ b/udev.h
@@ -65,7 +65,7 @@ extern int udev_add_device(char *path, char *subsystem, int fake);
 extern int udev_remove_device(char *path, char *subsystem);
 extern void udev_init_config(void);
 extern int parse_get_pair(char **orig_string, char **left, char **right);
-extern void dev_d_send(struct udevice *dev, char *subsystem);
+extern void dev_d_send(struct udevice *dev, char *subsystem, char *devpath);
 
 extern char **main_argv;
 extern char **main_envp;
index fe26850a87f69e7cc5e2036ba44c2d58c4217f89..ba04003e909285c89349f2178c4d1f82da37dd38 100644 (file)
@@ -86,13 +86,13 @@ static void init_variables(void)
 
 #define set_var(_name, _var)                           \
        if (strcasecmp(variable, _name) == 0) {         \
-               dbg_parse("%s = '%s'", _name, value);   \
-               strfieldcpymax(_var, value, sizeof(_var));\
+               dbg_parse("%s='%s'", _name, value);     \
+               strfieldcpy(_var, value);\
        }
 
 #define set_bool(_name, _var)                          \
        if (strcasecmp(variable, _name) == 0) {         \
-               dbg_parse("%s = '%s'", _name, value);   \
+               dbg_parse("%s='%s'", _name, value);     \
                _var = string_is_true(value);           \
        }
 
diff --git a/udevd.c b/udevd.c
index 301625fd927a58e7868cf1da31551a3d993f7e4a..d464b9a196fd46506084fb093270d3ba2d416849 100644 (file)
--- a/udevd.c
+++ b/udevd.c
@@ -139,8 +139,10 @@ static void udev_run(struct hotplug_msg *msg)
        char devpath[DEVPATH_SIZE];
        char *env[] = { action, devpath, NULL };
 
-       snprintf(action, sizeof(action), "ACTION=%s", msg->action);
-       snprintf(devpath, sizeof(devpath), "DEVPATH=%s", msg->devpath);
+       strcpy(action, "ACTION=");
+       strfieldcat(action, msg->action);
+       strcpy(devpath, "DEVPATH=");
+       strfieldcat(devpath, msg->devpath);
 
        pid = fork();
        switch (pid) {
index eda6355b534e68e6b8cbc4502579255afbe9ab53..7e19c379a503ed8ff7f2885dd419ffd236f3157b 100644 (file)
@@ -33,6 +33,7 @@
 #include <unistd.h>
 
 #include "logging.h"
+#include "udev_lib.h"
 
 
 #ifdef LOG
@@ -61,8 +62,8 @@ static void udev_exec(const char *path, const char* subsystem)
        char nosleep[] = "UDEV_NO_SLEEP=1";
        char *env[] = { action, devpath, nosleep, NULL };
 
-       snprintf(devpath, MAX_PATHLEN, "DEVPATH=%s", path);
-       devpath[MAX_PATHLEN-1] = '\0';
+       strcpy(action, "DEVPATH=%s");
+       strfieldcat(action, path);
 
        pid = fork();
        switch (pid) {