]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
Put the uds path in its own field, and adjust the logic
authorJim Jagielski <jim@apache.org>
Thu, 17 Oct 2013 14:10:43 +0000 (14:10 +0000)
committerJim Jagielski <jim@apache.org>
Thu, 17 Oct 2013 14:10:43 +0000 (14:10 +0000)
to look for an empty string rather than a flag.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1533087 13f79535-47bb-0310-9956-ffa450edef68

modules/proxy/mod_proxy.h
modules/proxy/mod_proxy_balancer.c
modules/proxy/proxy_util.c

index b64f78ba4b5296d6a295cb759001ad9ae42d3c0d..46e2380fbcea898f635244b1dbb5097db96fd7f9 100644 (file)
@@ -342,6 +342,7 @@ typedef struct {
     char      route[PROXY_WORKER_MAX_ROUTE_SIZE];     /* balancing route */
     char      redirect[PROXY_WORKER_MAX_ROUTE_SIZE];  /* temporary balancing redirection route */
     char      flusher[PROXY_WORKER_MAX_SCHEME_SIZE];  /* flush provider used by mod_proxy_fdpass */
+    char      uds_path[PROXY_WORKER_MAX_NAME_SIZE];   /* path to worker's unix domain socket if applicable */
     int             lbset;      /* load balancer cluster set */
     int             retries;    /* number of retries on this worker */
     int             lbstatus;   /* Current lbstatus */
@@ -388,7 +389,6 @@ typedef struct {
     unsigned int     keepalive_set:1;
     unsigned int     disablereuse_set:1;
     unsigned int     was_malloced:1;
-    unsigned int     uds:1;
 } proxy_worker_shared;
 
 #define ALIGNED_PROXY_WORKER_SHARED_SIZE (APR_ALIGN_DEFAULT(sizeof(proxy_worker_shared)))
index 4f68d24a23b4982a90dd66b89f9d95a9cb63117a..c927d3bf6e5f0529212ea6fa6c5d8b867e2a02b2 100644 (file)
@@ -1533,8 +1533,8 @@ static int balancer_handler(request_rec *r)
                           ap_escape_uri(r->pool, worker->s->name),
                           "&nonce=", balancer->s->nonce,
                           "\">", NULL);
