]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - lib/kobject_uevent.c
[IPG]: add IP1000A driver to kernel tree
[linux-2.6-omap-h63xx.git] / lib / kobject_uevent.c
index 82fc1794b69113ab09266b2ca26534c194418e83..e06a8dcec0f04ce9e566901be3fa52c786a74e41 100644 (file)
 #define BUFFER_SIZE    2048    /* buffer for the variables */
 #define NUM_ENVP       32      /* number of env pointers */
 
+/* the strings here must match the enum in include/linux/kobject.h */
+const char *kobject_actions[] = {
+       "add",
+       "remove",
+       "change",
+       "move",
+       "online",
+       "offline",
+};
+
 #if defined(CONFIG_HOTPLUG)
 u64 uevent_seqnum;
 char uevent_helper[UEVENT_HELPER_PATH_LEN] = "/sbin/hotplug";
@@ -33,30 +43,6 @@ static DEFINE_SPINLOCK(sequence_lock);
 static struct sock *uevent_sock;
 #endif
 
-static char *action_to_string(enum kobject_action action)
-{
-       switch (action) {
-       case KOBJ_ADD:
-               return "add";
-       case KOBJ_REMOVE:
-               return "remove";
-       case KOBJ_CHANGE:
-               return "change";
-       case KOBJ_MOUNT:
-               return "mount";
-       case KOBJ_UMOUNT:
-               return "umount";
-       case KOBJ_OFFLINE:
-               return "offline";
-       case KOBJ_ONLINE:
-               return "online";
-       case KOBJ_MOVE:
-               return "move";
-       default:
-               return NULL;
-       }
-}
-
 /**
  * kobject_uevent_env - send an uevent with environmental data
  *
@@ -87,7 +73,7 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
 
        pr_debug("%s\n", __FUNCTION__);
 
-       action_string = action_to_string(action);
+       action_string = kobject_actions[action];
        if (!action_string) {
                pr_debug("kobject attempted to send uevent without action_string!\n");
                return -EINVAL;
@@ -95,10 +81,8 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
 
        /* search the kset we belong to */
        top_kobj = kobj;
-       if (!top_kobj->kset && top_kobj->parent) {
-               do {
-                       top_kobj = top_kobj->parent;
-               } while (!top_kobj->kset && top_kobj->parent);
+       while (!top_kobj->kset && top_kobj->parent) {
+               top_kobj = top_kobj->parent;
        }
        if (!top_kobj->kset) {
                pr_debug("kobject attempted to send uevent without kset!\n");
@@ -115,6 +99,16 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
                        return 0;
                }
 
+       /* originating subsystem */
+       if (uevent_ops && uevent_ops->name)
+               subsystem = uevent_ops->name(kset, kobj);
+       else
+               subsystem = kobject_name(&kset->kobj);
+       if (!subsystem) {
+               pr_debug("unset subsytem caused the event to drop!\n");
+               return 0;
+       }
+
        /* environment index */
        envp = kzalloc(NUM_ENVP * sizeof (char *), GFP_KERNEL);
        if (!envp)
@@ -134,12 +128,6 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
                goto exit;
        }
 
-       /* originating subsystem */
-       if (uevent_ops && uevent_ops->name)
-               subsystem = uevent_ops->name(kset, kobj);
-       else
-               subsystem = kobject_name(&kset->kobj);
-
        /* event environemnt for helper process only */
        envp[i++] = "HOME=/";
        envp[i++] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin";
@@ -210,7 +198,7 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
                argv [0] = uevent_helper;
                argv [1] = (char *)subsystem;
                argv [2] = NULL;
-               call_usermodehelper (argv[0], argv, envp, 0);
+               call_usermodehelper (argv[0], argv, envp, UMH_WAIT_EXEC);
        }
 
 exit:
@@ -292,9 +280,8 @@ EXPORT_SYMBOL_GPL(add_uevent_var);
 #if defined(CONFIG_NET)
 static int __init kobject_uevent_init(void)
 {
-       uevent_sock = netlink_kernel_create(NETLINK_KOBJECT_UEVENT, 1, NULL,
-                                           NULL, THIS_MODULE);
-
+       uevent_sock = netlink_kernel_create(&init_net, NETLINK_KOBJECT_UEVENT,
+                                           1, NULL, NULL, THIS_MODULE);
        if (!uevent_sock) {
                printk(KERN_ERR
                       "kobject_uevent: unable to create netlink socket!\n");