Implemented '--syslog' and '--syslog-facility'.
authorshort <>
Sun, 7 Sep 2003 08:28:46 +0000 (08:28 +0000)
committershort <>
Sun, 7 Sep 2003 08:28:46 +0000 (08:28 +0000)
src/client/gnomevfs/captive.conf.in
src/client/lufs/mount.captive.in
src/libcaptive/client/init.c
src/libcaptive/client/init.h
src/libcaptive/client/options.c
src/libcaptive/client/vfs.c
src/libcaptive/include/captive/options.h
src/libcaptive/sandbox/server-GLogFunc.c

index 32ff37b..c03663e 100644 (file)
@@ -2,58 +2,68 @@ captive-ntfs: libcaptive-gnomevfs \
                --load-module=@localstatedir@/lib/captive/ntoskrnl.exe \
                 --filesystem=@localstatedir@/lib/captive/ntfs.sys --disk --rw \
                --sandbox-server=@sbindir@/captive-sandbox-server \
-               --bug-pathname=@localstatedir@/lib/captive/bug-%FT%T.captivebug.xml.gz
+               --bug-pathname=@localstatedir@/lib/captive/bug-%FT%T.captivebug.xml.gz \
+               --syslog
 
 captive-ntfs-ro: libcaptive-gnomevfs \
                --load-module=@localstatedir@/lib/captive/ntoskrnl.exe \
                 --filesystem=@localstatedir@/lib/captive/ntfs.sys --disk --ro \
                --sandbox-server=@sbindir@/captive-sandbox-server \
-               --bug-pathname=@localstatedir@/lib/captive/bug-%FT%T.captivebug.xml.gz
+               --bug-pathname=@localstatedir@/lib/captive/bug-%FT%T.captivebug.xml.gz \
+               --syslog
 
 captive-ntfs-blind: libcaptive-gnomevfs \
                --load-module=@localstatedir@/lib/captive/ntoskrnl.exe \
                 --filesystem=@localstatedir@/lib/captive/ntfs.sys --disk --blind \
                --sandbox-server=@sbindir@/captive-sandbox-server \
-               --bug-pathname=@localstatedir@/lib/captive/bug-%FT%T.captivebug.xml.gz
+               --bug-pathname=@localstatedir@/lib/captive/bug-%FT%T.captivebug.xml.gz \
+               --syslog
 
 captive-fastfat: libcaptive-gnomevfs \
                --load-module=@localstatedir@/lib/captive/ntoskrnl.exe \
                 --filesystem=@localstatedir@/lib/captive/fastfat.sys --disk --rw \
                --sandbox-server=@sbindir@/captive-sandbox-server \
-               --bug-pathname=@localstatedir@/lib/captive/bug-%FT%T.captivebug.xml.gz
+               --bug-pathname=@localstatedir@/lib/captive/bug-%FT%T.captivebug.xml.gz \
+               --syslog
 
 captive-fastfat-ro: libcaptive-gnomevfs \
                --load-module=@localstatedir@/lib/captive/ntoskrnl.exe \
                 --filesystem=@localstatedir@/lib/captive/fastfat.sys --disk --ro \
                --sandbox-server=@sbindir@/captive-sandbox-server \
-               --bug-pathname=@localstatedir@/lib/captive/bug-%FT%T.captivebug.xml.gz
+               --bug-pathname=@localstatedir@/lib/captive/bug-%FT%T.captivebug.xml.gz \
+               --syslog
 
 captive-fastfat-blind: libcaptive-gnomevfs \
                --load-module=@localstatedir@/lib/captive/ntoskrnl.exe \
                 --filesystem=@localstatedir@/lib/captive/fastfat.sys --disk --blind \
                --sandbox-server=@sbindir@/captive-sandbox-server \
-               --bug-pathname=@localstatedir@/lib/captive/bug-%FT%T.captivebug.xml.gz
+               --bug-pathname=@localstatedir@/lib/captive/bug-%FT%T.captivebug.xml.gz \
+               --syslog
 
 captive-cdfs: libcaptive-gnomevfs \
                --load-module=@localstatedir@/lib/captive/ntoskrnl.exe \
                 --filesystem=@localstatedir@/lib/captive/cdfs.sys --cdrom --ro \
                --sandbox-server=@sbindir@/captive-sandbox-server \
