thread safe error reporting
authorMichal Voců <michal@ruk.cuni.cz>
Thu, 31 Jan 2013 16:31:22 +0000 (16:31 +0000)
committerFrantišek Dvořák <valtri@civ.zcu.cz>
Thu, 31 Jan 2013 20:43:00 +0000 (21:43 +0100)
org.glite.lb.logger/src/event_store.c
org.glite.lb.logger/src/il_error.c
org.glite.lb.logger/src/il_master.c
org.glite.lb.logger/src/logd.c
org.glite.lb.logger/src/queue_thread.c

index 13d1ac1..71fa84d 100644 (file)
@@ -34,6 +34,12 @@ limitations under the License.
 
 #include "interlogd.h"
 
+#if (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && ! _GNU_SOURCE
+#define il_strerror_r strerror_r
+#else
+#define il_strerror_r(a,b,c)  if(1) { char *p = strerror_r((a), (b), (c)); if(p && p != (b)) { int len = strlen(p); memset((b), 0, (c)); strncpy((b), p, len > (c) ? (c) : len); } }
+#endif
+
 #ifdef __GNUC__
 #define UNUSED_VAR __attribute__((unused))
 #else
@@ -601,9 +607,10 @@ event_store_recover(struct event_store *es)
   /* check the file modification time and size to avoid unnecessary operations */
   memset(&stbuf, 0, sizeof(stbuf));
   if(fstat(fd, &stbuf) < 0) {
+         il_strerror_r(errno, err_msg, sizeof(err_msg));
          glite_common_log(IL_LOG_CATEGORY, LOG_PRIORITY_ERROR, 
                           "    could not stat event file %s: %s", 
-                          es->event_file_name, strerror(errno));
+                          es->event_file_name, err_msg);
          fclose(ef);
          event_store_unlock(es);
          if(pthread_rwlock_unlock(&es->offset_lock))
@@ -1007,6 +1014,7 @@ event_store_clean(struct event_store *es)
   int fd;
   FILE *ef;
   struct flock efl;
+  char buf[256];
 
   assert(es != NULL);
 
@@ -1043,8 +1051,9 @@ event_store_clean(struct event_store *es)
     event_store_unlock(es);
     if(pthread_rwlock_unlock(&es->offset_lock))
            abort();
+    il_strerror_r(errno, buf, sizeof(buf));
     glite_common_log(IL_LOG_CATEGORY, LOG_PRIORITY_ERROR,  
-                    "  event_store_clean: error opening event file: %s", strerror(errno));
+                    "  event_store_clean: error opening event file: %s", buf);
     return(1);
   }
 
