was [PATCH] sulogin size reduction and clean up -- now: new do_syslog for libbb

Tito farmatito at tiscali.it
Wed Jul 19 08:55:03 PDT 2006


On Tuesday 18 July 2006 03:29, Rob Landley wrote:
> On Monday 17 July 2006 9:38 am, Tito wrote:
> > On Monday 17 July 2006 00:17, Rob Landley wrote:
> > > On Saturday 15 July 2006 4:25 pm, Tito wrote:
> > > > Hi,
> > > > this patch reduces the size of sulogin and cleans up the code.
> > > > The patch also adds a config option to enable/disable syslogging in
> > > > sulogin.
> > >
> > > If you'd like a global switch to enable/disable syslog support in
> > > applets, that's one thing.  But adding an "And should THIS applet do
> > > syslog?  Or how about THIS one?  What about THIS one?" to each applet's
> > > config?  Not so much. (At the very least: CONFIG_NITPICK.)
> >
> > Hi,
> > I thought to add one general switch for loginutils (default on?), but only
> > after all applets were ported to this feature, but if you like it we can do
> > it the other way first create the global switch and then modify the single
> > applets
> >
> > Let me know your opinion.
> 
> You mean syslog?  I prefer adding the one general switch and then porting the 
> applets to use it.
this is the list of the apps doing some syslog:
file:///root/Desktop/busybox/init/init.c
file:///root/Desktop/busybox/init/init_shared.c

file:///root/Desktop/busybox/libbb/setup_environment.c

file:///root/Desktop/busybox/loginutils/getty.c
file:///root/Desktop/busybox/loginutils/login.c
file:///root/Desktop/busybox/loginutils/passwd.c
file:///root/Desktop/busybox/loginutils/su.c
file:///root/Desktop/busybox/loginutils/sulogin.c

file:///root/Desktop/busybox/miscutils/crond.c
file:///root/Desktop/busybox/miscutils/devfsd.c

file:///root/Desktop/busybox/networking/fakeidentd.c
file:///root/Desktop/busybox/networking/inetd.c
file:///root/Desktop/busybox/networking/nameif.c 
file:///root/Desktop/busybox/networking/telnetd.c
file:///root/Desktop/busybox/networking/udhcp/common.c  
file:///root/Desktop/busybox/networking/zcip.c

file:///root/Desktop/busybox/sysklogd/klogd.c
file:///root/Desktop/busybox/sysklogd/logger.c
so should the switch go in GENERAL CONFIGURATION
or Login/Password Management Utilities, Networking Utilities and so on ?
> Also, any thoughts on some kind of libbb do_syslog() wrapper function that 
> does it all in one go?  (Is there a lot of overhead for openlog() and 
> closelog()?  Is an applet not supposed to do it more than once...?)
> 
> Rob

Hi,
this a proposal for a new and flexible do_syslog for libbb.
This is not tested nor compiled but just an idea to be discussed
on the list first.


DESCRIPTION:
This function opens a connection to the system logger for a  program.
The facility value is set through a global variable bb_facility as it 
is changed just one time per applet and so we spare one argument.
Generates a log message.
Closes the descriptor if ENABLE_FEATURE_CLEAN_UP is set.
Generates also an error message:
	if level is:   LOG_DEBUG,  LOG_INFO, LOG_NOTICE 
                           the message will not contain the applet's name and 
                           goes to stdout.
	if level is:  LOG_WARNING 
                           the message will contain the applet's name and 
                           goes to stderr.	
        if level is:  LOG_ERR,  LOG_CRIT, LOG_ALERT, LOG_EMERG	
                           the message will contain the applet's name and 
                           goes to stderr ,
                          The progam will exit.

So by choosing an appropriate level value we can influence the behaviour
of the function.
                           	
int bb_facility;

void do_syslog(int level, const char *fmt, ...)
{
	va_list p;
	va_list p2;

	va_start(p, fmt);
	__va_copy(p2, p);

	openlog(bb_applet_name, LOG_PID | LOG_CONS | LOG_NOWAIT ,  bb_facility);
	vsyslog(level, fmt, p2);
	if (ENABLE_FEATURE_CLEAN_UP) closelog();

	switch (level) {
		case LOG_DEBUG:
		case LOG_INFO: 
		case LOG_NOTICE:
			vprintf(fmt, p);
			putchar('\n');
			fflush(stdout);
			break;
		case LOG_WARNING:
			bb_verror_msg(fmt, p)
			putc('\n', stderr);
			switch (level) {
				case LOG_ERR:
				case LOG_CRIT:
				case LOG_ALERT:
				case LOG_EMERG:
					exit(EXIT_FAILURE);
			}
	}

	va_end(p);
}

Comments are welcome!!!


Ciao,
Tito


More information about the busybox mailing list