Date: Sat, 22 Feb 2014 18:54:56 -0500 From: =?iso-8859-1?B?QnJ1bm8gTGF1euk=?= <brunolauze@msn.com> To: "freebsd-current@freebsd.org" <freebsd-current@freebsd.org> Subject: libinit idea Message-ID: <BLU179-W28221A0539478FDDF45ADDC6840@phx.gbl>
next in thread | raw e-mail | index | archive | help
https://github.com/brunolauze/libnit=0A= =0A= I know there's really big debate about init system but here's my tentative = to propose a new model to replace rc.=0A= =0A= Let's call it libinit but the name as no significance for now.=0A= =0A= I started coding a library with the following architecture.=0A= =0A= the main idea is to rewrite rc in C language.=0A= =0A= a utility called system would act a little bit like service command does.= =0A= =0A= a folder would contains libraries instead of scripts inside [target]/etc/rc= .d=0A= so we can add as many librairies a user desire and interlink the order of e= ach piece among all like in rc.=0A= =0A= each library would follow and expose the following pattern:=0A= =0A= char **provide()=3B /* returns all the PROVIDE a library contains */=0A= =0A= then for each provide() value the library would expose :=0A= =0A= XXX_provide()=0A= XXX_require()=0A= XXX_before()=0A= XXX_keywords()=0A= =0A= and optionally:=0A= XXX_canstart()=3B=0A= XXX_prestart()=3B=0A= XXX_start()=3B=0A= XXX_status()=3B=0A= XXX_stop()=3B=0A= =0A= and also:=0A= =0A= XXX_mycommand(int argc=2C char **argv)=3B=0A= =0A= essentially repeating the rc.subr =A0model=0A= =0A= system utilty would source /etc/defaults/rc.conf=2C then source result of r= c_conf_files loaded=0A= =0A= On init=2C /sbin/init would call /sbin/system init instead of running scrip= t /etc/rc=0A= =0A= on init=2C system would scan folder (let's suppose /lib/init.d and /usr/loc= al/init.d for now)=0A= try dlopen() each *.so* files=0A= and grab provide()=3B xxx_provide()=2C xxx_require()=2C xxx_before() and xx= x_keyword() for each one.=0A= compile a list of "service" discovered and do an "rcorder".=0A= =0A= The benefits is to avoid firing so many utility to manage to init the syste= m.=0A= =0A= Replicating all small helper function from rc to C language like load_kld w= ould avoid opening a process and do real syscall at moment.=0A= Heavily use pthread=2C waitpid=2C etc...=0A= =0A= So instead of firing /sbin/devfs /dev rule -s 1 applyset=A0=0A= call direcly what's would run inside devfs -> rule_main in src/sbin/devfs/r= ule.c ...=0A= cut the fat=0A= =0A= here's an example to show /etc/rc.d/abi conversion to abi.c=0A= =0A= abi.h:=0A= #ifndef __ABI_H__=0A= #define __ABI_H__=0A= #include "../default.h"=0A= =0A= #define PROVIDE =A0 =A0 =A0 =A0 abi=0A= #define REQUIRE =A0 =A0 =A0 =A0 { "archdep" }=0A= #define KEYWORD =A0 =A0 =A0 =A0 { NOJAIL }=0A= =0A= #include "../common.h"=0A= =0A= #endif=0A= =0A= =0A= abi.c:=0A= #include "abi.h"=0A= =0A= int sysvipc_start()=0A= {=0A= =A0 =A0 =A0 =A0 if (load_kld("sysvmsg"))=0A= =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (load_kld("sysvsem"))=0A= =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return load_kld("sysvshm")= =3B=0A= =A0 =A0 =A0 =A0 return -1=3B=0A= }=0A= =0A= int linux_start()=0A= {=0A= =A0 =A0 =A0 =A0 return load_kld("linux")=3B=0A= }=0A= =0A= int srv4_start()=0A= {=0A= =A0 =A0 =A0 =A0 if (load_kld("svr4elf") =3D=3D 0)=0A= =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return load_kld("svr4")=3B=0A= =A0 =A0 =A0 =A0 return (-1)=3B=0A= }=0A= =0A= #define __canstart=0A= int abi_canstart()=0A= {=0A= =A0 =A0 =A0 =A0 return is_enabled("sysvipc") || is_enabled("linux") || is_e= nabled("srv4")=3B=0A= }=0A= =0A= int abi_start()=0A= {=0A= =A0 =A0 =A0 =A0 int err1 =3D 0=2C err2 =3D 0=2C err3 =3D 0=3B=0A= =A0 =A0 =A0 =A0 if (is_enabled("sysvipc")) err1 =3D sysvipc_start()=3B=0A= =A0 =A0 =A0 =A0 if (is_enabled("linux")) err2 =3D linux_start()=3B=0A= =A0 =A0 =A0 =A0 if (is_enabled("srv4")) err3 =3D srv4_start()=3B=0A= =A0 =A0 =A0 =A0 return err1 && err2 && err3=3B=0A= }=0A= =0A= #include "../common.c"=0A= =0A= =0A= where common.h and common.c implement everything by default a little bit li= ke rc.subr does.=0A= e.g: PID_FILE and COMMAND macros implement the start by itself=2C etc...=0A= =0A= =0A= as you can see really similar to what we have in the script file...=0A= =0A= Then the system utility would also allow digging into the libraries with co= mmand like:=0A= system accounting rotatelog=0A= etc..=0A= =0A= I uploaded a quick start to show some code and expose more the idea.=0A= =0A= https://github.com/brunolauze/libinit=0A= =0A= =0A= =0A= Thanks in advance for your comments. =
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?BLU179-W28221A0539478FDDF45ADDC6840>