Busybox won't init

Denys Vlasenko vda.linux at googlemail.com
Fri Nov 5 08:20:48 UTC 2010


On Friday 05 November 2010 02:48, Matt Johnson wrote:
> 
> >
> > I guess at this point you need to resort to adding
> > debug printouts to init's main, a-la:
> >
> > int init_main(int argc UNUSED_PARAM, char **argv)
> > {
> > bb_error_msg("%s:%u", __func__, __LINE__);
> >
>  
> Thanks for pointing me in the right direction. Using bb_error_msg, I was able to trace in init.c to:
>  
> static void message(int where, const char *fmt, ...)
> {
> ...
>  
> #if ENABLE_FEATURE_INIT_SYSLOG
>  msg[l] = '\0';
>  if (where & L_LOG) {
>   /* Log the message to syslogd */
>   openlog(applet_name, 0, LOG_DAEMON);
> bb_error_msg("%s:%u", __func__, __LINE__);
>   /* don't print "\r" */
>   syslog(LOG_INFO, "%s", msg + 1);
> bb_error_msg("%s:%u", __func__, __LINE__);
>   closelog();
>  }
>  
> If you see my two bb_error_msg statements, the first one shows up, but the second doesn't.
> So simply the call to syslog is crashing the process.  This seems very strange to me.

Apparently, syslog() call segfaults.

> Next, I tried turning off ENABLE_FEATURE_INIT_SYSLOG in the config.  This gets me much further, but then dies trying to start klogd:
>  
> VFS: Mounted root (nfs filesystem) on device 0:12.
> Freeing init memory: 128K
> init started: BusyBox v1.17.3 (2010-11-03 21:33:57 MST)
> starting pid 878, tty '': '/etc/init.d/rcS'
> Initializing random number generator... read-only file system detected...done
> Starting network...
> ip: RTNETLINK answers: File exists
> Segmentation fault
> starting pid 895, tty '/dev/ttySAC0': '/sbin/getty -L ttySAC0 115200 vt100 '
> eth0: no IPv6 routers present
> Welcome!
> process '/sbin/klogd -n' (pid 897) exited. Scheduling for restart.
> process '/sbin/klogd -n' (pid 902) exited. Scheduling for restart.
> process '/sbin/klogd -n' (pid 903) exited. Scheduling for restart.
> process '/sbin/klogd -n' (pid 904) exited. Scheduling for restart.
> ... (ad infinitum) ...
>  
> I'm not to worried about the RTNETLINK message, because I think
> it's just due to me using NFS durng this testing phase.
> Not sure if the segmentation fault following is related or not.  

Since some other programs use syslog() call too, it's
not surprising you see more segfaults.


> I tried adding more bb_error_msg statments to sysklogd/klogd.c, but none show up.
> Not even one right at the start of klogd_main. 
>  
> It seems crazy to me that I can't write to syslog.
> Any ideas why that might be?

No idea yet, but I have a suggestion how to find out.

First, comment out the line where klogd is started.

Second, determine what libc do you use (glibc? uclibc? etc),
download its source tarball. In that tarball, find
source code of openlog() and syslog() functions.

Then, write this small test program:

#include <syslog.h>
#include <stdio.h>
#include <stdarg.h>
void my_openlog(const char *ident, int option, int facility) {
        ...
}
void my_syslog(int priority, const char *format, ...) {
        ...
}
int main() {
	printf("%s:%u: calling openlog\n", __func__, __LINE__);
        my_openlog("testing", 0, LOG_DAEMON);

	printf("%s:%u: calling syslog\n", __func__, __LINE__);
        my_syslog(LOG_INFO, "%s", "test message");

	printf("%s:%u: exiting\n", __func__, __LINE__);
        return 0;
}

Substitute ... with bodies of your libc's openlog() and syslog()
functions. Add more printf("%s:%u\n", __func__, __LINE__);
statements into their bodies.

Compile it, then run it on your target machine.

When you determine where exactly it segfault _inside_
my_syslog() function, post your results.

-- 
vda


More information about the busybox mailing list