httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Justin Erenkrantz <jerenkra...@apache.org>
Subject [PATCH] Clean up ap_read_pid
Date Sun, 26 May 2002 03:06:16 GMT
Since I can't start httpd on Darwin right now, I can't test this.
But, I believe that ap_read_pid() needs to be cleaned up in some
similiar fashion to the following patch - it also now calls
apr_file_read_full.  So, if someone would like to test this before
2.0.37 is tagged, that'd be nice.

The current version in CVS incorrectly thinks EOL is \n, so we have
to fix this before release since we'll be broken on a bunch of
platforms.  -- justin

Index: server/log.c
===================================================================
RCS file: /home/cvs/httpd-2.0/server/log.c,v
retrieving revision 1.121
diff -u -r1.121 log.c
--- server/log.c	23 May 2002 12:19:09 -0000	1.121
+++ server/log.c	26 May 2002 03:01:34 -0000
@@ -634,7 +634,7 @@
     apr_status_t rv;
     const char *fname;
     char *buf, *endptr;
-    apr_size_t bytes_wanted, bytes_read;
+    apr_size_t bytes_read;
 
     if (!filename) {
         return APR_EGENERAL;
@@ -652,24 +652,22 @@
         return rv;
     }
 
-    bytes_wanted = BUFFER_SIZE;
-    endptr = buf = apr_palloc(p, BUFFER_SIZE);
-    do {
-        bytes_read = bytes_wanted;
-        rv = apr_file_read(pid_file, endptr, &bytes_read);
-        if (rv != APR_SUCCESS && rv != APR_EOF) {
-            return rv;
-        }
-        bytes_wanted -= bytes_read;
-        endptr += bytes_read; 
+    /* Ensure null-termination, so that strtol doesn't go crazy. */
+    buf = apr_palloc(p, BUFFER_SIZE);
+    buf[BUFFER_SIZE - 1] = '\0';
+
+    rv = apr_file_read_full(pid_file, buf, BUFFER_SIZE - 1, &bytes_read);
+    if (rv != APR_SUCCESS && rv != APR_EOF) {
+        return rv;
     }
-    while (bytes_wanted > 0 && rv != APR_EOF);
 
-    *mypid = strtol(buf, &endptr, 10);
-    /* We only know for sure that the beginning part is the pid. */
-    if (*buf == '\0' || *endptr != '\n') {
+    /* If we fill the buffer, we're probably reading a corrupt pid file.
+     * To be nice, let's also ensure the first char is a digit. */
+    if (bytes_read == BUFFER_SIZE - 1 || !apr_isdigit(*buf)) {
         return APR_EGENERAL;
     }
+
+    *mypid = strtol(buf, &endptr, 10);
 
     apr_file_close(pid_file);
     return APR_SUCCESS;

Mime
View raw message