On Thursday 29 July 2010 04:29, Jeremie Koenig wrote:
> The klogctl() interface allows changing the console loglevel, but is
> Linux-specific. The more portable method of reading from _PATH_KLOG is
> added as an alternative.
> 
> Adapted from the Debian kFreeBSD patch at:
> http://svn.debian.org/viewsvn/d-i/people/slackydeb/kfreebsd/busybox/1.14/debian/klogd.diff
> ---
>  sysklogd/Config.src |   18 ++++++++++-
>  sysklogd/klogd.c    |   86 
> ++++++++++++++++++++++++++++++++++++++++++++++-----
>  2 files changed, 95 insertions(+), 9 deletions(-)
> 
> +/* FIXME: consumes global static memory */
> +static int klogfd = 0;
> +
> +static inline void klogd_open(void)
> +{

Use fixed fd == 3 in order to not use globals:

enum { klogfd = 3 };
...
>       fd = open(_PATH_KLOG, O_RDONLY, 0),
>
> +     if (fd < 0) {
> +             syslog(LOG_ERR, "klogd: can't open "_PATH_KLOG" (error %d: %m)",
> +                             errno);
> +             exit(EXIT_FAILURE);
     ^^^^^^^^^ "logmode = SYSLOG; bb_perror_msg_and_die(...)" will be smaller.
> +     }
        xmove_fd(fd, klogfd);
> +}

Just be sure to call klogd_open() before openlog(), since
openlog() may use fd 3 otherwise!



> +static inline void klogd_close(void)

Do not inline use-once functions, gcc will do it for you where needed.



> +{
> +     if (klogfd != 0)
> +             close(klogfd);
> +}
> +
> +static inline int klogd_read(char *bufp, int len)
> +{
> +     return read(klogfd, bufp, len);
> +}
> +
> +static inline void klogd_setloglevel(int lvl UNUSED_PARAM)
> +{
> +     syslog(LOG_WARNING, "klogd warning: this build does not support"
> +                     " changing the console log level");

Can you use /proc/sys/kernel/printk for it?


-- 
vda
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to