lib/kobject_uevent.c
Source file repositories/reference/linux-study-clean/lib/kobject_uevent.c
File Facts
- System
- Linux kernel
- Corpus path
lib/kobject_uevent.c- Extension
.c- Size
- 20356 bytes
- Lines
- 852
- Domain
- Kernel Services
- Bucket
- lib
- Inferred role
- Kernel Services: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/spinlock.hlinux/string.hlinux/kobject.hlinux/export.hlinux/kmod.hlinux/slab.hlinux/socket.hlinux/skbuff.hlinux/netlink.hlinux/uidgid.hlinux/uuid.hlinux/ctype.hnet/sock.hnet/netlink.hnet/net_namespace.h
Detected Declarations
struct uevent_sockfunction kobject_action_typefunction kobject_action_argsfunction kobject_synthetic_ueventfunction kobj_usermode_filterfunction init_uevent_argvfunction cleanup_uevent_envfunction uevent_net_broadcast_untaggedfunction uevent_net_broadcast_taggedfunction kobject_uevent_net_broadcastfunction zap_modalias_envfunction kobject_uevent_envfunction kobject_ueventfunction add_uevent_varfunction uevent_net_broadcastfunction uevent_net_rcv_skbfunction uevent_net_rcvfunction uevent_net_initfunction uevent_net_exitfunction kobject_uevent_initfunction init_uevent_helper_sysctlexport kobject_uevent_envexport kobject_ueventexport add_uevent_var
Annotated Snippet
struct uevent_sock {
struct list_head list;
struct sock *sk;
};
#ifdef CONFIG_NET
static LIST_HEAD(uevent_sock_list);
/* This lock protects uevent_sock_list */
static DEFINE_MUTEX(uevent_sock_mutex);
#endif
/* the strings here must match the enum in include/linux/kobject.h */
static const char *kobject_actions[] = {
[KOBJ_ADD] = "add",
[KOBJ_REMOVE] = "remove",
[KOBJ_CHANGE] = "change",
[KOBJ_MOVE] = "move",
[KOBJ_ONLINE] = "online",
[KOBJ_OFFLINE] = "offline",
[KOBJ_BIND] = "bind",
[KOBJ_UNBIND] = "unbind",
};
static int kobject_action_type(const char *buf, size_t count,
enum kobject_action *type,
const char **args)
{
enum kobject_action action;
size_t count_first;
const char *args_start;
int ret = -EINVAL;
if (count && (buf[count-1] == '\n' || buf[count-1] == '\0'))
count--;
if (!count)
goto out;
args_start = strnchr(buf, count, ' ');
if (args_start) {
count_first = args_start - buf;
args_start = args_start + 1;
} else
count_first = count;
for (action = 0; action < ARRAY_SIZE(kobject_actions); action++) {
if (strncmp(kobject_actions[action], buf, count_first) != 0)
continue;
if (kobject_actions[action][count_first] != '\0')
continue;
if (args)
*args = args_start;
*type = action;
ret = 0;
break;
}
out:
return ret;
}
static const char *action_arg_word_end(const char *buf, const char *buf_end,
char delim)
{
const char *next = buf;
while (next <= buf_end && *next != delim)
if (!isalnum(*next++))
return NULL;
if (next == buf)
return NULL;
return next;
}
static int kobject_action_args(const char *buf, size_t count,
struct kobj_uevent_env **ret_env)
{
struct kobj_uevent_env *env = NULL;
const char *next, *buf_end, *key;
int key_len;
int r = -EINVAL;
if (count && (buf[count - 1] == '\n' || buf[count - 1] == '\0'))
count--;
if (!count)
return -EINVAL;
env = kzalloc_obj(*env);
Annotation
- Immediate include surface: `linux/spinlock.h`, `linux/string.h`, `linux/kobject.h`, `linux/export.h`, `linux/kmod.h`, `linux/slab.h`, `linux/socket.h`, `linux/skbuff.h`.
- Detected declarations: `struct uevent_sock`, `function kobject_action_type`, `function kobject_action_args`, `function kobject_synthetic_uevent`, `function kobj_usermode_filter`, `function init_uevent_argv`, `function cleanup_uevent_env`, `function uevent_net_broadcast_untagged`, `function uevent_net_broadcast_tagged`, `function kobject_uevent_net_broadcast`.
- Atlas domain: Kernel Services / lib.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.