[BusyBox] [PATCH] devfsd

Tito farmatito at tiscali.it
Thu Nov 18 21:39:44 UTC 2004


On Monday 15 November 2004 OO:44, Allen Chan wrote:
> In BusyBox 1.00, with CONFIG_DEVFSD_VERBOSE=y, devfsd sometimes 
> generate incorrect error messages.  For example, after adding 
> '/sbin/devfsd /dev" to a startup script in /etc/init.d, I get the 
> following output in dmesg even though /etc/devfsd.conf exists and 
> devfsd creates all the symlinks as defined in the config file:
 
>  devfsd v1.3.25  started for /dev
>  devfsd: read config file: /etc/devfsd.conf: No such file or directory
Hi Allen,
after taking a look at the devsfd code (I've busyboxed some time ago)
  i'm wondering how it could be possible
with this kind of error that the symlinks are created because if they are,
(in lines 582-600) the errno is reset to 0 (line 601).

	if ( ( fp = fopen (path, "r") ) != NULL )
	{
		while (fgets (buf, STRING_LENGTH, fp) != NULL)
		{
			/*buf[strlen (buf) - 1] = '\0';*/
			/*  Skip whitespace  */
			for (line = buf; isspace (*line); ++line)
				/*VOID*/;
			if (line[0] == '\0' || line[0] == '#' )
				continue;
			process_config_line (line, event_mask);
		}
		fclose (fp);
		errno=0;
}
 read_config_file_err:
#ifdef CONFIG_DEVFSD_VERBOSE
msg_logger(((optional ==  0 ) && (errno == ENOENT))? DIE : NO_DIE, LOG_ERR, "read config file: %s: %m\n", path);

BTW: at this point as optional for /etc/devfsd.conf is set to FALSE the program should exit with EXIT_FAILURE if errno==ENOENT.

> The problem is due to the possible corruption of the global errno 
> variable while inside the msg_logger function, possibly causing 
> arbitrary messages to be displayed.  The value of errno needs to be 
> saved and restored as described on the errno man page.

By a fast look at the man pages it seems to me that the only call  in msg_logger
able to set errno to ENOENT is acces() in which case /dev/log would be not accessible
so how is it possible that you have some output in dmesg?

I just want to understand exactly what is happening.
For me your patch is ok as it doesn't break things and fixes your problems.

Thank in advance for your help and explanations.
I hope that i can  learn something from this issue.

Best regards and Ciao,
Tito
>diff -Npur orig/miscutils/devfsd.c new/miscutils/devfsd.c
>--- orig/miscutils/devfsd.c 2004-10-13 02:25:52.000000000 -0400
>+++ new/miscutils/devfsd.c 2004-11-15 14:08:12.000000000 -0500
>@@ -306,19 +306,24 @@ const char * const bb_msg_variable_not_f
> #if defined(CONFIG_DEVFSD_VERBOSE) || defined(CONFIG_DEBUG)
>static void msg_logger(int die, int pri, const char * fmt, ... )
>{
>+ int errno_save = errno;
>  va_list ap;
> 
>  va_start(ap, fmt);
>  if (access ("/dev/log", F_OK) == 0)
>  {
>   openlog(bb_applet_name, 0, LOG_DAEMON);
>+  errno = errno_save;
>   vsyslog( pri , fmt , ap);
>   closelog();
>   }
> #ifndef CONFIG_DEBUG
>  else
> #endif
>+ {
>+  errno = errno_save;
>   bb_verror_msg(fmt, ap);
>+ }
>  va_end(ap);
>  if(die==DIE)
>   exit(EXIT_FAILURE);
>----- end of patch -----
> -- 
> Allen Chan
> allen at developers.alyz.com
> http://www.alyz.com
> 



More information about the busybox mailing list