[BusyBox] Re: busybox-cvs Digest, Vol 29, Issue 4

Rainer Weikusat rainer.weikusat at sncag.com
Tue Aug 2 10:31:29 MDT 2005


"Vladimir N. Oleynik" <dzo at simtreas.ru> writes:

[...]

>> /*
>>   run a program in a background session
>> */
>
> Its strange applet and haven`t 'supervisor' features:
> fork()+exec*() only, and have not wait and restart if damage.

That's the purpose of it. The 'supervisor' would be init (which the
system this code came from uses to manage daemon processes). This is
just a small tool which is very useful to start background tasks that
actually run in the background (eg fork off long running configure
tasks from init scripts). And it's a UNIX(*) program, not a Gnu one
:->.

>> /*  functions */
>> static int sys_die(char const *fnc, char const *sysc) __attribute__ ((noreturn));
>> static int sys_die(char const *fnc, char const *sysc)
>> {
>>     syslog(LOG_ERR, "%s: %s: %m(%d)", fnc, sysc, errno);
>>     exit(1);
>> }
>
> Hmm. This compiled without warning: return for not returned
> function?

If the 'noreturn' wasn't there, gcc would complain that there is no
return at the end of the routine, which is "kinda pointless" after
exit. 

>
>> static void remove_lock_params(void)
>> {
>>     char **e_run, **e_last;
>>     e_last = e_run = environ;
>>     if (!*e_last) return;
>>     while (e_last[1]) ++e_last;
>>         e_run = environ;
>>     while (e_run < e_last)
>> 	if (strncmp(*e_run, LOCK_PREFIX, LOCK_PREFIX_LEN) == 0) {
>> 	    *e_run = *e_last;
>> 	    *e_last-- = NULL;
>> 	} else
>> 	    ++e_run;
>>         if (strncmp(*e_run, LOCK_PREFIX, LOCK_PREFIX_LEN) == 0)
>> *e_run = NULL;
>> }
>
> Hmm. Knotty.

It has the nice property to actually work ... :-)

> May be simply (not tested):
>
> static void remove_lock_params(void)
> {
>      char **e, **t;
>
>      for (e = t = environ; t && *t; t++)
> 	if (strncmp(*t, LOCK_PREFIX, LOCK_PREFIX_LEN) != 0) {
> 	    *e = *t;
> 	    e++;	
> 	}
>      if(e)
> 	*e = NULL;
> }

... while this is not only a classic example of 'Cargo Cult Programming',
but additionally wouldn't (for instance, it would kill all of the
environment if no lock indicator variables where found).


More information about the busybox mailing list