On Wed, Jul 02, 2008 at 09:32:45AM -0500, David Teigland wrote:
> > It doesn't address the setting of logsys_subsys_id but defines it.  I
> > want to avoid the situation where logsys_subsys_id is defined, but then
> > not set.  What I suggest here is to set logsys_subsys_id to some known
> > value (-1) and assert if that the subsystem id is that value within
> > log_printf to help developers catch this scenario.  At the moment the
> > current API enforces proper behavior (it wont link if the developer does
> > the wrong thing).  With your patch it will link, but may not behave
> > properly sending log messages to the wrong subsystem (0) instead of the
> > subsystem desired by the developer.  This is why the macros are there
> > (to set the subsystem id and define it).  Your patch addresses the
> > removal of the definition to a generic location but doesn't address at
> > all the setting of the subsystem id.
> 
> Good thought, done.

That turned out to break things badly :-)  Each file ends up with its own
static copy of logsys_subsys_id, all of which are initialized to -1, and
the only instance set to 0 is the one in the file that calls
logsys_init().  log_printf's in other files assert.

Attached patch should make it work again.

Dave

Index: logsys.c
===================================================================
--- logsys.c    (revision 1573)
+++ logsys.c    (working copy)
@@ -84,7 +84,9 @@
 #endif
 struct logsys_logger logsys_loggers[MAX_LOGGERS];
 
+int logsys_single_id = 0;
 
