carbon-config

config submodule of carbon-core-system
git clone https://ccx.te2000.cz/git/carbon-config
Log | Files | Refs

commit 6fae165cd28b470a36775f289ee63335c1dea22e
parent 16dd71e214f0858a38b1f92101b1c573d4b9d5d8
Author: Jan Pobříslo <ccx@te2000.cz>
Date:   Sat, 29 Oct 2022 00:46:35 +0200

Stable bundle ordering, reuse service-generating code

Diffstat:
MMakefile | 8++++----
Mfstab.aat | 5+++--
Mparse_fs.include.awk | 4++--
Arc-common.aat | 82+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ms6-rc-mount.aat | 18+++---------------
Ms6-rc.aat | 69+--------------------------------------------------------------------
6 files changed, 95 insertions(+), 91 deletions(-)

diff --git a/Makefile b/Makefile @@ -27,12 +27,12 @@ build/%.awk: %.aat common.aat RSFILTER="$@.new" fileset "$<" >/dev/null mv "$@.new" "$@" -build/s6-rc-mount.awk: s6-rc-mount.aat parse_fs.include.awk -build/fstab.awk: fstab.aat parse_fs.include.awk +build/s6-rc-mount.awk: s6-rc-mount.aat parse_fs.include.awk rc-common.aat +build/fstab.awk: fstab.aat parse_fs.include.awk rc-common.aat s6-rc.fileset: build/s6-rc.qawk build/s6-rc-mount.awk fs build/config - $(AWK) -f build/s6-rc-mount.awk fs >"$@.new" - $(AWK) -f build/s6-rc.qawk build/config >>"$@.new" + $(AWK) -v sort_tmpfile="./build/s6-rc-mount.awk.tmp_sort" -f build/s6-rc-mount.awk fs >"$@.new" + $(AWK) -v sort_tmpfile="./build/s6-rc.qawk.tmp_sort" -f build/s6-rc.qawk build/config >>"$@.new" mv "$@.new" "$@" static/etc/fstab: build/fstab.awk fs diff --git a/fstab.aat b/fstab.aat @@ -2,7 +2,8 @@ |function write_oneshot() { {{get("source")}} {{mtp}} {{get("type")}} {{get("options")}} 0 0 |} -|### write_bundle ### -|function write_bundle(name) { } +|### bundle handling ### +|function add_to_bundle(bundle_name, svc_name) { } +|function print_bundles() { } |### include main loop / parsing code ### @awk parse_fs.include.awk diff --git a/parse_fs.include.awk b/parse_fs.include.awk @@ -215,7 +215,7 @@ function process_record( name, i, mtp2) { if((mtp,"bundles") in params) { split(get("bundles"), bundle_list) for(i in bundle_list) { - bundles[bundle_list[i]] = bundles[bundle_list[i]] "\t" svc_name "\n" + add_to_bundle(bundle_list[i], svc_name) } delete bundle_list } @@ -299,5 +299,5 @@ END{ if(mtp) { process_record() } - process_bundles() + print_bundles() } diff --git a/rc-common.aat b/rc-common.aat @@ -0,0 +1,82 @@ +|function service(name, type, deps) { +|gsub("[ \t]+", "\n", deps) # Allow whitespace-separated dependencies for readability +/{{name}} d m755 +/{{name}}/type cN {{type}} m644 +/{{name}}/{{ type == "bundle" ? "contents" : "dependencies" }}{{ deps?C(deps)"m644":"\tr\t" }} +| return name +|} +|function with_counter(base_name, suffix) { +| suffix = svc_counter[base_name]++ +| if(suffix) { return base_name "-" suffix } +| return base_name +|} +|function oneshot(name, deps) { +| return service(name, "oneshot", deps) +|} +|function longrun(name, deps) { +| return service(name, "longrun", deps) +|} +|function runscript_el_cgroup2(svc_name) { +/{{svc_name}}/run +CN #!/command/execlineb -P + getpid SERVICE_PID + foreground { + importas -i SERVICE_PID SERVICE_PID + if { test -d /run/cgroup2 } + if { mkdir -p /run/cgroup2/s6-rc/{{svc_name}} } + redirfd -w 1 /run/cgroup2/s6-rc/{{svc_name}}/cgroup.procs + printf "%s" ${SERVICE_PID} + } + unexport SERVICE_PID +|} +|function runscript_simple(svc_name, cmd) { +|runscript_el_cgroup2(svc_name) + fdmove -c 2 1 + {{cmd}} +m755 +|} +|function longrun_with_logger(name, deps) { +| longrun(name "-log", "mount-run-cgroup2\nrootfs") +/{{name}}-log/consumer-for cN {{name}} m640 +|runscript_el_cgroup2(name "-log") + if { mkdir -p /var/log/{{name}} } + s6-log -b -- n10 s10240000 t /var/log/{{name}} +m755 +| longrun(name, deps) +/{{name}}/producer-for cN {{name}}-log m640 +|} +|function list_services_with_counter(base_name, suffix, list) { +| for(suffix = 0; suffix < svc_counter[base_name]; suffix++) { +| list = list base_name (suffix ? "-" suffix : "") "\n" +| } +| return list +|} +|function add_to_bundle(bundle_name, svc_name) { +| if(already_in_bundle[bundle_name,svc_name]) { return } +| already_in_bundle[bundle_name,svc_name] = 1 +| if(bundles[bundle_name]) { +| bundles[bundle_name] = bundles[bundle_name] "\n" svc_name +| } else { +| bundles[bundle_name] = svc_name +| bundle_names[++bundle_count] = bundle_name +| } +|} +|function print_bundles( n, command) { +| if(length(sort_tmpfile) && bundle_count) { +| command = "sort >" sort_tmpfile +| for(n=1; n<=bundle_count; n++) { +| print bundle_names[n] | command +| } +| close(command) +| n = 0 +| while((getline bundle_names[++n] < sort_tmpfile) > 0) { } +| close(sort_tmpfile) +| if(n != bundle_count) { +| print "FATAL: error sorting bundles" >"/dev/stderr" +| } +| } +| for(n=1; n<=bundle_count; n++) { +| service(bundle_names[n], "bundle", bundles[bundle_names[n]]) + +| } +|} diff --git a/s6-rc-mount.aat b/s6-rc-mount.aat @@ -1,17 +1,13 @@ +@include common.aat +@include rc-common.aat |### write_oneshot ### |function write_oneshot() { -/{{svc_name}} d m755 -|if(dependencies()) { -/{{svc_name}}/dependencies -CN{{dependencies()}} -m644 -|} +|oneshot(svc_name, dependencies()) |if(down_umount()) { /{{svc_name}}/down cN s6-umount {{q_file}} m644 |} else if (down_readonly()) { /{{svc_name}}/down cN mount -o remount,ro {{q_file}} m644 |} -/{{svc_name}}/type cN oneshot m644 /{{svc_name}}/up CN # mount {{get("source")}} on {{mtp}} |if(boolean("mkdir")) { @@ -20,13 +16,5 @@ CN # mount {{get("source")}} on {{mtp}} if -n -t { mount -t {{q_vfstype}} -o {{q_remount_options}} {{q_spec}} {{q_file}} } mount -t {{q_vfstype}} -o {{q_options}} {{q_spec}} {{q_file}} |} -|### write_bundle ### -|function write_bundle(name) { -/{{name}} d m755 -/{{name}}/contents -CN{{bundles[name]}} -m644 -/{{name}}/type cN bundle m644 -|} |### include main loop / parsing code ### @awk parse_fs.include.awk diff --git a/s6-rc.aat b/s6-rc.aat @@ -1,72 +1,5 @@ @include common.aat -|function service(name, type, deps) { -|gsub("[ \t]+", "\n", deps) # Allow whitespace-separated dependencies for readability -/{{name}} d m755 -/{{name}}/type cN {{type}} m644 -/{{name}}/{{ type == "bundle" ? "contents" : "dependencies" }}{{ deps?C(deps)"m644":"\tr\t" }} -| return name -|} -|function with_counter(base_name, suffix) { -| suffix = svc_counter[base_name]++ -| if(suffix) { return base_name "-" suffix } -| return base_name -|} -|function oneshot(name, deps) { -| return service(name, "oneshot", deps) -|} -|function longrun(name, deps) { -| return service(name, "longrun", deps) -|} -|function runscript_el_cgroup2(svc_name) { -/{{svc_name}}/run -CN #!/command/execlineb -P - getpid SERVICE_PID - foreground { - importas -i SERVICE_PID SERVICE_PID - if { test -d /run/cgroup2 } - if { mkdir -p /run/cgroup2/s6-rc/{{svc_name}} } - redirfd -w 1 /run/cgroup2/s6-rc/{{svc_name}}/cgroup.procs - printf "%s" ${SERVICE_PID} - } - unexport SERVICE_PID -|} -|function runscript_simple(svc_name, cmd) { -|runscript_el_cgroup2(svc_name) - fdmove -c 2 1 - {{cmd}} -m755 -|} -|function longrun_with_logger(name, deps) { -| longrun(name "-log", "mount-run-cgroup2\nrootfs") -/{{name}}-log/consumer-for cN {{name}} m640 -|runscript_el_cgroup2(name "-log") - if { mkdir -p /var/log/{{name}} } - s6-log -b -- n10 s10240000 t /var/log/{{name}} -m755 -| longrun(name, deps) -/{{name}}/producer-for cN {{name}}-log m640 -|} -|function list_services_with_counter(base_name, suffix, list) { -| for(suffix = 0; suffix < svc_counter[base_name]; suffix++) { -| list = list base_name (suffix ? "-" suffix : "") "\n" -| } -| return list -|} -|function add_to_bundle(bundle_name, svc_name) { -| if(already_in_bundle[bundle_name,svc_name]) { return } -| already_in_bundle[bundle_name,svc_name] = 1 -| if(bundles[bundle_name]) { -| bundles[bundle_name] = bundles[bundle_name] "\n" svc_name -| } else { -| bundles[bundle_name] = svc_name -| } -|} -|function print_bundles( bundle_name) { -| for(bundle_name in bundles) { -| service(bundle_name, "bundle", bundles[bundle_name]) - -| } -|} +@include rc-common.aat |END{ / d m755