-                ap_rvputs(r, (worker->s->uds ? "<i>" : ""), ap_proxy_worker_name(r->pool, worker),
-                          (worker->s->uds ? "</i>" : ""), "</a></td>", NULL);
+                ap_rvputs(r, (*worker->s->uds_path ? "<i>" : ""), ap_proxy_worker_name(r->pool, worker),
+                          (*worker->s->uds_path ? "</i>" : ""), "</a></td>", NULL);
                 ap_rvputs(r, "<td>", ap_escape_html(r->pool, worker->s->route),
                           NULL);
                 ap_rvputs(r, "</td><td>",
@@ -1559,7 +1559,7 @@ static int balancer_handler(request_rec *r)
         ap_rputs("<hr />\n", r);
         if (wsel && bsel) {
             ap_rputs("<h3>Edit worker settings for ", r);
-            ap_rvputs(r, (wsel->s->uds?"<i>":""), ap_proxy_worker_name(r->pool, wsel), (wsel->s->uds?"</i>":""), "</h3>\n", NULL);
+            ap_rvputs(r, (*wsel->s->uds_path?"<i>":""), ap_proxy_worker_name(r->pool, wsel), (*wsel->s->uds_path?"</i>":""), "</h3>\n", NULL);
             ap_rputs("<form method=\"POST\" enctype=\"application/x-www-form-urlencoded\" action=\"", r);
             ap_rvputs(r, ap_escape_uri(r->pool, action), "\">\n", NULL);
             ap_rputs("<dl>\n<table><tr><td>Load factor:</td><td><input name='w_lf' id='w_lf' type=text ", r);
index 3faf2ff4794efd0254df1109a29118df3956d2d4..bbd77490ae96954d4d87f71a46585a87e9f67941 100644 (file)
@@ -1493,7 +1493,7 @@ PROXY_DECLARE(char *) ap_proxy_worker_name(apr_pool_t *p,
     int rv;
     apr_uri_t uri;
     apr_pool_t *pool = p;
-    if (!worker->s->uds) {
+    if (!(*worker->s->uds_path)) {
         return worker->s->name;
     }
     if (!pool) {
@@ -1504,11 +1504,7 @@ PROXY_DECLARE(char *) ap_proxy_worker_name(apr_pool_t *p,
             return worker->s->name;
         }
     }
-    rv = apr_uri_parse(pool, worker->s->name, &uri);
-    if (rv != APR_SUCCESS) {
-        return apr_pstrcat(pool, worker->s->name, "|", NULL);
-    }
-    return apr_pstrcat(pool, "unix:", uri.path, "|", uri.scheme, ":", NULL);
+    return apr_pstrcat(pool, "unix:", worker->s->uds_path, "|", worker->s->name, NULL);
 }
 
 PROXY_DECLARE(proxy_worker *) ap_proxy_get_worker(apr_pool_t *p,
@@ -1609,16 +1605,17 @@ PROXY_DECLARE(char *) ap_proxy_define_worker(apr_pool_t *p,
     proxy_worker_shared *wshared;
     char *ptr, *sockpath = NULL;
 
-    /* Look to see if we are using UDS:
-       require format: unix:/path/foo/bar.sock|http:
-       This results in talking http to the socket at /path/foo/bar.sock
-    */
+    /*
+     * Look to see if we are using UDS:
+     * require format: unix:/path/foo/bar.sock|http://ignored/path2/
+     * This results in talking http to the socket at /path/foo/bar.sock
+     */
     ptr = ap_strchr((char *)url, '|');
     if (ptr) {
         *ptr = '\0';
         rv = apr_uri_parse(p, url, &urisock);
         if (rv == APR_SUCCESS && !strcasecmp(urisock.scheme, "unix")) {
-            sockpath = urisock.path;
+            sockpath = ap_runtime_dir_relative(p, urisock.path);;
             url = ptr+1;    /* so we get the scheme for the uds */
         }
         else {
@@ -1633,16 +1630,13 @@ PROXY_DECLARE(char *) ap_proxy_define_worker(apr_pool_t *p,
     if (!uri.scheme) {
         return apr_pstrcat(p, "URL must be absolute!: ", url, NULL);
     }
-    /* allow for http:|sock:/path */
+    /* allow for unix:/path|http: */
     if (!uri.hostname && !sockpath) {
         return apr_pstrcat(p, "URL must be absolute!: ", url, NULL);;
     }
 
     if (sockpath) {
         uri.hostname = "localhost";
-        uri.path = ap_runtime_dir_relative(p, sockpath);
-        uri.query = NULL;
-        uri.fragment = NULL;
     }
     else {
         ap_str_tolower(uri.hostname);
@@ -1702,7 +1696,15 @@ PROXY_DECLARE(char *) ap_proxy_define_worker(apr_pool_t *p,
     wshared->hash.def = ap_proxy_hashfunc(wshared->name, PROXY_HASHFUNC_DEFAULT);
     wshared->hash.fnv = ap_proxy_hashfunc(wshared->name, PROXY_HASHFUNC_FNV);
     wshared->was_malloced = (do_malloc != 0);
-    wshared->uds = (sockpath != NULL);
+    if (sockpath) {
+        if (PROXY_STRNCPY(wshared->uds_path, sockpath) != APR_SUCCESS) {
+            return apr_psprintf(p, "worker uds path (%s) too long", sockpath);
+        }
+
+    }
+    else {
+        *wshared->uds_path = '\0';
+    }
 
     (*worker)->hash = wshared->hash;
     (*worker)->context = NULL;
@@ -2087,12 +2089,9 @@ PROXY_DECLARE(int) ap_proxy_acquire_connection(const char *proxy_function,
     (*conn)->close  = 0;
     (*conn)->inreslist = 0;
 
-    if (worker->s->uds) {
+    if (*worker->s->uds_path) {
         if ((*conn)->uds_path == NULL) {
-            apr_uri_t puri;
-            if (apr_uri_parse(worker->cp->pool, worker->s->name, &puri) == APR_SUCCESS) {
-                (*conn)->uds_path = apr_pstrdup(worker->cp->pool, puri.path);
-            }
+            (*conn)->uds_path = apr_pstrdup(worker->cp->pool, worker->s->uds_path);
         }
         if ((*conn)->uds_path) {
             ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(02545)
@@ -2100,9 +2099,10 @@ PROXY_DECLARE(int) ap_proxy_acquire_connection(const char *proxy_function,
                          proxy_function, (*conn)->uds_path);
         }
         else {
+            /* should never happen */
             ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(02546)
-                         "%s: cannot parse for UDS (%s)",
-                         proxy_function, worker->s->name);
+                         "%s: cannot determine UDS (%s)",
+                         proxy_function, worker->s->uds_path);
 
         }
     }
@@ -2182,7 +2182,7 @@ ap_proxy_determine_connection(apr_pool_t *p, request_rec *r,
      *      spilling the cached addr from the worker.
      */
     if (!conn->hostname || !worker->s->is_address_reusable ||
-        worker->s->disablereuse || worker->s->uds) {
+        worker->s->disablereuse || *worker->s->uds_path) {
         if (proxyname) {
             conn->hostname = apr_pstrdup(conn->pool, proxyname);
             conn->port = proxyport;
@@ -2220,7 +2220,7 @@ ap_proxy_determine_connection(apr_pool_t *p, request_rec *r,
             conn->port = uri->port;
         }
         socket_cleanup(conn);
-        if (!worker->s->uds && worker->s->is_address_reusable && !worker->s->disablereuse) {
+        if (!(*worker->s->uds_path) && worker->s->is_address_reusable && !worker->s->disablereuse) {
             /*
              * Only do a lookup if we should not reuse the backend address.
              * Otherwise we will look it up once for the worker.
@@ -2231,7 +2231,7 @@ ap_proxy_determine_connection(apr_pool_t *p, request_rec *r,
                                         conn->pool);
         }
     }
-    if (!worker->s->uds && worker->s->is_address_reusable && !worker->s->disablereuse) {
+    if (!(*worker->s->uds_path) && worker->s->is_address_reusable && !worker->s->disablereuse) {
         /*
          * Looking up the backend address for the worker only makes sense if
          * we can reuse the address.