aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile3
-rw-r--r--lib/kobject.c135
-rw-r--r--lib/kobject_uevent.c216
3 files changed, 163 insertions, 191 deletions
diff --git a/lib/Makefile b/lib/Makefile
index 4f3f3e256501..6c4ea33bb2cb 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -10,7 +10,7 @@ lib-y := ctype.o string.o vsprintf.o cmdline.o \
10lib-$(CONFIG_MMU) += ioremap.o 10lib-$(CONFIG_MMU) += ioremap.o
11lib-$(CONFIG_SMP) += cpumask.o 11lib-$(CONFIG_SMP) += cpumask.o
12 12
13lib-y += kobject.o kref.o kobject_uevent.o klist.o 13lib-y += kobject.o kref.o klist.o
14 14
15obj-y += div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \ 15obj-y += div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \
16 bust_spinlocks.o hexdump.o kasprintf.o 16 bust_spinlocks.o hexdump.o kasprintf.o
@@ -20,6 +20,7 @@ CFLAGS_kobject.o += -DDEBUG
20CFLAGS_kobject_uevent.o += -DDEBUG 20CFLAGS_kobject_uevent.o += -DDEBUG
21endif 21endif
22 22
23lib-$(CONFIG_HOTPLUG) += kobject_uevent.o
23obj-$(CONFIG_GENERIC_IOMAP) += iomap.o 24obj-$(CONFIG_GENERIC_IOMAP) += iomap.o
24obj-$(CONFIG_HAS_IOMEM) += iomap_copy.o devres.o 25obj-$(CONFIG_HAS_IOMEM) += iomap_copy.o devres.o
25obj-$(CONFIG_CHECK_SIGNATURE) += check_signature.o 26obj-$(CONFIG_CHECK_SIGNATURE) += check_signature.o
diff --git a/lib/kobject.c b/lib/kobject.c
index 4b08e0ff95c8..03d40360ff1b 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -2,6 +2,8 @@
2 * kobject.c - library routines for handling generic kernel objects 2 * kobject.c - library routines for handling generic kernel objects
3 * 3 *
4 * Copyright (c) 2002-2003 Patrick Mochel <mochel@osdl.org> 4 * Copyright (c) 2002-2003 Patrick Mochel <mochel@osdl.org>
5 * Copyright (c) 2006-2007 Greg Kroah-Hartman <greg@kroah.com>
6 * Copyright (c) 2006-2007 Novell Inc.
5 * 7 *
6 * This file is released under the GPLv2. 8 * This file is released under the GPLv2.
7 * 9 *
@@ -44,11 +46,11 @@ static int populate_dir(struct kobject * kobj)
44 return error; 46 return error;
45} 47}
46 48
47static int create_dir(struct kobject *kobj, struct sysfs_dirent *shadow_parent) 49static int create_dir(struct kobject * kobj)
48{ 50{
49 int error = 0; 51 int error = 0;
50 if (kobject_name(kobj)) { 52 if (kobject_name(kobj)) {
51 error = sysfs_create_dir(kobj, shadow_parent); 53 error = sysfs_create_dir(kobj);
52 if (!error) { 54 if (!error) {
53 if ((error = populate_dir(kobj))) 55 if ((error = populate_dir(kobj)))
54 sysfs_remove_dir(kobj); 56 sysfs_remove_dir(kobj);
@@ -131,7 +133,6 @@ void kobject_init(struct kobject * kobj)
131 return; 133 return;
132 kref_init(&kobj->kref); 134 kref_init(&kobj->kref);
133 INIT_LIST_HEAD(&kobj->entry); 135 INIT_LIST_HEAD(&kobj->entry);
134 init_waitqueue_head(&kobj->poll);
135 kobj->kset = kset_get(kobj->kset); 136 kobj->kset = kset_get(kobj->kset);
136} 137}
137 138
@@ -157,12 +158,11 @@ static void unlink(struct kobject * kobj)
157} 158}
158 159
159/** 160/**
160 * kobject_shadow_add - add an object to the hierarchy. 161 * kobject_add - add an object to the hierarchy.
161 * @kobj: object. 162 * @kobj: object.
162 * @shadow_parent: sysfs directory to add to.
163 */ 163 */
164 164
165int kobject_shadow_add(struct kobject *kobj, struct sysfs_dirent *shadow_parent) 165int kobject_add(struct kobject * kobj)
166{ 166{
167 int error = 0; 167 int error = 0;
168 struct kobject * parent; 168 struct kobject * parent;
@@ -170,7 +170,7 @@ int kobject_shadow_add(struct kobject *kobj, struct sysfs_dirent *shadow_parent)
170 if (!(kobj = kobject_get(kobj))) 170 if (!(kobj = kobject_get(kobj)))
171 return -ENOENT; 171 return -ENOENT;
172 if (!kobj->k_name) 172 if (!kobj->k_name)
173 kobj->k_name = kobj->name; 173 kobject_set_name(kobj, "NO_NAME");
174 if (!*kobj->k_name) { 174 if (!*kobj->k_name) {
175 pr_debug("kobject attempted to be registered with no name!\n"); 175 pr_debug("kobject attempted to be registered with no name!\n");
176 WARN_ON(1); 176 WARN_ON(1);
@@ -181,7 +181,7 @@ int kobject_shadow_add(struct kobject *kobj, struct sysfs_dirent *shadow_parent)
181 181
182 pr_debug("kobject %s: registering. parent: %s, set: %s\n", 182 pr_debug("kobject %s: registering. parent: %s, set: %s\n",
183 kobject_name(kobj), parent ? kobject_name(parent) : "<NULL>", 183 kobject_name(kobj), parent ? kobject_name(parent) : "<NULL>",
184 kobj->kset ? kobj->kset->kobj.name : "<NULL>" ); 184 kobj->kset ? kobject_name(&kobj->kset->kobj) : "<NULL>" );
185 185
186 if (kobj->kset) { 186 if (kobj->kset) {
187 spin_lock(&kobj->kset->list_lock); 187 spin_lock(&kobj->kset->list_lock);
@@ -194,7 +194,7 @@ int kobject_shadow_add(struct kobject *kobj, struct sysfs_dirent *shadow_parent)
194 kobj->parent = parent; 194 kobj->parent = parent;
195 } 195 }
196 196
197 error = create_dir(kobj, shadow_parent); 197 error = create_dir(kobj);
198 if (error) { 198 if (error) {
199 /* unlink does the kobject_put() for us */ 199 /* unlink does the kobject_put() for us */
200 unlink(kobj); 200 unlink(kobj);
@@ -216,16 +216,6 @@ int kobject_shadow_add(struct kobject *kobj, struct sysfs_dirent *shadow_parent)
216} 216}
217 217
218/** 218/**
219 * kobject_add - add an object to the hierarchy.
220 * @kobj: object.
221 */
222int kobject_add(struct kobject * kobj)
223{
224 return kobject_shadow_add(kobj, NULL);
225}
226
227
228/**
229 * kobject_register - initialize and add an object. 219 * kobject_register - initialize and add an object.
230 * @kobj: object in question. 220 * @kobj: object in question.
231 */ 221 */
@@ -255,54 +245,50 @@ int kobject_register(struct kobject * kobj)
255int kobject_set_name(struct kobject * kobj, const char * fmt, ...) 245int kobject_set_name(struct kobject * kobj, const char * fmt, ...)
256{ 246{
257 int error = 0; 247 int error = 0;
258 int limit = KOBJ_NAME_LEN; 248 int limit;
259 int need; 249 int need;
260 va_list args; 250 va_list args;
261 char * name; 251 char *name;
262 252
263 /* 253 /* find out how big a buffer we need */
264 * First, try the static array 254 name = kmalloc(1024, GFP_KERNEL);
265 */ 255 if (!name) {
266 va_start(args,fmt); 256 error = -ENOMEM;
267 need = vsnprintf(kobj->name,limit,fmt,args); 257 goto done;
258 }
259 va_start(args, fmt);
260 need = vsnprintf(name, 1024, fmt, args);
268 va_end(args); 261 va_end(args);
269 if (need < limit) 262 kfree(name);
270 name = kobj->name; 263
271 else { 264 /* Allocate the new space and copy the string in */
272 /* 265 limit = need + 1;
273 * Need more space? Allocate it and try again 266 name = kmalloc(limit, GFP_KERNEL);
274 */ 267 if (!name) {
275 limit = need + 1; 268 error = -ENOMEM;
276 name = kmalloc(limit,GFP_KERNEL); 269 goto done;
277 if (!name) { 270 }
278 error = -ENOMEM; 271 va_start(args, fmt);
279 goto Done; 272 need = vsnprintf(name, limit, fmt, args);
280 } 273 va_end(args);
281 va_start(args,fmt); 274
282 need = vsnprintf(name,limit,fmt,args); 275 /* something wrong with the string we copied? */
283 va_end(args); 276 if (need >= limit) {
284 277 kfree(name);
285 /* Still? Give up. */ 278 error = -EFAULT;
286 if (need >= limit) { 279 goto done;
287 kfree(name);
288 error = -EFAULT;
289 goto Done;
290 }
291 } 280 }
292 281
293 /* Free the old name, if necessary. */ 282 /* Free the old name, if necessary. */
294 if (kobj->k_name && kobj->k_name != kobj->name) 283 kfree(kobj->k_name);
295 kfree(kobj->k_name);
296 284
297 /* Now, set the new name */ 285 /* Now, set the new name */
298 kobj->k_name = name; 286 kobj->k_name = name;
299 Done: 287done:
300 return error; 288 return error;
301} 289}
302
303EXPORT_SYMBOL(kobject_set_name); 290EXPORT_SYMBOL(kobject_set_name);
304 291
305
306/** 292/**
307 * kobject_rename - change the name of an object 293 * kobject_rename - change the name of an object
308 * @kobj: object in question. 294 * @kobj: object in question.
@@ -338,7 +324,7 @@ int kobject_rename(struct kobject * kobj, const char *new_name)
338 /* Note : if we want to send the new name alone, not the full path, 324 /* Note : if we want to send the new name alone, not the full path,
339 * we could probably use kobject_name(kobj); */ 325 * we could probably use kobject_name(kobj); */
340 326
341 error = sysfs_rename_dir(kobj, kobj->parent->sd, new_name); 327 error = sysfs_rename_dir(kobj, new_name);
342 328
343 /* This function is mostly/only used for network interface. 329 /* This function is mostly/only used for network interface.
344 * Some hotplug package track interfaces by their name and 330 * Some hotplug package track interfaces by their name and
@@ -355,27 +341,6 @@ out:
355} 341}
356 342
357/** 343/**
358 * kobject_rename - change the name of an object
359 * @kobj: object in question.
360 * @new_parent: object's new parent
361 * @new_name: object's new name
362 */
363
364int kobject_shadow_rename(struct kobject *kobj,
365 struct sysfs_dirent *new_parent, const char *new_name)
366{
367 int error = 0;
368
369 kobj = kobject_get(kobj);
370 if (!kobj)
371 return -EINVAL;
372 error = sysfs_rename_dir(kobj, new_parent, new_name);
373 kobject_put(kobj);
374
375 return error;
376}
377
378/**
379 * kobject_move - move object to another parent 344 * kobject_move - move object to another parent
380 * @kobj: object in question. 345 * @kobj: object in question.
381 * @new_parent: object's new parent (can be NULL) 346 * @new_parent: object's new parent (can be NULL)
@@ -477,13 +442,16 @@ void kobject_cleanup(struct kobject * kobj)
477 struct kobj_type * t = get_ktype(kobj); 442 struct kobj_type * t = get_ktype(kobj);
478 struct kset * s = kobj->kset; 443 struct kset * s = kobj->kset;
479 struct kobject * parent = kobj->parent; 444 struct kobject * parent = kobj->parent;
445 const char *name = kobj->k_name;
480 446
481 pr_debug("kobject %s: cleaning up\n",kobject_name(kobj)); 447 pr_debug("kobject %s: cleaning up\n",kobject_name(kobj));
482 if (kobj->k_name != kobj->name) 448 if (t && t->release) {
483 kfree(kobj->k_name);
484 kobj->k_name = NULL;
485 if (t && t->release)
486 t->release(kobj); 449 t->release(kobj);
450 /* If we have a release function, we can guess that this was
451 * not a statically allocated kobject, so we should be safe to
452 * free the name */
453 kfree(name);
454 }
487 if (s) 455 if (s)
488 kset_put(s); 456 kset_put(s);
489 kobject_put(parent); 457 kobject_put(parent);
@@ -651,11 +619,6 @@ struct kobject * kset_find_obj(struct kset * kset, const char * name)
651 return ret; 619 return ret;
652} 620}
653 621
654void subsystem_init(struct kset *s)
655{
656 kset_init(s);
657}
658
659int subsystem_register(struct kset *s) 622int subsystem_register(struct kset *s)
660{ 623{
661 return kset_register(s); 624 return kset_register(s);
@@ -679,9 +642,9 @@ int subsys_create_file(struct kset *s, struct subsys_attribute *a)
679 if (!s || !a) 642 if (!s || !a)
680 return -EINVAL; 643 return -EINVAL;
681 644
682 if (subsys_get(s)) { 645 if (kset_get(s)) {
683 error = sysfs_create_file(&s->kobj, &a->attr); 646 error = sysfs_create_file(&s->kobj, &a->attr);
684 subsys_put(s); 647 kset_put(s);
685 } 648 }
686 return error; 649 return error;
687} 650}
diff --git a/lib/kobject_uevent.c b/lib/kobject_uevent.c
index e06a8dcec0f0..2e4eae5b0824 100644
--- a/lib/kobject_uevent.c
+++ b/lib/kobject_uevent.c
@@ -22,31 +22,62 @@
22#include <linux/kobject.h> 22#include <linux/kobject.h>
23#include <net/sock.h> 23#include <net/sock.h>
24 24
25#define BUFFER_SIZE 2048 /* buffer for the variables */
26#define NUM_ENVP 32 /* number of env pointers */
27 25
28/* the strings here must match the enum in include/linux/kobject.h */
29const char *kobject_actions[] = {
30 "add",
31 "remove",
32 "change",
33 "move",
34 "online",
35 "offline",
36};
37
38#if defined(CONFIG_HOTPLUG)
39u64 uevent_seqnum; 26u64 uevent_seqnum;
40char uevent_helper[UEVENT_HELPER_PATH_LEN] = "/sbin/hotplug"; 27char uevent_helper[UEVENT_HELPER_PATH_LEN] = CONFIG_UEVENT_HELPER_PATH;
41static DEFINE_SPINLOCK(sequence_lock); 28static DEFINE_SPINLOCK(sequence_lock);
42#if defined(CONFIG_NET) 29#if defined(CONFIG_NET)
43static struct sock *uevent_sock; 30static struct sock *uevent_sock;
44#endif 31#endif
45 32
33/* the strings here must match the enum in include/linux/kobject.h */
34static 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 */
52int 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 }
73out:
74 return ret;
75}
76
46/** 77/**
47 * kobject_uevent_env - send an uevent with environmental data 78 * kobject_uevent_env - send an uevent with environmental data
48 * 79 *
49 * @action: action that is happening (usually KOBJ_MOVE) 80 * @action: action that is happening
50 * @kobj: struct kobject that the action is happening to 81 * @kobj: struct kobject that the action is happening to
51 * @envp_ext: pointer to environmental data 82 * @envp_ext: pointer to environmental data
52 * 83 *
@@ -54,36 +85,26 @@ static struct sock *uevent_sock;
54 * corresponding error when it fails. 85 * corresponding error when it fails.
55 */ 86 */
56int kobject_uevent_env(struct kobject *kobj, enum kobject_action action, 87int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
57 char *envp_ext[]) 88 char *envp_ext[])
58{ 89{
59 char **envp; 90 struct kobj_uevent_env *env;
60 char *buffer; 91 const char *action_string = kobject_actions[action];
61 char *scratch;
62 const char *action_string;
63 const char *devpath = NULL; 92 const char *devpath = NULL;
64 const char *subsystem; 93 const char *subsystem;
65 struct kobject *top_kobj; 94 struct kobject *top_kobj;
66 struct kset *kset; 95 struct kset *kset;
67 struct kset_uevent_ops *uevent_ops; 96 struct kset_uevent_ops *uevent_ops;
68 u64 seq; 97 u64 seq;
69 char *seq_buff;
70 int i = 0; 98 int i = 0;
71 int retval = 0; 99 int retval = 0;
72 int j;
73 100
74 pr_debug("%s\n", __FUNCTION__); 101 pr_debug("%s\n", __FUNCTION__);
75 102
76 action_string = kobject_actions[action];
77 if (!action_string) {
78 pr_debug("kobject attempted to send uevent without action_string!\n");
79 return -EINVAL;
80 }
81
82 /* search the kset we belong to */ 103 /* search the kset we belong to */
83 top_kobj = kobj; 104 top_kobj = kobj;
84 while (!top_kobj->kset && top_kobj->parent) { 105 while (!top_kobj->kset && top_kobj->parent)
85 top_kobj = top_kobj->parent; 106 top_kobj = top_kobj->parent;
86 } 107
87 if (!top_kobj->kset) { 108 if (!top_kobj->kset) {
88 pr_debug("kobject attempted to send uevent without kset!\n"); 109 pr_debug("kobject attempted to send uevent without kset!\n");
89 return -EINVAL; 110 return -EINVAL;
@@ -92,7 +113,7 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
92 kset = top_kobj->kset; 113 kset = top_kobj->kset;
93 uevent_ops = kset->uevent_ops; 114 uevent_ops = kset->uevent_ops;
94 115
95 /* skip the event, if the filter returns zero. */ 116 /* skip the event, if the filter returns zero. */
96 if (uevent_ops && uevent_ops->filter) 117 if (uevent_ops && uevent_ops->filter)
97 if (!uevent_ops->filter(kset, kobj)) { 118 if (!uevent_ops->filter(kset, kobj)) {
98 pr_debug("kobject filter function caused the event to drop!\n"); 119 pr_debug("kobject filter function caused the event to drop!\n");
@@ -109,18 +130,11 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
109 return 0; 130 return 0;
110 } 131 }
111 132
112 /* environment index */ 133 /* environment buffer */
113 envp = kzalloc(NUM_ENVP * sizeof (char *), GFP_KERNEL); 134 env = kzalloc(sizeof(struct kobj_uevent_env), GFP_KERNEL);
114 if (!envp) 135 if (!env)
115 return -ENOMEM; 136 return -ENOMEM;
116 137
117 /* environment values */
118 buffer = kmalloc(BUFFER_SIZE, GFP_KERNEL);
119 if (!buffer) {
120 retval = -ENOMEM;
121 goto exit;
122 }
123
124 /* complete object path */ 138 /* complete object path */
125 devpath = kobject_get_path(kobj, GFP_KERNEL); 139 devpath = kobject_get_path(kobj, GFP_KERNEL);
126 if (!devpath) { 140 if (!devpath) {
@@ -128,29 +142,29 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
128 goto exit; 142 goto exit;
129 } 143 }
130 144
131 /* event environemnt for helper process only */
132 envp[i++] = "HOME=/";
133 envp[i++] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin";
134
135 /* default keys */ 145 /* default keys */
136 scratch = buffer; 146 retval = add_uevent_var(env, "ACTION=%s", action_string);
137 envp [i++] = scratch; 147 if (retval)
138 scratch += sprintf(scratch, "ACTION=%s", action_string) + 1; 148 goto exit;
139 envp [i++] = scratch; 149 retval = add_uevent_var(env, "DEVPATH=%s", devpath);
140 scratch += sprintf (scratch, "DEVPATH=%s", devpath) + 1; 150 if (retval)
141 envp [i++] = scratch; 151 goto exit;
142 scratch += sprintf(scratch, "SUBSYSTEM=%s", subsystem) + 1; 152 retval = add_uevent_var(env, "SUBSYSTEM=%s", subsystem);
143 for (j = 0; envp_ext && envp_ext[j]; j++) 153 if (retval)
144 envp[i++] = envp_ext[j]; 154 goto exit;
145 /* just reserve the space, overwrite it after kset call has returned */ 155
146 envp[i++] = seq_buff = scratch; 156 /* keys passed in from the caller */
147 scratch += strlen("SEQNUM=18446744073709551616") + 1; 157 if (envp_ext) {
158 for (i = 0; envp_ext[i]; i++) {
159 retval = add_uevent_var(env, envp_ext[i]);
160 if (retval)
161 goto exit;
162 }
163 }
148 164
149 /* let the kset specific function add its stuff */ 165 /* let the kset specific function add its stuff */
150 if (uevent_ops && uevent_ops->uevent) { 166 if (uevent_ops && uevent_ops->uevent) {
151 retval = uevent_ops->uevent(kset, kobj, 167 retval = uevent_ops->uevent(kset, kobj, env);
152 &envp[i], NUM_ENVP - i, scratch,
153 BUFFER_SIZE - (scratch - buffer));
154 if (retval) { 168 if (retval) {
155 pr_debug ("%s - uevent() returned %d\n", 169 pr_debug ("%s - uevent() returned %d\n",
156 __FUNCTION__, retval); 170 __FUNCTION__, retval);
@@ -158,11 +172,13 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
158 } 172 }
159 } 173 }
160 174
161 /* we will send an event, request a new sequence number */ 175 /* we will send an event, so request a new sequence number */
162 spin_lock(&sequence_lock); 176 spin_lock(&sequence_lock);
163 seq = ++uevent_seqnum; 177 seq = ++uevent_seqnum;
164 spin_unlock(&sequence_lock); 178 spin_unlock(&sequence_lock);
165 sprintf(seq_buff, "SEQNUM=%llu", (unsigned long long)seq); 179 retval = add_uevent_var(env, "SEQNUM=%llu", (unsigned long long)seq);
180 if (retval)
181 goto exit;
166 182
167#if defined(CONFIG_NET) 183#if defined(CONFIG_NET)
168 /* send netlink message */ 184 /* send netlink message */
@@ -172,17 +188,19 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
172 188
173 /* allocate message with the maximum possible size */ 189 /* allocate message with the maximum possible size */
174 len = strlen(action_string) + strlen(devpath) + 2; 190 len = strlen(action_string) + strlen(devpath) + 2;
175 skb = alloc_skb(len + BUFFER_SIZE, GFP_KERNEL); 191 skb = alloc_skb(len + env->buflen, GFP_KERNEL);
176 if (skb) { 192 if (skb) {
193 char *scratch;
194
177 /* add header */ 195 /* add header */
178 scratch = skb_put(skb, len); 196 scratch = skb_put(skb, len);
179 sprintf(scratch, "%s@%s", action_string, devpath); 197 sprintf(scratch, "%s@%s", action_string, devpath);
180 198
181 /* copy keys to our continuous event payload buffer */ 199 /* copy keys to our continuous event payload buffer */
182 for (i = 2; envp[i]; i++) { 200 for (i = 0; i < env->envp_idx; i++) {
183 len = strlen(envp[i]) + 1; 201 len = strlen(env->envp[i]) + 1;
184 scratch = skb_put(skb, len); 202 scratch = skb_put(skb, len);
185 strcpy(scratch, envp[i]); 203 strcpy(scratch, env->envp[i]);
186 } 204 }
187 205
188 NETLINK_CB(skb).dst_group = 1; 206 NETLINK_CB(skb).dst_group = 1;
@@ -198,13 +216,19 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
198 argv [0] = uevent_helper; 216 argv [0] = uevent_helper;
199 argv [1] = (char *)subsystem; 217 argv [1] = (char *)subsystem;
200 argv [2] = NULL; 218 argv [2] = NULL;
201 call_usermodehelper (argv[0], argv, envp, UMH_WAIT_EXEC); 219 retval = add_uevent_var(env, "HOME=/");
220 if (retval)
221 goto exit;
222 retval = add_uevent_var(env, "PATH=/sbin:/bin:/usr/sbin:/usr/bin");
223 if (retval)
224 goto exit;
225
226 call_usermodehelper (argv[0], argv, env->envp, UMH_WAIT_EXEC);
202 } 227 }
203 228
204exit: 229exit:
205 kfree(devpath); 230 kfree(devpath);
206 kfree(buffer); 231 kfree(env);
207 kfree(envp);
208 return retval; 232 return retval;
209} 233}
210 234
@@ -213,7 +237,7 @@ EXPORT_SYMBOL_GPL(kobject_uevent_env);
213/** 237/**
214 * kobject_uevent - notify userspace by ending an uevent 238 * kobject_uevent - notify userspace by ending an uevent
215 * 239 *
216 * @action: action that is happening (usually KOBJ_ADD and KOBJ_REMOVE) 240 * @action: action that is happening
217 * @kobj: struct kobject that the action is happening to 241 * @kobj: struct kobject that the action is happening to
218 * 242 *
219 * Returns 0 if kobject_uevent() is completed with success or the 243 * Returns 0 if kobject_uevent() is completed with success or the
@@ -227,52 +251,38 @@ int kobject_uevent(struct kobject *kobj, enum kobject_action action)
227EXPORT_SYMBOL_GPL(kobject_uevent); 251EXPORT_SYMBOL_GPL(kobject_uevent);
228 252
229/** 253/**
230 * add_uevent_var - helper for creating event variables 254 * add_uevent_var - add key value string to the environment buffer
231 * @envp: Pointer to table of environment variables, as passed into 255 * @env: environment buffer structure
232 * uevent() method. 256 * @format: printf format for the key=value pair
233 * @num_envp: Number of environment variable slots available, as
234 * passed into uevent() method.
235 * @cur_index: Pointer to current index into @envp. It should be
236 * initialized to 0 before the first call to add_uevent_var(),
237 * and will be incremented on success.
238 * @buffer: Pointer to buffer for environment variables, as passed
239 * into uevent() method.
240 * @buffer_size: Length of @buffer, as passed into uevent() method.
241 * @cur_len: Pointer to current length of space used in @buffer.
242 * Should be initialized to 0 before the first call to
243 * add_uevent_var(), and will be incremented on success.
244 * @format: Format for creating environment variable (of the form
245 * "XXX=%x") for snprintf().
246 * 257 *
247 * Returns 0 if environment variable was added successfully or -ENOMEM 258 * Returns 0 if environment variable was added successfully or -ENOMEM
248 * if no space was available. 259 * if no space was available.
249 */ 260 */
250int add_uevent_var(char **envp, int num_envp, int *cur_index, 261int add_uevent_var(struct kobj_uevent_env *env, const char *format, ...)
251 char *buffer, int buffer_size, int *cur_len,
252 const char *format, ...)
253{ 262{
254 va_list args; 263 va_list args;
264 int len;
255 265
256 /* 266 if (env->envp_idx >= ARRAY_SIZE(env->envp)) {
257 * We check against num_envp - 1 to make sure there is at 267 printk(KERN_ERR "add_uevent_var: too many keys\n");
258 * least one slot left after we return, since kobject_uevent() 268 WARN_ON(1);
259 * needs to set the last slot to NULL.
260 */
261 if (*cur_index >= num_envp - 1)
262 return -ENOMEM; 269 return -ENOMEM;
263 270 }
264 envp[*cur_index] = buffer + *cur_len;
265 271
266 va_start(args, format); 272 va_start(args, format);
267 *cur_len += vsnprintf(envp[*cur_index], 273 len = vsnprintf(&env->buf[env->buflen],
268 max(buffer_size - *cur_len, 0), 274 sizeof(env->buf) - env->buflen,
269 format, args) + 1; 275 format, args);
270 va_end(args); 276 va_end(args);
271 277
272 if (*cur_len > buffer_size) 278 if (len >= (sizeof(env->buf) - env->buflen)) {
279 printk(KERN_ERR "add_uevent_var: buffer size too small\n");
280 WARN_ON(1);
273 return -ENOMEM; 281 return -ENOMEM;
282 }
274 283
275 (*cur_index)++; 284 env->envp[env->envp_idx++] = &env->buf[env->buflen];
285 env->buflen += len + 1;
276 return 0; 286 return 0;
277} 287}
278EXPORT_SYMBOL_GPL(add_uevent_var); 288EXPORT_SYMBOL_GPL(add_uevent_var);
@@ -293,5 +303,3 @@ static int __init kobject_uevent_init(void)
293 303
294postcore_initcall(kobject_uevent_init); 304postcore_initcall(kobject_uevent_init);
295#endif 305#endif
296
297#endif /* CONFIG_HOTPLUG */