Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * kernel userspace event delivery |
| 3 | * |
| 4 | * Copyright (C) 2004 Red Hat, Inc. All rights reserved. |
| 5 | * Copyright (C) 2004 Novell, Inc. All rights reserved. |
| 6 | * Copyright (C) 2004 IBM, Inc. All rights reserved. |
| 7 | * |
| 8 | * Licensed under the GNU GPL v2. |
| 9 | * |
| 10 | * Authors: |
| 11 | * Robert Love <rml@novell.com> |
| 12 | * Kay Sievers <kay.sievers@vrfy.org> |
| 13 | * Arjan van de Ven <arjanv@redhat.com> |
| 14 | * Greg Kroah-Hartman <greg@kroah.com> |
| 15 | */ |
| 16 | |
| 17 | #include <linux/spinlock.h> |
| 18 | #include <linux/socket.h> |
| 19 | #include <linux/skbuff.h> |
| 20 | #include <linux/netlink.h> |
| 21 | #include <linux/string.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <linux/kobject.h> |
| 23 | #include <net/sock.h> |
| 24 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
Cornelia Huck | cd030c4 | 2007-07-20 13:58:13 +0200 | [diff] [blame] | 26 | u64 uevent_seqnum; |
Kay Sievers | 6a8d8ab | 2007-08-15 15:38:28 +0200 | [diff] [blame] | 27 | char uevent_helper[UEVENT_HELPER_PATH_LEN] = CONFIG_UEVENT_HELPER_PATH; |
Cornelia Huck | cd030c4 | 2007-07-20 13:58:13 +0200 | [diff] [blame] | 28 | static DEFINE_SPINLOCK(sequence_lock); |
| 29 | #if defined(CONFIG_NET) |
| 30 | static struct sock *uevent_sock; |
| 31 | #endif |
| 32 | |
Kay Sievers | 5c5daf6 | 2007-08-12 20:43:55 +0200 | [diff] [blame] | 33 | /* the strings here must match the enum in include/linux/kobject.h */ |
| 34 | static const char *kobject_actions[] = { |
| 35 | [KOBJ_ADD] = "add", |
| 36 | [KOBJ_REMOVE] = "remove", |
| 37 | [KOBJ_CHANGE] = "change", |
| 38 | [KOBJ_MOVE] = "move", |
| 39 | [KOBJ_ONLINE] = "online", |
| 40 | [KOBJ_OFFLINE] = "offline", |
| 41 | }; |
| 42 | |
| 43 | /** |
| 44 | * kobject_action_type - translate action string to numeric type |
| 45 | * |
| 46 | * @buf: buffer containing the action string, newline is ignored |
| 47 | * @len: length of buffer |
| 48 | * @type: pointer to the location to store the action type |
| 49 | * |
| 50 | * Returns 0 if the action string was recognized. |
| 51 | */ |
| 52 | int kobject_action_type(const char *buf, size_t count, |
| 53 | enum kobject_action *type) |
| 54 | { |
| 55 | enum kobject_action action; |
| 56 | int ret = -EINVAL; |
| 57 | |
| 58 | if (count && buf[count-1] == '\n') |
| 59 | count--; |
| 60 | |
| 61 | if (!count) |
| 62 | goto out; |
| 63 | |
| 64 | for (action = 0; action < ARRAY_SIZE(kobject_actions); action++) { |
| 65 | if (strncmp(kobject_actions[action], buf, count) != 0) |
| 66 | continue; |
| 67 | if (kobject_actions[action][count] != '\0') |
| 68 | continue; |
| 69 | *type = action; |
| 70 | ret = 0; |
| 71 | break; |
| 72 | } |
| 73 | out: |
| 74 | return ret; |
| 75 | } |
| 76 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | /** |
Cornelia Huck | 8a82472 | 2006-11-20 17:07:51 +0100 | [diff] [blame] | 78 | * kobject_uevent_env - send an uevent with environmental data |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | * |
Kay Sievers | ccd490a | 2007-08-12 20:43:55 +0200 | [diff] [blame] | 80 | * @action: action that is happening |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | * @kobj: struct kobject that the action is happening to |
Cornelia Huck | 8a82472 | 2006-11-20 17:07:51 +0100 | [diff] [blame] | 82 | * @envp_ext: pointer to environmental data |
Aneesh Kumar K.V | 542cfce | 2006-12-19 13:01:27 -0800 | [diff] [blame] | 83 | * |
| 84 | * Returns 0 if kobject_uevent() is completed with success or the |
| 85 | * corresponding error when it fails. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | */ |
Aneesh Kumar K.V | 542cfce | 2006-12-19 13:01:27 -0800 | [diff] [blame] | 87 | int kobject_uevent_env(struct kobject *kobj, enum kobject_action action, |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 88 | char *envp_ext[]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | { |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 90 | struct kobj_uevent_env *env; |
| 91 | const char *action_string = kobject_actions[action]; |
Kay Sievers | 5f123fb | 2005-11-11 14:43:07 +0100 | [diff] [blame] | 92 | const char *devpath = NULL; |
| 93 | const char *subsystem; |
| 94 | struct kobject *top_kobj; |
| 95 | struct kset *kset; |
Kay Sievers | 312c004 | 2005-11-16 09:00:00 +0100 | [diff] [blame] | 96 | struct kset_uevent_ops *uevent_ops; |
Kay Sievers | 5f123fb | 2005-11-11 14:43:07 +0100 | [diff] [blame] | 97 | u64 seq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | int i = 0; |
Aneesh Kumar K.V | 542cfce | 2006-12-19 13:01:27 -0800 | [diff] [blame] | 99 | int retval = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | |
Greg Kroah-Hartman | 9f66fa2 | 2007-11-28 23:49:41 -0800 | [diff] [blame^] | 101 | pr_debug("kobject: '%s' (%p): %s\n", |
| 102 | kobject_name(kobj), kobj, __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | |
Kay Sievers | 5f123fb | 2005-11-11 14:43:07 +0100 | [diff] [blame] | 104 | /* search the kset we belong to */ |
| 105 | top_kobj = kobj; |
Kay Sievers | ccd490a | 2007-08-12 20:43:55 +0200 | [diff] [blame] | 106 | while (!top_kobj->kset && top_kobj->parent) |
John Anthony Kazos Jr | 14193fb | 2007-04-04 07:39:17 -0400 | [diff] [blame] | 107 | top_kobj = top_kobj->parent; |
Kay Sievers | ccd490a | 2007-08-12 20:43:55 +0200 | [diff] [blame] | 108 | |
Aneesh Kumar K.V | 542cfce | 2006-12-19 13:01:27 -0800 | [diff] [blame] | 109 | if (!top_kobj->kset) { |
Greg Kroah-Hartman | 9f66fa2 | 2007-11-28 23:49:41 -0800 | [diff] [blame^] | 110 | pr_debug("kobject: '%s' (%p): %s: attempted to send uevent " |
| 111 | "without kset!\n", kobject_name(kobj), kobj, |
| 112 | __FUNCTION__); |
Aneesh Kumar K.V | 542cfce | 2006-12-19 13:01:27 -0800 | [diff] [blame] | 113 | return -EINVAL; |
| 114 | } |
Kay Sievers | 5f123fb | 2005-11-11 14:43:07 +0100 | [diff] [blame] | 115 | |
| 116 | kset = top_kobj->kset; |
Kay Sievers | 312c004 | 2005-11-16 09:00:00 +0100 | [diff] [blame] | 117 | uevent_ops = kset->uevent_ops; |
Kay Sievers | 5f123fb | 2005-11-11 14:43:07 +0100 | [diff] [blame] | 118 | |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 119 | /* skip the event, if the filter returns zero. */ |
Kay Sievers | 312c004 | 2005-11-16 09:00:00 +0100 | [diff] [blame] | 120 | if (uevent_ops && uevent_ops->filter) |
Aneesh Kumar K.V | 542cfce | 2006-12-19 13:01:27 -0800 | [diff] [blame] | 121 | if (!uevent_ops->filter(kset, kobj)) { |
Greg Kroah-Hartman | 9f66fa2 | 2007-11-28 23:49:41 -0800 | [diff] [blame^] | 122 | pr_debug("kobject: '%s' (%p): %s: filter function " |
| 123 | "caused the event to drop!\n", |
| 124 | kobject_name(kobj), kobj, __FUNCTION__); |
Aneesh Kumar K.V | 542cfce | 2006-12-19 13:01:27 -0800 | [diff] [blame] | 125 | return 0; |
| 126 | } |
Kay Sievers | 5f123fb | 2005-11-11 14:43:07 +0100 | [diff] [blame] | 127 | |
Kay Sievers | 8640624 | 2007-03-14 03:25:56 +0100 | [diff] [blame] | 128 | /* originating subsystem */ |
| 129 | if (uevent_ops && uevent_ops->name) |
| 130 | subsystem = uevent_ops->name(kset, kobj); |
| 131 | else |
| 132 | subsystem = kobject_name(&kset->kobj); |
| 133 | if (!subsystem) { |
Greg Kroah-Hartman | 9f66fa2 | 2007-11-28 23:49:41 -0800 | [diff] [blame^] | 134 | pr_debug("kobject: '%s' (%p): %s: unset subsystem caused the " |
| 135 | "event to drop!\n", kobject_name(kobj), kobj, |
| 136 | __FUNCTION__); |
Kay Sievers | 8640624 | 2007-03-14 03:25:56 +0100 | [diff] [blame] | 137 | return 0; |
| 138 | } |
| 139 | |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 140 | /* environment buffer */ |
| 141 | env = kzalloc(sizeof(struct kobj_uevent_env), GFP_KERNEL); |
| 142 | if (!env) |
Aneesh Kumar K.V | 542cfce | 2006-12-19 13:01:27 -0800 | [diff] [blame] | 143 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | |
Kay Sievers | 5f123fb | 2005-11-11 14:43:07 +0100 | [diff] [blame] | 145 | /* complete object path */ |
| 146 | devpath = kobject_get_path(kobj, GFP_KERNEL); |
Aneesh Kumar K.V | 542cfce | 2006-12-19 13:01:27 -0800 | [diff] [blame] | 147 | if (!devpath) { |
| 148 | retval = -ENOENT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | goto exit; |
Aneesh Kumar K.V | 542cfce | 2006-12-19 13:01:27 -0800 | [diff] [blame] | 150 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | |
Kay Sievers | 5f123fb | 2005-11-11 14:43:07 +0100 | [diff] [blame] | 152 | /* default keys */ |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 153 | retval = add_uevent_var(env, "ACTION=%s", action_string); |
| 154 | if (retval) |
| 155 | goto exit; |
| 156 | retval = add_uevent_var(env, "DEVPATH=%s", devpath); |
| 157 | if (retval) |
| 158 | goto exit; |
| 159 | retval = add_uevent_var(env, "SUBSYSTEM=%s", subsystem); |
| 160 | if (retval) |
| 161 | goto exit; |
| 162 | |
| 163 | /* keys passed in from the caller */ |
| 164 | if (envp_ext) { |
| 165 | for (i = 0; envp_ext[i]; i++) { |
| 166 | retval = add_uevent_var(env, envp_ext[i]); |
| 167 | if (retval) |
| 168 | goto exit; |
| 169 | } |
| 170 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | |
Kay Sievers | 5f123fb | 2005-11-11 14:43:07 +0100 | [diff] [blame] | 172 | /* let the kset specific function add its stuff */ |
Kay Sievers | 312c004 | 2005-11-16 09:00:00 +0100 | [diff] [blame] | 173 | if (uevent_ops && uevent_ops->uevent) { |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 174 | retval = uevent_ops->uevent(kset, kobj, env); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | if (retval) { |
Greg Kroah-Hartman | 9f66fa2 | 2007-11-28 23:49:41 -0800 | [diff] [blame^] | 176 | pr_debug("kobject: '%s' (%p): %s: uevent() returned " |
| 177 | "%d\n", kobject_name(kobj), kobj, |
| 178 | __FUNCTION__, retval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | goto exit; |
| 180 | } |
| 181 | } |
| 182 | |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 183 | /* we will send an event, so request a new sequence number */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | spin_lock(&sequence_lock); |
Kay Sievers | 312c004 | 2005-11-16 09:00:00 +0100 | [diff] [blame] | 185 | seq = ++uevent_seqnum; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | spin_unlock(&sequence_lock); |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 187 | retval = add_uevent_var(env, "SEQNUM=%llu", (unsigned long long)seq); |
| 188 | if (retval) |
| 189 | goto exit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | |
Kay Sievers | 4d17ffd | 2006-04-25 15:37:26 +0200 | [diff] [blame] | 191 | #if defined(CONFIG_NET) |
Kay Sievers | 5f123fb | 2005-11-11 14:43:07 +0100 | [diff] [blame] | 192 | /* send netlink message */ |
| 193 | if (uevent_sock) { |
| 194 | struct sk_buff *skb; |
| 195 | size_t len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | |
Kay Sievers | 5f123fb | 2005-11-11 14:43:07 +0100 | [diff] [blame] | 197 | /* allocate message with the maximum possible size */ |
| 198 | len = strlen(action_string) + strlen(devpath) + 2; |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 199 | skb = alloc_skb(len + env->buflen, GFP_KERNEL); |
Kay Sievers | 5f123fb | 2005-11-11 14:43:07 +0100 | [diff] [blame] | 200 | if (skb) { |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 201 | char *scratch; |
| 202 | |
Kay Sievers | 5f123fb | 2005-11-11 14:43:07 +0100 | [diff] [blame] | 203 | /* add header */ |
| 204 | scratch = skb_put(skb, len); |
| 205 | sprintf(scratch, "%s@%s", action_string, devpath); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | |
Kay Sievers | 5f123fb | 2005-11-11 14:43:07 +0100 | [diff] [blame] | 207 | /* copy keys to our continuous event payload buffer */ |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 208 | for (i = 0; i < env->envp_idx; i++) { |
| 209 | len = strlen(env->envp[i]) + 1; |
Kay Sievers | 5f123fb | 2005-11-11 14:43:07 +0100 | [diff] [blame] | 210 | scratch = skb_put(skb, len); |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 211 | strcpy(scratch, env->envp[i]); |
Kay Sievers | 5f123fb | 2005-11-11 14:43:07 +0100 | [diff] [blame] | 212 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | |
Kay Sievers | 5f123fb | 2005-11-11 14:43:07 +0100 | [diff] [blame] | 214 | NETLINK_CB(skb).dst_group = 1; |
| 215 | netlink_broadcast(uevent_sock, skb, 0, 1, GFP_KERNEL); |
| 216 | } |
| 217 | } |
Kay Sievers | 4d17ffd | 2006-04-25 15:37:26 +0200 | [diff] [blame] | 218 | #endif |
Kay Sievers | 5f123fb | 2005-11-11 14:43:07 +0100 | [diff] [blame] | 219 | |
| 220 | /* call uevent_helper, usually only enabled during early boot */ |
Kay Sievers | 312c004 | 2005-11-16 09:00:00 +0100 | [diff] [blame] | 221 | if (uevent_helper[0]) { |
Kay Sievers | 5f123fb | 2005-11-11 14:43:07 +0100 | [diff] [blame] | 222 | char *argv [3]; |
| 223 | |
Kay Sievers | 312c004 | 2005-11-16 09:00:00 +0100 | [diff] [blame] | 224 | argv [0] = uevent_helper; |
Kay Sievers | 5f123fb | 2005-11-11 14:43:07 +0100 | [diff] [blame] | 225 | argv [1] = (char *)subsystem; |
| 226 | argv [2] = NULL; |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 227 | retval = add_uevent_var(env, "HOME=/"); |
| 228 | if (retval) |
| 229 | goto exit; |
| 230 | retval = add_uevent_var(env, "PATH=/sbin:/bin:/usr/sbin:/usr/bin"); |
| 231 | if (retval) |
| 232 | goto exit; |
| 233 | |
| 234 | call_usermodehelper (argv[0], argv, env->envp, UMH_WAIT_EXEC); |
Kay Sievers | 5f123fb | 2005-11-11 14:43:07 +0100 | [diff] [blame] | 235 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | |
| 237 | exit: |
Kay Sievers | 5f123fb | 2005-11-11 14:43:07 +0100 | [diff] [blame] | 238 | kfree(devpath); |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 239 | kfree(env); |
Aneesh Kumar K.V | 542cfce | 2006-12-19 13:01:27 -0800 | [diff] [blame] | 240 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | } |
Cornelia Huck | 8a82472 | 2006-11-20 17:07:51 +0100 | [diff] [blame] | 242 | |
| 243 | EXPORT_SYMBOL_GPL(kobject_uevent_env); |
| 244 | |
| 245 | /** |
| 246 | * kobject_uevent - notify userspace by ending an uevent |
| 247 | * |
Kay Sievers | ccd490a | 2007-08-12 20:43:55 +0200 | [diff] [blame] | 248 | * @action: action that is happening |
Cornelia Huck | 8a82472 | 2006-11-20 17:07:51 +0100 | [diff] [blame] | 249 | * @kobj: struct kobject that the action is happening to |
Aneesh Kumar K.V | 542cfce | 2006-12-19 13:01:27 -0800 | [diff] [blame] | 250 | * |
| 251 | * Returns 0 if kobject_uevent() is completed with success or the |
| 252 | * corresponding error when it fails. |
Cornelia Huck | 8a82472 | 2006-11-20 17:07:51 +0100 | [diff] [blame] | 253 | */ |
Aneesh Kumar K.V | 542cfce | 2006-12-19 13:01:27 -0800 | [diff] [blame] | 254 | int kobject_uevent(struct kobject *kobj, enum kobject_action action) |
Cornelia Huck | 8a82472 | 2006-11-20 17:07:51 +0100 | [diff] [blame] | 255 | { |
Aneesh Kumar K.V | 542cfce | 2006-12-19 13:01:27 -0800 | [diff] [blame] | 256 | return kobject_uevent_env(kobj, action, NULL); |
Cornelia Huck | 8a82472 | 2006-11-20 17:07:51 +0100 | [diff] [blame] | 257 | } |
| 258 | |
Kay Sievers | 312c004 | 2005-11-16 09:00:00 +0100 | [diff] [blame] | 259 | EXPORT_SYMBOL_GPL(kobject_uevent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | |
| 261 | /** |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 262 | * add_uevent_var - add key value string to the environment buffer |
| 263 | * @env: environment buffer structure |
| 264 | * @format: printf format for the key=value pair |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | * |
| 266 | * Returns 0 if environment variable was added successfully or -ENOMEM |
| 267 | * if no space was available. |
| 268 | */ |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 269 | int add_uevent_var(struct kobj_uevent_env *env, const char *format, ...) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | { |
| 271 | va_list args; |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 272 | int len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 274 | if (env->envp_idx >= ARRAY_SIZE(env->envp)) { |
| 275 | printk(KERN_ERR "add_uevent_var: too many keys\n"); |
| 276 | WARN_ON(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | return -ENOMEM; |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 278 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | |
| 280 | va_start(args, format); |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 281 | len = vsnprintf(&env->buf[env->buflen], |
| 282 | sizeof(env->buf) - env->buflen, |
| 283 | format, args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | va_end(args); |
| 285 | |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 286 | if (len >= (sizeof(env->buf) - env->buflen)) { |
| 287 | printk(KERN_ERR "add_uevent_var: buffer size too small\n"); |
| 288 | WARN_ON(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | return -ENOMEM; |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 290 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 292 | env->envp[env->envp_idx++] = &env->buf[env->buflen]; |
| 293 | env->buflen += len + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | return 0; |
| 295 | } |
Kay Sievers | 312c004 | 2005-11-16 09:00:00 +0100 | [diff] [blame] | 296 | EXPORT_SYMBOL_GPL(add_uevent_var); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | |
Kay Sievers | 4d17ffd | 2006-04-25 15:37:26 +0200 | [diff] [blame] | 298 | #if defined(CONFIG_NET) |
Kay Sievers | 5f123fb | 2005-11-11 14:43:07 +0100 | [diff] [blame] | 299 | static int __init kobject_uevent_init(void) |
| 300 | { |
Eric W. Biederman | b4b5102 | 2007-09-12 13:05:38 +0200 | [diff] [blame] | 301 | uevent_sock = netlink_kernel_create(&init_net, NETLINK_KOBJECT_UEVENT, |
| 302 | 1, NULL, NULL, THIS_MODULE); |
Kay Sievers | 5f123fb | 2005-11-11 14:43:07 +0100 | [diff] [blame] | 303 | if (!uevent_sock) { |
| 304 | printk(KERN_ERR |
| 305 | "kobject_uevent: unable to create netlink socket!\n"); |
| 306 | return -ENODEV; |
| 307 | } |
| 308 | |
| 309 | return 0; |
| 310 | } |
| 311 | |
| 312 | postcore_initcall(kobject_uevent_init); |
Kay Sievers | 4d17ffd | 2006-04-25 15:37:26 +0200 | [diff] [blame] | 313 | #endif |