 d13e86d4c2
			
		
	
	d13e86d4c2
	
	
	
		
			
			This adds a wrapper (uci_load_validate) for uci_validate_section() that allows callers (through a callback function) to access the values set by uci_validate_section(), without having to manually declare a (potentially long) list of local variables. The callback function receives two arguments when called, the config section name and the return value of uci_validate_section(). If no callback function is given, then the wrapper exits with the value returned by uci_validate_section(). This also updates several init scripts to use the new wrapper function. Signed-off-by: Jeffery To <jeffery.to@gmail.com>
		
			
				
	
	
		
			47 lines
		
	
	
		
			978 B
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			47 lines
		
	
	
		
			978 B
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
| #!/bin/sh /etc/rc.common
 | |
| # Copyright (C) 2014 OpenWrt.org
 | |
| 
 | |
| START=10
 | |
| USE_PROCD=1
 | |
| 
 | |
| validate_system_section()
 | |
| {
 | |
| 	uci_load_validate system system "$1" "$2" \
 | |
| 		'hostname:string:OpenWrt' \
 | |
| 		'conloglevel:uinteger' \
 | |
| 		'buffersize:uinteger' \
 | |
| 		'timezone:string:UTC' \
 | |
| 		'zonename:string'
 | |
| }
 | |
| 
 | |
| system_config() {
 | |
| 	[ "$2" = 0 ] || {
 | |
| 		echo "validation failed"
 | |
| 		return 1
 | |
| 	}
 | |
| 
 | |
| 	echo "$hostname" > /proc/sys/kernel/hostname
 | |
| 	[ -z "$conloglevel" -a -z "$buffersize" ] || dmesg ${conloglevel:+-n $conloglevel} ${buffersize:+-s $buffersize}
 | |
| 	echo "$timezone" > /tmp/TZ
 | |
| 	[ -n "$zonename" ] && [ -f "/usr/share/zoneinfo/$zonename" ] && \
 | |
| 		ln -sf "/usr/share/zoneinfo/$zonename" /tmp/localtime && rm -f /tmp/TZ
 | |
| 
 | |
| 	# apply timezone to kernel
 | |
| 	date -k
 | |
| }
 | |
| 
 | |
| reload_service() {
 | |
| 	config_load system
 | |
| 	config_foreach validate_system_section system system_config
 | |
| }
 | |
| 
 | |
| service_triggers()
 | |
| {
 | |
| 	procd_add_reload_trigger "system"
 | |
| 	procd_add_validation validate_system_section
 | |
| }
 | |
| 
 | |
| start_service() {
 | |
| 	reload_service
 | |
| }
 |