child init/ exit and the apr_cleanup_register

2011-11-22 Thread michaelr
Hello again,

maybe another stupid question but i could not found any
example in the modules dir of the httpd source.

Let's say i have an child_init_function which opens a 
filehandle. This filehandle should be open until the child
ends.

In mod_example.c they register an cleanup function to call a
function on child exit.

static apr_status_t child_exit ( void *data )
{
//close file handle...

return OK;
}

static void child_init ( apr_pool_t *p, server_rec *s )
{
//open file handle...

apr_pool_cleanup_register(p, s, NULL, child_exit) ;
}

I understand the cleanup as a function which runs on pool_cleanup.
This could happend on any time which i can't control - right?

When i return an HTTP_INTERNAL_SERVER_ERROR in my handler function
as an example the cleanup get's called also but the child is still
alive. The filehandle is closed and on the next request i run into
some kind of trouble.

Is there a way to define a 'real' exit function or can i force child
shutdown in above example? What's the right way to do it correctly?

Thanks a lot and greetings
 Michael
 





Re: child init/ exit and the apr_cleanup_register

2011-11-22 Thread michaelr
Hi Sorin,

thank's for your explanation. Eyerything work fine when i register the
cleanup in the way you suggested.

apr_pool_cleanup_register(p, NULL, child_exit, apr_pool_cleanup_null);

That saved my day.

Greetings 
 Michael



On Tue, 2011-11-22 at 10:02 +0100, Sorin Manolache wrote:
 On Tue, Nov 22, 2011 at 09:19, michaelr my...@freenet.de wrote:
  Hello again,
 
  maybe another stupid question but i could not found any
  example in the modules dir of the httpd source.
 
  Let's say i have an child_init_function which opens a
  filehandle. This filehandle should be open until the child
  ends.
 
  In mod_example.c they register an cleanup function to call a
  function on child exit.
 
  static apr_status_t child_exit ( void *data )
 {
 //close file handle...
 
 return OK;
 }
 
  static void child_init ( apr_pool_t *p, server_rec *s )
 {
 //open file handle...
 
 apr_pool_cleanup_register(p, s, NULL, child_exit) ;
 }
 
  I understand the cleanup as a function which runs on pool_cleanup.
  This could happend on any time which i can't control - right?
 
  When i return an HTTP_INTERNAL_SERVER_ERROR in my handler function
  as an example the cleanup get's called also but the child is still
  alive. The filehandle is closed and on the next request i run into
  some kind of trouble.
 
 
 The cleanup callback should not be called when you finish processing a
 request. It should be called only when the child exits.
 
 Register the cleanup function as follows:
 
 apr_pool_cleanup_register(p, NULL, child_exit, apr_pool_cleanup_null);
 
 The third argument (child_exit) is invoked when the pool is destroyed.
 The 4th (apr_pool_cleanup_null) is invoked when subpools of p are
 destroyed.
 
 You can pass the file handle in the second argument (where I've put
 NULL). Then it will show up as the data argument in child_exit.
 
 
 S
 
 
  Is there a way to define a 'real' exit function or can i force child
  shutdown in above example? What's the right way to do it correctly?
 
  Thanks a lot and greetings
   Michael
 
 
 
 
 




basic example shared memory code

2011-11-22 Thread Oğuzhan TOPGÜL
Hi guys, I'm trying to learn shared memory and mutex concepts and i need an
example shared memory apache module code that was written in c.
I found some codes, but none of them is working properly. I'm using ubuntu
10.10 as a development environment. Do you have any basic codes like shared
memory counter or etc.
If you can send me a working example, i'll be appreciated because i'm very
very confused and stuck about shared memory concepts. I just need a basic
example code snippet

thanks

Oğuzhan TOPGÜL


RE: Modules needing the approval of modules-dev@httpd.apache.org

2011-11-22 Thread Gavin McDonald


 -Original Message-
 From: MATSUMOTO Ryosuke [mailto:matsu1...@gmail.com]
 Sent: Tuesday, 22 November 2011 4:27 PM
 To: modules-dev@httpd.apache.org
 Subject: Modules needing the approval of modules-dev@httpd.apache.org
 
 Hi, all
 I submitted my module to apache module registry on 10 days ago, but
 response is nothing yet.The site is woking now?
 Submitted module name is mod_process_security.


Sorry for delay, can't seem to find it currently, give me another day or two
to
check things out.

