Skip to content

Commit aa43ae3

Browse files
committed
Add warning to log, when fpm socket was not registered on the expected path
1 parent d3f82f3 commit aa43ae3

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

sapi/fpm/fpm/fpm_sockets.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,9 +396,20 @@ static int fpm_socket_af_inet_listening_socket(struct fpm_worker_pool_s *wp) /*
396396
static int fpm_socket_af_unix_listening_socket(struct fpm_worker_pool_s *wp) /* {{{ */
397397
{
398398
struct sockaddr_un sa_un;
399+
size_t socket_length = sizeof(sa_un.sun_path);
400+
size_t address_length = strlen(wp->config->listen_address);
399401

400402
memset(&sa_un, 0, sizeof(sa_un));
401-
strlcpy(sa_un.sun_path, wp->config->listen_address, sizeof(sa_un.sun_path));
403+
strlcpy(sa_un.sun_path, wp->config->listen_address, socket_length);
404+
405+
if (address_length >= socket_length) {
406+
zlog(
407+
ZLOG_WARNING,
408+
"[pool %s] cannot bind to UNIX socket '%s' as path is too long (found length: %lu, maximal length: %lu), trying cut socket path instead '%s'",
409+
wp->config->name, wp->config->listen_address, address_length, socket_length, sa_un.sun_path
410+
);
411+
}
412+
402413
sa_un.sun_family = AF_UNIX;
403414
return fpm_sockets_get_listening_socket(wp, (struct sockaddr *) &sa_un, sizeof(struct sockaddr_un));
404415
}

sapi/fpm/fpm/fpm_unix.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <stdlib.h>
99
#include <unistd.h>
1010
#include <sys/types.h>
11+
#include <sys/un.h>
1112
#include <pwd.h>
1213
#include <grp.h>
1314

@@ -63,6 +64,25 @@ static struct passwd *fpm_unix_get_passwd(struct fpm_worker_pool_s *wp, const ch
6364
return pwd;
6465
}
6566

67+
static inline bool fpm_unix_check_listen_address(struct fpm_worker_pool_s *wp, const char *address, int flags)
68+
{
69+
struct sockaddr_un test_socket;
70+
size_t address_length = strlen(address);
71+
size_t socket_length = sizeof(test_socket.sun_path);
72+
73+
if (wp->listen_address_domain != FPM_AF_UNIX) {
74+
return true;
75+
}
76+
77+
if (address_length < socket_length) {
78+
return true;
79+
}
80+
81+
zlog(flags, "[pool %s] cannot bind to UNIX socket '%s' as path is too long (found length: %lu, maximal length: %lu)", wp->config->name, address, address_length, socket_length);
82+
83+
return false;
84+
}
85+
6686
static inline bool fpm_unix_check_passwd(struct fpm_worker_pool_s *wp, const char *name, int flags)
6787
{
6888
return !name || fpm_unix_is_id(name) || fpm_unix_get_passwd(wp, name, flags);
@@ -88,8 +108,10 @@ bool fpm_unix_test_config(struct fpm_worker_pool_s *wp)
88108
{
89109
struct fpm_worker_pool_config_s *config = wp->config;
90110
return (
111+
fpm_unix_check_listen_address(wp, config->listen_address, ZLOG_ERROR) &&
91112
fpm_unix_check_passwd(wp, config->user, ZLOG_ERROR) &&
92113
fpm_unix_check_group(wp, config->group, ZLOG_ERROR) &&
114+
fpm_unix_check_listen_address(wp, config->listen_address, ZLOG_SYSERROR) &&
93115
fpm_unix_check_passwd(wp, config->listen_owner, ZLOG_SYSERROR) &&
94116
fpm_unix_check_group(wp, config->listen_group, ZLOG_SYSERROR)
95117
);

0 commit comments

Comments
 (0)