perl-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stas Bekman <s...@stason.org>
Subject [mp2 patch] $Apache::Server::(re)starting functionality
Date Tue, 30 Nov 2004 20:56:12 GMT
This patch returns the functionality we had in mp1:

use Apache::ServerUtil ();
my $cnt = Apache->server->start_cnt();
open my $fh, ">>/tmp/out" or die "$!";
print $fh "cnt: $cnt\n";
close $fh;

but I'm not sure at all if we want to keep those $Starting/$Restarting 
vars, based on previous discussions on httpd-dev those could be totally 
wrong since httpd.conf is reparsed too many times (including graceful and 
shutdown).

So i was thinking to just give a variable which will return the 
generation. So start_cnt() returns 1 when server starts, and 2 when it 
immediately restarts.

please post comments since I want to integrate it now. I need it at least 
for the tests.

Index: src/modules/perl/mod_perl.c
===================================================================
--- src/modules/perl/mod_perl.c	(revision 109224)
+++ src/modules/perl/mod_perl.c	(working copy)
@@ -280,8 +280,12 @@
              newSVpv(ap_server_root_relative(p, "lib/perl"), 0));
  #endif /* MP_COMPAT_1X */

+
+    /* things to be done only in the main server */
      if (!s->is_virtual) {
          modperl_handler_anon_init(aTHX_ p);
+
+        modperl_init_cnt_inc(s);
      }

      if (!modperl_config_apply_PerlRequire(s, scfg, perl, p)) {
Index: src/modules/perl/modperl_util.c
===================================================================
--- src/modules/perl/modperl_util.c	(revision 106739)
+++ src/modules/perl/modperl_util.c	(working copy)
@@ -797,3 +797,26 @@
      }

  }
+
+#define MP_INIT_KEY "mod_perl_init_cnt"
+
+void modperl_init_cnt_inc(server_rec *main_server)
+{
+    void *data;
+    int cnt = 1;
+    apr_pool_userdata_get(&data, MP_INIT_KEY, main_server->process->pool);
+    if (data) {
+        cnt = (int)data + 1;
+    }
+
+    apr_pool_userdata_set((const void *)cnt, MP_INIT_KEY,
+                          apr_pool_cleanup_null,
+                          main_server->process->pool);
+}
+
+int modperl_init_cnt(server_rec *main_server)
+{
+    void *data;
+    apr_pool_userdata_get(&data, MP_INIT_KEY, main_server->process->pool);
+    return data ? (int)data : 0;
+ }
Index: src/modules/perl/modperl_util.h
===================================================================
--- src/modules/perl/modperl_util.h	(revision 106739)
+++ src/modules/perl/modperl_util.h	(working copy)
@@ -139,4 +139,12 @@
          : (char *)apr_psprintf(p, "%s...",                               \
                                 apr_pstrmemdup(p, str, MP_TRACE_STR_LEN))

+/* functions maintaining the amount of times mod_perl was restarted,
+ * e.g. on Apache start, it restarts itself, so the count will be
+ * first 1, and on on restart 2 */
+void modperl_init_cnt_inc(server_rec *main_server);
+int  modperl_init_cnt(server_rec *main_server);
+
+
+
  #endif /* MODPERL_UTIL_H */
Index: xs/maps/apache_functions.map
===================================================================
--- xs/maps/apache_functions.map	(revision 106739)
+++ xs/maps/apache_functions.map	(working copy)
@@ -157,6 +157,7 @@
  -ap_scan_script_header_err_brigade

  MODULE=Apache::ServerUtil   PACKAGE=Apache::ServerRec BOOT=1
+ int:DEFINE_start_cnt | | server_rec *:s
  ~ap_method_register
   int:DEFINE_method_register | | server_rec *:s, const char *:methname
  ~add_version_component
Index: xs/Apache/ServerUtil/Apache__ServerUtil.h
===================================================================
--- xs/Apache/ServerUtil/Apache__ServerUtil.h	(revision 106739)
+++ xs/Apache/ServerUtil/Apache__ServerUtil.h	(working copy)
@@ -13,7 +13,9 @@
   * limitations under the License.
   */

-#define mpxs_Apache__ServerRec_method_register(s, methname)    \
+#define mpxs_Apache__ServerRec_start_cnt modperl_init_cnt
+
+#define mpxs_Apache__ServerRec_method_register(s, methname)     \
      ap_method_register(s->process->pconf, methname);

  #define mpxs_Apache__ServerRec_add_version_component(s, component)    \

-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Mime
View raw message