Gav...

 
 https://github.com/matsumoto-r/release-code/tree/master/APACHE-
 MODULE/mod_process_security
 
 Modules needing the approval of modules-dev@httpd.apache.org
 mod_process_security - This module is a suEXEC module for CGI and DSO
 using thread. Improvement of mod_ruid2(vulnerability) and
 suEXEC(performance).
 regards,
 --
 MATSUMOTO Ryosuke  matsu1229 at gmail.com  http://blog.matsumoto-
 r.jp/



Re: basic example shared memory code

2011-11-22 Thread MATSUMOTO Ryosuke
mod_vlimit https://modules.apache.org/search.php?id=2570

This module count a number of simultaneous connections on shared memory.

2011/11/22 michaelr my...@freenet.de:
 On Tue, 2011-11-22 at 11:26 +0200, Oğuzhan TOPGÜL wrote:
 Hi guys, I'm trying to learn shared memory and mutex concepts and i need an
 example shared memory apache module code that was written in c.
 I found some codes, but none of them is working properly. I'm using ubuntu
 10.10 as a development environment. Do you have any basic codes like shared
 memory counter or etc.
 If you can send me a working example, i'll be appreciated because i'm very
 very confused and stuck about shared memory concepts. I just need a basic
 example code snippet


 The example module from: http://www.codemass.com/mod_shm_counter/
 helped me a lot understanding the basic concepts of the apr shared
 memory functions.







-- 
MATSUMOTO Ryosuke  matsu1229 at gmail.com 
http://blog.matsumoto-r.jp/


Re: basic example shared memory code

2011-11-22 Thread Nick Kew

On 22 Nov 2011, at 09:26, Oğuzhan TOPGÜL wrote:

 Hi guys, I'm trying to learn shared memory and mutex concepts and i need an
 example shared memory apache module code that was written in c.

If you're planning to write a module, bear in mind that apache now provides
easy-to-use higher-level abstractions for shared memory.  Older modules
had to work much harder to do the same thing, so looking at them may not
be your best approach.

-- 
Nick Kew

Re: basic example shared memory code

2011-11-22 Thread Nick Kew
On Tue, 22 Nov 2011 09:41:02 -0500
Pranesh Vadhirajan vadhira...@teralogics.com wrote:

 Nick, can you suggest some of these higher-level abstractions, please?  I 
 have been trying to make a module of mine work with a POSIX shared memory 
 implementation, but I'm going nowhere with that.  Are you referring to the 
 apache shared memory implementation (apr_shm_...) or something else?  Either 
 way, if you could suggest what I should look into, it would be greatly 
 appreciated.

apr_shm is the old way of doing it.

Today I'd recommend looking at mod_slotmem, and the socache modules.
I used the latter for mod_authn_socache, which is a simple example.

-- 
Nick Kew


Re: basic example shared memory code

2011-11-22 Thread Oğuzhan TOPGÜL
hey guys,
i'm in terrible with these shared memory.
I tried to write a basic module by looking at the examples that basic
module just holds a counter and prints it to the client.
when i compile the code attached, i got no error messages. But in apache
error.log file i got
lots of
[notice] child pid 32653 exit signal Segmentation fault (11)
and my module does not working.
if you have time to look at my code and send me your advices i'll be
appreciated. Because i'm getting crazy about these shared memory concepts.
I just want to define a global variable and process it in each request from
different sources.

Regards,
Oğuzhan TOPGÜL


On Tue, Nov 22, 2011 at 9:14 PM, Oğuzhan TOPGÜL oguzhantop...@gmail.comwrote:

 Thank you guys so much.
 What i want to do with shared memory is to hold the requester IPs and a
 counter that holds how many times an IP made request. I'm planning to hold
 them in a binary tree.
 I thought holding these IPs and counters in a file is slower than holding
 them in a shared memory because of the file I/O loss. And using binary tree
 as a data structure is going to make my search process faster and easier.
 Do you have any suggestions about shared memory-file usage or data
 structure usage.

 Regards
 Oğuzhan TOPGÜL



 On Tue, Nov 22, 2011 at 5:15 PM, Nick Kew n...@apache.org wrote:

 On Tue, 22 Nov 2011 09:41:02 -0500
 Pranesh Vadhirajan vadhira...@teralogics.com wrote:

  Nick, can you suggest some of these higher-level abstractions, please?
  I have been trying to make a module of mine work with a POSIX shared
 memory implementation, but I'm going nowhere with that.  Are you referring
 to the apache shared memory implementation (apr_shm_...) or something else?
  Either way, if you could suggest what I should look into, it would be
 greatly appreciated.

 apr_shm is the old way of doing it.

 Today I'd recommend looking at mod_slotmem, and the socache modules.
 I used the latter for mod_authn_socache, which is a simple example.

 --
 Nick Kew