-               --bug-pathname=@localstatedir@/lib/captive/bug-%FT%T.captivebug.xml.gz
+               --bug-pathname=@localstatedir@/lib/captive/bug-%FT%T.captivebug.xml.gz \
+               --syslog
 
 captive-ext2fsd: libcaptive-gnomevfs \
                --load-module=@localstatedir@/lib/captive/ntoskrnl.exe \
                 --filesystem=@localstatedir@/lib/captive/ext2fsd.sys --disk --rw \
                --sandbox-server=@sbindir@/captive-sandbox-server \
-               --bug-pathname=@localstatedir@/lib/captive/bug-%FT%T.captivebug.xml.gz
+               --bug-pathname=@localstatedir@/lib/captive/bug-%FT%T.captivebug.xml.gz \
+               --syslog
 
 captive-ext2fsd-ro: libcaptive-gnomevfs \
                --load-module=@localstatedir@/lib/captive/ntoskrnl.exe \
                 --filesystem=@localstatedir@/lib/captive/ext2fsd.sys --disk --ro \
                --sandbox-server=@sbindir@/captive-sandbox-server \
-               --bug-pathname=@localstatedir@/lib/captive/bug-%FT%T.captivebug.xml.gz
+               --bug-pathname=@localstatedir@/lib/captive/bug-%FT%T.captivebug.xml.gz \
+               --syslog
 
 captive-ext2fsd-blind: libcaptive-gnomevfs \
                --load-module=@localstatedir@/lib/captive/ntoskrnl.exe \
                 --filesystem=@localstatedir@/lib/captive/ext2fsd.sys --disk --blind \
                --sandbox-server=@sbindir@/captive-sandbox-server \
-               --bug-pathname=@localstatedir@/lib/captive/bug-%FT%T.captivebug.xml.gz
+               --bug-pathname=@localstatedir@/lib/captive/bug-%FT%T.captivebug.xml.gz \
+               --syslog
index 4850e0f..38751dc 100755 (executable)
@@ -61,6 +61,7 @@ $oo=""
                ."--load-module=$ntoskrnl,--filesystem=$filesystem,"
                ."--sandbox-server=$captive_sandbox_server_bin,"
                ."--bug-pathname=$vardir/bug-%FT%T.captivebug.xml.gz,"
+               ."--syslog,"
                ."mntent.mnt_fsname=$image,mntent.mnt_type=captive-$fsname,"    # Double-dashes forbidden.
                ."image=$image,"
                .$oo;
index d49eed3..e5649cc 100644 (file)
@@ -19,6 +19,7 @@
 
 #include "config.h"
 
+#include "init.h"      /* self */
 #include "captive/ldr.h"
 #include "captive/ldr_exports.h"
 #include "captive/unicode.h"
@@ -49,6 +50,7 @@
 #include <libgnomevfs/gnome-vfs-result.h>
 #include "lib.h"
 #include <reactos/ddk/obfuncs.h>
+#include <syslog.h>
 
 
 struct captive_options *captive_options;
@@ -212,11 +214,94 @@ NTSTATUS err;
 }
 
 
-static void    log_discard_func(const gchar *log_domain,GLogLevelFlags log_level,const gchar *message,gpointer user_data)
+static void    captive_log_init_g_log_func_discard
+               (const gchar *log_domain,GLogLevelFlags log_level,const gchar *message,gpointer user_data)
 {
+       g_return_if_fail(message!=NULL);
+
        /* NOP */
 }
 
