From b44dc2f38849e6bb67a088da22413492cb2735a1 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Mon, 4 Mar 2013 19:56:20 +0100 Subject: [PATCH] MEDIUM: config: make str2listener() use str2sa_range() to parse unix addresses 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 | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/src/cfgparse.c b/src/cfgparse.c index e33ab6129..61b78a56d 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -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 .. */ - /* 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 {