+
 struct log_entry {
        char *file;
        int line;
@@ -641,7 +643,8 @@
 {
        char *errstr;
 
-       logsys_subsys_id = 0;
+       /* logsys_subsys_id will be 0 */
+       logsys_single_id = 1;
 
        strncpy (logsys_loggers[0].subsys, name,
                 sizeof (logsys_loggers[0].subsys));
@@ -670,7 +673,6 @@
 
 void logsys_exit (void)
 {
-       logsys_subsys_id = -1;
        logsys_flush ();
 }
 
Index: logsys.h
===================================================================
--- logsys.h    (revision 1573)
+++ logsys.h    (working copy)
@@ -97,6 +97,8 @@
 
 extern struct logsys_logger logsys_loggers[];
 
+extern int logsys_single_id;
+
 extern inline int logsys_mkpri (int priority, int id);
 
 extern void logsys_config_mode_set (
@@ -191,6 +193,8 @@
 }
 
 #define log_printf(lvl, format, args...) do {                          \
+       if (logsys_single_id)                                           \
+               logsys_subsys_id = 0;                                   \
        assert (logsys_subsys_id != -1);                                \
        if ((lvl) <= logsys_loggers[logsys_subsys_id].priority) {       \
                _logsys_log_printf2 (__FILE__, __LINE__, lvl,           \
@@ -199,6 +203,8 @@
 } while(0)
 
 #define dprintf(format, args...) do {                                  \
+       if (logsys_single_id)                                           \
+               logsys_subsys_id = 0;                                   \
        assert (logsys_subsys_id != -1);                                \
        if (LOG_LEVEL_DEBUG <= logsys_loggers[logsys_subsys_id].priority) { \
                _logsys_log_printf2 (__FILE__, __LINE__, LOG_DEBUG,     \
@@ -207,6 +213,8 @@
 } while(0)
 
 #define ENTER_VOID() do {                                              \
+       if (logsys_single_id)                                           \
+               logsys_subsys_id = 0;                                   \
        assert (logsys_subsys_id != -1);                                \
        if (LOG_LEVEL_DEBUG <= logsys_loggers[logsys_subsys_id].priority) { \
                _logsys_trace (__FILE__, __LINE__, LOGSYS_TAG_ENTER,    \
@@ -215,6 +223,8 @@
 } while(0)
 
 #define ENTER(format, args...) do {                                    \
+       if (logsys_single_id)                                           \
+               logsys_subsys_id = 0;                                   \
        assert (logsys_subsys_id != -1);                                \
        if (LOG_LEVEL_DEBUG <= logsys_loggers[logsys_subsys_id].priority) { \
                _logsys_trace (__FILE__, __LINE__, LOGSYS_TAG_ENTER,    \
@@ -224,6 +234,8 @@
 } while(0)
 
 #define LEAVE_VOID() do {                                              \
+       if (logsys_single_id)                                           \
+               logsys_subsys_id = 0;                                   \
        assert (logsys_subsys_id != -1);                                \
        if (LOG_LEVEL_DEBUG <= logsys_loggers[logsys_subsys_id].priority) { \
                _logsys_trace (__FILE__, __LINE__, LOGSYS_TAG_LEAVE,    \
@@ -232,6 +244,8 @@
 } while(0)
 
 #define LEAVE(format, args...) do {                                    \
+       if (logsys_single_id)                                           \
+               logsys_subsys_id = 0;                                   \
        assert (logsys_subsys_id != -1);                                \
        if (LOG_LEVEL_DEBUG <= logsys_loggers[logsys_subsys_id].priority) { \
                _logsys_trace (__FILE__, __LINE__, LOGSYS_TAG_LEAVE,    \
@@ -241,6 +255,8 @@
 } while(0)
 
 #define TRACE1(format, args...) do {                                   \
+       if (logsys_single_id)                                           \
+               logsys_subsys_id = 0;                                   \
        assert (logsys_subsys_id != -1);                                \
        if (LOG_LEVEL_DEBUG <= logsys_loggers[logsys_subsys_id].priority) { \
                _logsys_trace (__FILE__, __LINE__, LOGSYS_TAG_TRACE1,   \
@@ -249,6 +265,8 @@
 } while(0)
 
 #define TRACE2(format, args...) do {                                   \
+       if (logsys_single_id)                                           \
+               logsys_subsys_id = 0;                                   \
        assert (logsys_subsys_id != -1);                                \
        if (LOG_LEVEL_DEBUG <= logsys_loggers[logsys_subsys_id].priority) { \
                _logsys_trace (__FILE__, __LINE__, LOGSYS_TAG_TRACE2,   \
@@ -257,6 +275,8 @@
 } while(0)
 
 #define TRACE3(format, args...) do { \
+       if (logsys_single_id)                                           \
+               logsys_subsys_id = 0;                                   \
        assert (logsys_subsys_id != -1);                                \
        if (LOG_LEVEL_DEBUG <= logsys_loggers[logsys_subsys_id].priority) { \
                _logsys_trace (__FILE__, __LINE__, LOGSYS_TAG_TRACE3,   \
@@ -265,6 +285,8 @@
 } while(0)
 
 #define TRACE4(format, args...) do { \
+       if (logsys_single_id)                                           \
+               logsys_subsys_id = 0;                                   \
        assert (logsys_subsys_id != -1);                                \
        if (LOG_LEVEL_DEBUG <= logsys_loggers[logsys_subsys_id].priority) { \
                _logsys_trace (__FILE__, __LINE__, LOGSYS_TAG_TRACE4,   \
@@ -273,6 +295,8 @@
 } while(0)
 
 #define TRACE5(format, args...) do {                                   \
+       if (logsys_single_id)                                           \
+               logsys_subsys_id = 0;                                   \
        assert (logsys_subsys_id != -1);                                \
        if (LOG_LEVEL_DEBUG <= logsys_loggers[logsys_subsys_id].priority) { \
                _logsys_trace (__FILE__, __LINE__, LOGSYS_TAG_TRACE5,   \
@@ -281,6 +305,8 @@
 } while(0)
 
 #define TRACE6(format, args...) do {                                   \
+       if (logsys_single_id)                                           \
+               logsys_subsys_id = 0;                                   \
        assert (logsys_subsys_id != -1);                                \
        if (LOG_LEVEL_DEBUG <= logsys_loggers[logsys_subsys_id].priority) { \
                _logsys_trace (__FILE__, __LINE__, LOGSYS_TAG_TRACE6,   \
@@ -289,6 +315,8 @@
 } while(0)
 
 #define TRACE7(format, args...) do {                                   \
+       if (logsys_single_id)                                           \
+               logsys_subsys_id = 0;                                   \
        assert (logsys_subsys_id != -1);                                \
        if (LOG_LEVEL_DEBUG <= logsys_loggers[logsys_subsys_id].priority) { \
                _logsys_trace (__FILE__, __LINE__, LOGSYS_TAG_TRACE7,   \
@@ -297,6 +325,8 @@
 } while(0)
 
 #define TRACE8(format, args...) do {                                   \
+       if (logsys_single_id)                                           \
+               logsys_subsys_id = 0;                                   \
        assert (logsys_subsys_id != -1);                                \
        if (LOG_LEVEL_DEBUG <= logsys_loggers[logsys_subsys_id].priority) { \
        _logsys_trace (__FILE__, __LINE__, LOGSYS_TAG_TRACE8,           \
_______________________________________________
Openais mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/openais

Reply via email to