Question on bb_info_msg, printf, and bb_error_msg?

Michael D. Setzer II mikes at kuentos.guam.net
Fri Jul 8 13:50:16 UTC 2016


On 8 Jul 2016 at 12:15, Denys Vlasenko wrote:

From:           	Denys Vlasenko <vda.linux at googlemail.com>
Date sent:      	Fri, 8 Jul 2016 12:15:05 +0200
Subject:        	Re: Question on bb_info_msg, printf, and bb_error_msg?
To:             	"Michael D. Setzer II" <mikes at kuentos.guam.net>
Copies to:      	busybox <busybox at busybox.net>

> On Wed, Jul 6, 2016 at 10:02 AM, Michael D. Setzer II
> <mikes at kuentos.guam.net> wrote:
> > Did further testing, and the output has definitely changed to going to
> > Standard Error instead of Standard Out.
> >
> > Running my current image under VirtualBox with busybox 124.2
> >
> > udhcpc -n -t 8 -T 5 i eth0 -s /udcpc.sh >out1 2>out2
> >
> > out1 contains following
> >
> > udhcpc (v1.24.2) started
> > Sending discover...
> > Sending select for 192.168.128.101...
> > Lease of 192.168.128.101 obtained, lease time 43200
> >
> > out2 contains nothing.
> >
> > Copied a build of the 1.25.0 busybox and did same command.
> >
> > ./busybox125 udhcpc -n -t 8 -T 5 i eth0 -s /udcpc.sh >out1a 2>out2a
> >
> > out1a  contains nothing??
> >
> > out2a contains
> >
> > udhcpc: started, v1.25.0
> > udhcpc: sending discover
> > udhcpc: sending select for 192.168.128.101
> > udhcpc: lease of 192.168.128.101 obtained, lease time 43200
> >
> > So, the change is actually causing three issues
> > Original line in script is like this
> >   ipaddress=`udhcpc -n -i $device -s./udhcpc.sh | grep Lease | cut -d\  -f3 | tr
> > -d "\n"`
> >
> > 1. Output needs to be switched from stderr to stdout using 2>&1
> > 2. Since the case of the word I selected to use to select line is changed,
> > either case needs to be changed or -i used with grep.
> > 3. With the additional field added to the output, the -f3 has to be changed to
> > -f4
> 
> Sorry for the inconvenience this change is causing you.
> 
> Instead of scraping output, it's possible to use environment variables
> in udhcpc.sh - that is how DHCP information is supposed to be accessed.

First, Thanks for the reply. I still not clear why in the changes list it shows that 
sometimes bb_info_msg is changed to printf and sometimes changed to 
bb_error_msg. Actually, did a test and modified the dhcpc.c to change the 
bb_error_msg to printf to see if it would work the same. Did find that I also 
had to add \n or output was on same line, but it did get the output to go to 
stdout instead of stderr, and  had the output without the added field. The 
case issue would still be there, but that is an easy fix. It is not the 
inconvience, but the consistance, and it may be there is good reason that I 
am not aware of? 

Second, I was not aware that the udhcpc.sh was a script to be modified?? I 
do see the variable $ip, but it is only one renew section, and doesn't seem to 
show where it gets defined. Is there somewhere that this process is defined?
A user had submitted the script that would process systems with multiple nics 
to find the active nics, and which one actually got an IP address. Since it 
worked fine I didn't go farther. I've got a couple systems with 2 nics, and have 
one system that has 9 ethernet ports with one single nic, and two 4 port nics, 
and it works fine with that.

the udhcpc.sh script I have doesn't seem to have info. Perhaps there is 
another file that explans the options you mention for getting the variable?

#!/bin/sh

# udhcpc script edited by Tim Riker <Tim at Rikers.org> and Devin Bayer

[ -z "$1" ] && echo "Error: should be called from udhcpc" && exit 1

{ # redirect to logger
  
  RESOLV_CONF="/etc/resolv.conf"
  [ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
  [ -n "$subnet" ] && NETMASK="netmask $subnet"
  
  case "$1" in
    deconfig)
    /sbin/ifconfig $interface 0.0.0.0
    ;;
    
    renew|bound)
    /sbin/ifconfig $interface $ip $BROADCAST $NETMASK
    
    if [ -n "$router" ] ; then
      echo "deleting routers for interface $interface"
      while route -n del default gw 0.0.0.0 dev $interface 2> /dev/null; do
      true
    done
    
    if route -n | egrep "^0.0.0.0"; then
      echo "default route already in place"
    else
      echo "adding default router $router"
      route add default gw $router dev $interface
    fi
  fi
  
  if (! grep -q -v DISABLE_DHCP $RESOLV_CONF) && echo -n > 
$RESOLV_CONF; then
    [ -n "$domain" ] && echo search $domain >> $RESOLV_CONF
    for i in $dns ; do
    echo adding dns $i
    echo nameserver $i >> $RESOLV_CONF
  done
fi
;;
esac
} 2>&1 | ( logger -s -p daemon.info -t uhdcp || cat )

exit



+----------------------------------------------------------+
  Michael D. Setzer II -  Computer Science Instructor      
  Guam Community College  Computer Center                  
  mailto:mikes at kuentos.guam.net                            
  mailto:msetzerii at gmail.com
  Guam - Where America's Day Begins                        
  G4L Disk Imaging Project maintainer 
  http://sourceforge.net/projects/g4l/
+----------------------------------------------------------+

http://setiathome.berkeley.edu (Original)
Number of Seti Units Returned:  19,471
Processing time:  32 years, 290 days, 12 hours, 58 minutes
(Total Hours: 287,489)

BOINC at HOME CREDITS
ABC         16613838.513356   |   EINSTEIN    
104060534.95569545831554.462189
ROSETTA     45831554.462189   |   SETI        86269417.639918



More information about the busybox mailing list