Hello, Attached is an updated Debian patch for 1.4.7-2, from 2009, to avoid PATH_MAX problems for GNU/Hurd in rrd_graph.{c,h} and rrd_tool.c. This patch is conditioned on if MAXPATH (and __GLIBC__) is defined or not.
I would suggest to avoid PATH_MAX (MAXPATH) if possible to maximize portability and reduce code cluttering. Depending on your decision, the rest of my patches will be conditioned on PATH_MAX or not (there are also a number of other Debian patches pending). Thanks, Svante
diff --git a/src/rrd_graph.c b/src/rrd_graph.c index 4d91793..7ed51cf 100644 --- a/src/rrd_graph.c +++ b/src/rrd_graph.c @@ -4085,6 +4085,7 @@ rrd_info_t *rrd_graph_v( rrd_info_t *grinfo; char *old_locale; rrd_graph_init(&im); + size_t graphfile_len; /* a dummy surface so that we can measure text sizes for placements */ old_locale = setlocale(LC_NUMERIC, NULL); setlocale(LC_NUMERIC, "C"); @@ -4104,7 +4105,9 @@ rrd_info_t *rrd_graph_v( return NULL; } - if (strlen(argv[optind]) >= MAXPATH) { + graphfile_len = strlen(argv[optind]); +#ifdef MAXPATH + if (graphfile_len >= MAXPATH) { setlocale(LC_NUMERIC, old_locale); /* reenable locale */ rrd_set_error("filename (including path) too long"); rrd_info_free(im.grinfo); @@ -4115,6 +4118,17 @@ rrd_info_t *rrd_graph_v( strncpy(im.graphfile, argv[optind], MAXPATH - 1); im.graphfile[MAXPATH - 1] = '\0'; +#else + im.graphfile = malloc(graphfile_len + 1); + if (im.graphfile == NULL) { + rrd_set_error("cannot allocate sufficient memory for filename length"); + rrd_info_free(im.grinfo); + im_free(&im); + return NULL; + } + strncpy(im.graphfile, argv[optind], graphfile_len + 1); +#endif + if (strcmp(im.graphfile, "-") == 0) { im.graphfile[0] = '\0'; } diff --git a/src/rrd_graph.h b/src/rrd_graph.h index b97a742..60063e7 100644 --- a/src/rrd_graph.h +++ b/src/rrd_graph.h @@ -252,7 +252,11 @@ typedef struct graph_desc_t { typedef struct image_desc_t { /* configuration of graph */ +#ifdef MAXPATH char graphfile[MAXPATH]; /* filename for graphic */ +#else + char *graphfile; +#endif enum gfx_type_en graph_type; /* type of the graph */ long xsize, ysize; /* graph area size in pixels */ struct gfx_color_t graph_col[__GRC_END__]; /* real colors for the graph */ diff --git a/src/rrd_tool.c b/src/rrd_tool.c index ea585ab..3581001 100644 --- a/src/rrd_tool.c +++ b/src/rrd_tool.c @@ -573,7 +573,11 @@ int HandleInputLine( printf("ERROR: invalid parameter count for pwd\n"); return (1); } +#ifdef __GLIBC__ + cwd = get_current_dir_name(); +#else cwd = getcwd(NULL, MAXPATH); +#endif if (cwd == NULL) { printf("ERROR: getcwd %s\n", rrd_strerror(errno)); return (1);
_______________________________________________ rrd-developers mailing list rrd-developers@lists.oetiker.ch https://lists.oetiker.ch/cgi-bin/listinfo/rrd-developers