summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkay.sievers@vrfy.org <kay.sievers@vrfy.org>2004-11-12 06:21:16 +0100
committerGreg KH <gregkh@suse.de>2005-04-26 22:25:09 -0700
commit8673dcb84299fd2adba6281c5359bed4399d5b2d (patch)
tree9db3b5d4e7218b098c53d62b8805c9c9368a78af
parentaf4b05d4917fdfa55eff3d8d53a830464d8162a1 (diff)
[PATCH] Make dev.d/ handling a separate processing stage
Move the logic when and how to call the dev.d/ scripts into the main processing path.
-rw-r--r--dev_d.c38
-rw-r--r--namedev.c2
-rw-r--r--udev.c9
-rw-r--r--udev.h5
-rw-r--r--udev_add.c6
-rw-r--r--udev_lib.c2
-rw-r--r--udev_remove.c6
-rw-r--r--udevdb.c4
-rw-r--r--udevstart.c10
-rw-r--r--wait_for_sysfs.c4
10 files changed, 43 insertions, 43 deletions
diff --git a/dev_d.c b/dev_d.c
index 1108c8cee4..b3d05d9220 100644
--- a/dev_d.c
+++ b/dev_d.c
@@ -32,9 +32,6 @@
#include "udevdb.h"
#include "logging.h"
-#define DEVD_DIR "/etc/dev.d/"
-#define DEVD_SUFFIX ".dev"
-
static int run_program(const char *filename, void *data)
{
pid_t pid;
@@ -75,7 +72,7 @@ static int run_program(const char *filename, void *data)
* subsystem/
* default/
*/
-void dev_d_execute(struct udevice *udev)
+void dev_d_execute(struct udevice *udev, const char *basedir, const char *suffix)
{
char dirname[PATH_MAX];
char devname[NAME_SIZE];
@@ -85,37 +82,30 @@ void dev_d_execute(struct udevice *udev)
if (udev_dev_d == 0)
return;
- /* skip if udev did nothing, like unchanged netif or no "dev" file */
- if (udev->devname[0] == '\0')
- return;
-
- /* add the node name or the netif name to the environment */
- setenv("DEVNAME", udev->devname, 1);
- dbg("DEVNAME='%s'", udev->devname);
-
strfieldcpy(devname, udev->name);
- /* Chop the device name up into pieces based on '/' */
+ /* chop the device name up into pieces based on '/' */
temp = strchr(devname, '/');
while (temp != NULL) {
temp[0] = '\0';
- strcpy(dirname, DEVD_DIR);
- strfieldcat(dirname, devname);
- call_foreach_file(run_program, dirname, DEVD_SUFFIX, udev);
+ snprintf(dirname, PATH_MAX, "%s/%s", basedir, devname);
+ dirname[PATH_MAX-1] = '\0';
+ call_foreach_file(run_program, dirname, suffix, udev);
temp[0] = '/';
++temp;
temp = strchr(temp, '/');
}
- strcpy(dirname, DEVD_DIR);
- strfieldcat(dirname, udev->name);
- call_foreach_file(run_program, dirname, DEVD_SUFFIX, udev);
+ snprintf(dirname, PATH_MAX, "%s/%s", basedir, udev->name);
+ dirname[PATH_MAX-1] = '\0';
+ call_foreach_file(run_program, dirname, suffix, udev);
- strcpy(dirname, DEVD_DIR);
- strfieldcat(dirname, udev->subsystem);
- call_foreach_file(run_program, dirname, DEVD_SUFFIX, udev);
+ snprintf(dirname, PATH_MAX, "%s/%s", basedir, udev->subsystem);
+ dirname[PATH_MAX-1] = '\0';
+ call_foreach_file(run_program, dirname, suffix, udev);
- strcpy(dirname, DEVD_DIR "default");
- call_foreach_file(run_program, dirname, DEVD_SUFFIX, udev);
+ snprintf(dirname, PATH_MAX, "%s/default", basedir);
+ dirname[PATH_MAX-1] = '\0';
+ call_foreach_file(run_program, dirname, suffix, udev);
}
diff --git a/namedev.c b/namedev.c
index 268a3d5be6..9c94e69082 100644
--- a/namedev.c
+++ b/namedev.c
@@ -204,7 +204,7 @@ static int find_free_number(struct udevice *udev, const char *name)
info("find_free_number gone crazy (num=%d), aborted", num);
return -1;
}
- snprintf(filename, NAME_SIZE-1, "%s%d", name, num);
+ snprintf(filename, NAME_SIZE, "%s%d", name, num);
filename[NAME_SIZE-1] = '\0';
}
}
diff --git a/udev.c b/udev.c
index 300e85ceb0..bb3385e67d 100644
--- a/udev.c
+++ b/udev.c
@@ -165,8 +165,11 @@ int main(int argc, char *argv[], char *envp[])
/* name, create node, store in db */
retval = udev_add_device(&udev, class_dev);
- /* run scripts */
- dev_d_execute(&udev);
+ /* run dev.d/ scripts if we created a node or changed a netif name */
+ if (udev.devname[0] != '\0') {
+ setenv("DEVNAME", udev.devname, 1);
+ dev_d_execute(&udev, DEVD_DIR, DEVD_SUFFIX);
+ }
sysfs_close_class_device(class_dev);
break;
@@ -177,7 +180,7 @@ int main(int argc, char *argv[], char *envp[])
retval = udev_remove_device(&udev);
/* run scripts */
- dev_d_execute(&udev);
+ dev_d_execute(&udev, DEVD_DIR, DEVD_SUFFIX);
}
exit:
diff --git a/udev.h b/udev.h
index d031b9699c..73733ad3bb 100644
--- a/udev.h
+++ b/udev.h
@@ -41,6 +41,9 @@
#define LINE_SIZE 256
+#define DEVD_DIR "/etc/dev.d"
+#define DEVD_SUFFIX ".dev"
+
struct udevice {
char devpath[DEVPATH_SIZE];
char subsystem[SUBSYSTEM_SIZE];
@@ -71,7 +74,7 @@ extern int udev_remove_device(struct udevice *udev);
extern void udev_init_config(void);
extern int udev_start(void);
extern int parse_get_pair(char **orig_string, char **left, char **right);
-extern void dev_d_execute(struct udevice *udev);
+extern void dev_d_execute(struct udevice *udev, const char *basedir, const char *suffix);
extern char sysfs_path[SYSFS_PATH_MAX];
extern char udev_root[PATH_MAX];
diff --git a/udev_add.c b/udev_add.c
index 60506b4243..c139bd38bf 100644
--- a/udev_add.c
+++ b/udev_add.c
@@ -129,7 +129,7 @@ static int create_node(struct udevice *udev)
char *pos;
int len;
- snprintf(filename, NAME_SIZE-1, "%s/%s", udev_root, udev->name);
+ snprintf(filename, NAME_SIZE, "%s/%s", udev_root, udev->name);
filename[NAME_SIZE-1] = '\0';
switch (udev->type) {
@@ -210,7 +210,7 @@ static int create_node(struct udevice *udev)
char linktarget[NAME_SIZE];
strfieldcpymax(linkname, pos, len+1);
- snprintf(filename, NAME_SIZE-1, "%s/%s", udev_root, linkname);
+ snprintf(filename, NAME_SIZE, "%s/%s", udev_root, linkname);
filename[NAME_SIZE-1] = '\0';
dbg("symlink '%s' to node '%s' requested", filename, udev->name);
@@ -308,7 +308,7 @@ int udev_add_device(struct udevice *udev, struct sysfs_class_device *class_dev)
"remove might not work for custom names");
/* use full path to the environment */
- snprintf(udev->devname, NAME_SIZE-1, "%s/%s", udev_root, udev->name);
+ snprintf(udev->devname, NAME_SIZE, "%s/%s", udev_root, udev->name);
udev->devname[NAME_SIZE-1] = '\0';
} else if (udev->type == 'n') {
diff --git a/udev_lib.c b/udev_lib.c
index 012d60b0ea..6807f817a1 100644
--- a/udev_lib.c
+++ b/udev_lib.c
@@ -219,7 +219,7 @@ int call_foreach_file(file_fnct_t fnct, const char *dirname,
list_for_each_entry_safe(loop_file, tmp_file, &file_list, list) {
char filename[NAME_SIZE];
- snprintf(filename, NAME_SIZE-1, "%s/%s", dirname, loop_file->name);
+ snprintf(filename, NAME_SIZE, "%s/%s", dirname, loop_file->name);
filename[NAME_SIZE-1] = '\0';
fnct(filename, data);
diff --git a/udev_remove.c b/udev_remove.c
index d855fce52c..56834a45b9 100644
--- a/udev_remove.c
+++ b/udev_remove.c
@@ -112,7 +112,7 @@ static int delete_node(struct udevice *udev)
int len;
int num;
- snprintf(filename, NAME_SIZE-1, "%s/%s", udev_root, udev->name);
+ snprintf(filename, NAME_SIZE, "%s/%s", udev_root, udev->name);
filename[NAME_SIZE-1] = '\0';
info("removing device node '%s'", filename);
@@ -143,7 +143,7 @@ static int delete_node(struct udevice *udev)
char linkname[NAME_SIZE];
strfieldcpymax(linkname, pos, len+1);
- snprintf(filename, NAME_SIZE-1, "%s/%s", udev_root, linkname);
+ snprintf(filename, NAME_SIZE, "%s/%s", udev_root, linkname);
filename[NAME_SIZE-1] = '\0';
dbg("unlinking symlink '%s'", filename);
@@ -189,7 +189,7 @@ int udev_remove_device(struct udevice *udev)
udevdb_delete_dev(udev);
/* use full path to the environment */
- snprintf(udev->devname, NAME_SIZE-1, "%s/%s", udev_root, udev->name);
+ snprintf(udev->devname, NAME_SIZE, "%s/%s", udev_root, udev->name);
return delete_node(udev);
}
diff --git a/udevdb.c b/udevdb.c
index fc579a9451..38830b098e 100644
--- a/udevdb.c
+++ b/udevdb.c
@@ -51,7 +51,7 @@ static int get_db_filename(struct udevice *udev, char *filename, int len)
pos[0] = PATH_TO_NAME_CHAR;
pos = strchr(&pos[1], '/');
}
- snprintf(filename, len-1, "%s%s", udev_db_path, devpath);
+ snprintf(filename, len, "%s%s", udev_db_path, devpath);
filename[len-1] = '\0';
return 0;
@@ -175,7 +175,7 @@ int udevdb_get_dev_byname(struct udevice *udev, const char *name)
if (ent->d_name[0] == '.')
continue;
- snprintf(filename, NAME_SIZE-1, "%s/%s", udev_db_path, ent->d_name);
+ snprintf(filename, NAME_SIZE, "%s/%s", udev_db_path, ent->d_name);
filename[NAME_SIZE-1] = '\0';
memset(&db_udev, 0x00, sizeof(struct udevice));
diff --git a/udevstart.c b/udevstart.c
index 0433e568d4..c1d877fb37 100644
--- a/udevstart.c
+++ b/udevstart.c
@@ -97,7 +97,8 @@ static int add_device(char *devpath, char *subsystem)
setenv("DEVPATH", devpath, 1);
setenv("SUBSYSTEM", subsystem, 1);
- snprintf(path, SYSFS_PATH_MAX-1, "%s%s", sysfs_path, devpath);
+ snprintf(path, SYSFS_PATH_MAX, "%s%s", sysfs_path, devpath);
+ path[SYSFS_PATH_MAX-1] = '\0';
class_dev = sysfs_open_class_device_path(path);
if (class_dev == NULL) {
dbg ("sysfs_open_class_device_path failed");
@@ -107,8 +108,11 @@ static int add_device(char *devpath, char *subsystem)
udev_set_values(&udev, devpath, subsystem, "add");
udev_add_device(&udev, class_dev);
- /* run scripts */
- dev_d_execute(&udev);
+ /* run dev.d/ scripts if we created a node or changed a netif name */
+ if (udev.devname[0] != '\0') {
+ setenv("DEVNAME", udev.devname, 1);
+ dev_d_execute(&udev, DEVD_DIR, DEVD_SUFFIX);
+ }
sysfs_close_class_device(class_dev);
diff --git a/wait_for_sysfs.c b/wait_for_sysfs.c
index 3b1b0cd248..42b9d383dc 100644
--- a/wait_for_sysfs.c
+++ b/wait_for_sysfs.c
@@ -96,7 +96,7 @@ int main(int argc, char *argv[], char *envp[])
}
if ((strncmp(devpath, "/block/", 7) == 0) || (strncmp(devpath, "/class/", 7) == 0)) {
- snprintf(filename, SYSFS_PATH_MAX-1, "%s%s", sysfs_mnt_path, devpath);
+ snprintf(filename, SYSFS_PATH_MAX, "%s%s", sysfs_mnt_path, devpath);
filename[SYSFS_PATH_MAX-1] = '\0';
/* skip bad events where we get no device for the class */
@@ -128,7 +128,7 @@ int main(int argc, char *argv[], char *envp[])
sysfs_close_class_device(class_dev);
} else if ((strncmp(devpath, "/devices/", 9) == 0)) {
- snprintf(filename, SYSFS_PATH_MAX-1, "%s%s", sysfs_mnt_path, devpath);
+ snprintf(filename, SYSFS_PATH_MAX, "%s%s", sysfs_mnt_path, devpath);
filename[SYSFS_PATH_MAX-1] = '\0';
/* open the path we are called for */