/usr boot time dependencies

Pekka Savola pekkas at netcore.fi
Wed Aug 20 16:57:10 UTC 2003


On Wed, 20 Aug 2003, Paul Jakma wrote:
> On Wed, 20 Aug 2003, Pekka Savola wrote:
> > > > 
> > > > sysctl -a | awk '$0 ~ /^net\.ipv6\.conf\./ { split($1,a,/\./); 
> > > > foo[a[4]] = a[4]; } END {asort(foo); for (i in foo) { if (foo[i] != 
> > > > "all" && foo[i] != "default") print foo[i];}}'
> > > > 
> > > > at a minimum, grep regex | awk '....' can nearly always trivially be
> > > > replaced with: awk '$0 ~ /regex/ ....' - grep | awk -> no! :)
> 
> > At least the first three-line systctl -a parsing is WAY too
> > confusing to a random John Doe reading the code.  Just because we
> > can do it doesn't mean we have to.  This is not an obfuscated
> > string parsing contest :-), 
> 
> :)
> 
> but look on it as:
> 
> $0 ~ /^net\.ipv6\.conf\./ {
> 	split($1,a,/\./);
> 	foo[a[4]] = a[4];
> }
> 
> END {
> 	asort(foo);
> 	for (i in foo) {
> 		if (foo[i] != "all" && foo[i] != "default")
> 			print foo[i];
> 	}
> }
> 
> and perhaps it makes more sense. NB: the above also strips out the 
> 'all' and 'default' interfaces which i dont think the while read 
> interfaces needs.

Yes, now it makes much more sense (I _think_ I understand what it tries to 
do, except for the stuff around "split"), but I fear that really just 
proves the point: that code is very unreadable when compressed, and still 
difficult to read even if spelled out.

> Indeed, this is all a lot of work just to get the list of interfaces 
> on a system, no? why not just read /proc directly instead of using 
> sysctl? (sysctl uses proc, so proc must be available anyway):
> 
> 	interfaces=`ls /proc/sys/net/ipv6/conf/`

Yeah, if we can assume proc, that would probably be the simplest thing.
 
I don't know about this either way.  Opinions?

> or if you want to avoid the dependency on /proc, use the ip tool:
> 
> 	/sbin/ip -6 link | awk '$1 ~ /^[0-9]/ { gsub(":","",$2); print $2}'

The use of /sbin/ip is non-trivial, for example here it prints out:

lo
sit0 at NONE
eth0
sit1 at NONE
cipcb0

while the interface list (from proc) really is:

all  default  eth0  lo  sit1

(and I think the awk thing is a bit too fancy still, but that's just my 
opinion :-)

> > perhaps the first grep could be eliminated, but it's much more
> > readable if we keep it in.
> 
> dont see how. :)
> 
> (NB: I do have a penchant for awk)

Yeah, I figured :-)
 
> > could be usable otherwise too.
> 
> Thinking about it, i think 'ip link' and 'ip -6 link' should be 
> canonical source of interface info, no?

Should be, perhaps, but the information will be used to change values in 
the sysctl variables, and these bits of information (for whatever reason) 
don't seem to be in sync and in the same format..

-- 
Pekka Savola                 "You each name yourselves king, yet the
Netcore Oy                    kingdom bleeds."
Systems. Networks. Security. -- George R.R. Martin: A Clash of Kings





More information about the devel mailing list