[openwrt/openwrt] ubox: only start log to file when filesystem has been mounted

LEDE Commits lede-commits at lists.infradead.org
Sun Jan 30 12:22:18 PST 2022


dangole pushed a commit to openwrt/openwrt.git, branch master:
https://git.openwrt.org/88baf6ce2c880149bd1c1d8ddacc7bc61dd4f18b

commit 88baf6ce2c880149bd1c1d8ddacc7bc61dd4f18b
Author: Daniel Golle <daniel at makrotopia.org>
AuthorDate: Sun Jan 30 19:39:21 2022 +0000

    ubox: only start log to file when filesystem has been mounted
    
    If log_file is on an filesystem mounted using /etc/config/fstab we have
    to wait for that to happen before starting the logread process.
    Inhibit the start of the file-writer process and use a mount trigger to
    fire it up once the filesystem actually becomes available.
    
    Signed-off-by: Daniel Golle <daniel at makrotopia.org>
---
 package/system/ubox/files/log.init | 28 +++++++++++++++++++++++++---
 1 file changed, 25 insertions(+), 3 deletions(-)

diff --git a/package/system/ubox/files/log.init b/package/system/ubox/files/log.init
index c4802d4199..6587cf6b06 100644
--- a/package/system/ubox/files/log.init
+++ b/package/system/ubox/files/log.init
@@ -9,6 +9,8 @@ PIDCOUNT=0
 USE_PROCD=1
 PROG=/sbin/logread
 
+extra_command "start_file" "Start writing to log file"
+
 validate_log_section()
 {
 	uci_load_validate system system "$1" "$2" \
@@ -34,7 +36,7 @@ start_service_daemon()
 {
 	[ $log_buffer_size -eq 0 -a $log_size -gt 0 ] && log_buffer_size=$log_size
 	[ $log_buffer_size -eq 0 ] && log_buffer_size=64
-	procd_open_instance
+	procd_open_instance logd
 	procd_set_param command "/sbin/logd"
 	procd_append_param command -S "${log_buffer_size}"
 	procd_set_param respawn 5 1 -1
@@ -52,9 +54,12 @@ start_service_file()
 	}
 	[ -z "${log_file}" ] && return
 
+	[ "$_BOOT" = "1" ] &&
+		[ "$(procd_get_mountpoints "${log_file}")" ] && return 0
+
 	mkdir -p "$(dirname "${log_file}")"
 
-	procd_open_instance
+	procd_open_instance logfile
 	procd_set_param command "$PROG" -f -F "$log_file" -p "$pid_file"
 	[ -n "${log_size}" ] && procd_append_param command -S "$log_size"
 	procd_close_instance
@@ -73,7 +78,7 @@ start_service_remote()
 	[ -z "${log_ip}" ] && return
 	[ -z "${log_hostname}" ] && log_hostname=$(cat /proc/sys/kernel/hostname)
 
-	procd_open_instance
+	procd_open_instance logremote
 	procd_set_param command "$PROG" -f -h "$log_hostname" -r "$log_ip" "${log_port}" -p "$pid_file"
 	case "${log_proto}" in
 		"udp") procd_append_param command -u;;
@@ -83,10 +88,17 @@ start_service_remote()
 	procd_close_instance
 }
 
+register_mount_trigger()
+{
+	[ -n "${log_file}" ] && procd_add_action_mount_trigger start_file "${log_file}"
+}
+
 service_triggers()
 {
+	config_load system
 	procd_add_reload_trigger "system"
 	procd_add_validation validate_log_section
+	config_foreach validate_log_section system register_mount_trigger
 }
 
 start_service()
@@ -96,3 +108,13 @@ start_service()
 	config_foreach validate_log_section system start_service_file
 	config_foreach validate_log_section system start_service_remote
 }
+
+start_file()
+{
+	config_load system
+	config_foreach validate_log_section system start_service_file
+}
+
+boot() {
+	_BOOT=1 start
+}



More information about the lede-commits mailing list