]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: config: make str2listener() use str2sa_range() to parse unix addresses
authorWilly Tarreau <w@1wt.eu>
Mon, 4 Mar 2013 18:56:20 +0000 (19:56 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 8 Mar 2013 13:04:54 +0000 (14:04 +0100)
Now that str2sa_range() knows how to parse UNIX addresses, make str2listener()
use it. It simplifies the function. Next step consists in unifying the error
handling to further simplify the call.

Tests have been done and show that unix sockets are correctly handled, with
and without prefixes, both for global stats and normal "bind" statements.

src/cfgparse.c

index e33ab6129abe9ec3a2dc038f2901f3a712cb196d..61b78a56d51681da572443fc1a601eef6bc1afc1 100644 (file)
@@ -215,25 +215,13 @@ int str2listener(char *str, struct proxy *curproxy, struct bind_conf *bind_conf,
                }
 
                if (*str == '/') {
-                       /* sun_path during a soft_stop rename is <unix_bind_prefix><path>.<pid>.<bak|tmp> */
-                       /* so compute max path */
-                       int prefix_path_len = (curproxy != global.stats_fe && global.unix_bind.prefix) ? strlen(global.unix_bind.prefix) : 0;
-                       int max_path_len = (sizeof(((struct sockaddr_un *)&ss)->sun_path) - 1) - (prefix_path_len + 1 + 5 + 1 + 3);
+                       struct sockaddr_storage *ss2;
 
-                       if (strlen(str) > max_path_len) {
-                               memprintf(err, "socket path '%s' too long (max %d)\n", str, max_path_len);
+                       ss2 = str2sa_range(str, &port, &end, err,
+                                          curproxy == global.stats_fe ? NULL : global.unix_bind.prefix);
+                       if (!ss2)
                                goto fail;
-                       }
-
-                       memset(&ss, 0, sizeof(ss));
-                       ss.ss_family = AF_UNIX;
-                       if (global.unix_bind.prefix) {
-                               memcpy(((struct sockaddr_un *)&ss)->sun_path, global.unix_bind.prefix, prefix_path_len);
-                               strcpy(((struct sockaddr_un *)&ss)->sun_path+prefix_path_len, str);
-                       }
-                       else {
-                               strcpy(((struct sockaddr_un *)&ss)->sun_path, str);
-                       }
+                       ss = *ss2;
                        port = end = 0;
                }
                else {