[rrd-developers] PATCH: rrd_graph / setlocale / librrd
Peter Stamfest
peter at stamfest.at
Thu Apr 24 09:26:34 MEST 2003
Hello,
I just stumbled across a possible problem in rrd_graph. That function uses
to call tzset and setlocale. When using librrd this is not desirable, as
this might override any settings done by the application linking
with librrd (language bindings come to mind). Besides, it is possibly not
thread-safe ;-) ).
Here is a patch to move these calls into the rrdtool binary and removing
them from librrd.
This adds a new requirement for software using librrd: tzset and setlocale
have to be called from the calling application.
The patch also includes an unrelated comment for the rrd_context.
peter
Index: rrd.h
===================================================================
RCS file: /usr/cvs/rrdtool/program/src/rrd.h,v
retrieving revision 1.4
diff -u -r1.4 rrd.h
--- rrd.h 1 Apr 2003 22:52:23 -0000 1.4
+++ rrd.h 24 Apr 2003 07:19:40 -0000
@@ -85,9 +85,13 @@
struct tm tm;
};
+/* A rrd_context is used to achieve thread-safety by encapsulating
+ thread-specific "global" data. */
struct rrd_context {
- int len;
- int errlen;
+ int len; /* The length of the buffer allocated
+ for lib_errstr */
+ int errlen; /* The length of the buffer allocated
+ for rrd_error */
char *lib_errstr;
char *rrd_error;
};
Index: rrd_graph.c
===================================================================
RCS file: /usr/cvs/rrdtool/program/src/rrd_graph.c,v
retrieving revision 1.58
diff -u -r1.58 rrd_graph.c
--- rrd_graph.c 1 Apr 2003 22:52:23 -0000 1.58
+++ rrd_graph.c 24 Apr 2003 07:19:46 -0000
@@ -18,10 +18,6 @@
#include <time.h>
#endif
-#ifdef HAVE_LOCALE_H
-#include <locale.h>
-#endif
-
#include "rrd_graph.h"
/* some constant definitions */
@@ -2636,13 +2632,6 @@
rrd_graph_init(image_desc_t *im)
{
unsigned int i;
-
-#ifdef HAVE_TZSET
- tzset();
-#endif
-#ifdef HAVE_SETLOCALE
- setlocale(LC_TIME,"");
-#endif
im->xlab_user.minsec = -1;
im->ximg=0;
Index: rrd_tool.c
===================================================================
RCS file: /usr/cvs/rrdtool/program/src/rrd_tool.c,v
retrieving revision 1.17
diff -u -r1.17 rrd_tool.c
--- rrd_tool.c 11 Apr 2003 19:43:44 -0000 1.17
+++ rrd_tool.c 24 Apr 2003 07:19:47 -0000
@@ -7,6 +7,10 @@
#include "rrd_tool.h"
#include "rrd_xport.h"
+#ifdef HAVE_LOCALE_H
+#include <locale.h>
+#endif
+
void PrintUsage(char *cmd);
int CountArgs(char *aLine);
int CreateArgs(char *, char *, int, char **);
@@ -313,6 +317,18 @@
fprintf(stderr,"ERROR: change root is not supported by your OS "
"or at least by this copy of rrdtool\n");
exit(1);
+#endif
+
+ /* tzset and setlocale are required for
+ rrd_graph. Originally this was done in rrd_graph itself,
+ but this might collide with software using librrd as
+ these function have global implications. Such software is
+ responsible for setting up timezone information. */
+#ifdef HAVE_TZSET
+ tzset();
+#endif
+#ifdef HAVE_SETLOCALE
+ setlocale(LC_TIME,"");
#endif
while (fgets(aLine, sizeof(aLine)-1, stdin)){
--
Unsubscribe mailto:rrd-developers-request at list.ee.ethz.ch?subject=unsubscribe
Help mailto:rrd-developers-request at list.ee.ethz.ch?subject=help
Archive http://www.ee.ethz.ch/~slist/rrd-developers
WebAdmin http://www.ee.ethz.ch/~slist/lsg2.cgi
More information about the rrd-developers
mailing list