Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
docs:techref:init.detail.cc [2018/02/20 18:51] – ↷ Page moved from doc:techref:init.detail.cc to docs:techref:init.detail.cc bobafetthotmaildocs:techref:init.detail.cc [2018/03/04 11:46] (current) – ↷ Links adapted because of a move operation
Line 14: Line 14:
     ...     ...
 </code> </code>
-At boot, Linux kernel starts ''/sbin/init'' as the first user process. In Chaos Calmer, ''/sbin/init'' does the preinit/failsafe steps, those that depend only on the read-only partition in flashed image, then execs (that is: is replaced by) ''/sbin/procd'' to continue boot as specified by the configuration in writable flash partition. Procd started as pid 1 assumes several roles: service manager, hotplug events handler; this as of February 2016, when this research was done. [[doc:techref:procd|Procd techref wiki page]] at this point in time is a design document and work in progress, if you are reading here and know/understand procd's semantics and API, please update that page.+At boot, Linux kernel starts ''/sbin/init'' as the first user process. In Chaos Calmer, ''/sbin/init'' does the preinit/failsafe steps, those that depend only on the read-only partition in flashed image, then execs (that is: is replaced by) ''/sbin/procd'' to continue boot as specified by the configuration in writable flash partition. Procd started as pid 1 assumes several roles: service manager, hotplug events handler; this as of February 2016, when this research was done. [[docs:techref:procd|Procd techref wiki page]] at this point in time is a design document and work in progress, if you are reading here and know/understand procd's semantics and API, please update that page.
  
 Procd sources:\\ Procd sources:\\
