Browse Source

[core] lighttpd -tt performs preflight startup checks (fixes #411)

lighttpd -t loads config file and performs syntax check
lighttpd -tt (new) performs preflight startup checks,
  including loading and initializing modules, but skipping any
  potentially destructive actions which might affect an already
  running server (separate instance).  These currently include:
  - skipping pidfile modification
  - skipping bind() to network sockets
  - skipping open of error and access logs

From: Glenn Strauss <gstrauss@gluelogic.com>

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@3130 152afb58-edef-0310-8abb-c4023f1b3aa9
svn/heads/lighttpd-1.4.x
Glenn Strauss 6 years ago
committed by Stefan Bühler
parent
commit
292309f88b
  1. 1
      NEWS
  2. 1
      src/base.h
  3. 2
      src/mod_accesslog.c
  4. 12
      src/network.c
  5. 23
      src/server.c

1
NEWS

@ -54,6 +54,7 @@ NEWS
* [core] wait for grandchild to be ready when daemonizing (fixes #2712, thx pasdVn)
* [core] respond 411 Length Required if request has Transfer-Encoding: chunked (fixes #631)
* [core] fixed the loading for default modules if they are specified explicitly
* [core] lighttpd -tt performs preflight startup checks (fixes #411)
- 1.4.39 - 2016-01-02
* [core] fix memset_s call (fixes #2698)

1
src/base.h

@ -510,6 +510,7 @@ typedef struct {
buffer *breakagelog_file;
unsigned short dont_daemonize;
unsigned short preflight_check;
buffer *changeroot;
buffer *username;
buffer *groupname;

2
src/mod_accesslog.c

@ -584,6 +584,8 @@ SETDEFAULTS_FUNC(log_access_open) {
if (buffer_string_is_empty(s->access_logfile)) continue;
if (srv->srvconf.preflight_check) continue;
if (-1 == (s->log_access_fd = open_logfile_or_pipe(srv, s->access_logfile->ptr)))
return HANDLER_ERROR;

12
src/network.c

@ -170,11 +170,11 @@ static int network_server_init(server *srv, buffer *host_token, specific_config
buffer *b;
int is_unix_domain_socket = 0;
int fd;
int err;
#ifdef __WIN32
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD( 2, 2 );
@ -185,6 +185,7 @@ static int network_server_init(server *srv, buffer *host_token, specific_config
return -1;
}
#endif
err = -1;
srv_socket = calloc(1, sizeof(*srv_socket));
force_assert(NULL != srv_socket);
@ -380,6 +381,8 @@ static int network_server_init(server *srv, buffer *host_token, specific_config
#endif
}
if (srv->srvconf.preflight_check) break;
/* check if the socket exists and try to connect to it. */
if (-1 != (fd = connect(srv_socket->fd, (struct sockaddr *) &(srv_socket->addr), addr_len))) {
close(fd);
@ -412,6 +415,11 @@ static int network_server_init(server *srv, buffer *host_token, specific_config
goto error_free_socket;
}
if (srv->srvconf.preflight_check) {
err = 0;
goto error_free_socket;
}
if (0 != bind(srv_socket->fd, (struct sockaddr *) &(srv_socket->addr), addr_len)) {
switch(srv_socket->addr.plain.sa_family) {
case AF_UNIX:
@ -501,7 +509,7 @@ error_free_socket:
buffer_free(b);
return -1;
return err; /* -1 if error; 0 if srv->srvconf.preflight_check successful */
}
int network_close(server *srv) {

23
src/server.c

@ -649,6 +649,7 @@ int main (int argc, char **argv) {
i_am_root = 0;
#endif
srv->srvconf.dont_daemonize = 0;
srv->srvconf.preflight_check = 0;
while(-1 != (o = getopt(argc, argv, "f:m:hvVDpt"))) {
switch(o) {
@ -669,7 +670,7 @@ int main (int argc, char **argv) {
buffer_copy_string(srv->srvconf.modules_dir, optarg);
break;
case 'p': print_config = 1; break;
case 't': test_config = 1; break;
case 't': ++test_config; break;
case 'D': srv->srvconf.dont_daemonize = 1; break;
case 'v': show_version(); return 0;
case 'V': show_features(); return 0;
@ -701,7 +702,14 @@ int main (int argc, char **argv) {
}
if (test_config) {
printf("Syntax OK\n");
if (1 == test_config) {
printf("Syntax OK\n");
} else { /*(test_config > 1)*/
test_config = 0;
srv->srvconf.preflight_check = 1;
srv->srvconf.dont_daemonize = 1;
buffer_reset(srv->srvconf.pid_file);
}
}
if (test_config || print_config) {
@ -1084,7 +1092,7 @@ int main (int argc, char **argv) {
/* Close stderr ASAP in the child process to make sure that nothing
* is being written to that fd which may not be valid anymore. */
if (-1 == log_error_open(srv)) {
if (!srv->srvconf.preflight_check && -1 == log_error_open(srv)) {
log_error_write(srv, __FILE__, __LINE__, "s", "Opening errorlog failed. Going down.");
plugins_free(srv);
@ -1143,6 +1151,15 @@ int main (int argc, char **argv) {
return -1;
}
if (srv->srvconf.preflight_check) {
/*printf("Preflight OK");*//*(stdout reopened to /dev/null)*/
plugins_free(srv);
network_close(srv);
server_free(srv);
exit(0);
}
#ifdef HAVE_FORK
/**

Loading…
Cancel
Save