[vlc-commits] log: refuse to run without a logger

Rémi Denis-Courmont git at videolan.org
Sun Nov 18 16:57:42 CET 2018


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Nov 18 16:50:30 2018 +0200| [ce233a82f60053fc8ff6d3321a169635700fd4ee] | committer: Rémi Denis-Courmont

log: refuse to run without a logger

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=ce233a82f60053fc8ff6d3321a169635700fd4ee
---

 src/libvlc.c        |  5 +++--
 src/libvlc.h        |  4 ++--
 src/misc/messages.c | 19 ++++---------------
 3 files changed, 9 insertions(+), 19 deletions(-)

diff --git a/src/libvlc.c b/src/libvlc.c
index 2c946af84e..93ce67a00d 100644
--- a/src/libvlc.c
+++ b/src/libvlc.c
@@ -166,11 +166,12 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
     char        *psz_val;
     int          i_ret = VLC_EGENERIC;
 
+    if (unlikely(vlc_LogPreinit(p_libvlc)))
+        return VLC_ENOMEM;
+
     /* System specific initialization code */
     system_Init();
 
-    vlc_LogPreinit(p_libvlc);
-
     /* Initialize the module bank and load the configuration of the
      * core module. We need to do this at this stage to be able to display
      * a short help if required by the user. (short help == core module
diff --git a/src/libvlc.h b/src/libvlc.h
index c8bd7394e3..7fc6934406 100644
--- a/src/libvlc.h
+++ b/src/libvlc.h
@@ -78,8 +78,8 @@ void vlc_mutex_unmark(const vlc_mutex_t *);
  */
 typedef struct vlc_logger_t vlc_logger_t;
 
-int vlc_LogPreinit(libvlc_int_t *);
-int vlc_LogInit(libvlc_int_t *);
+int vlc_LogPreinit(libvlc_int_t *) VLC_USED;
+void vlc_LogInit(libvlc_int_t *);
 void vlc_LogDeinit(libvlc_int_t *);
 
 /*
diff --git a/src/misc/messages.c b/src/misc/messages.c
index 65194f4217..722713a312 100644
--- a/src/misc/messages.c
+++ b/src/misc/messages.c
@@ -354,17 +354,16 @@ static void vlc_LogSwitch(libvlc_int_t *vlc,
 int vlc_LogPreinit(libvlc_int_t *vlc)
 {
     vlc_logger_t *logger = vlc_custom_create(vlc, sizeof (*logger), "logger");
-
-    libvlc_priv(vlc)->logger = logger;
-
     if (unlikely(logger == NULL))
         return -1;
 
+    libvlc_priv(vlc)->logger = logger;
     vlc_rwlock_init(&logger->lock);
+    logger->ops = &discard_ops;
 
     if (vlc_LogEarlyOpen(logger))
     {
-        logger->ops = &discard_ops;
+        vlc_LogDeinit(vlc);
         return -1;
     }
 
@@ -379,25 +378,19 @@ int vlc_LogPreinit(libvlc_int_t *vlc)
 /**
  * Initializes the messages logging subsystem and drain the early messages to
  * the configured log.
- *
- * \return 0 on success, -1 on error.
  */
-int vlc_LogInit(libvlc_int_t *vlc)
+void vlc_LogInit(libvlc_int_t *vlc)
 {
     vlc_logger_t *logger = libvlc_priv(vlc)->logger;
     const struct vlc_logger_operations *ops;
     void *opaque;
 
-    if (unlikely(logger == NULL))
-        return -1;
-
     /* TODO: module configuration item */
     if (vlc_module_load(logger, "logger", NULL, false,
                         vlc_logger_load, logger, &ops, &opaque) == NULL)
         ops = NULL;
 
     vlc_LogSwitch(vlc, ops, opaque);
-    return 0;
 }
 
 /**
@@ -421,13 +414,9 @@ void vlc_LogDeinit(libvlc_int_t *vlc)
 {
     vlc_logger_t *logger = libvlc_priv(vlc)->logger;
 
-    if (unlikely(logger == NULL))
-        return;
-
     if (logger->ops->destroy != NULL)
         logger->ops->destroy(logger->sys);
 
     vlc_rwlock_destroy(&logger->lock);
     vlc_object_release(logger);
-    libvlc_priv(vlc)->logger = NULL;
 }



More information about the vlc-commits mailing list