https://github.com/brunolauze/libnit I know there's really big debate about init system but here's my tentative to propose a new model to replace rc. Let's call it libinit but the name as no significance for now. I started coding a library with the following architecture. the main idea is to rewrite rc in C language. a utility called system would act a little bit like service command does. a folder would contains libraries instead of scripts inside [target]/etc/rc.d so we can add as many librairies a user desire and interlink the order of each piece among all like in rc. each library would follow and expose the following pattern: char **provide(); /* returns all the PROVIDE a library contains */ then for each provide() value the library would expose : XXX_provide() XXX_require() XXX_before() XXX_keywords() and optionally: XXX_canstart(); XXX_prestart(); XXX_start(); XXX_status(); XXX_stop(); and also: XXX_mycommand(int argc, char **argv); essentially repeating the rc.subr model system utilty would source /etc/defaults/rc.conf, then source result of rc_conf_files loaded On init, /sbin/init would call /sbin/system init instead of running script /etc/rc on init, system would scan folder (let's suppose /lib/init.d and /usr/local/init.d for now) try dlopen() each *.so* files and grab provide(); xxx_provide(), xxx_require(), xxx_before() and xxx_keyword() for each one. compile a list of "service" discovered and do an "rcorder". The benefits is to avoid firing so many utility to manage to init the system. Replicating all small helper function from rc to C language like load_kld would avoid opening a process and do real syscall at moment. Heavily use pthread, waitpid, etc... So instead of firing /sbin/devfs /dev rule -s 1 applyset call direcly what's would run inside devfs -> rule_main in src/sbin/devfs/rule.c ... cut the fat here's an example to show /etc/rc.d/abi conversion to abi.c abi.h: #ifndef __ABI_H__ #define __ABI_H__ #include "../default.h" #define PROVIDE abi #define REQUIRE { "archdep" } #define KEYWORD { NOJAIL } #include "../common.h" #endif abi.c: #include "abi.h" int sysvipc_start() { if (load_kld("sysvmsg")) if (load_kld("sysvsem")) return load_kld("sysvshm"); return -1; } int linux_start() { return load_kld("linux"); } int srv4_start() { if (load_kld("svr4elf") == 0) return load_kld("svr4"); return (-1); } #define __canstart int abi_canstart() { return is_enabled("sysvipc") || is_enabled("linux") || is_enabled("srv4"); } int abi_start() { int err1 = 0, err2 = 0, err3 = 0; if (is_enabled("sysvipc")) err1 = sysvipc_start(); if (is_enabled("linux")) err2 = linux_start(); if (is_enabled("srv4")) err3 = srv4_start(); return err1 && err2 && err3; } #include "../common.c" where common.h and common.c implement everything by default a little bit like rc.subr does. e.g: PID_FILE and COMMAND macros implement the start by itself, etc... as you can see really similar to what we have in the script file... Then the system utility would also allow digging into the libraries with command like: system accounting rotatelog etc.. I uploaded a quick start to show some code and expose more the idea. https://github.com/brunolauze/libinit Thanks in advance for your comments.Received on Sat Feb 22 2014 - 22:56:03 UTC
This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:47 UTC