mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-11-09 13:01:00 +01:00
MINOR: init: Make devnullfd global and create it earlier in init
The devnull fd might be needed during configuration parsing, if some options require to fork/exec for instance. So we now create it much earlier in the init process and without depending on the '-q' or '-d' parameters.
This commit is contained in:
parent
c606ff45a0
commit
1ec59d3426
@ -53,6 +53,7 @@ extern char *progname;
|
|||||||
extern char **old_argv;
|
extern char **old_argv;
|
||||||
extern const char *old_unixsocket;
|
extern const char *old_unixsocket;
|
||||||
extern int daemon_fd[2];
|
extern int daemon_fd[2];
|
||||||
|
extern int devnullfd;
|
||||||
|
|
||||||
struct proxy;
|
struct proxy;
|
||||||
struct server;
|
struct server;
|
||||||
|
|||||||
@ -149,6 +149,7 @@ int pid; /* current process id */
|
|||||||
char **init_env; /* to keep current process env variables backup */
|
char **init_env; /* to keep current process env variables backup */
|
||||||
int pidfd = -1; /* FD to keep PID */
|
int pidfd = -1; /* FD to keep PID */
|
||||||
int daemon_fd[2] = {-1, -1}; /* pipe to communicate with parent process */
|
int daemon_fd[2] = {-1, -1}; /* pipe to communicate with parent process */
|
||||||
|
int devnullfd = -1;
|
||||||
|
|
||||||
static unsigned long stopping_tgroup_mask; /* Thread groups acknowledging stopping */
|
static unsigned long stopping_tgroup_mask; /* Thread groups acknowledging stopping */
|
||||||
|
|
||||||
@ -3159,7 +3160,6 @@ static void set_identity(const char *program_name)
|
|||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int devnullfd = -1;
|
|
||||||
struct rlimit limit;
|
struct rlimit limit;
|
||||||
int intovf = (unsigned char)argc + 1; /* let the compiler know it's strictly positive */
|
int intovf = (unsigned char)argc + 1; /* let the compiler know it's strictly positive */
|
||||||
struct cfgfile *cfg, *cfg_tmp;
|
struct cfgfile *cfg, *cfg_tmp;
|
||||||
@ -3289,6 +3289,18 @@ int main(int argc, char **argv)
|
|||||||
*/
|
*/
|
||||||
set_verbosity();
|
set_verbosity();
|
||||||
|
|
||||||
|
/* We might need to use this devnullfd during configuration parsing. */
|
||||||
|
devnullfd = open("/dev/null", O_RDWR, 0);
|
||||||
|
if (devnullfd < 0) {
|
||||||
|
ha_alert("Cannot open /dev/null\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
if (fcntl(devnullfd, FD_CLOEXEC) != 0) {
|
||||||
|
ha_alert("Cannot make /dev/null CLOEXEC\n");
|
||||||
|
close(devnullfd);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
/* Add entries for master and worker in proc_list, create sockpair,
|
/* Add entries for master and worker in proc_list, create sockpair,
|
||||||
* that will be copied to both processes after master-worker fork to
|
* that will be copied to both processes after master-worker fork to
|
||||||
* enable the master CLI at worker side (worker can send messages to master),
|
* enable the master CLI at worker side (worker can send messages to master),
|
||||||
@ -3427,18 +3439,6 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* End of initialization for standalone and worker modes */
|
/* End of initialization for standalone and worker modes */
|
||||||
if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)) {
|
|
||||||
devnullfd = open("/dev/null", O_RDWR, 0);
|
|
||||||
if (devnullfd < 0) {
|
|
||||||
ha_alert("Cannot open /dev/null\n");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
if (fcntl(devnullfd, FD_CLOEXEC) != 0) {
|
|
||||||
ha_alert("Cannot make /dev/null CLOEXEC\n");
|
|
||||||
close(devnullfd);
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* applies the renice value in the worker or standalone after configuration parsing
|
/* applies the renice value in the worker or standalone after configuration parsing
|
||||||
* but before changing identity */
|
* but before changing identity */
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user