[Toybox] Put syslogd and logger into the same file?

Felix Janda felix.janda at posteo.de
Sun Aug 18 09:55:22 PDT 2013


Rob Landley wrote:
> On 08/10/2013 04:22:58 PM, Felix Janda wrote:
> > Right now syslogd.c contains code from <sys/syslog.h> declaring the  
> > arrays
> > prioritynames and facilitynames, which map human readable strings to
> > numerical ids. logger.c contains very similar array definitions.
> > 
> > <sys/syslog.h> declares these arrays only when SYSLOG_NAMES has been
> > #defined. The structure with the descriptive name "CODE" used for the
> > array members is also only defined conditionally. Something like
> > 
> > #ifndef SYSLOG_NAMES
> > extern CODE prioritynames[];
> > extern CODE facilitynames[];
> > #endif
> > 
> > is also missing in <sys/syslog.h>.
> > 
> > IMO the least bad way to use the arrays from <sys/syslog.h> would be  
> > to
> > combine syslogd.c and logger.c into one file and there define
> > SYSLOG_NAMES before including toys.h.
> 
> It's a good idea, but:
> 
> What I haven't figured out yet is how to do the argument parsing.  
> syslogd and logger have very different option strings.
> 
> Right now there's only one GLOBALS block per file. That's easy enough  
> to fix, and we can #undef TT and #define TT toys. But the FLAG_* macros  
> are also defined based on FOR_command. And that's harder to clean up...

I was aware that there might be some problems with the build architecture
but couldn't name them. Thanks for the clarification.

I have no idea how to get two commands with overlapping conflicting options
to work when put into the same file.

So how about the following hack?

Keep them in separate files. Have one common config symbol, tear everything
out of logger.c but logger_main, declare SYSLOG_NAMES in syslogd.c, put
something like the current lookup() in logger.c to syslogd.c and make an
extern declaration in logger.c. The new lookup() (better use a less generic
name then) should accept an integer as its first argument instead of the
table, say 0 stands for facilities and 1 for priorities.

Felix

 1376844922.0


More information about the Toybox mailing list