Chinaunix首页 | 论坛 | 博客
  • 博客访问: 417009
  • 博文数量: 124
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 872
  • 用 户 组: 普通用户
  • 注册时间: 2018-03-29 14:38
个人简介

默默的一块石头

文章分类

全部博文(124)

文章存档

2022年(26)

2021年(10)

2020年(28)

2019年(60)

我的朋友

分类: LINUX

2019-11-01 17:31:41

int main(int argc, char *argv[]) {
       _cleanup_free_ char *cgroup = NULL;
       int fd_ctrl = -1, fd_uevent = -1;
       int r;
       r = parse_argv(argc, argv);
       if (r <= 0)       goto exit;
       r = proc_cmdline_parse(parse_proc_cmdline_item, NULL,
     PROC_CMDLINE_STRIP_RD_PREFIX);
       ……
       r = must_be_root();
       ……
       r = listen_fds(&fd_ctrl, &fd_uevent);
       ……
       r = run(fd_ctrl, fd_uevent, cgroup);
exit:
       mac_selinux_finish();
       log_close();
       return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}

static int run(int fd_ctrl, int fd_uevent, const char *cgroup) {
       _cleanup_(manager_freep) Manager *manager = NULL;
       int r;
       r = manager_new(&manager, fd_ctrl, fd_uevent, cgroup);
       r = udev_rules_apply_static_dev_perms(manager->rules);
       if (r < 0)
               log_error_errno(r, "failed to apply permissions on static device nodes: %m");
       (void) sd_notifyf(false,"READY=1\n"
                         "STATUS=Processing with %u children at max", arg_children_max);
       r = sd_event_loop(manager->event);
       sd_event_get_exit_code(manager->event, &r);
exit:
       sd_notify(false,"STOPPING=1\n""STATUS=Shutting down...");
       if (manager)
               udev_ctrl_cleanup(manager->ctrl);
       return r;
}

static int manager_new(Manager **ret, int fd_ctrl, int fd_uevent, const char *cgroup) {
       _cleanup_(manager_freep) Manager *manager = NULL;
       int r, fd_worker, one = 1;
  
       ……
       manager->rules = udev_rules_new(manager->udev, arg_resolve_names);
       ……
       *ret = manager;
       manager = NULL;
       return 0;
}

struct udev_rules *udev_rules_new(struct udev *udev, int resolve_names) {
       struct udev_rules *rules;
       struct udev_list file_list;
       struct token end_token;
       char **files, **f;
       int r;
       ……
       r = conf_files_list_strv(&files, ".rules", NULL, 0, rules_dirs);
       ……
       rules->uids = mfree(rules->uids);
       rules->uids_cur = 0;
       rules->uids_max = 0;
       rules->gids = mfree(rules->gids);
       rules->gids_cur = 0;
       rules->gids_max = 0;
       dump_rules(rules);
       return rules;
}

static const char* const rules_dirs[] = {
       "/etc/udev/rules.d",
       "/run/udev/rules.d",
       UDEVLIBEXECDIR "/rules.d",
       NULL
};


Note:
   systemd src code:

阅读(1972) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~