#include stdio.h
#include stdlib.h
#include httpd.h
#include http_protocol.h
#include http_config.h
#include apr_shm.h
#include apr_global_mutex.h
#include util_mutex.h
#include http_log.h  //APLOG_MARK, APLOG_ERR 

#include apr.h
#include apr_strings.h
#include http_core.h
#include ap_config.h

apr_shm_t *mod_basic_shm;/* Pointer to shared memory block */ /* Shared memory structure */
apr_global_mutex_t *mod_basic_mutex; /* Lock around shared memory segment access */
static const char *mod_basic_mutex_type=mod-basic-mutex-shm;


typedef struct mod_basic_data{
int count;
}counter_data;


static apr_status_t shm_cleanup_wrapper(void *unused){
if(mod_basic_shm)
return apr_shm_destroy(mod_basic_shm);
return OK;
}


static int mod_basic_pre_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp){
ap_mutex_register(pconf, mod_basic_mutex_type, NULL, APR_LOCK_DEFAULT, 0);
return OK;
}


static int mod_basic_post_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s){
apr_status_t rs;
counter_data *counter;
  
//Create shared memory segment
rs = apr_shm_create(mod_basic_shm, sizeof(counter_data), NULL, pconf);
  
//counter equals to zero
counter=(counter_data*)apr_shm_baseaddr_get(mod_basic_shm);
counter-count=0;

//Create mutex
rs=ap_global_mutex_create(mod_basic_mutex, NULL, mod_basic_mutex_type, NULL, s, pconf, 0);

//Destroy the shm segment when the configuration pool gets destroyed
apr_pool_cleanup_register(pconf, NULL, shm_cleanup_wrapper, apr_pool_cleanup_null);
return OK;
}

static void mod_basic_child_init(apr_pool_t *p, server_rec *s){
apr_status_t rs;

//open mutex to init child
rs=apr_global_mutex_child_init(mod_basic_mutex, NULL, p);
exit(1);

}

static int basic_handler(request_rec *r)
{
   apr_status_t rs;
   counter_data *counter;
   
   if (strcmp(r-handler, basic)) {
return DECLINED;
}
   
   //lock the global variable before proceed it
   rs=apr_global_mutex_lock(mod_basic_mutex); 
  
   //lets increase the counter
   counter = (counter_data*)apr_shm_baseaddr_get(mod_basic_shm);
   counter-count++;
   ap_rprintf(r,%i,counter-count);
   
   // Unlock mutex after increase the counter
   rs=apr_global_mutex_unlock(mod_basic_mutex);

return OK;
}


static void basic_hooks(apr_pool_t *pool)
{
ap_hook_pre_config(mod_basic_pre_config, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_post_config(mod_basic_post_config, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_child_init(mod_basic_child_init, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_handler(basic_handler, NULL, NULL, APR_HOOK_MIDDLE);
}


module AP_MODULE_DECLARE_DATA basic_module = {
STANDARD20_MODULE_STUFF,
NULL,
NULL,
NULL,
NULL,
NULL,
basic_hooks
};



Re: Modules needing the approval of modules-dev@httpd.apache.org

2011-11-22 Thread MATSUMOTO Ryosuke
 Sorry for delay, can't seem to find it currently, give me another day or two 
 to check things out.

OK. If you can't find submitted module, I will submit it again.
regard,

2011/11/22 Gavin McDonald ga...@16degrees.com.au:


 -Original Message-
 From: MATSUMOTO Ryosuke [mailto:matsu1...@gmail.com]
 Sent: Tuesday, 22 November 2011 4:27 PM
 To: modules-dev@httpd.apache.org
 Subject: Modules needing the approval of modules-dev@httpd.apache.org

 Hi, all
 I submitted my module to apache module registry on 10 days ago, but
 response is nothing yet.The site is woking now?
 Submitted module name is mod_process_security.


 Sorry for delay, can't seem to find it currently, give me another day or two
 to
 check things out.

 Gav...


 https://github.com/matsumoto-r/release-code/tree/master/APACHE-
 MODULE/mod_process_security

 Modules needing the approval of modules-dev@httpd.apache.org
 mod_process_security - This module is a suEXEC module for CGI and DSO
 using thread. Improvement of mod_ruid2(vulnerability) and
 suEXEC(performance).
 regards,
 --
 MATSUMOTO Ryosuke  matsu1229 at gmail.com  http://blog.matsumoto-
 r.jp/





-- 
MATSUMOTO Ryosuke  matsu1229 at gmail.com 
http://blog.matsumoto-r.jp/