You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by James Godrej <ja...@yahoo.in> on 2011/03/21 22:56:27 UTC

[users@httpd] apache source code

I want to look at the apache source code those lines which are responsible for making it a daemon.Is the source available in html format online?
Which file should I browse?



---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] apache source code

Posted by Mark Montague <ma...@catseye.org>.
  On March 21, 2011 17:56 , James Godrej <ja...@yahoo.in>  wrote:
> I want to look at the apache source code those lines which are responsible for making it a daemon.Is the source available in html format online?
> Which file should I browse?

Why?  The reason you are asking actually can make a big difference.  As 
an example, if you are writing your own program and want to make it a 
daemon, you would be much better served by doing a web search for "unix 
create daemon".  The reason is that copying the code from Apache HTTP 
Server is likely to be frustrating, because the code that does this is 
highly specialized to the needs of Apache HTTP Server and is complicated 
by the need to support a large variety of platforms and environments.

As a different example, if you suspect you have a problem with how 
Apache HTTP Server is making itself a daemon on your system, please 
describe the problem, and include relevant details about your situation 
(output of "httpd -V", operating system and version, and, if you've 
compiled httpd yourself, your configure command line and the compiler 
name and version).

If you want to look at the source code for Apache HTTP Server, I 
recommend downloading the source code for the version you are running.   
This will allow you to search the code using your favorite tools.  You 
can get the source code from http://httpd.apache.org/download.cgi  Let 
us know if you can't find the version you are interested in.

To answer the first question you actually asked, you can view the source 
code via the web at http://svn.apache.org/viewvc/httpd/httpd/   However, 
the features of this web interface are aimed at developers and you may 
find them difficult to use unless you're familiar with source code 
control systems.

To answer the second question you actually asked, there is no one 
function in Apache HTTP Server that handles all of the "daemon-like" 
steps all in one place, since some parts of  and are intricately tied to 
child management.  However, most of the work of daemonizing is done in 
the function apr_proc_detach(), which is actually a part of the APR 
library, rather than a part of Apache HTTP Server itself.  A copy of APR 
is included in official releases of the Apache HTTP Server source code 
in the srclib subdirectory.  But if you are using source code for Apache 
HTTP Server that is not from an official release, then you can get the 
APR source code from http://apr.apache.org/

If you're reading the source code for the official release of Apache 
HTTP Server 2.2.17, then:

srclib/apr/threadproc/unix/procsup.c
- This is where the source code for the apr_proc_detach() function is.  
apr_proc_detach() does most of the work of daemonizing.

srclib/apr/threadproc/unix/proc.c
- apr_proc_create(), which is called by various MPMs, is defined here.

You may also want to look at the other files in the 
srclib/apr/threadproc/unix directory.

server/mpm/prefork/prefork.c (if you are using the prefork MPM)
- The prefork_pre_config() function handles a lot of the setup tasks, 
including calling apr_proc_detach()

server/mpm/worker/worker.c (if you are using the worker MPM)
- The worker_pre_config() function handles a lot of the setup tasks, 
including calling apr_proc_detach()

os/unix/unixd.c
- unixd_setup_child() is responsible for chroot, chdir, and changing user id
- also see the various unixd_set_* functions in this file


I hope this helps.

--
   Mark Montague
   mark@catseye.org


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org