Line 31: Line 31:
  
   - ''[[http://git.openwrt.org/?p=project/procd.git;a=blob;f=initd/init.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l71|main(int argc, char **argv)]]'' in /sbin/init, line 71\\ User space life begins here. OpenWrt calls this phase "preinit".   - ''[[http://git.openwrt.org/?p=project/procd.git;a=blob;f=initd/init.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l71|main(int argc, char **argv)]]'' in /sbin/init, line 71\\ User space life begins here. OpenWrt calls this phase "preinit".
-    - ''[[http://git.openwrt.org/?p=project/procd.git;a=blob;f=initd/init.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l81|early()]]'' [[http://git.openwrt.org/?p=project/procd.git;a=blob;f=initd/early.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l92|(definition)]]\\ Mount filesystems: ''/proc'', ''/sys'', ''/sys/fs/cgroup'', ''/dev'' (a tmpfs), ''/dev/pts''\\ Populate ''/dev'' with entries from ''/sys/dev/{char;block}''\\ Open ''/dev/console'' as STDIN/STDOUT/STDERR\\ Make directories ''/tmp'' (optionally on zram), ''/tmp/run'', ''tmp/lock'', ''/tmp/state''\\ \\ This accounts for most of the filesystem layout, observed that ''/etc/fstab'' is a [[http://git.openwrt.org/?p=15.05/openwrt.git;a=blob;f=package/base-files/Makefile;hb=483dac821788b457d349233e770329186a0aa860#l161|broken symlink, line 161]], with the following additions:\\ - ''[[http://git.openwrt.org/?p=project/procd.git;a=blob;f=plug/coldplug.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l40|procd_coldplug()]]'' [[http://git.openwrt.org/?p=project/procd.git;a=blob;f=state.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l105|invoked at hotplug setup time]] will recreate ''/dev'' from scratch.\\ - ''[[http://git.openwrt.org/?p=15.05/openwrt.git;a=blob;f=package/base-files/files/etc/init.d/boot;hb=483dac821788b457d349233e770329186a0aa860#l20|/etc/rc.d/S10boot]]'' will invoke ''mount_root'' to setup a writable filesystem based on extroot or jffs2 overlay or a tmpfs backed [[/inbox/snapshot|snapshot capable]] overlay, add some directories and files, and mount debugfs.+    - ''[[http://git.openwrt.org/?p=project/procd.git;a=blob;f=initd/init.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l81|early()]]'' [[http://git.openwrt.org/?p=project/procd.git;a=blob;f=initd/early.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l92|(definition)]]\\ Mount filesystems: ''/proc'', ''/sys'', ''/sys/fs/cgroup'', ''/dev'' (a tmpfs), ''/dev/pts''\\ Populate ''/dev'' with entries from ''/sys/dev/{char;block}''\\ Open ''/dev/console'' as STDIN/STDOUT/STDERR\\ Make directories ''/tmp'' (optionally on zram), ''/tmp/run'', ''tmp/lock'', ''/tmp/state''\\ \\ This accounts for most of the filesystem layout, observed that ''/etc/fstab'' is a [[http://git.openwrt.org/?p=15.05/openwrt.git;a=blob;f=package/base-files/Makefile;hb=483dac821788b457d349233e770329186a0aa860#l161|broken symlink, line 161]], with the following additions:\\ - ''[[http://git.openwrt.org/?p=project/procd.git;a=blob;f=plug/coldplug.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l40|procd_coldplug()]]'' [[http://git.openwrt.org/?p=project/procd.git;a=blob;f=state.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l105|invoked at hotplug setup time]] will recreate ''/dev'' from scratch.\\ - ''[[http://git.openwrt.org/?p=15.05/openwrt.git;a=blob;f=package/base-files/files/etc/init.d/boot;hb=483dac821788b457d349233e770329186a0aa860#l20|/etc/rc.d/S10boot]]'' will invoke ''mount_root'' to setup a writable filesystem based on extroot or jffs2 overlay or a tmpfs backed [[docs:guide-user:installation:snapshot|snapshot capable]] overlay, add some directories and files, and mount debugfs.
     - ''[[http://git.openwrt.org/?p=project/procd.git;a=blob;f=initd/init.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l82|cmdline()]]'' [[http://git.openwrt.org/?p=project/procd.git;a=blob;f=initd/init.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l56|(definition)]]\\ Check kernel cmdline for boot parameter "''init_debug={1,2,3,4}''".     - ''[[http://git.openwrt.org/?p=project/procd.git;a=blob;f=initd/init.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l82|cmdline()]]'' [[http://git.openwrt.org/?p=project/procd.git;a=blob;f=initd/init.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l56|(definition)]]\\ Check kernel cmdline for boot parameter "''init_debug={1,2,3,4}''".
     - Fork ''[[http://git.openwrt.org/?p=project/procd.git;a=blob;f=initd/init.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l87|/sbin/kmodloader (/rom)/etc/modules-boot.d/]]'' [[http://git.openwrt.org/?p=project/ubox.git;a=blob;f=kmodloader.c;hb=907d046c8929fb74e5a3502a9498198695e62ad8#l830|kmodloader source]]\\ Wait up to 120 seconds for ''/sbin/kmodloader'' to probe the kernel modules declared in ''(/rom)/etc/modules-boot.d/''\\ At this point in the boot sequence, '/etc/modules-boot.d' is the one from the rom image (''/rom/etc/...'' when boot is done). The overlay filesystem is mounted later.\\ \\ kmodloader is a multicall binary, invoked as\\ ''   kmodloader''\\ does \\ ''  [[http://git.openwrt.org/?p=project/ubox.git;a=blob;f=kmodloader.c;hb=907d046c8929fb74e5a3502a9498198695e62ad8#l732|main_loader()]]''\\ which reads files in ''(/rom)/etc/modules-boot.d/'', looking for lines starting with the name of a module to load, optionally followed by a space and module parameters. There appear to be [[http://git.openwrt.org/?p=project/ubox.git;a=blob;f=kmodloader.c;hb=907d046c8929fb74e5a3502a9498198695e62ad8#l788|special treatment for files with names beginning with a number]]: the modules they list are immediately loaded, then modules from files with name beginning with an ascii char greater than "9" are loaded all together in a final load_modprobe call.     - Fork ''[[http://git.openwrt.org/?p=project/procd.git;a=blob;f=initd/init.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l87|/sbin/kmodloader (/rom)/etc/modules-boot.d/]]'' [[http://git.openwrt.org/?p=project/ubox.git;a=blob;f=kmodloader.c;hb=907d046c8929fb74e5a3502a9498198695e62ad8#l830|kmodloader source]]\\ Wait up to 120 seconds for ''/sbin/kmodloader'' to probe the kernel modules declared in ''(/rom)/etc/modules-boot.d/''\\ At this point in the boot sequence, '/etc/modules-boot.d' is the one from the rom image (''/rom/etc/...'' when boot is done). The overlay filesystem is mounted later.\\ \\ kmodloader is a multicall binary, invoked as\\ ''   kmodloader''\\ does \\ ''  [[http://git.openwrt.org/?p=project/ubox.git;a=blob;f=kmodloader.c;hb=907d046c8929fb74e5a3502a9498198695e62ad8#l732|main_loader()]]''\\ which reads files in ''(/rom)/etc/modules-boot.d/'', looking for lines starting with the name of a module to load, optionally followed by a space and module parameters. There appear to be [[http://git.openwrt.org/?p=project/ubox.git;a=blob;f=kmodloader.c;hb=907d046c8929fb74e5a3502a9498198695e62ad8#l788|special treatment for files with names beginning with a number]]: the modules they list are immediately loaded, then modules from files with name beginning with an ascii char greater than "9" are loaded all together in a final load_modprobe call.
-    - ''[[http://git.openwrt.org/?p=project/procd.git;a=blob;f=initd/init.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l116|uloop_init()]]'' line 116 [[http://git.openwrt.org/?p=project/libubox.git;a=blob;f=uloop.c;hb=d1c66ef1131d14f0ed197b368d03f71b964e45f8#l211|(definition)]]\\ [[/doc/techref/libubox#libuboxulooph|Documentation of libubox/uloop.h]] says:\\ //Uloop is a loop runner for i/o. Gets in charge of polling the different file descriptors you have added to it, gets in charge of running timers, and helps you manage child processes. Supports epoll and kqueue as event running backends.//\\ [[http://git.openwrt.org/?p=project/libubox.git;a=blob;f=uloop.c;hb=d1c66ef1131d14f0ed197b368d03f71b964e45f8#l666|uloop.c source in libubox]] says uloop's process management duty is assigned by a call to\\ ''   [[http://git.openwrt.org/?p=project/libubox.git;a=blob;f=uloop.c;hb=d1c66ef1131d14f0ed197b368d03f71b964e45f8#l492|int uloop_process_add(struct uloop_process *p)]]''\\ ''%%p->pid%%'' is the process id of a child process to monitor and ''%%p->cb%%'' a pointer to a callback function.\\ When the managed child process will exit, uloop_run, running in parent context to receive SIGCHLD signal, will trigger execution of the callback.+    - ''[[http://git.openwrt.org/?p=project/procd.git;a=blob;f=initd/init.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l116|uloop_init()]]'' line 116 [[http://git.openwrt.org/?p=project/libubox.git;a=blob;f=uloop.c;hb=d1c66ef1131d14f0ed197b368d03f71b964e45f8#l211|(definition)]]\\ [[docs:techref:libubox#libuboxulooph|Documentation of libubox/uloop.h]] says:\\ //Uloop is a loop runner for i/o. Gets in charge of polling the different file descriptors you have added to it, gets in charge of running timers, and helps you manage child processes. Supports epoll and kqueue as event running backends.//\\ [[http://git.openwrt.org/?p=project/libubox.git;a=blob;f=uloop.c;hb=d1c66ef1131d14f0ed197b368d03f71b964e45f8#l666|uloop.c source in libubox]] says uloop's process management duty is assigned by a call to\\ ''   [[http://git.openwrt.org/?p=project/libubox.git;a=blob;f=uloop.c;hb=d1c66ef1131d14f0ed197b368d03f71b964e45f8#l492|int uloop_process_add(struct uloop_process *p)]]''\\ ''%%p->pid%%'' is the process id of a child process to monitor and ''%%p->cb%%'' a pointer to a callback function.\\ When the managed child process will exit, uloop_run, running in parent context to receive SIGCHLD signal, will trigger execution of the callback.
     - ''[[http://git.openwrt.org/?p=project/procd.git;a=blob;f=initd/init.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l117|preinit()]]'' line 117 [[http://git.openwrt.org/?p=project/procd.git;a=blob;f=initd/preinit.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l86|(definition)]]     - ''[[http://git.openwrt.org/?p=project/procd.git;a=blob;f=initd/init.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l117|preinit()]]'' line 117 [[http://git.openwrt.org/?p=project/procd.git;a=blob;f=initd/preinit.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l86|(definition)]]
       - [[http://git.openwrt.org/?p=project/procd.git;a=blob;f=initd/preinit.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l94|Forks a "plugd instance"]], line 94\\ ''   /sbin/procd -h [[http://git.openwrt.org/?p=15.05/openwrt.git;a=blob;f=package/system/procd/files/hotplug-preinit.json;hb=483dac821788b457d349233e770329186a0aa860|(/rom)/etc/hotplug-preinit.json]]''\\ to listen to kernel uevents for any required firmware or for notification of button pressed, handled by ''    [[http://git.openwrt.org/?p=15.05/openwrt.git;a=blob;f=package/base-files/files/etc/rc.button/failsafe;hb=483dac821788b457d349233e770329186a0aa860|(/rom)/etc/rc.button/failsafe]]''\\ as the request to enter failsafe mode. A flag file ''/tmp/failsafe_button'' containing the value of ''${BUTTON}'' is created if failsafe has been requested.       - [[http://git.openwrt.org/?p=project/procd.git;a=blob;f=initd/preinit.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l94|Forks a "plugd instance"]], line 94\\ ''   /sbin/procd -h [[http://git.openwrt.org/?p=15.05/openwrt.git;a=blob;f=package/system/procd/files/hotplug-preinit.json;hb=483dac821788b457d349233e770329186a0aa860|(/rom)/etc/hotplug-preinit.json]]''\\ to listen to kernel uevents for any required firmware or for notification of button pressed, handled by ''    [[http://git.openwrt.org/?p=15.05/openwrt.git;a=blob;f=package/base-files/files/etc/rc.button/failsafe;hb=483dac821788b457d349233e770329186a0aa860|(/rom)/etc/rc.button/failsafe]]''\\ as the request to enter failsafe mode. A flag file ''/tmp/failsafe_button'' containing the value of ''${BUTTON}'' is created if failsafe has been requested.
       - Forks, [[http://git.openwrt.org/?p=project/procd.git;a=blob;f=initd/preinit.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l106|at lines 106-111]],\\ ''    PREINIT=1 /bin/sh [[http://git.openwrt.org/?p=15.05/openwrt.git;a=blob;f=package/base-files/files/etc/preinit;hb=483dac821788b457d349233e770329186a0aa860|(/rom)/etc/preinit]]''\\ a shell to execute ''(/rom)/etc/preinit'' with ''PREINIT=1'' in its environment. Submits the child process to uloop management with the callback\\ ''      [[http://git.openwrt.org/?p=project/procd.git;a=blob;f=initd/preinit.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l51|spawn_procd()]]''\\ that will exec procd to replace init as pid 1 at completion of ''(/rom)/etc/preinit''.       - Forks, [[http://git.openwrt.org/?p=project/procd.git;a=blob;f=initd/preinit.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l106|at lines 106-111]],\\ ''    PREINIT=1 /bin/sh [[http://git.openwrt.org/?p=15.05/openwrt.git;a=blob;f=package/base-files/files/etc/preinit;hb=483dac821788b457d349233e770329186a0aa860|(/rom)/etc/preinit]]''\\ a shell to execute ''(/rom)/etc/preinit'' with ''PREINIT=1'' in its environment. Submits the child process to uloop management with the callback\\ ''      [[http://git.openwrt.org/?p=project/procd.git;a=blob;f=initd/preinit.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l51|spawn_procd()]]''\\ that will exec procd to replace init as pid 1 at completion of ''(/rom)/etc/preinit''.
-        - ''[[http://git.openwrt.org/?p=15.05/openwrt.git;a=blob;f=package/base-files/files/etc/preinit;h=9cc8a9a8f63dd824f9c75b711d779aa8b2452259;hb=483dac821788b457d349233e770329186a0aa860|/etc/preinit]]''\\ A shell script, fully documented here [[/doc/techref/preinit_mount#preinit_operation]]. In short, parse files in ''(/rom)/lib/preinit'' to build 5 lists of hooks and an environment, then run the hooks from some of the lists depending on the state of the environment.\\ One of the steps in a successful boot sequence is to mount the overlay file system with a hook setup by\\ ''    [[http://git.openwrt.org/?p=15.05/openwrt.git;a=blob;f=package/base-files/files/lib/preinit/80_mount_root;hb=483dac821788b457d349233e770329186a0aa860|(/rom)/lib/preinit/80_mount_root]]''\\ to call\\ ''      [[http://git.openwrt.org/?p=project/fstools.git;a=blob;f=mount_root.c;hb=09027fc86babc3986027a0e677aca1b6999a9e14|mount_root]]''\\ which if extroot is not configured, mounts the writable data partition "rootfs_data" as overlay over the / partition "rootfs". If the data partition is being prepared, overlays a tmpfs in ram.\\ Filesystem snapshots are supported; this is a feature listed in Barrier Breaker announce, shell wrapper is ''[[http://git.openwrt.org/?p=15.05/openwrt.git;a=blob;f=package/system/fstools/files/snapshot;hb=483dac821788b457d349233e770329186a0aa860|/sbin/snapshot]]'' script. The "''SNAPSHOT=magic''" environment variable is set in ''[[http://git.openwrt.org/?p=project/fstools.git;a=blob;f=libfstools/snapshot.c;hb=09027fc86babc3986027a0e677aca1b6999a9e14#l330|mount_snapshot()]]'' line 330.+        - ''[[http://git.openwrt.org/?p=15.05/openwrt.git;a=blob;f=package/base-files/files/etc/preinit;h=9cc8a9a8f63dd824f9c75b711d779aa8b2452259;hb=483dac821788b457d349233e770329186a0aa860|/etc/preinit]]''\\ A shell script, fully documented here [[docs:techref:preinit_mount#preinit_operation]]. In short, parse files in ''(/rom)/lib/preinit'' to build 5 lists of hooks and an environment, then run the hooks from some of the lists depending on the state of the environment.\\ One of the steps in a successful boot sequence is to mount the overlay file system with a hook setup by\\ ''    [[http://git.openwrt.org/?p=15.05/openwrt.git;a=blob;f=package/base-files/files/lib/preinit/80_mount_root;hb=483dac821788b457d349233e770329186a0aa860|(/rom)/lib/preinit/80_mount_root]]''\\ to call\\ ''      [[http://git.openwrt.org/?p=project/fstools.git;a=blob;f=mount_root.c;hb=09027fc86babc3986027a0e677aca1b6999a9e14|mount_root]]''\\ which if extroot is not configured, mounts the writable data partition "rootfs_data" as overlay over the / partition "rootfs". If the data partition is being prepared, overlays a tmpfs in ram.\\ Filesystem snapshots are supported; this is a feature listed in Barrier Breaker announce, shell wrapper is ''[[http://git.openwrt.org/?p=15.05/openwrt.git;a=blob;f=package/system/fstools/files/snapshot;hb=483dac821788b457d349233e770329186a0aa860|/sbin/snapshot]]'' script. The "''SNAPSHOT=magic''" environment variable is set in ''[[http://git.openwrt.org/?p=project/fstools.git;a=blob;f=libfstools/snapshot.c;hb=09027fc86babc3986027a0e677aca1b6999a9e14#l330|mount_snapshot()]]'' line 330.
     - ''[[http://git.openwrt.org/?p=project/procd.git;a=blob;f=initd/init.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l118|uloop_run()]]'', line 118\\ At exit of the ''(/rom)/etc/preinit'' shell script, invokes the callback spawn_procd()     - ''[[http://git.openwrt.org/?p=project/procd.git;a=blob;f=initd/init.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l118|uloop_run()]]'', line 118\\ At exit of the ''(/rom)/etc/preinit'' shell script, invokes the callback spawn_procd()
     - ''[[http://git.openwrt.org/?p=project/procd.git;a=blob;f=initd/preinit.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l51|spawn_procd()]]''\\ As a callback by uloop_run in pid 1, this is pid 1; execs ''/sbin/procd''\\ \\      - ''[[http://git.openwrt.org/?p=project/procd.git;a=blob;f=initd/preinit.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l51|spawn_procd()]]''\\ As a callback by uloop_run in pid 1, this is pid 1; execs ''/sbin/procd''\\ \\ 
Line 45: Line 45:
     - ''[[http://git.openwrt.org/?p=project/procd.git;a=blob;f=procd.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l68|uloop_init()]]'', line 68\\ The uloop instance set up before by ''/sbin/init'' is gone. Creates a new one.     - ''[[http://git.openwrt.org/?p=project/procd.git;a=blob;f=procd.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l68|uloop_init()]]'', line 68\\ The uloop instance set up before by ''/sbin/init'' is gone. Creates a new one.
     - ''[[http://git.openwrt.org/?p=project/procd.git;a=blob;f=procd.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l69|procd_signal()]]'', line 69 [[http://git.openwrt.org/?p=project/procd.git;a=blob;f=signal.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l82|(definition)]], line 82.\\ Setup signal handlers. Reboot on SIGTERM or SIGINT, poweroff on SIGUSR2 or SIGUSR2.     - ''[[http://git.openwrt.org/?p=project/procd.git;a=blob;f=procd.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l69|procd_signal()]]'', line 69 [[http://git.openwrt.org/?p=project/procd.git;a=blob;f=signal.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l82|(definition)]], line 82.\\ Setup signal handlers. Reboot on SIGTERM or SIGINT, poweroff on SIGUSR2 or SIGUSR2.
-    - ''[[http://git.openwrt.org/?p=project/procd.git;a=blob;f=procd.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l70|trigger_init()]]'', line 70 [[http://git.openwrt.org/?p=project/procd.git;a=blob;f=service/trigger.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l319|(definition)]]\\ Procd triggers on config file/network interface changes, see [[/inbox/procd-init-scripts#procd_triggers_on_config_filenetwork_interface_changes]]\\ Initialise a run queue. An [[http://git.openwrt.org/?p=project/libubox.git;a=blob;f=examples/runqueue-example.c;hb=d1c66ef1131d14f0ed197b368d03f71b964e45f8|example]] is the sole documentation. A queued task has an uloop callback invoked when done, here sets the empty queue callback to do nothing.+    - ''[[http://git.openwrt.org/?p=project/procd.git;a=blob;f=procd.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l70|trigger_init()]]'', line 70 [[http://git.openwrt.org/?p=project/procd.git;a=blob;f=service/trigger.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l319|(definition)]]\\ Procd triggers on config file/network interface changes, see [[docs:guide-developer:procd-init-scripts#procd_triggers_on_config_filenetwork_interface_changes]]\\ Initialise a run queue. An [[http://git.openwrt.org/?p=project/libubox.git;a=blob;f=examples/runqueue-example.c;hb=d1c66ef1131d14f0ed197b368d03f71b964e45f8|example]] is the sole documentation. A queued task has an uloop callback invoked when done, here sets the empty queue callback to do nothing.
     - ''[[http://git.openwrt.org/?p=project/procd.git;a=blob;f=procd.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l74|procd_state_next()]]'', line 74 [[http://git.openwrt.org/?p=project/procd.git;a=blob;f=state.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l179|(definition)]]\\ Transitions from NONE to EARLY the state of a state machine implemented in ''[[http://git.openwrt.org/?p=project/procd.git;a=blob;f=state.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l96|state_enter(void)]]'' used to sequence the remaining boot steps.     - ''[[http://git.openwrt.org/?p=project/procd.git;a=blob;f=procd.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l74|procd_state_next()]]'', line 74 [[http://git.openwrt.org/?p=project/procd.git;a=blob;f=state.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l179|(definition)]]\\ Transitions from NONE to EARLY the state of a state machine implemented in ''[[http://git.openwrt.org/?p=project/procd.git;a=blob;f=state.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l96|state_enter(void)]]'' used to sequence the remaining boot steps.
     - ''[[http://git.openwrt.org/?p=project/procd.git;a=blob;f=state.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l101|STATE_EARLY]]'' in ''state_enter()''     - ''[[http://git.openwrt.org/?p=project/procd.git;a=blob;f=state.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l101|STATE_EARLY]]'' in ''state_enter()''
Line 58: Line 58:
         - The ''[[http://git.openwrt.org/?p=15.05/openwrt.git;a=blob;f=package/system/procd/files/hotplug.json;hb=87e9837a818a71f39c445ee33569279bd78451de|/etc/hotplug.json]]'' script\\ - creates and removes devices files, assigns them permissions,\\ - loads firmware,\\ - handles buttons by calling scripts in ''/etc/rc.button/%BUTTON%'' if the uevent has the "''BUTTON''" value,\\ - and invokes ''/sbin/hotplug-call "%SUBSYSTEM%"'' to handle all other subsystem related actions.\\ Subystems are: "platform" "net", "input", "usb", "usbmisc", "ieee1394", "block", "atm", "zaptel", "tty", "button" (without BUTTON value, possible?), "usb-serial". "usb-serial" is aliased to "tty" in hotplug.json.\\ Documentation of json script syntax? Offline. [[http://git.openwrt.org/?p=project/libubox.git;a=blob;f=json_script.c;hb=d1c66ef1131d14f0ed197b368d03f71b964e45f8|Use the source]]. It is the json representation of the abstract syntax tree of a script in a fairly intuitive scripting language.\\ There are 2 levels at which decisions are taken: hotplug.json acts as fast path executor or lightweight dispatcher, the subsystem scripts in /etc/hotplug.d/%SUBSYSTEM%/ do the heavy lifting.\\ Uevent messages from the kernel contain key-value pairs passed as environment variables to the scripts. The kernel function\\ ''    [[http://lxr.free-electrons.com/source/lib/kobject_uevent.c?v=3.18#L387|int add_uevent_var(struct kobj_uevent_env *env, const char *format, ...)]]''\\ creates them. This link [[http://lxr.free-electrons.com/ident?v=3.18;i=add_uevent_var]] provides a list of all places in the Linux kernel where it is used. It is an authoritative reference of the upstream defined uevent variables. Button events are generated by the out of tree kernel modules ''[[http://git.openwrt.org/?p=15.05/openwrt.git;a=blob;f=package/kernel/button-hotplug/src/button-hotplug.c;hb=483dac821788b457d349233e770329186a0aa860#l124|button-hotplug]]'' ''[[http://git.openwrt.org/?p=15.05/openwrt.git;a=blob;f=package/kernel/gpio-button-hotplug/src/gpio-button-hotplug.c;hb=483dac821788b457d349233e770329186a0aa860#l133|gpio-button-hotplug]]'' specific to OpenWrt.          - The ''[[http://git.openwrt.org/?p=15.05/openwrt.git;a=blob;f=package/system/procd/files/hotplug.json;hb=87e9837a818a71f39c445ee33569279bd78451de|/etc/hotplug.json]]'' script\\ - creates and removes devices files, assigns them permissions,\\ - loads firmware,\\ - handles buttons by calling scripts in ''/etc/rc.button/%BUTTON%'' if the uevent has the "''BUTTON''" value,\\ - and invokes ''/sbin/hotplug-call "%SUBSYSTEM%"'' to handle all other subsystem related actions.\\ Subystems are: "platform" "net", "input", "usb", "usbmisc", "ieee1394", "block", "atm", "zaptel", "tty", "button" (without BUTTON value, possible?), "usb-serial". "usb-serial" is aliased to "tty" in hotplug.json.\\ Documentation of json script syntax? Offline. [[http://git.openwrt.org/?p=project/libubox.git;a=blob;f=json_script.c;hb=d1c66ef1131d14f0ed197b368d03f71b964e45f8|Use the source]]. It is the json representation of the abstract syntax tree of a script in a fairly intuitive scripting language.\\ There are 2 levels at which decisions are taken: hotplug.json acts as fast path executor or lightweight dispatcher, the subsystem scripts in /etc/hotplug.d/%SUBSYSTEM%/ do the heavy lifting.\\ Uevent messages from the kernel contain key-value pairs passed as environment variables to the scripts. The kernel function\\ ''    [[http://lxr.free-electrons.com/source/lib/kobject_uevent.c?v=3.18#L387|int add_uevent_var(struct kobj_uevent_env *env, const char *format, ...)]]''\\ creates them. This link [[http://lxr.free-electrons.com/ident?v=3.18;i=add_uevent_var]] provides a list of all places in the Linux kernel where it is used. It is an authoritative reference of the upstream defined uevent variables. Button events are generated by the out of tree kernel modules ''[[http://git.openwrt.org/?p=15.05/openwrt.git;a=blob;f=package/kernel/button-hotplug/src/button-hotplug.c;hb=483dac821788b457d349233e770329186a0aa860#l124|button-hotplug]]'' ''[[http://git.openwrt.org/?p=15.05/openwrt.git;a=blob;f=package/kernel/gpio-button-hotplug/src/gpio-button-hotplug.c;hb=483dac821788b457d349233e770329186a0aa860#l133|gpio-button-hotplug]]'' specific to OpenWrt. 
           - ''[[http://git.openwrt.org/?p=15.05/openwrt.git;a=blob;f=package/base-files/files/sbin/hotplug-call;hb=483dac821788b457d349233e770329186a0aa860|/sbin/hotplug-call]] "%SUBSYSTEM%"''\\ is a shell script that scans ''/etc/hotlug.d/%SUBSYSTEM%/*'' and sources all scripts assigned to a subsystem. "button" subsystem is handled here if the uevent lacks the "BUTTON" value, unlikely or impossible?.           - ''[[http://git.openwrt.org/?p=15.05/openwrt.git;a=blob;f=package/base-files/files/sbin/hotplug-call;hb=483dac821788b457d349233e770329186a0aa860|/sbin/hotplug-call]] "%SUBSYSTEM%"''\\ is a shell script that scans ''/etc/hotlug.d/%SUBSYSTEM%/*'' and sources all scripts assigned to a subsystem. "button" subsystem is handled here if the uevent lacks the "BUTTON" value, unlikely or impossible?.
-      - ''[[http://git.openwrt.org/?p=project/procd.git;a=blob;f=state.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l108|STATE_UBUS]]''\\ At end of coldplug uevents processing, the callback [[http://git.openwrt.org/?p=project/procd.git;a=blob;f=plug/coldplug.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l34|coldplug_complete calls]] ''procd_state_next'' which results in advancing procd to STATE_UBUS.\\ "- ubus -" is logged to console, the services infrastructure is initialised, then procd schedules connect to after 1" ([[http://git.openwrt.org/?p=project/procd.git;a=blob;f=ubus.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l64|line 67]]) and starts ''/sbin/ubus'' as the system [[doc/techref/ubus|ubus]] service.\\ Transition to next state is triggered by the callback ''[[http://git.openwrt.org/?p=project/procd.git;a=blob;f=ubus.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l43|ubus_connect_cb]]'' that at the end, line 118, calls ''[[http://git.openwrt.org/?p=project/procd.git;a=blob;f=state.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l186|procd_state_ubus_connect()]]'', line 186, that calls ''procd_state_next'' to transition to+      - ''[[http://git.openwrt.org/?p=project/procd.git;a=blob;f=state.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l108|STATE_UBUS]]''\\ At end of coldplug uevents processing, the callback [[http://git.openwrt.org/?p=project/procd.git;a=blob;f=plug/coldplug.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l34|coldplug_complete calls]] ''procd_state_next'' which results in advancing procd to STATE_UBUS.\\ "- ubus -" is logged to console, the services infrastructure is initialised, then procd schedules connect to after 1" ([[http://git.openwrt.org/?p=project/procd.git;a=blob;f=ubus.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l64|line 67]]) and starts ''/sbin/ubus'' as the system [[docs:techref:ubus|ubus]] service.\\ Transition to next state is triggered by the callback ''[[http://git.openwrt.org/?p=project/procd.git;a=blob;f=ubus.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l43|ubus_connect_cb]]'' that at the end, line 118, calls ''[[http://git.openwrt.org/?p=project/procd.git;a=blob;f=state.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l186|procd_state_ubus_connect()]]'', line 186, that calls ''procd_state_next'' to transition to
       - ''[[http://git.openwrt.org/?p=project/procd.git;a=blob;f=state.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l118|STATE_INIT]]''\\ "- init -" is logged, ''[[http://git.openwrt.org/?p=15.05/openwrt.git;a=blob;f=package/base-files/files/etc/inittab;hb=483dac821788b457d349233e770329186a0aa860|/etc/inittab]]'' is parsed and entries\\ ''     ::askconsole:/bin/ash --login''\\ ''     ::sysinit:/etc/init.d/rcS S boot''\\ executed. inittab format is the same as the one from busybox ([[https://git.busybox.net/busybox/tree/examples/inittab?h=1_23_1&id=1ecfe811fe2f70380170ef7d820e8150054e88ca|Busybox example inittab]]).\\ The "''sysinit'' action" handler       - ''[[http://git.openwrt.org/?p=project/procd.git;a=blob;f=state.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l118|STATE_INIT]]''\\ "- init -" is logged, ''[[http://git.openwrt.org/?p=15.05/openwrt.git;a=blob;f=package/base-files/files/etc/inittab;hb=483dac821788b457d349233e770329186a0aa860|/etc/inittab]]'' is parsed and entries\\ ''     ::askconsole:/bin/ash --login''\\ ''     ::sysinit:/etc/init.d/rcS S boot''\\ executed. inittab format is the same as the one from busybox ([[https://git.busybox.net/busybox/tree/examples/inittab?h=1_23_1&id=1ecfe811fe2f70380170ef7d820e8150054e88ca|Busybox example inittab]]).\\ The "''sysinit'' action" handler
         - ''[[http://git.openwrt.org/?p=project/procd.git;a=blob;f=inittab.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l148|runrc]]''\\ instantiates a queue, whose empty handler ''[[http://git.openwrt.org/?p=project/procd.git;a=blob;f=inittab.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l143|rcdone]]'' will advance procd state.\\ ''runrc'' [[http://git.openwrt.org/?p=project/procd.git;a=blob;f=inittab.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l151|ignores]] the process specification "''/etc/init.d/rcS''" (there is no such a script!), and runs         - ''[[http://git.openwrt.org/?p=project/procd.git;a=blob;f=inittab.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l148|runrc]]''\\ instantiates a queue, whose empty handler ''[[http://git.openwrt.org/?p=project/procd.git;a=blob;f=inittab.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l143|rcdone]]'' will advance procd state.\\ ''runrc'' [[http://git.openwrt.org/?p=project/procd.git;a=blob;f=inittab.c;hb=0da5bf2ff222d1a499172a6e09507388676b5a08#l151|ignores]] the process specification "''/etc/init.d/rcS''" (there is no such a script!), and runs
  • Last modified: 2018/02/20 18:51
  • by bobafetthotmail