Ticket #15133: ntpclient_fix_server_check.patch

File ntpclient_fix_server_check.patch, 1.0 KB (added by devel@…, 3 years ago)

carefully check ntpclient's output

  • packages/net/ntpclient/files/ntpclient.hotplug

    fix 'check_server' function in ntpclient's hotplug script
    
    Before the server check function just examined the exit code of a single-run
    of ntpclient.
    But sadly ntpclient (according to the source) does not indicate closed ports
    of the server with an exitcode > 0. Thus this patch verifies if the exit code
    is zero _and_ if ntpclient prints an RFC 1305 compatible status output.
    
    see https://dev.openwrt.org/ticket/15133
    
    a b check_server() { 
    2828        } 
    2929 
    3030        [ -z "$hostname" ] && return 
    31         $NTPC -c 1 -p ${port:-123} -i 2 -h $hostname > /dev/null && { SERVER=$hostname; PORT=${port:-123}; } 
     31        # successful operation always results in an RFC-1305 Appendix A status message (digits, dots and spaces) 
     32        # connection failures are not supposed to raise errors (according to ntpclient's source) 
     33        "$NTPC" -c 1 -p ${port:-123} -i 2 -h "$hostname" | grep -q "^[0-9. \t]\+$" && { SERVER=$hostname; PORT=${port:-123}; } 
    3234} 
    3335 
    3436set_drift() {