[PATCH] crond for no-mmu

Alex Landau landau_alex at yahoo.com
Tue Jan 22 06:29:10 PST 2008


----- Original Message ----
> From: Denis Vlasenko <vda.linux at googlemail.com>
> To: busybox at busybox.net
> Cc: Alex Landau <landau_alex at yahoo.com>
> Sent: Monday, January 14, 2008 2:13:15 AM
> Subject: Re: [PATCH] crond for no-mmu
> 
> On Tuesday 11 December 2007 10:33, Alex Landau wrote:
> > Hi All,
> > 
> > The attached trivial patch changes fork() to vfork()
> > in two places in crond.c. With this change, cron works on no-mmu. 
> > Maybe it's even worth adding an #if BB_MMU to choose between
> > fork and vfork... 
> 
> Sorry, this needs more work.
> 
> With s/fork/vfork/:
> 
> ChangeUser(): does setenv, which modifies global environ
> and stuff it points too. This leaks old malloced block
> from old setenv's. This is libc API breakage, not fixable.
> 
> If you need to repeatedly set variable,
> don't use setenv. Use something like:
> 
>     if (envvar) {
>         unsetenv(envvar);
>         free(envvar);
>     }
>     envvar = xasprintf("VAR=%s", val);
>     putenv(envvar);
> 
> crondlog(): does a lot of things which are problematic
> after vfork. Avoid using it.
> 
> Basically, you need to pull apart ChangeUser(), and do first half:
> getpwnam(), setting env - before vfork, doing bare minimum of
> needed things after vfork - setting group vector, setuid,
> chdir, exec. After vfork, do all error reporting to stderr, not log.
> In order to minimize chaces of late errors, do as much
> of error checking before vfork as possible.
> Use _exit() to exit inside vforked child.
> 
> In other words, it is doable, but not with one-line patch.
> 
> Regarding those mysteriuos dups -
> they may be written simpler and more understandable:
> 
>                 if (mailFd >= 0) {
> -                       dup2(mailFd, mailf != NULL);
> -                       dup2((mailf ? mailFd : 1), 2);
> -                       close(mailFd);
> +                       xmove_fd(mailFd, mail_filename ? 1 : 0);
> +                       dup2(1, 2);
>                 }
> 
> --
> vda
> 

Well, I needed a quick and dirty solution and thought that a working but leaking crond is better
than a non-working crond. Actually, I didn't think of the leaks then, but that's my opinion now.
I don't have the resources now to audit the whole code and make the needed modifications,
so if anyone wants to volunteer...

Regards,
Alex



      ____________________________________________________________________________________
Looking for last minute shopping deals?  
Find them fast with Yahoo! Search.  http://tools.search.yahoo.com/newsearch/category.php?category=shopping


More information about the busybox mailing list