[PATCH] crond for no-mmu
Denis Vlasenko
vda.linux at googlemail.com
Sun Jan 13 16:13:15 PST 2008
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
More information about the busybox
mailing list