--- ./include/arch/unix/apr_arch_file_io.h.orig Tue Oct 16 20:16:38 2007 +++ ./include/arch/unix/apr_arch_file_io.h Wed Feb 4 08:23:47 2009 @@ -90,6 +90,17 @@ /* For backwards-compat */ #define APR_FILE_BUFSIZE APR_FILE_DEFAULT_BUFSIZE +#ifdef YAHOO +#include +typedef struct apr_rotating_info_t { + apr_finfo_t finfo; + apr_interval_time_t timeout; + apr_time_t lastcheck; + int oflags; + apr_fileperms_t perm; +} apr_rotating_info_t; +#endif + struct apr_file_t { apr_pool_t *pool; int filedes; @@ -115,6 +126,9 @@ #if APR_HAS_THREADS struct apr_thread_mutex_t *thlock; #endif +#ifdef YAHOO + apr_rotating_info_t *rotating; +#endif }; #if APR_HAS_THREADS --- ./include/apr_file_io.h.orig Mon Nov 5 19:15:01 2007 +++ ./include/apr_file_io.h Wed Feb 4 08:27:22 2009 @@ -77,9 +77,20 @@ #define APR_FOPEN_LARGEFILE 0x04000 /**< Platform dependent flag to enable * large file support, see WARNING below */ +#ifdef YAHOO +#define APR_FOPEN_ROTATING 0x08000 /**< Do file file rotation checking + * keeping binary compat we have to bump + * new values + */ + +#define APR_FOPEN_SPARSE 0x10000 /**< Platform dependent flag to enable + * sparse file support, see WARNING below + */ +#else /* YAHOO */ #define APR_FOPEN_SPARSE 0x08000 /**< Platform dependent flag to enable * sparse file support, see WARNING below */ +#endif /* YAHOO */ /* backcompat */ #define APR_READ APR_FOPEN_READ /**< @deprecated @see APR_FOPEN_READ */ @@ -915,6 +926,10 @@ /** @} */ +#ifdef YAHOO +APR_DECLARE(apr_status_t) apr_file_rotating_check(apr_file_t *thefile); +#endif /* YAHOO */ + #ifdef __cplusplus } #endif --- ./file_io/unix/open.c.orig Sun May 20 23:49:32 2007 +++ ./file_io/unix/open.c Wed Feb 4 08:23:47 2009 @@ -26,6 +26,11 @@ #include "fsio.h" #endif + +#ifdef YAHOO +#include +#endif /* YAHOO */ + static apr_status_t file_cleanup(apr_file_t *file, int is_child) { apr_status_t rv = APR_SUCCESS; @@ -216,6 +221,24 @@ apr_unix_file_cleanup, apr_unix_child_file_cleanup); } + +#ifdef YAHOO + if (flag & APR_FOPEN_ROTATING) { + (*new)->rotating = (apr_rotating_info_t *)apr_pcalloc(pool, sizeof(apr_rotating_info_t)); + + if (apr_file_info_get(&(*new)->rotating->finfo, APR_FINFO_DEV|APR_FINFO_INODE, *new) != APR_SUCCESS) { + return errno; + } + + (*new)->rotating->timeout = 60; + (*new)->rotating->lastcheck = apr_time_sec(apr_time_now()); + (*new)->rotating->oflags = oflags; + (*new)->rotating->perm = perm; + } + else { + (*new)->rotating = NULL; + } +#endif /* YAHOO */ return APR_SUCCESS; } --- ./file_io/unix/readwrite.c.orig Tue May 15 10:48:43 2007 +++ ./file_io/unix/readwrite.c Wed Feb 4 08:32:09 2009 @@ -19,6 +19,11 @@ #include "apr_thread_mutex.h" #include "apr_support.h" +#ifdef YAHOO +#include +#include +#endif /* YAHOO */ + /* The only case where we don't use wait_for_io_or_timeout is on * pre-BONE BeOS, so this check should be sufficient and simpler */ #if !BEOS_R5 @@ -144,10 +149,65 @@ } } +#ifdef YAHOO +APR_DECLARE(apr_status_t) apr_file_rotating_check(apr_file_t *thefile) +{ + apr_size_t rv = APR_SUCCESS; + + if (thefile->rotating) { + apr_time_t now = apr_time_sec(apr_time_now()); + + if ((now - thefile->rotating->lastcheck) >= thefile->rotating->timeout) { + apr_finfo_t new_finfo; + apr_pool_t *tmp_pool; + + apr_pool_create(&tmp_pool, thefile->pool); + + rv = APR_SUCCESS; + + if (apr_stat(&new_finfo, thefile->fname, APR_FINFO_DEV|APR_FINFO_INODE, tmp_pool) != APR_SUCCESS || + new_finfo.inode != thefile->rotating->finfo.inode || new_finfo.device != thefile->rotating->finfo.device) { + + if (thefile->buffered) { + apr_file_flush(thefile); + } + + close(thefile->filedes); + thefile->filedes = -1; + + if (thefile->rotating->perm == APR_OS_DEFAULT) { + thefile->filedes = open(thefile->fname, thefile->rotating->oflags, 0666); + } + else { + thefile->filedes = open(thefile->fname, thefile->rotating->oflags, apr_unix_perms2mode(thefile->rotating->perm)); + } + + if (thefile->filedes < 0 || + apr_file_info_get(&thefile->rotating->finfo, APR_FINFO_DEV|APR_FINFO_INODE, thefile) != APR_SUCCESS) { + rv = errno; + } + } + + apr_pool_destroy(tmp_pool); + + thefile->rotating->lastcheck = now; + } + } + + return rv; +} +#endif /* YAHOO */ + APR_DECLARE(apr_status_t) apr_file_write(apr_file_t *thefile, const void *buf, apr_size_t *nbytes) { apr_size_t rv; +#ifdef YAHOO + if ((rv = apr_file_rotating_check(thefile)) != APR_SUCCESS) { + return rv; + } +#endif /* YAHOO */ + if (thefile->buffered) { char *pos = (char *)buf; int blocksize; @@ -251,6 +311,15 @@ file_unlock(thefile); } + +#ifdef YAHOO +{ + apr_size_t rv; + if ((rv = apr_file_rotating_check(thefile)) != APR_SUCCESS) { + return rv; + } +} +#endif /* YAHOO */ if ((bytes = writev(thefile->filedes, vec, nvec)) < 0) { *nbytes = 0; --- ./file_io/unix/filedup.c.orig Sun May 20 23:49:32 2007 +++ ./file_io/unix/filedup.c Wed Feb 4 08:23:47 2009 @@ -95,6 +95,18 @@ /* make sure unget behavior is consistent */ (*new_file)->ungetchar = old_file->ungetchar; +#ifdef YAHOO + if (old_file->rotating != NULL) { + (*new_file)->rotating = (apr_rotating_info_t *)apr_pcalloc(p, sizeof(apr_rotating_info_t)); + + memcpy(&((*new_file)->rotating->finfo), &(old_file->rotating->finfo), sizeof(apr_finfo_t)); + + (*new_file)->rotating->timeout = old_file->rotating->timeout; + (*new_file)->rotating->lastcheck = old_file->rotating->lastcheck; + (*new_file)->rotating->oflags = old_file->rotating->oflags; + (*new_file)->rotating->perm = old_file->rotating->perm; + } +#endif /* YAHOO */ /* apr_file_dup2() retains the original cleanup, reflecting * the existing inherit and nocleanup flags. This means, * that apr_file_dup2() cannot be called against an apr_file_t