+static void captive_log_init_g_log_func
+               (const gchar *log_domain,GLogLevelFlags log_level,const gchar *message,gpointer user_data /* unused */)
+{
+int priority;
+
+       g_return_if_fail(message!=NULL);
+
+               /* unused: LOG_EMERG */
+               /* unused: LOG_ALERT */
+       /**/ if (log_level&G_LOG_LEVEL_ERROR)
+               priority=LOG_CRIT;
+       else if (log_level&G_LOG_LEVEL_CRITICAL)
+               priority=LOG_ERR;
+       else if (log_level&G_LOG_LEVEL_WARNING)
+               priority=LOG_WARNING;
+       else if (log_level&G_LOG_LEVEL_MESSAGE)
+               priority=LOG_NOTICE;
+       else if (log_level&G_LOG_LEVEL_INFO)
+               priority=LOG_INFO;
+       else if (log_level&G_LOG_LEVEL_DEBUG)
+               priority=LOG_DEBUG;
+       else /* bogus? */
+               priority=LOG_WARNING;
+
+       syslog(priority,"%s%s%s",
+                       (!(log_level&G_LOG_FLAG_RECURSION) ? "" : "RECURSION: "),
+                       (!(log_level&G_LOG_FLAG_FATAL    ) ? "" : "FATAL: "),
+                       message);
+}
+
+void captive_log_init(const struct captive_options *captive_options)
+{
+       g_return_if_fail(captive_options!=NULL);
+
+       if (!captive_options->debug_messages) {
+               /* FIXME: Save handler_id and destroy it in captive_vfs_close(). */
+               g_log_set_handler(
+                               G_LOG_DOMAIN,   /* log_domain; "Captive" */
+                               0       /* log_levels */
+                                               | G_LOG_FLAG_RECURSION
+                                               | G_LOG_FLAG_FATAL
+                                               /* The same mask is in:
+                                                * libcaptive/sandbox/server-GLogFunc.c
+                                                * libcaptive/client/init.c
+                                                */
+                                               | G_LOG_LEVEL_MESSAGE
+                                               | G_LOG_LEVEL_INFO
+                                               | G_LOG_LEVEL_DEBUG,
+                               captive_log_init_g_log_func_discard,    /* log_func */
+                               NULL);  /* user_data */
+               }
+       /* We are not the sandboxed slave;
+        * 'syslog_facility' would be '-1' in slave anyway as it is not transferred through CORBA.
+        */
+       if (!captive_options->sandbox || (captive_options->sandbox_server_argv || captive_options->sandbox_server_ior)) {
+               if (captive_options->syslog_facility!=-1) {
+                       openlog(
+                                       /* FIXME: Prefix 'ident' by device/mountpoint. */
+                                       G_LOG_DOMAIN,   /* ident; "Captive"; FIXME: lowercase it for syslog(3)? */
+                                       LOG_CONS|LOG_PID,       /* options */
+                                       captive_options->syslog_facility);      /* facility */
+                       /* FIXME: Save handler_id and destroy it in captive_vfs_close(). */
+                       g_log_set_handler(
+                                       G_LOG_DOMAIN,   /* log_domain; "Captive" */
+                                       0       /* log_levels */
+                                                       | 0     /* !G_LOG_FLAG_RECURSION */
+                                                       | G_LOG_FLAG_FATAL
+                                                       | (G_LOG_LEVEL_MASK & ~(captive_options->debug_messages ? 0 : 0
+                                                                       /* The same mask is in:
+                                                                        * libcaptive/sandbox/server-GLogFunc.c
+                                                                        * libcaptive/client/init.c
+                                                                        */
+                                                                       | G_LOG_LEVEL_MESSAGE
+                                                                       | G_LOG_LEVEL_INFO
+                                                                       | G_LOG_LEVEL_DEBUG)),
+                                       (GLogFunc)captive_log_init_g_log_func,  /* log_func */
+                                       NULL);  /* user_data */
+                       }
+               }
+}
 
 /**
  * captive_init:
@@ -247,23 +332,7 @@ gboolean errbool;
        /* Initialize GObject subsystem of GLib. */
        g_type_init();
 
-       if (!captive_options->debug_messages) {
-               g_log_set_handler(
-                               G_LOG_DOMAIN,   /* log_domain; "Captive" */
-                               0       /* log_levels */
-                                               | G_LOG_FLAG_RECURSION
-                                               | G_LOG_FLAG_FATAL
-                                               /* The same mask is in:
-                                                * libcaptive/sandbox/server-GLogFunc.c
-                                                * libcaptive/client/init.c
-                                                * libcaptive/client/vfs.c
-                                                */
-                                               | G_LOG_LEVEL_MESSAGE
-                                               | G_LOG_LEVEL_INFO
-                                               | G_LOG_LEVEL_DEBUG,
-                               log_discard_func,       /* log_func */
-                               NULL);  /* user_data */
-               }
+       captive_log_init(captive_options);
 
        if (captive_options->rwmode==CAPTIVE_OPTION_RWMODE_BLIND)
                captive_image_iochannel=(GIOChannel *)captive_giochannel_blind_new(captive_options->image_iochannel,
index df0b188..197ccde 100644 (file)
 
 
 #include <glib/gtypes.h>
+#include "captive/options.h"
 
 
 G_BEGIN_DECLS
 
 gboolean captive_init(void);
 gboolean captive_shutdown(void);
+void captive_log_init(const struct captive_options *captive_options);
 
 G_END_DECLS
 
index da06bb0..0d92b91 100644 (file)
 #include "captive/macros.h"
 #include <glib/gstrfuncs.h>
 #include <stdlib.h>
+#include <syslog.h>
+
+
+/* Config: */
+#define DEFAULT_SYSLOG_FACILITY LOG_DAEMON
 
 
 void captive_options_init(struct captive_options *options)
@@ -37,6 +42,7 @@ void captive_options_init(struct captive_options *options)
        options->debug_messages=FALSE;
        options->load_module=NULL;
        options->sandbox=FALSE;
+       options->syslog_facility=-1;
 }
 
 
