>Number:         1056
>Category:       general
>Synopsis:       USE_FLOCK_SERIALIZED_ACCEPT is no use.
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    apache (Apache HTTP Project)
>State:          open
>Class:          sw-bug
>Submitter-Id:   apache
>Arrival-Date:   Tue Aug 26 04:40:02 1997
>Originator:     [EMAIL PROTECTED]
>Organization:
apache
>Release:        1.2.1
>Environment:
FreeBSD 2.1.7.1-RELEASE, FreeBSD 2.2-STABLE
>Description:
If USE_FLOCK_SERIALIZED_ACCEPT is defined,
1. First, the parent will create a lock file and get the file descriptor
   associated with the file in accept_mutex_init().
2. Then, the children will intend to do flock() on the descriptor
   in accept_mutex_on() and accept_mutex_off().

The flock(lock_fd, LOCK_EX) will always success without blocking in the case.
I think it isn't the expected action.
However, it doesn't currently seem to cause any problem on FreeBSD.
>How-To-Repeat:
At the next of the line ``accept_mutex_on();'', insert
``log_printf(server_conf, "accept_mutex_on: %d", (int)getpid());''.
Then make, install and start the Apache on the FreeBSD system.
You'll see the multiple "accept_mutex_on: xxxx" in the error log
even if no client accesses the server.
>Fix:
I made a patch.
It seems to work fine on my system.
--------
--- http_main.c.original        Tue Aug 26 20:15:21 1997
+++ http_main.c Tue Aug 26 20:15:12 1997
@@ -271,7 +271,7 @@
        fprintf (stderr, "Cannot open lock file\n");
        exit (1);
     }
-    unlink(lock_fname);
+    pclosef(p, lock_fd);
 }
 
 void accept_mutex_on()
@@ -1228,6 +1228,9 @@
 void sig_term() {
     log_error("httpd: caught SIGTERM, shutting down", server_conf);
     cleanup_scoreboard();
+#if defined(USE_FLOCK_SERIALIZED_ACCEPT)
+    unlink(lock_fname);
+#endif
     ap_killpg (pgrp, SIGKILL);
     close(sd);
     exit(1);
@@ -1665,6 +1668,16 @@
     dupped_csd = -1;
     child_num = child_num_arg;
     requests_this_child = 0;
+    
+#if defined(USE_FLOCK_SERIALIZED_ACCEPT)
+    lock_fd = popenf(pconf, lock_fname, O_WRONLY, 0);
+    if (lock_fd == -1)
+    {
+       perror ("open");
+       fprintf (stderr, "Cannot open lock file\n");
+       exit (1);
+    }
+#endif
 
     reopen_scoreboard(pconf);
     (void)update_child_status(child_num, SERVER_READY, (request_rec*)NULL);
-------
>Audit-Trail:
>Unformatted:


Reply via email to