前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Linux uevent分析、用户接收uevent以及mdev分析

Linux uevent分析、用户接收uevent以及mdev分析

作者头像
233333
发布2023-07-24 21:38:07
3440
发布2023-07-24 21:38:07
举报
文章被收录于专栏:linux驱动个人学习

int mdev_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int mdev_main(int argc UNUSED_PARAM, char **argv) { RESERVE_CONFIG_BUFFER(temp, PATH_MAX + SCRATCH_SIZE);

代码语言:javascript
复制
INIT_G();

if ENABLE_FEATURE_MDEV_CONF

代码语言:javascript
复制
G.filename = "/etc/mdev.conf";

endif

代码语言:javascript
复制
bb_sanitize_stdio();

umask(0);

xchdir("/dev");--------------------------------------------------?????????/dev??

if (argv[1] && strcmp(argv[1], "-s") == 0) {---------------------mdev -s?????/sys/dev???????
    /*
     * Scan: mdev -s
     */
    struct stat st;

if ENABLE_FEATURE_MDEV_CONF

代码语言:javascript
复制
    /* Same as xrealloc_vector(NULL, 4, 0): */
    G.rule_vec = xzalloc((1 << 4) * sizeof(*G.rule_vec));

endif

代码语言:javascript
复制
    xstat("/", &st);
    G.root_major = major(st.st_dev);
    G.root_minor = minor(st.st_dev);

    putenv((char*)"ACTION=add");

    /* Create all devices from /sys/dev hierarchy */
    recursive_action("/sys/dev",
             ACTION_RECURSE | ACTION_FOLLOWLINKS,
             fileAction, dirAction, temp, 0);----------------????????????/sys/dev??????????dev??????/etc/mdev.con??????????
} else {
    char *fw;
    char *seq;
    char *action;
    char *env_devname;
    char *env_devpath;
    unsigned my_pid;
    unsigned seqnum = seqnum; /* for compiler */
    int seq_fd;
    smalluint op;

    /* Hotplug:
     * env ACTION=... DEVPATH=... SUBSYSTEM=... [SEQNUM=...] mdev
     * ACTION can be "add", "remove", "change"
     * DEVPATH is like "/block/sda" or "/class/input/mice"
     */
    env_devname = getenv("DEVNAME"); /* can be NULL */----------????kobject_uevent_env()?????????????????do_execve()????mdev????getenv????
    G.subsystem = getenv("SUBSYSTEM");
    action = getenv("ACTION");
    env_devpath = getenv("DEVPATH");
    if (!action || !env_devpath /*|| !G.subsystem*/)
        bb_show_usage();
    fw = getenv("FIRMWARE");
    seq = getenv("SEQNUM");
    op = index_in_strings(keywords, action);--------------------keywords???add?remove???op???OP_add?OP_remove?

... snprintf(temp, PATH_MAX, "/sys%s", env_devpath); if (op == OP_remove) { /* Ignoring "remove firmware". It was reported * to happen and to cause erroneous deletion * of device nodes. */ if (!fw) make_device(env_devname, temp, op);-----------------?temp????????env_devnam?????? } else { make_device(env_devname, temp, op);---------------------??temp??????env_devname???? if (ENABLE_FEATURE_MDEV_LOAD_FIRMWARE) { if (op == OP_add && fw) load_firmware(fw, temp);------------------------?fw?????temp???? } } ... }

代码语言:javascript
复制
if (ENABLE_FEATURE_CLEAN_UP)
    RELEASE_CONFIG_BUFFER(temp);

return EXIT_SUCCESS;

}

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2023-07-19,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • if ENABLE_FEATURE_MDEV_CONF
  • endif
  • if ENABLE_FEATURE_MDEV_CONF
  • endif
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档