@@ -203,6 +209,104 @@ static void arg_bug_pathname(void)
        captive_options->bug_pathname=g_strdup(captive_popt_optarg);
 }
 
+/* Do not: #define SYSLOG_NAMES 1
+ * to enable <syslog.h>/facilitynames[] as such array is global (non-static)
+ * and it is likely it would conflict with facilitynames[] defined elsewhere
+ * (such as even conflicts by libcaptive.so).
+ */
+static const struct syslog_facility {
+       const gchar *name;
+       int value;
+       } syslog_facility[]={
+#ifdef LOG_AUTHPRIV
+               { "authpriv", LOG_AUTHPRIV },
+#endif
+#ifdef LOG_CRON
+               { "cron"    , LOG_CRON },
+#endif
+#ifdef LOG_DAEMON
+               { "daemon"  , LOG_DAEMON },
+#endif
+#ifdef LOG_FTP
+               { "ftp"     , LOG_FTP },
+#endif
+#ifdef LOG_KERN
+               { "kern"    , LOG_KERN },
+#endif
+#ifdef LOG_LPR
+               { "lpr"     , LOG_LPR },
+#endif
+#ifdef LOG_MAIL
+               { "mail"    , LOG_MAIL },
+#endif
+#ifdef LOG_NEWS
+               { "news"    , LOG_NEWS },
+#endif
+#ifdef LOG_SYSLOG
+               { "syslog"  , LOG_SYSLOG },
+#endif
+#ifdef LOG_USER
+               { "user"    , LOG_USER },
+#endif
+#ifdef LOG_UUCP
+               { "uucp"    , LOG_UUCP },
+#endif
+#ifdef LOG_LOCAL0
+               { "local0"  , LOG_LOCAL0 },
+#endif
+#ifdef LOG_LOCAL1
+               { "local1"  , LOG_LOCAL1 },
+#endif
+#ifdef LOG_LOCAL2
+               { "local2"  , LOG_LOCAL2 },
+#endif
+#ifdef LOG_LOCAL3
+               { "local3"  , LOG_LOCAL3 },
+#endif
+#ifdef LOG_LOCAL4
+               { "local4"  , LOG_LOCAL4 },
+#endif
+#ifdef LOG_LOCAL5
+               { "local5"  , LOG_LOCAL5 },
+#endif
+#ifdef LOG_LOCAL6
+               { "local6"  , LOG_LOCAL6 },
+#endif
+#ifdef LOG_LOCAL7
+               { "local7"  , LOG_LOCAL7 },
+#endif
+       };
+
+static void arg_syslog(void)
+{
+       captive_options->syslog_facility=DEFAULT_SYSLOG_FACILITY;
+}
+
+static int arg_syslog_facility_value;
+
+static void arg_syslog_facility(void)
+{
+const struct syslog_facility *facility;
+GString *gstring;
+gchar *gs;
+
+       for (facility=syslog_facility;facility<syslog_facility+G_N_ELEMENTS(syslog_facility);facility++)
+               if (!strcmp(captive_popt_optarg,facility->name)) {
+                       arg_syslog_facility_value=facility->value;
+                       return;
+                       }
+
+       gstring=g_string_new(captive_printf_alloca(_("Unknown '--syslog' facility '%s'; known:"),captive_popt_optarg));
+       for (facility=syslog_facility;facility<syslog_facility+G_N_ELEMENTS(syslog_facility);facility++) {
+               gstring=g_string_append_c(gstring,' ');
+               gstring=g_string_append(gstring,facility->name);
+               }
+       gs=g_string_free(gstring,
+                       FALSE); /* free_segment */
+       g_warning(gs);
+       g_free(gs);
+}
+
 
 static void captive_popt_callback
                (poptContext con,enum poptCallbackReason reason,const struct poptOption *opt,const char *arg,const void *data);
