summaryrefslogtreecommitdiff
path: root/udev-add.c
diff options
context:
space:
mode:
authorkay.sievers@vrfy.org <kay.sievers@vrfy.org>2003-12-10 00:47:00 -0800
committerGreg KH <gregkh@suse.de>2005-04-26 21:13:07 -0700
commit4763256c65859b94ac7a309cbb8f772d5426a08d (patch)
tree60c1857fd2891bb7fde065895ac10bae805b4dc5 /udev-add.c
parent10a479f5e6df7010a47f1edfab8173de85a34d0d (diff)
[PATCH] allow multiple symlinks
Here is a patch to allow the creation of multiple symlinks. The names must be separated by a space character. REPLACE, KERNEL="ttyUSB0", NAME="visor", SYMLINK="first-%n second-%n third-%n" results in: Dec 9 05:28:51 pim udev[12019]: create_node: mknod(udev-root/visor, 020666, 188, 0) Dec 9 05:28:51 pim udev[12019]: create_node: symlink 'udev-root/first-0' to node 'visor' requested Dec 9 05:28:51 pim udev[12019]: create_node: symlink(./visor, udev-root/first-0) Dec 9 05:28:51 pim udev[12019]: create_node: symlink 'udev-root/second-0' to node 'visor' requested Dec 9 05:28:51 pim udev[12019]: create_node: symlink(./visor, udev-root/second-0) Dec 9 05:28:51 pim udev[12019]: create_node: symlink 'udev-root/third-0' to node 'visor' requested Dec 9 05:28:51 pim udev[12019]: create_node: symlink(./visor, udev-root/third-0)
Diffstat (limited to 'udev-add.c')
-rw-r--r--udev-add.c66
1 files changed, 37 insertions, 29 deletions
diff --git a/udev-add.c b/udev-add.c
index 17b69eadab..e64a845c7e 100644
--- a/udev-add.c
+++ b/udev-add.c
@@ -102,6 +102,8 @@ static int create_node(struct udevice *dev)
{
char filename[255];
char linktarget[255];
+ char *linkname;
+ char *symlinks;
int retval = 0;
uid_t uid = 0;
gid_t gid = 0;
@@ -186,39 +188,45 @@ static int create_node(struct udevice *dev)
filename, uid, gid, strerror(errno));
}
-
/* create symlink if requested */
if (*dev->symlink) {
- strncpy(filename, udev_root, sizeof(filename));
- strncat(filename, dev->symlink, sizeof(filename));
- dbg("symlink '%s' to node '%s' requested", filename, dev->name);
- if (strrchr(dev->symlink, '/'))
- create_path(filename);
-
- /* optimize relative link */
- linktarget[0] = '\0';
- i = 0;
- tail = 0;
- while ((dev->name[i] == dev->symlink[i]) && dev->name[i]) {
- if (dev->name[i] == '/')
- tail = i+1;
- i++;
- }
- while (dev->symlink[i]) {
- if (dev->symlink[i] == '/')
- strcat(linktarget, "../");
- i++;
- }
+ symlinks = dev->symlink;
+ while (1) {
+ linkname = strsep(&symlinks, " ");
+ if (linkname == NULL)
+ break;
+
+ strncpy(filename, udev_root, sizeof(filename));
+ strncat(filename, linkname, sizeof(filename));
+ dbg("symlink '%s' to node '%s' requested", filename, dev->name);
+ if (strrchr(linkname, '/'))
+ create_path(filename);
+
+ /* optimize relative link */
+ linktarget[0] = '\0';
+ i = 0;
+ tail = 0;
+ while ((dev->name[i] == linkname[i]) && dev->name[i]) {
+ if (dev->name[i] == '/')
+ tail = i+1;
+ i++;
+ }
+ while (linkname[i]) {
+ if (linkname[i] == '/')
+ strcat(linktarget, "../");
+ i++;
+ }
- if (*linktarget == '\0')
- strcpy(linktarget, "./");
- strcat(linktarget, &dev->name[tail]);
+ if (*linktarget == '\0')
+ strcpy(linktarget, "./");
+ strcat(linktarget, &dev->name[tail]);
- dbg("symlink(%s, %s)", linktarget, filename);
- retval = symlink(linktarget, filename);
- if (retval)
- dbg("symlink(%s, %s) failed with error '%s'",
- linktarget, filename, strerror(errno));
+ dbg("symlink(%s, %s)", linktarget, filename);
+ retval = symlink(linktarget, filename);
+ if (retval)
+ dbg("symlink(%s, %s) failed with error '%s'",
+ linktarget, filename, strerror(errno));
+ }
}
return retval;