diff options
author | Greg Kroah-Hartman <greg@kroah.com> | 2004-09-14 21:36:09 -0700 |
---|---|---|
committer | Greg Kroah-Hartman <greg@kroah.com> | 2004-09-14 21:36:09 -0700 |
commit | db062d4a6fefc23b61c0315ac286cfeae0791329 (patch) | |
tree | ab6167af86dfd63c0d871b50558e9a215dd4393d /lib | |
parent | 04bf582d34faefd76101c16033d00dad974d7c2d (diff) | |
download | history-db062d4a6fefc23b61c0315ac286cfeae0791329.tar.gz |
kevent: standardize on the event types
This prevents any potential typos from happening.
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/kobject.c | 4 | ||||
-rw-r--r-- | lib/kobject_uevent.c | 46 |
2 files changed, 40 insertions, 10 deletions
diff --git a/lib/kobject.c b/lib/kobject.c index 4bc028f1abdf02..d623f0575f2300 100644 --- a/lib/kobject.c +++ b/lib/kobject.c @@ -186,7 +186,7 @@ int kobject_add(struct kobject * kobj) if (parent) kobject_put(parent); } else { - kobject_hotplug("add", kobj); + kobject_hotplug(kobj, KOBJ_ADD); } return error; @@ -300,7 +300,7 @@ int kobject_rename(struct kobject * kobj, char *new_name) void kobject_del(struct kobject * kobj) { - kobject_hotplug("remove", kobj); + kobject_hotplug(kobj, KOBJ_REMOVE); sysfs_remove_dir(kobj); unlink(kobj); } diff --git a/lib/kobject_uevent.c b/lib/kobject_uevent.c index af30c6e8075667..34983987292564 100644 --- a/lib/kobject_uevent.c +++ b/lib/kobject_uevent.c @@ -19,9 +19,29 @@ #include <linux/skbuff.h> #include <linux/netlink.h> #include <linux/string.h> +#include <linux/kobject_uevent.h> #include <linux/kobject.h> #include <net/sock.h> +/* + * These must match up with the values for enum kobject_action + * as found in include/linux/kobject_uevent.h + */ +static char *actions[] = { + "add", /* 0x00 */ + "remove", /* 0x01 */ + "change", /* 0x02 */ + "mount", /* 0x03 */ +}; + +static char *action_to_string(enum kobject_action action) +{ + if (action >= KOBJ_MAX_ACTION) + return NULL; + else + return actions[action]; +} + #ifdef CONFIG_KOBJECT_UEVENT static struct sock *uevent_sock; @@ -60,11 +80,12 @@ static int send_uevent(const char *signal, const char *obj, const void *buf, return netlink_broadcast(uevent_sock, skb, 0, 1, gfp_mask); } -static int do_kobject_uevent(const char *signal, struct kobject *kobj, +static int do_kobject_uevent(struct kobject *kobj, enum kobject_action action, struct attribute *attr, int gfp_mask) { char *path; char *attrpath; + char *signal; int len; int rc = -ENOMEM; @@ -72,6 +93,10 @@ static int do_kobject_uevent(const char *signal, struct kobject *kobj, if (!path) return -ENOMEM; + signal = action_to_string(action); + if (!signal) + return -EINVAL; + if (attr) { len = strlen(path); len += strlen(attr->name) + 2; @@ -97,17 +122,17 @@ exit: * @kobj: struct kobject that the event is happening to * @attr: optional struct attribute the event belongs to */ -int kobject_uevent(const char *signal, struct kobject *kobj, +int kobject_uevent(struct kobject *kobj, enum kobject_action action, struct attribute *attr) { - return do_kobject_uevent(signal, kobj, attr, GFP_KERNEL); + return do_kobject_uevent(kobj, action, attr, GFP_KERNEL); } EXPORT_SYMBOL_GPL(kobject_uevent); -int kobject_uevent_atomic(const char *signal, struct kobject *kobj, +int kobject_uevent_atomic(struct kobject *kobj, enum kobject_action action, struct attribute *attr) { - return do_kobject_uevent(signal, kobj, attr, GFP_ATOMIC); + return do_kobject_uevent(kobj, action, attr, GFP_ATOMIC); } EXPORT_SYMBOL_GPL(kobject_uevent_atomic); @@ -149,7 +174,7 @@ static spinlock_t sequence_lock = SPIN_LOCK_UNLOCKED; * @action: action that is happening (usually "ADD" or "REMOVE") * @kobj: struct kobject that the action is happening to */ -void kobject_hotplug(const char *action, struct kobject *kobj) +void kobject_hotplug(struct kobject *kobj, enum kobject_action action) { char *argv [3]; char **envp = NULL; @@ -159,6 +184,7 @@ void kobject_hotplug(const char *action, struct kobject *kobj) int retval; char *kobj_path = NULL; char *name = NULL; + char *action_string; u64 seq; struct kobject *top_kobj = kobj; struct kset *kset; @@ -183,6 +209,10 @@ void kobject_hotplug(const char *action, struct kobject *kobj) pr_debug ("%s\n", __FUNCTION__); + action_string = action_to_string(action); + if (!action_string) + return; + envp = kmalloc(NUM_ENVP * sizeof (char *), GFP_KERNEL); if (!envp) return; @@ -208,7 +238,7 @@ void kobject_hotplug(const char *action, struct kobject *kobj) scratch = buffer; envp [i++] = scratch; - scratch += sprintf(scratch, "ACTION=%s", action) + 1; + scratch += sprintf(scratch, "ACTION=%s", action_string) + 1; kobj_path = kobject_get_path(kobj, GFP_KERNEL); if (!kobj_path) @@ -242,7 +272,7 @@ void kobject_hotplug(const char *action, struct kobject *kobj) pr_debug ("%s: %s %s %s %s %s %s %s\n", __FUNCTION__, argv[0], argv[1], envp[0], envp[1], envp[2], envp[3], envp[4]); - send_uevent(action, kobj_path, buffer, scratch - buffer, GFP_KERNEL); + send_uevent(action_string, kobj_path, buffer, scratch - buffer, GFP_KERNEL); if (!hotplug_path[0]) goto exit; |