From: Roy Marples Date: Fri, 3 Jun 2011 20:08:28 +0000 (+0000) Subject: Use printf correctly X-Git-Tag: v5.5.0~28 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f86a2da5624d75fd528fc778671460e1f1d20d11;p=thirdparty%2Fdhcpcd.git Use printf correctly --- diff --git a/dhcpcd-hooks/20-resolv.conf b/dhcpcd-hooks/20-resolv.conf index 85f388cd..fbb64dca 100644 --- a/dhcpcd-hooks/20-resolv.conf +++ b/dhcpcd-hooks/20-resolv.conf @@ -7,6 +7,8 @@ # or dnsmasq. This is important as the libc resolver isn't that powerful. resolv_conf_dir="$state_dir/resolv.conf" +NL=" +" build_resolv_conf() { @@ -33,15 +35,15 @@ build_resolv_conf() if [ -n "$2" ]; then search="$search $*" elif [ -n "$1" ]; then - domain="domain $1\n" + domain="domain $1$NL" fi - [ -n "$search" ] && search="search $(uniqify $search)\n" + [ -n "$search" ] && search="search $(uniqify $search)$NL" # Build the nameserver list srvs=$(cd "$resolv_conf_dir"; \ key_get_value "nameserver " ${interfaces}) for x in $(uniqify ${srvs}); do - servers="${servers}nameserver $x\n" + servers="${servers}nameserver $x$NL" done fi header="$signature_base${header:+ $from }$header" @@ -55,7 +57,7 @@ build_resolv_conf() else echo "# /etc/resolv.conf.head can replace this line" >> "$cf" fi - printf "$domain$search$servers" >> "$cf" + printf %s "$domain$search$servers" >> "$cf" if [ -f /etc/resolv.conf.tail ]; then cat /etc/resolv.conf.tail >> "$cf" else @@ -68,7 +70,7 @@ build_resolv_conf() add_resolv_conf() { - local x= conf="$signature\n" + local x= conf="$signature$NL" # If we don't have any configuration, remove it if [ -z "$new_domain_name_servers" -a \ @@ -82,7 +84,7 @@ add_resolv_conf() set -- $new_domain_name new_domain_name="$1" if valid_domainname "$new_domain_name"; then - conf="${conf}domain $new_domain_name\n" + conf="${conf}domain $new_domain_name$NL" else syslog err "Invalid domain name: $new_domain_name" fi @@ -93,17 +95,17 @@ add_resolv_conf() fi if [ -n "$new_domain_search" ]; then if valid_domainname_list; then - conf="${conf}search $new_domain_search\n" + conf="${conf}search $new_domain_search$NL" else syslog err "Invalid domain name in list: $new_domain_search" fi fi for x in ${new_domain_name_servers}; do - conf="${conf}nameserver $x\n" + conf="${conf}nameserver $x$NL" done if type resolvconf >/dev/null 2>&1; then [ -n "$ifmetric" ] && export IF_METRIC="$ifmetric" - printf "$conf" | resolvconf -a "$interface" + printf %s "$conf" | resolvconf -a "$interface" return $? fi @@ -111,7 +113,7 @@ add_resolv_conf() rm -f "$resolv_conf_dir/$interface" fi [ -d "$resolv_conf_dir" ] || mkdir -p "$resolv_conf_dir" - printf "$conf" > "$resolv_conf_dir/$interface" + printf %s "$conf" > "$resolv_conf_dir/$interface" build_resolv_conf } diff --git a/dhcpcd-hooks/50-ntp.conf b/dhcpcd-hooks/50-ntp.conf index 765baa79..a670f9fb 100644 --- a/dhcpcd-hooks/50-ntp.conf +++ b/dhcpcd-hooks/50-ntp.conf @@ -18,6 +18,8 @@ fi ntp_conf_dir="$state_dir/ntp.conf" ntp_conf=${NTP_CONF:-/etc/ntp.conf} +NL=" +" build_ntp_conf() { @@ -38,7 +40,7 @@ build_ntp_conf() key_get_value "server " $interfaces) if [ -n "$srvs" ]; then for x in $(uniqify $srvs); do - servers="${servers}server $x\n" + servers="${servers}server $x$NL" done fi fi @@ -57,7 +59,7 @@ build_ntp_conf() if [ -n "$servers" ]; then echo "$signature_base${header:+ $from }$header" >> "$cf" - printf "$search$servers" >> "$cf" + printf %s "$search$servers" >> "$cf" echo "$signature_base_end${header:+ $from }$header" >> "$cf" else [ -e "$ntp_conf" ] || return