mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-22 06:11:32 +02:00
MINOR: peers: do not use localpeer as an array anymore
It is now dynamically allocated by using strdup().
This commit is contained in:
parent
f1cad38281
commit
4f01415d3b
@ -45,7 +45,7 @@ extern const struct linger nolinger;
|
|||||||
extern int stopping; /* non zero means stopping in progress */
|
extern int stopping; /* non zero means stopping in progress */
|
||||||
extern int killed; /* >0 means a hard-stop is triggered, >1 means hard-stop immediately */
|
extern int killed; /* >0 means a hard-stop is triggered, >1 means hard-stop immediately */
|
||||||
extern char hostname[MAX_HOSTNAME_LEN];
|
extern char hostname[MAX_HOSTNAME_LEN];
|
||||||
extern char localpeer[MAX_HOSTNAME_LEN];
|
extern char *localpeer;
|
||||||
extern unsigned int warned; /* bitfield of a few warnings to emit just once */
|
extern unsigned int warned; /* bitfield of a few warnings to emit just once */
|
||||||
extern volatile unsigned long sleeping_thread_mask;
|
extern volatile unsigned long sleeping_thread_mask;
|
||||||
extern struct list proc_list; /* list of process in mworker mode */
|
extern struct list proc_list; /* list of process in mworker mode */
|
||||||
|
@ -215,7 +215,7 @@ const int one = 1;
|
|||||||
const struct linger nolinger = { .l_onoff = 1, .l_linger = 0 };
|
const struct linger nolinger = { .l_onoff = 1, .l_linger = 0 };
|
||||||
|
|
||||||
char hostname[MAX_HOSTNAME_LEN];
|
char hostname[MAX_HOSTNAME_LEN];
|
||||||
char localpeer[MAX_HOSTNAME_LEN];
|
char *localpeer = NULL;
|
||||||
|
|
||||||
static char **old_argv = NULL; /* previous argv but cleaned up */
|
static char **old_argv = NULL; /* previous argv but cleaned up */
|
||||||
|
|
||||||
@ -1728,8 +1728,11 @@ static void init(int argc, char **argv)
|
|||||||
*/
|
*/
|
||||||
memset(hostname, 0, sizeof(hostname));
|
memset(hostname, 0, sizeof(hostname));
|
||||||
gethostname(hostname, sizeof(hostname) - 1);
|
gethostname(hostname, sizeof(hostname) - 1);
|
||||||
memset(localpeer, 0, sizeof(localpeer));
|
|
||||||
memcpy(localpeer, hostname, (sizeof(hostname) > sizeof(localpeer) ? sizeof(localpeer) : sizeof(hostname)) - 1);
|
if ((localpeer = strdup(hostname)) == NULL) {
|
||||||
|
ha_alert("Cannot allocate memory for local peer.\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
setenv("HAPROXY_LOCALPEER", localpeer, 1);
|
setenv("HAPROXY_LOCALPEER", localpeer, 1);
|
||||||
|
|
||||||
/* we were in mworker mode, we should restart in mworker mode */
|
/* we were in mworker mode, we should restart in mworker mode */
|
||||||
@ -1955,7 +1958,11 @@ static void init(int argc, char **argv)
|
|||||||
case 'm' : global.rlimit_memmax_all = atol(*argv); break;
|
case 'm' : global.rlimit_memmax_all = atol(*argv); break;
|
||||||
case 'N' : cfg_maxpconn = atol(*argv); break;
|
case 'N' : cfg_maxpconn = atol(*argv); break;
|
||||||
case 'L' :
|
case 'L' :
|
||||||
strncpy(localpeer, *argv, sizeof(localpeer) - 1);
|
free(localpeer);
|
||||||
|
if ((localpeer = strdup(*argv)) == NULL) {
|
||||||
|
ha_alert("Cannot allocate memory for local peer.\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
setenv("HAPROXY_LOCALPEER", localpeer, 1);
|
setenv("HAPROXY_LOCALPEER", localpeer, 1);
|
||||||
break;
|
break;
|
||||||
case 'f' :
|
case 'f' :
|
||||||
@ -2840,6 +2847,7 @@ void deinit(void)
|
|||||||
free(global.node); global.node = NULL;
|
free(global.node); global.node = NULL;
|
||||||
free(global.desc); global.desc = NULL;
|
free(global.desc); global.desc = NULL;
|
||||||
free(oldpids); oldpids = NULL;
|
free(oldpids); oldpids = NULL;
|
||||||
|
free(localpeer); localpeer = NULL;
|
||||||
task_destroy(idle_conn_task);
|
task_destroy(idle_conn_task);
|
||||||
idle_conn_task = NULL;
|
idle_conn_task = NULL;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user