aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJean Tourrilhes <jt@hpl.hp.com>2007-03-07 10:49:30 -0800
committerGreg Kroah-Hartman <gregkh@suse.de>2007-04-27 10:57:29 -0700
commitca2f37dbc5324c7278577731033a358f1f86050a (patch)
tree5085e9826220e047c1f53070355c4f194988241f /lib
parent1b0b3b9980e482ab7c603430462538334f69f14a (diff)
Driver core: notify userspace of network device renames
Provide rename event for when we rename network devices. Signed-off-by: Jean Tourrilhes <jt@hpl.hp.com> Cc: Kay Sievers <kay.sievers@vrfy.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/kobject.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/kobject.c b/lib/kobject.c
index bbbfab4145e..db1d23707eb 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -311,13 +311,43 @@ EXPORT_SYMBOL(kobject_set_name);
int kobject_rename(struct kobject * kobj, const char *new_name)
{
int error = 0;
+ const char *devpath = NULL;
+ char *devpath_string = NULL;
+ char *envp[2];
kobj = kobject_get(kobj);
if (!kobj)
return -EINVAL;
if (!kobj->parent)
return -EINVAL;
+
+ devpath = kobject_get_path(kobj, GFP_KERNEL);
+ if (!devpath) {
+ error = -ENOMEM;
+ goto out;
+ }
+ devpath_string = kmalloc(strlen(devpath) + 15, GFP_KERNEL);
+ if (!devpath_string) {
+ error = -ENOMEM;
+ goto out;
+ }
+ sprintf(devpath_string, "DEVPATH_OLD=%s", devpath);
+ envp[0] = devpath_string;
+ envp[1] = NULL;
+ /* Note : if we want to send the new name alone, not the full path,
+ * we could probably use kobject_name(kobj); */
+
error = sysfs_rename_dir(kobj, kobj->parent->dentry, new_name);
+
+ /* This function is mostly/only used for network interface.
+ * Some hotplug package track interfaces by their name and
+ * therefore want to know when the name is changed by the user. */
+ if (!error)
+ kobject_uevent_env(kobj, KOBJ_MOVE, envp);
+
+out:
+ kfree(devpath_string);
+ kfree(devpath);
kobject_put(kobj);
return error;