From 13505ca8fce1c22a7f124314a07b4ecbb62bee22 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Tue, 10 May 2005 20:56:07 +0000 Subject: * Makefile.in (DLL_OFILES): Add fhandler_mailslot.o. * devices.h (FH_KMSG): Define new device. * devices.in: Add "/dev/kmsg" entry. * devices.cc: Regenerate. * dtable.cc (build_fh_pc): Handle case FH_KMSG. * fhandler.h (class fhandler_mailslot): New class. (class select_stuff): Add device_specific_mailslot pointer. * fhandler_mailslot.cc: New file. * select.cc (peek_mailslot): New function. (verify_mailslot): Ditto. (struct mailslotinf): New stuct to handle select on mailslots. (thread_mailslot): New function. (start_thread_mailslot): Ditto. (mailslot_cleanup): Ditto. (fhandler_mailslot::select_read): New method. * syslog.cc (klog_guard): New muto. (dev_kmsg): Local mailslot for kernel message device. (vklog): New function. (klog): Ditto. * winsup.h (vklog): Declare. (klog): Ditto. * include/sys/syslog.h: Define _PATH_KLOG. --- winsup/cygwin/syslog.cc | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'winsup/cygwin/syslog.cc') diff --git a/winsup/cygwin/syslog.cc b/winsup/cygwin/syslog.cc index b856bb7aa..38c8ecc31 100644 --- a/winsup/cygwin/syslog.cc +++ b/winsup/cygwin/syslog.cc @@ -461,6 +461,38 @@ syslog (int priority, const char *message, ...) va_end (ap); } +static NO_COPY muto klog_guard; +fhandler_mailslot *dev_kmsg; + +extern "C" void +vklog (int priority, const char *message, va_list ap) +{ + /* TODO: kernel messages are under our control entirely and they should + be quick. No playing with /dev/null, but a fixed upper size for now. */ + char buf[2060]; /* 2048 + a prority */ + __small_sprintf (buf, "<%d>", priority); + __small_vsprintf (buf + strlen (buf), message, ap); + klog_guard.init ("klog_guard")->acquire (); + if (!dev_kmsg) + dev_kmsg = (fhandler_mailslot *) build_fh_name ("/dev/kmsg"); + if (dev_kmsg && !dev_kmsg->get_handle ()) + dev_kmsg->open (O_WRONLY, 0); + if (dev_kmsg && dev_kmsg->get_handle ()) + dev_kmsg->write (buf, strlen (buf) + 1); + else + vsyslog (priority, message, ap); + klog_guard.release (); +} + +extern "C" void +klog (int priority, const char *message, ...) +{ + va_list ap; + va_start (ap, message); + vklog (priority, message, ap); + va_end (ap); +} + extern "C" void closelog (void) { -- cgit v1.2.3