2016-03-28 10:12:37 +08:00
|
|
|
/*
|
|
|
|
* libwebsockets web server application
|
|
|
|
*
|
2020-02-24 10:06:43 +00:00
|
|
|
* Written in 2010-2020 by Andy Green <andy@warmcat.com>
|
2016-03-28 10:12:37 +08:00
|
|
|
*
|
2016-09-19 19:16:47 +08:00
|
|
|
* This file is made available under the Creative Commons CC0 1.0
|
|
|
|
* Universal Public Domain Dedication.
|
2016-03-28 10:12:37 +08:00
|
|
|
*
|
2016-09-19 19:16:47 +08:00
|
|
|
* The person who associated a work with this deed has dedicated
|
|
|
|
* the work to the public domain by waiving all of his or her rights
|
|
|
|
* to the work worldwide under copyright law, including all related
|
|
|
|
* and neighboring rights, to the extent allowed by law. You can copy,
|
|
|
|
* modify, distribute and perform the work, even for commercial purposes,
|
|
|
|
* all without asking permission.
|
2016-03-28 10:12:37 +08:00
|
|
|
*
|
2016-09-19 19:16:47 +08:00
|
|
|
* The test apps are intended to be adapted for use in your code, which
|
|
|
|
* may be proprietary. So unlike the library itself, they are licensed
|
|
|
|
* Public Domain.
|
2016-03-28 10:12:37 +08:00
|
|
|
*/
|
2016-05-26 21:12:11 +08:00
|
|
|
#include "lws_config.h"
|
2016-03-28 10:12:37 +08:00
|
|
|
|
2016-05-26 21:12:11 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2019-01-11 16:48:53 +08:00
|
|
|
#if defined(LWS_HAS_GETOPT_LONG) || defined(WIN32)
|
2016-05-26 21:12:11 +08:00
|
|
|
#include <getopt.h>
|
2019-01-11 16:48:53 +08:00
|
|
|
#endif
|
2016-05-26 21:12:11 +08:00
|
|
|
#include <signal.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#ifndef _WIN32
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <syslog.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <unistd.h>
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
#include <sys/wait.h>
|
2016-05-26 21:12:11 +08:00
|
|
|
#else
|
|
|
|
#include <io.h>
|
|
|
|
#include "gettimeofday.h"
|
2018-04-29 10:44:36 +08:00
|
|
|
#include <uv.h>
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
|
|
|
|
int fork(void)
|
|
|
|
{
|
2017-02-14 11:17:09 -08:00
|
|
|
fprintf(stderr, "Sorry Windows doesn't support fork().\n");
|
|
|
|
return 0;
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
}
|
2016-05-26 21:12:11 +08:00
|
|
|
#endif
|
|
|
|
|
2018-08-23 09:46:01 +08:00
|
|
|
#include <libwebsockets.h>
|
2016-03-28 10:12:37 +08:00
|
|
|
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
#include <uv.h>
|
|
|
|
|
2020-02-24 10:06:43 +00:00
|
|
|
#if defined(LWS_HAVE_MALLOC_TRIM)
|
|
|
|
#include <malloc.h>
|
|
|
|
#endif
|
|
|
|
|
2016-05-10 10:16:52 +08:00
|
|
|
static struct lws_context *context;
|
2020-02-24 10:06:43 +00:00
|
|
|
static lws_sorted_usec_list_t sul_lwsws;
|
2020-10-20 11:06:10 +01:00
|
|
|
static char config_dir[128], default_plugin_path = 1;
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
static int opts = 0, do_reload = 1;
|
|
|
|
static uv_loop_t loop;
|
2018-04-29 10:44:36 +08:00
|
|
|
static uv_signal_t signal_outer[2];
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
static int pids[32];
|
2017-10-13 10:33:02 +08:00
|
|
|
void lwsl_emit_stderr(int level, const char *line);
|
2016-03-28 10:12:37 +08:00
|
|
|
|
2021-01-06 15:08:22 +00:00
|
|
|
#define LWSWS_CONFIG_STRING_SIZE (64 * 1024)
|
2016-03-28 10:12:37 +08:00
|
|
|
|
|
|
|
static const struct lws_extension exts[] = {
|
2018-03-19 09:33:55 +08:00
|
|
|
#if !defined(LWS_WITHOUT_EXTENSIONS)
|
2016-03-28 10:12:37 +08:00
|
|
|
{
|
|
|
|
"permessage-deflate",
|
|
|
|
lws_extension_callback_pm_deflate,
|
|
|
|
"permessage-deflate"
|
|
|
|
},
|
2017-08-26 12:18:47 +08:00
|
|
|
#endif
|
2016-03-28 10:12:37 +08:00
|
|
|
{ NULL, NULL, NULL /* terminator */ }
|
|
|
|
};
|
|
|
|
|
2020-09-01 07:44:54 +01:00
|
|
|
#if defined(LWS_WITH_PLUGINS)
|
2016-05-02 10:03:25 +08:00
|
|
|
static const char * const plugin_dirs[] = {
|
2016-05-10 10:16:52 +08:00
|
|
|
INSTALL_DATADIR"/libwebsockets-test-server/plugins/",
|
|
|
|
NULL
|
2016-05-02 10:03:25 +08:00
|
|
|
};
|
2020-09-01 07:44:54 +01:00
|
|
|
#endif
|
2016-05-02 10:03:25 +08:00
|
|
|
|
2019-01-11 16:48:53 +08:00
|
|
|
#if defined(LWS_HAS_GETOPT_LONG) || defined(WIN32)
|
2016-03-28 10:12:37 +08:00
|
|
|
static struct option options[] = {
|
|
|
|
{ "help", no_argument, NULL, 'h' },
|
|
|
|
{ "debug", required_argument, NULL, 'd' },
|
|
|
|
{ "configdir", required_argument, NULL, 'c' },
|
2020-10-20 11:06:10 +01:00
|
|
|
{ "no-default-plugins", no_argument, NULL, 'n' },
|
2016-03-28 10:12:37 +08:00
|
|
|
{ NULL, 0, 0, 0 }
|
|
|
|
};
|
2019-01-11 16:48:53 +08:00
|
|
|
#endif
|
2016-03-28 10:12:37 +08:00
|
|
|
|
|
|
|
void signal_cb(uv_signal_t *watcher, int signum)
|
|
|
|
{
|
|
|
|
switch (watcher->signum) {
|
|
|
|
case SIGTERM:
|
|
|
|
case SIGINT:
|
|
|
|
break;
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
|
|
|
|
case SIGHUP:
|
|
|
|
if (lws_context_is_deprecated(context))
|
|
|
|
return;
|
|
|
|
lwsl_notice("Dropping listen sockets\n");
|
|
|
|
lws_context_deprecate(context, NULL);
|
|
|
|
return;
|
|
|
|
|
2016-03-28 10:12:37 +08:00
|
|
|
default:
|
|
|
|
signal(SIGABRT, SIG_DFL);
|
|
|
|
abort();
|
|
|
|
break;
|
|
|
|
}
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
lwsl_err("Signal %d caught\n", watcher->signum);
|
2018-04-29 10:44:36 +08:00
|
|
|
uv_signal_stop(watcher);
|
|
|
|
uv_signal_stop(&signal_outer[1]);
|
|
|
|
lws_context_destroy(context);
|
2016-03-28 10:12:37 +08:00
|
|
|
}
|
2016-05-02 10:03:25 +08:00
|
|
|
|
2020-02-24 10:06:43 +00:00
|
|
|
static void
|
|
|
|
lwsws_min(lws_sorted_usec_list_t *sul)
|
|
|
|
{
|
|
|
|
lwsl_debug("%s\n", __func__);
|
|
|
|
|
|
|
|
#if defined(LWS_HAVE_MALLOC_TRIM)
|
|
|
|
malloc_trim(4 * 1024);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
lws_sul_schedule(context, 0, &sul_lwsws, lwsws_min, 60 * LWS_US_PER_SEC);
|
|
|
|
}
|
|
|
|
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
static int
|
|
|
|
context_creation(void)
|
2016-03-28 10:12:37 +08:00
|
|
|
{
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
int cs_len = LWSWS_CONFIG_STRING_SIZE - 1;
|
2016-03-28 10:12:37 +08:00
|
|
|
struct lws_context_creation_info info;
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
char *cs, *config_strings;
|
2018-04-29 10:44:36 +08:00
|
|
|
void *foreign_loops[1];
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
|
|
|
|
cs = config_strings = malloc(LWSWS_CONFIG_STRING_SIZE);
|
|
|
|
if (!config_strings) {
|
|
|
|
lwsl_err("Unable to allocate config strings heap\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&info, 0, sizeof(info));
|
|
|
|
|
|
|
|
info.external_baggage_free_on_destroy = config_strings;
|
2018-04-13 16:01:38 +08:00
|
|
|
info.pt_serv_buf_size = 8192;
|
2020-12-12 06:21:40 +00:00
|
|
|
info.options = (uint64_t)((uint64_t)opts | LWS_SERVER_OPTION_VALIDATE_UTF8 |
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
LWS_SERVER_OPTION_EXPLICIT_VHOSTS |
|
2020-12-12 06:21:40 +00:00
|
|
|
LWS_SERVER_OPTION_LIBUV);
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
|
2020-09-01 07:44:54 +01:00
|
|
|
#if defined(LWS_WITH_PLUGINS)
|
2020-10-20 11:06:10 +01:00
|
|
|
if (default_plugin_path)
|
|
|
|
info.plugin_dirs = plugin_dirs;
|
2020-09-01 07:44:54 +01:00
|
|
|
#endif
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
lwsl_notice("Using config dir: \"%s\"\n", config_dir);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* first go through the config for creating the outer context
|
|
|
|
*/
|
|
|
|
if (lwsws_get_config_globals(&info, config_dir, &cs, &cs_len))
|
|
|
|
goto init_failed;
|
|
|
|
|
2018-04-29 10:44:36 +08:00
|
|
|
foreign_loops[0] = &loop;
|
|
|
|
info.foreign_loops = foreign_loops;
|
|
|
|
info.pcontext = &context;
|
|
|
|
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
context = lws_create_context(&info);
|
|
|
|
if (context == NULL) {
|
|
|
|
lwsl_err("libwebsocket init failed\n");
|
|
|
|
goto init_failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* then create the vhosts... protocols are entirely coming from
|
|
|
|
* plugins, so we leave it NULL
|
|
|
|
*/
|
|
|
|
|
|
|
|
info.extensions = exts;
|
|
|
|
|
2018-04-29 10:44:36 +08:00
|
|
|
if (lwsws_get_config_vhosts(context, &info, config_dir, &cs, &cs_len))
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
return 1;
|
|
|
|
|
2020-02-24 10:06:43 +00:00
|
|
|
lws_sul_schedule(context, 0, &sul_lwsws, lwsws_min, 60 * LWS_US_PER_SEC);
|
|
|
|
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
init_failed:
|
|
|
|
free(config_strings);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* root-level sighup handler
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
|
|
|
reload_handler(int signum)
|
|
|
|
{
|
2016-03-28 10:12:37 +08:00
|
|
|
#ifndef _WIN32
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
int m;
|
|
|
|
|
|
|
|
switch (signum) {
|
|
|
|
|
|
|
|
case SIGHUP: /* reload */
|
|
|
|
fprintf(stderr, "root process receives reload\n");
|
|
|
|
if (!do_reload) {
|
|
|
|
fprintf(stderr, "passing HUP to child processes\n");
|
2018-08-16 19:10:32 +08:00
|
|
|
for (m = 0; m < (int)LWS_ARRAY_SIZE(pids); m++)
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
if (pids[m])
|
|
|
|
kill(pids[m], SIGHUP);
|
|
|
|
sleep(1);
|
|
|
|
}
|
|
|
|
do_reload = 1;
|
|
|
|
break;
|
|
|
|
case SIGINT:
|
|
|
|
case SIGTERM:
|
|
|
|
case SIGKILL:
|
2020-10-11 07:43:46 +01:00
|
|
|
fprintf(stderr, "parent process waiting 2s...\n");
|
2018-04-29 10:44:36 +08:00
|
|
|
sleep(2); /* give children a chance to deal with the signal */
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
fprintf(stderr, "killing service processes\n");
|
2018-08-16 19:10:32 +08:00
|
|
|
for (m = 0; m < (int)LWS_ARRAY_SIZE(pids); m++)
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
if (pids[m])
|
|
|
|
kill(pids[m], SIGTERM);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
// kill() implementation needed for WIN32
|
2016-03-28 10:12:37 +08:00
|
|
|
#endif
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2018-08-14 08:00:25 +08:00
|
|
|
int n = 0, budget = 100, debug_level = 1024 + 7;
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
#ifndef _WIN32
|
2017-06-09 20:20:42 +08:00
|
|
|
int m;
|
2018-09-05 14:43:16 +08:00
|
|
|
int status;//, syslog_options = LOG_PID | LOG_PERROR;
|
2016-03-28 10:12:37 +08:00
|
|
|
#endif
|
|
|
|
|
2016-05-22 07:01:35 +08:00
|
|
|
strcpy(config_dir, "/etc/lwsws");
|
2016-03-28 10:12:37 +08:00
|
|
|
while (n >= 0) {
|
2019-01-11 16:48:53 +08:00
|
|
|
#if defined(LWS_HAS_GETOPT_LONG) || defined(WIN32)
|
2020-10-20 11:06:10 +01:00
|
|
|
n = getopt_long(argc, argv, "hd:c:n", options, NULL);
|
2019-01-11 16:48:53 +08:00
|
|
|
#else
|
2020-10-20 11:06:10 +01:00
|
|
|
n = getopt(argc, argv, "hd:c:n");
|
2019-01-11 16:48:53 +08:00
|
|
|
#endif
|
2016-03-28 10:12:37 +08:00
|
|
|
if (n < 0)
|
|
|
|
continue;
|
|
|
|
switch (n) {
|
|
|
|
case 'd':
|
|
|
|
debug_level = atoi(optarg);
|
|
|
|
break;
|
2020-10-20 11:06:10 +01:00
|
|
|
case 'n':
|
|
|
|
default_plugin_path = 0;
|
|
|
|
break;
|
2016-03-28 10:12:37 +08:00
|
|
|
case 'c':
|
2018-03-12 09:28:26 +08:00
|
|
|
lws_strncpy(config_dir, optarg, sizeof(config_dir));
|
2016-03-28 10:12:37 +08:00
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
fprintf(stderr, "Usage: lwsws [-c <config dir>] "
|
2020-10-20 11:06:10 +01:00
|
|
|
"[-d <log bitfield>] [--help] "
|
|
|
|
"[-n]\n");
|
2016-03-28 10:12:37 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
2017-04-28 11:54:27 +08:00
|
|
|
#ifndef _WIN32
|
2016-03-28 10:12:37 +08:00
|
|
|
/*
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
* We leave our original process up permanently, because that
|
|
|
|
* suits systemd.
|
|
|
|
*
|
|
|
|
* Otherwise we get into problems when reload spawns new processes and
|
|
|
|
* the original one dies randomly.
|
2016-03-28 10:12:37 +08:00
|
|
|
*/
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
|
|
|
|
signal(SIGHUP, reload_handler);
|
|
|
|
signal(SIGINT, reload_handler);
|
|
|
|
|
2019-11-04 18:09:34 +08:00
|
|
|
fprintf(stderr, "Root process is %u\n", (unsigned int)getpid());
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
|
|
|
|
while (1) {
|
|
|
|
if (do_reload) {
|
|
|
|
do_reload = 0;
|
|
|
|
n = fork();
|
|
|
|
if (n == 0) /* new */
|
|
|
|
break;
|
|
|
|
/* old */
|
|
|
|
if (n > 0)
|
2018-08-16 19:10:32 +08:00
|
|
|
for (m = 0; m < (int)LWS_ARRAY_SIZE(pids); m++)
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
if (!pids[m]) {
|
|
|
|
pids[m] = n;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifndef _WIN32
|
|
|
|
sleep(2);
|
|
|
|
|
|
|
|
n = waitpid(-1, &status, WNOHANG);
|
|
|
|
if (n > 0)
|
2018-08-16 19:10:32 +08:00
|
|
|
for (m = 0; m < (int)LWS_ARRAY_SIZE(pids); m++)
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
if (pids[m] == n) {
|
|
|
|
pids[m] = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
// !!! implemenation needed
|
2016-03-28 10:12:37 +08:00
|
|
|
#endif
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
}
|
2017-04-28 11:54:27 +08:00
|
|
|
#endif
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
/* child process */
|
2016-03-28 10:12:37 +08:00
|
|
|
|
2018-11-13 17:03:33 +08:00
|
|
|
lws_set_log_level(debug_level, lwsl_emit_stderr_notimestamp);
|
2016-03-28 10:12:37 +08:00
|
|
|
|
2020-02-24 10:06:43 +00:00
|
|
|
lwsl_notice("lwsws libwebsockets web server - license CC0 + MIT\n");
|
|
|
|
lwsl_notice("(C) Copyright 2010-2020 Andy Green <andy@warmcat.com>\n");
|
2016-03-28 10:12:37 +08:00
|
|
|
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
#if (UV_VERSION_MAJOR > 0) // Travis...
|
|
|
|
uv_loop_init(&loop);
|
|
|
|
#else
|
|
|
|
fprintf(stderr, "Your libuv is too old!\n");
|
|
|
|
return 0;
|
|
|
|
#endif
|
2018-04-29 10:44:36 +08:00
|
|
|
uv_signal_init(&loop, &signal_outer[0]);
|
|
|
|
uv_signal_start(&signal_outer[0], signal_cb, SIGINT);
|
|
|
|
uv_signal_init(&loop, &signal_outer[1]);
|
|
|
|
uv_signal_start(&signal_outer[1], signal_cb, SIGHUP);
|
2016-03-28 10:12:37 +08:00
|
|
|
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
if (context_creation()) {
|
|
|
|
lwsl_err("Context creation failed\n");
|
|
|
|
return 1;
|
2016-03-28 10:12:37 +08:00
|
|
|
}
|
|
|
|
|
2018-04-29 10:44:36 +08:00
|
|
|
lws_service(context, 0);
|
2016-03-28 10:12:37 +08:00
|
|
|
|
2018-04-29 10:44:36 +08:00
|
|
|
lwsl_err("%s: closing\n", __func__);
|
2016-05-10 10:42:19 +08:00
|
|
|
|
2018-04-29 10:44:36 +08:00
|
|
|
for (n = 0; n < 2; n++) {
|
|
|
|
uv_signal_stop(&signal_outer[n]);
|
|
|
|
uv_close((uv_handle_t *)&signal_outer[n], NULL);
|
|
|
|
}
|
|
|
|
|
2020-02-24 10:06:43 +00:00
|
|
|
/* cancel the per-minute sul */
|
2020-05-28 12:48:17 +01:00
|
|
|
lws_sul_cancel(&sul_lwsws);
|
2020-02-24 10:06:43 +00:00
|
|
|
|
2018-04-29 10:44:36 +08:00
|
|
|
lws_context_destroy(context);
|
2018-04-30 19:17:32 +08:00
|
|
|
(void)budget;
|
|
|
|
#if (UV_VERSION_MAJOR > 0) // Travis...
|
2018-04-29 10:44:36 +08:00
|
|
|
while ((n = uv_loop_close(&loop)) && --budget)
|
|
|
|
uv_run(&loop, UV_RUN_ONCE);
|
2018-04-30 19:17:32 +08:00
|
|
|
#endif
|
2016-05-10 10:16:52 +08:00
|
|
|
|
2018-04-29 10:44:36 +08:00
|
|
|
fprintf(stderr, "lwsws exited cleanly: %d\n", n);
|
2016-03-28 10:12:37 +08:00
|
|
|
|
|
|
|
#ifndef _WIN32
|
|
|
|
closelog();
|
|
|
|
#endif
|
|
|
|
|
2017-07-15 14:37:04 +08:00
|
|
|
context = NULL;
|
|
|
|
|
2016-03-28 10:12:37 +08:00
|
|
|
return 0;
|
|
|
|
}
|