18 #include <linux/string.h>
20 #include <linux/export.h>
22 #include <linux/slab.h>
24 #include <linux/socket.h>
26 #include <linux/netlink.h>
45 static const char *kobject_actions[] = {
69 if (count && (buf[count-1] ==
'\n' || buf[count-1] ==
'\0'))
75 for (action = 0; action <
ARRAY_SIZE(kobject_actions); action++) {
76 if (
strncmp(kobject_actions[action], buf, count) != 0)
78 if (kobject_actions[action][count] !=
'\0')
96 const void *sock_ns, *
ns;
97 ns = kobj->
ktype->namespace(kobj);
106 static int kobj_usermode_filter(
struct kobject *kobj)
112 const void *init_ns, *
ns;
113 ns = kobj->
ktype->namespace(kobj);
115 return ns != init_ns;
135 const char *action_string = kobject_actions[
action];
136 const char *devpath =
NULL;
137 const char *subsystem;
144 struct uevent_sock *ue_sk;
147 pr_debug(
"kobject: '%s' (%p): %s\n",
148 kobject_name(kobj), kobj, __func__);
153 top_kobj = top_kobj->
parent;
155 if (!top_kobj->
kset) {
156 pr_debug(
"kobject: '%s' (%p): %s: attempted to send uevent "
157 "without kset!\n", kobject_name(kobj), kobj,
162 kset = top_kobj->
kset;
167 pr_debug(
"kobject: '%s' (%p): %s: uevent_suppress "
168 "caused the event to drop!\n",
169 kobject_name(kobj), kobj, __func__);
173 if (uevent_ops && uevent_ops->
filter)
174 if (!uevent_ops->
filter(kset, kobj)) {
175 pr_debug(
"kobject: '%s' (%p): %s: filter function "
176 "caused the event to drop!\n",
177 kobject_name(kobj), kobj, __func__);
182 if (uevent_ops && uevent_ops->
name)
183 subsystem = uevent_ops->
name(kset, kobj);
185 subsystem = kobject_name(&kset->
kobj);
187 pr_debug(
"kobject: '%s' (%p): %s: unset subsystem caused the "
188 "event to drop!\n", kobject_name(kobj), kobj,
218 for (i = 0; envp_ext[
i]; i++) {
226 if (uevent_ops && uevent_ops->
uevent) {
227 retval = uevent_ops->
uevent(kset, kobj, env);
229 pr_debug(
"kobject: '%s' (%p): %s: uevent() returned "
230 "%d\n", kobject_name(kobj), kobj,
255 #if defined(CONFIG_NET)
258 struct sock *uevent_sock = ue_sk->sk;
273 sprintf(scratch,
"%s@%s", action_string, devpath);
276 for (i = 0; i < env->
envp_idx; i++) {
301 argv [1] = (
char *)subsystem;
307 "PATH=/sbin:/bin:/usr/sbin:/usr/bin");
311 retval = call_usermodehelper(argv[0], argv,
361 if (len >= (
sizeof(env->
buf) - env->
buflen)) {
362 WARN(1,
KERN_ERR "add_uevent_var: buffer size too small\n");
372 #if defined(CONFIG_NET)
373 static int uevent_net_init(
struct net *
net)
375 struct uevent_sock *ue_sk;
388 "kobject_uevent: unable to create netlink socket!\n");
398 static void uevent_net_exit(
struct net *net)
400 struct uevent_sock *ue_sk;
404 if (sock_net(ue_sk->sk) == net)
419 .
init = uevent_net_init,
420 .exit = uevent_net_exit,
423 static int __init kobject_uevent_init(
void)