@@ -238,6 +342,11 @@ const struct poptOption captive_popt[]={
                CAPTIVE_POPT_STRING("sandbox-server-ior",N_("CORBA IOR of 'captive-sandbox-server', turns on sandboxing"),N_("IOR")),
                CAPTIVE_POPT_NONE(  "no-sandbox"        ,N_("Turn off sandboxing feature")),
                CAPTIVE_POPT_STRING("bug-pathname"      ,N_("Pathname to strftime(3) for .captivebug.xml.gz bugreports"),N_("pathname")),
+               /* Do not: POPT_ARGFLAG_OPTIONAL
+                * as it always eats one argument unless it is at end of argv[].
+                */
+               CAPTIVE_POPT_NONE(  "syslog"            ,N_("Messages sent to syslog(3) instead of stderr")),
+               CAPTIVE_POPT_STRING("syslog-facility"   ,N_("openlog(3) facility for --syslog"),N_("facility")),
 
 #undef CAPTIVE_POPT_NONE
 #undef CAPTIVE_POPT_STRING
@@ -265,6 +374,8 @@ static void (*const popt_func_table[])(void)={
                arg_sandbox_server_ior,
                arg_no_sandbox,
                arg_bug_pathname,
+               arg_syslog,
+               arg_syslog_facility,
                };
 
 
@@ -282,7 +393,7 @@ gint funci;
        if (popt_func_table[funci])
                (*popt_func_table[funci])();
        free(captive_popt_optarg);
-       captive_popt_optarg=NULL;       /* sanity, shouldn't be needed */
+       captive_popt_optarg=NULL;       /* sanity */
 }
 
 
@@ -300,6 +411,8 @@ gboolean r=FALSE;
        g_assert(captive_options==NULL);
        captive_options=options;
 
+       captive_popt_optarg=NULL;       /* sanity */
+       arg_syslog_facility_value=-1;
        errint=poptParseArgvString(captive_args,&captive_args_argc,&captive_args_argv);
        if (errint!=0) {
                g_assert_not_reached(); /* argument parsing args_error */
@@ -341,6 +454,9 @@ args_err:
                g_return_val_if_reached(r);
                }
 
+       if (captive_options->syslog_facility!=-1)
+               captive_options->syslog_facility=arg_syslog_facility_value;
+
        g_assert(captive_options!=NULL);
        captive_options=NULL;
 
index 360e9fa..e668f97 100644 (file)
@@ -32,6 +32,7 @@
 #include "captive/client-directory.h"
 #include "reactos/ntos/zw.h"   /* for NtQueryVolumeInformationFile() */
 #include "result.h"
+#include "init.h"
 
 
 static gpointer captive_vfs_object_parent_class=NULL;
@@ -91,11 +92,6 @@ static const GTypeInfo captive_vfs_object_info={
 }
 
 
-static void    log_discard_func(const gchar *log_domain,GLogLevelFlags log_level,const gchar *message,gpointer user_data)
-{
-       /* NOP */
-}
-
 GnomeVFSResult captive_vfs_new
                (CaptiveVfsObject **captive_vfs_object_return,const struct captive_options *options)
 {
@@ -106,23 +102,7 @@ gboolean errbool;
        g_return_val_if_fail(options!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
 
        /* Here is the first initializaton point of parent in sandboxed mode. */
-       if (!options->debug_messages) {
-               g_log_set_handler(
-                               G_LOG_DOMAIN,   /* log_domain; "Captive" */
-                               0       /* log_levels */
-                                               | G_LOG_FLAG_RECURSION
-                                               | G_LOG_FLAG_FATAL
-                                               /* The same mask is in:
-                                                * libcaptive/sandbox/server-GLogFunc.c
-                                                * libcaptive/client/init.c
-                                                * libcaptive/client/vfs.c
-                                                */
-                                               | G_LOG_LEVEL_MESSAGE
-                                               | G_LOG_LEVEL_INFO
-                                               | G_LOG_LEVEL_DEBUG,
-                               log_discard_func,       /* log_func */
-                               NULL);  /* user_data */
-               }
+       captive_log_init(options);
 
        *captive_vfs_object_return=NULL;
 
index f353b6f..02b4124 100644 (file)
@@ -60,6 +60,7 @@ struct captive_options {
        char **sandbox_server_argv;
        gchar *sandbox_server_ior;
        gchar *bug_pathname;
+       int syslog_facility;    /* LOG_*; -1 if not used */
        };
 
 /**
index b650a68..e03c219 100644 (file)
@@ -173,7 +173,6 @@ void impl_Captive_Vfs_init_g_log_func(const Captive_GLogFunc g_log_func,gboolean
                                                        /* The same mask is in:
                                                         * libcaptive/sandbox/server-GLogFunc.c
                                                         * libcaptive/client/init.c
-                                                        * libcaptive/client/vfs.c
                                                         */
                                                        | G_LOG_LEVEL_MESSAGE
                                                        | G_LOG_LEVEL_INFO