@@ -81,12 +81,11 @@ APLOG_USE_MODULE(tile);
8181
8282apr_shm_t * stats_shm ;
8383apr_shm_t * delaypool_shm ;
84- char * shmfilename ;
85- char * shmfilename_delaypool ;
8684apr_global_mutex_t * stats_mutex ;
87- apr_global_mutex_t * delay_mutex ;
85+ apr_global_mutex_t * delaypool_mutex ;
8886
89- char * mutexfilename ;
87+ char * stats_mutexfilename ;
88+ char * delaypool_mutexfilename ;
9089int layerCount = 0 ;
9190int global_max_zoom = 0 ;
9291
@@ -818,7 +817,7 @@ static int delay_allowed(request_rec *r, enum tileState state)
818817 return 1 ;
819818 }
820819
821- if (get_global_lock (r , delay_mutex ) == 0 ) {
820+ if (get_global_lock (r , delaypool_mutex ) == 0 ) {
822821 ap_log_rerror (APLOG_MARK , APLOG_INFO , 0 , r , "Could not acquire lock, skipping delay pool accounting\n" );
823822 return 1 ;
824823 };
@@ -847,11 +846,11 @@ static int delay_allowed(request_rec *r, enum tileState state)
847846 if (delay > 0 ) {
848847 /* If we are on the second round, we really hit an empty delaypool, timeout for a while to slow down clients */
849848 if (j > 0 ) {
850- apr_global_mutex_unlock (delay_mutex );
849+ apr_global_mutex_unlock (delaypool_mutex );
851850 ap_log_rerror (APLOG_MARK , APLOG_INFO , 0 , r , "Delaypool: Client %s has hit its limits, throttling (%i)\n" , ip_addr , delay );
852851 sleep (CLIENT_PENALTY );
853852
854- if (get_global_lock (r , delay_mutex ) == 0 ) {
853+ if (get_global_lock (r , delaypool_mutex ) == 0 ) {
855854 ap_log_rerror (APLOG_MARK , APLOG_INFO , 0 , r , "Could not acquire lock, but had to delay\n" );
856855 return 0 ;
857856 };
@@ -897,7 +896,7 @@ static int delay_allowed(request_rec *r, enum tileState state)
897896 delay = 0 ;
898897 }
899898
900- apr_global_mutex_unlock (delay_mutex );
899+ apr_global_mutex_unlock (delaypool_mutex );
901900
902901 if (delay > 0 ) {
903902 ap_log_rerror (APLOG_MARK , APLOG_INFO , 0 , r , "Delaypool: Client %s has hit its limits, rejecting (%i)\n" , ip_addr , delay );
@@ -1673,37 +1672,25 @@ static int mod_tile_post_config(apr_pool_t *pconf, apr_pool_t *plog,
16731672 return OK ;
16741673 } /* Kilroy was here */
16751674
1676- /* Create the shared memory segment */
1677-
1678- /*
1679- * Create a unique filename using our pid. This information is
1680- * stashed in the global variable so the children inherit it.
1681- * TODO get the location from the environment $TMPDIR or somesuch.
1682- */
1683- shmfilename = apr_psprintf (pconf , "/tmp/httpd_shm.%ld" , (long int )getpid ());
1684- shmfilename_delaypool = apr_psprintf (pconf , "/tmp/httpd_shm_delay.%ld" , (long int )getpid ());
1685-
1686- /* Now create that segment
1675+ /* Create the shared memory segment
16871676 * would prefer to use scfg->configs->nelts here but that does
16881677 * not seem to be set at this stage, so rely on previously set layerCount */
16891678
16901679 rs = apr_shm_create (& stats_shm , sizeof (stats_data ) + layerCount * 2 * sizeof (apr_uint64_t ),
1691- ( const char * ) shmfilename , pconf );
1680+ NULL , pconf );
16921681
16931682 if (rs != APR_SUCCESS ) {
16941683 ap_log_error (APLOG_MARK , APLOG_ERR , rs , s ,
1695- "Failed to create shared memory segment on file %s" ,
1696- shmfilename );
1684+ "Failed to create 'stats' shared memory segment" );
16971685 return HTTP_INTERNAL_SERVER_ERROR ;
16981686 }
16991687
17001688 rs = apr_shm_create (& delaypool_shm , sizeof (delaypool ),
1701- ( const char * ) shmfilename_delaypool , pconf );
1689+ NULL , pconf );
17021690
17031691 if (rs != APR_SUCCESS ) {
17041692 ap_log_error (APLOG_MARK , APLOG_ERR , rs , s ,
1705- "Failed to create shared memory segment on file %s" ,
1706- shmfilename_delaypool );
1693+ "Failed to create 'delaypool' shared memory segment" );
17071694 return HTTP_INTERNAL_SERVER_ERROR ;
17081695 }
17091696
@@ -1770,16 +1757,15 @@ static int mod_tile_post_config(apr_pool_t *pconf, apr_pool_t *plog,
17701757 * depending on OS and locking mechanism of choice, the file
17711758 * may or may not be actually created.
17721759 */
1773- mutexfilename = apr_psprintf (pconf , "/tmp/httpd_mutex.%ld" ,
1774- (long int )getpid ());
1760+ stats_mutexfilename = apr_psprintf (pconf , "%s/httpd_mutex_stats.%ld" , P_tmpdir , (long int )getpid ());
17751761
1776- rs = apr_global_mutex_create (& stats_mutex , (const char * )mutexfilename ,
1762+ rs = apr_global_mutex_create (& stats_mutex , (const char * )stats_mutexfilename ,
17771763 APR_LOCK_DEFAULT , pconf );
17781764
17791765 if (rs != APR_SUCCESS ) {
17801766 ap_log_error (APLOG_MARK , APLOG_ERR , rs , s ,
17811767 "Failed to create mutex on file %s" ,
1782- mutexfilename );
1768+ stats_mutexfilename );
17831769 return HTTP_INTERNAL_SERVER_ERROR ;
17841770 }
17851771
@@ -1800,21 +1786,20 @@ static int mod_tile_post_config(apr_pool_t *pconf, apr_pool_t *plog,
18001786 * depending on OS and locking mechanism of choice, the file
18011787 * may or may not be actually created.
18021788 */
1803- mutexfilename = apr_psprintf (pconf , "/tmp/httpd_mutex_delay.%ld" ,
1804- (long int )getpid ());
1789+ delaypool_mutexfilename = apr_psprintf (pconf , "%s/httpd_mutex_delaypool.%ld" , P_tmpdir , (long int )getpid ());
18051790
1806- rs = apr_global_mutex_create (& delay_mutex , (const char * )mutexfilename ,
1791+ rs = apr_global_mutex_create (& delaypool_mutex , (const char * )delaypool_mutexfilename ,
18071792 APR_LOCK_DEFAULT , pconf );
18081793
18091794 if (rs != APR_SUCCESS ) {
18101795 ap_log_error (APLOG_MARK , APLOG_ERR , rs , s ,
18111796 "Failed to create mutex on file %s" ,
1812- mutexfilename );
1797+ delaypool_mutexfilename );
18131798 return HTTP_INTERNAL_SERVER_ERROR ;
18141799 }
18151800
18161801#ifdef MOD_TILE_SET_MUTEX_PERMS
1817- rs = ap_unixd_set_global_mutex_perms (delay_mutex );
1802+ rs = ap_unixd_set_global_mutex_perms (delaypool_mutex );
18181803
18191804 if (rs != APR_SUCCESS ) {
18201805 ap_log_error (APLOG_MARK , APLOG_CRIT , rs , s ,
@@ -1846,13 +1831,13 @@ static void mod_tile_child_init(apr_pool_t *p, server_rec *s)
18461831 * the mutex pointer global here.
18471832 */
18481833 rs = apr_global_mutex_child_init (& stats_mutex ,
1849- (const char * )mutexfilename ,
1834+ (const char * )stats_mutexfilename ,
18501835 p );
18511836
18521837 if (rs != APR_SUCCESS ) {
18531838 ap_log_error (APLOG_MARK , APLOG_CRIT , rs , s ,
18541839 "Failed to reopen mutex on file %s" ,
1855- shmfilename );
1840+ stats_mutexfilename );
18561841 /* There's really nothing else we can do here, since
18571842 * This routine doesn't return a status. */
18581843 exit (1 ); /* Ugly, but what else? */
0 commit comments