@@ -1378,6 +1387,8 @@ out:
 int
 event_store_init(char *prefix)
 {
+  char buf[256];
+
   if(file_prefix == NULL) {
     file_prefix = strdup(prefix);
     store_list = NULL;
@@ -1391,7 +1402,6 @@ event_store_init(char *prefix)
     DIR *event_dir;
     struct dirent *entry;
 
-
     /* get directory name */
     p = strrchr(file_prefix, '/');
     if(p == NULL) {
@@ -1496,10 +1506,11 @@ event_store_init(char *prefix)
                      strcat(ef, s);
                      glite_common_log(IL_LOG_CATEGORY, LOG_PRIORITY_DEBUG, 
                                       "  removing stale file %s", ef);
-                     if(unlink(ef))
+                     if(unlink(ef)) {
+                             il_strerror_r(errno, buf, sizeof(buf));
                              glite_common_log(IL_LOG_CATEGORY, LOG_PRIORITY_ERROR, 
-                                              "  could not remove file %s: %s\n", ef, strerror(errno));
-
+                                              "  could not remove file %s: %s\n", ef, buf);
+                     }
              }
              free(ef);
 
index 3b8a86c..65e4154 100644 (file)
@@ -33,6 +33,11 @@ extern void _start (void), etext (void);
 #include "glite/security/glite_gss.h"
 #include "il_error.h"
 
+#if (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && ! _GNU_SOURCE
+#define il_strerror_r strerror_r
+#else
+#define il_strerror_r(a,b,c)  if(1) { char *p = strerror_r((a), (b), (c)); if(p && p != (b)) { int len = strlen(p); memset((b), 0, (c)); strncpy((b), p, len > (c) ? (c) : len); } }
+#endif
 
 static pthread_key_t err_key;
 
@@ -104,6 +109,7 @@ int
 set_error(int code, long minor, char *msg)
 {
   struct error_inf *err;
+  char buf[256];
 
   err = error_get_err();
 
@@ -113,7 +119,9 @@ set_error(int code, long minor, char *msg)
   switch(code) {
 
   case IL_SYS:
-    snprintf(err->msg, IL_ERR_MSG_LEN, "%s: %s", msg, strerror(err->code_min));
+    *buf = 0;
+    il_strerror_r(err->code_min, buf, sizeof(buf)); 
+    snprintf(err->msg, IL_ERR_MSG_LEN, "%s: %s", msg, buf);
     break;
 
   case IL_HOST:
@@ -136,7 +144,9 @@ set_error(int code, long minor, char *msg)
       break;
 
     case EDG_WLL_GSS_ERROR_ERRNO:
-      snprintf(err->msg, IL_ERR_MSG_LEN, "%s: %s", msg, strerror(errno));
+      *buf = 0;
+      il_strerror_r(errno, buf, sizeof(buf)); 
+      snprintf(err->msg, IL_ERR_MSG_LEN, "%s: %s", msg, buf);
       break;
       
     case EDG_WLL_GSS_ERROR_HERRNO:
index d99d0c1..263b47d 100644 (file)
@@ -33,6 +33,12 @@ limitations under the License.
 #include "glite/lb/lb_perftest.h"
 #endif
 
+#if (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && ! _GNU_SOURCE
+#define il_strerror_r strerror_r
+#else
+#define il_strerror_r(a,b,c)  if(1) { char *p = strerror_r((a), (b), (c)); if(p && p != (b)) { int len = strlen(p); memset((b), 0, (c)); strncpy((b), p, len > (c) ? (c) : len); } }
+#endif
+
 int
 enqueue_msg(struct event_queue *eq, struct server_msg *msg)
 /* global: parallel */
@@ -230,9 +236,12 @@ handle_cmd(il_octet_string_t *event, long offset)
        while(num_replies < num_threads) {
                int ret;
                if((ret=pthread_cond_timedwait(&flush_cond, &flush_lock, &endtime)) < 0) {
+                       char buf[256];
+
+                       il_strerror_r(errno, buf, sizeof(buf));
                        glite_common_log(IL_LOG_CATEGORY, LOG_PRIORITY_ERROR, 
                                         "    error waiting for thread reply: %s", 
-                                        strerror(errno));
+                                        buf);
                        result = (ret == ETIMEDOUT) ? 0 : -1;
                        break;
                }
index bc7bf21..74c1283 100644 (file)
@@ -584,7 +584,7 @@ This is LocalLogger, part of Workload Management System in EU DataGrid & EGEE.\n
        edg_wll_GssCred newcred;
        case 0: break;
        case 1:
-               ret = edg_wll_gss_acquire_cred(cert_file,key_file,GSS_C_ACCEPT, &newcred,&gss_stat);
+               ret = edg_wll_gss_acquire_cred(cert_file,key_file, GSS_C_ACCEPT, &newcred,&gss_stat);
                if (ret) {
                        glite_common_log(LOG_CATEGORY_SECURITY,LOG_PRIORITY_WARN,"Reloading credentials failed, continue with older\n");
                } else {
index 51769aa..f6f0409 100644 (file)
@@ -23,9 +23,16 @@ limitations under the License.
 #include <signal.h>
 #include <unistd.h>
 #include <sys/param.h>
+#include <string.h>
 
 #include "interlogd.h"
 
+#if (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && ! _GNU_SOURCE
+#define il_strerror_r strerror_r
+#else
+#define il_strerror_r(a,b,c)  if(1) { char *p = strerror_r((a), (b), (c)); if(p && p != (b)) { int len = strlen(p); memset((b), 0, (c)); strncpy((b), p, len > (c) ? (c) : len); } }
+#endif
+
 static 
 void 
 queue_thread_cleanup(void *q)
@@ -70,21 +77,24 @@ void
 event_queue_write_stat(struct event_queue *eq) {
        FILE *statfile;
        char fn[MAXPATHLEN];
+       char buf[256];
 
        snprintf(fn, sizeof(fn), "%s.%s.stat", file_prefix, eq->dest_name);
        statfile = fopen(fn, "w");
        if(NULL == statfile) {
+               il_strerror_r(errno, buf, sizeof(buf));
                glite_common_log(IL_LOG_CATEGORY, LOG_PRIORITY_WARN,
                                 "Error opening destination stat file %s: %s", 
-                                fn, strerror(errno));
+                                fn, buf);
                return;
        }
        if(fprintf(statfile, "last_connected=%ld\nlast_sent=%ld\n",
                   eq->last_connected,
                   eq->last_sent) < 0) {
+               il_strerror_r(errno, buf, sizeof(buf));
                glite_common_log(IL_LOG_CATEGORY, LOG_PRIORITY_WARN,
                                 "Error writing destination statistics into %s: %s",
-                                fn, strerror(errno));
+                                fn, buf);
        }
        fclose(statfile);
 }