[email protected] wrote: > Author: breser > Date: Sat Oct 19 19:10:33 2013 > New Revision: 1533810 > > URL: http://svn.apache.org/r1533810 > Log: > Add an option to autocreate directories to rotatelogs. > > * support/rotatelogs.c > (rotate_config): Remove const from szLogRoot since we'll be passing it to > apr_filepath_merge. Add create_path member. > (usage, dumpConfig): Update to reflect new -d option. > (doRotate): Add code that knows how to create the directories a log file > is going to go into. > (main): Add the -d option and canonicalize the incoming path with > apr_filepath_merge() so that the code in doRotate can work properly. > > * docs/man/rotatelogs.8, > docs/manual/programs/rotatelogs.html.en: Update for -d option. > > PR: 46669 > Submitted by: Philippe Lantin <plantin cobaltgroup.com> > (which was actually a patch written by myself when I worked > there) > Tweaked by: breser (ported to trunk and changed option from -p to -d) > > > Modified: > httpd/httpd/trunk/docs/man/rotatelogs.8 > httpd/httpd/trunk/docs/manual/programs/rotatelogs.html.en > httpd/httpd/trunk/support/rotatelogs.c >
> Modified: httpd/httpd/trunk/support/rotatelogs.c > URL: > http://svn.apache.org/viewvc/httpd/httpd/trunk/support/rotatelogs.c?rev=1533810&r1=1533809&r2=1533810&view=diff > ============================================================================== > --- httpd/httpd/trunk/support/rotatelogs.c (original) > +++ httpd/httpd/trunk/support/rotatelogs.c Sat Oct 19 19:10:33 2013 > @@ -430,6 +433,23 @@ static void doRotate(rotate_config_t *co > } > } > apr_pool_create(&newlog.pool, status->pool); > + if (config->create_path) { > + char *ptr = strrchr(newlog.name, '/'); > + if (ptr && ptr > newlog.name) { > + char *path = apr_pstrmemdup(newlog.pool, newlog.name, ptr - > newlog.name); > + if (config->verbose) { > + fprintf(stderr, "Creating directory tree %s\n", path); > + } > + rv = apr_dir_make_recursive(path, APR_FPROT_OS_DEFAULT, > newlog.pool); > + if (rv != APR_SUCCESS) { > + char error[120]; > + > + apr_strerror(rv, error, sizeof error); > + fprintf(stderr, "Could not create directory '%s' (%s)\n", > path, error); Can't we use apr_psprintf with %pm instead of the constant length buffer char [120]? > + exit(2); > + } > + } > + } > if (config->verbose) { > fprintf(stderr, "Opening file %s\n", newlog.name); > } Regards Rüdiger
