|
unbound 0.1
|
This file contains functions to integrate with the windows services API. More...
#include "config.h"#include "winrc/win_svc.h"#include "winrc/w_inst.h"#include "daemon/daemon.h"#include "daemon/worker.h"#include "daemon/remote.h"#include "util/config_file.h"#include "util/netevent.h"#include "util/ub_event.h"#include "util/net_help.h"Macros | |
| #define | ATTR_UNUSED(x) |
Functions | |
| static void | report_status (DWORD state, DWORD exitcode, DWORD wait) |
| Report current service status to service control manager. | |
| static void | hdlr (DWORD ctrl) |
| Service control handler. | |
| static void | reportev (const char *str) |
| report event to system event log For use during startup and shutdown. | |
| static char * | lookup_reg_str (const char *key, const char *name) |
| Obtain registry string (if it exists). | |
| static int | lookup_reg_int (const char *key, const char *name) |
| Obtain registry integer (if it exists). | |
| static void | waitforubanchor (PROCESS_INFORMATION *pinfo) |
| wait for unbound-anchor process to finish | |
| static void | call_root_update (void) |
| Perform root anchor update if so configured, by calling that process. | |
| static int | service_init (int r, struct daemon **d, struct config_file **c) |
| Init service. | |
| static void | service_deinit (struct daemon *daemon, struct config_file *cfg) |
| Deinit the service. | |
| static void | service_main (DWORD argc, LPTSTR *argv) |
| The main function for the service. | |
| static void | service_start (const char *cfgfile, int v, int c) |
| start the service | |
| void | wsvc_command_option (const char *wopt, const char *cfgfile, int v, int c) |
| Handle commandline service for windows. | |
| void | worker_win_stop_cb (int fd, short ev, void *arg) |
| windows worker stop event callback handler | |
| static void | waitforit (PROCESS_INFORMATION *pinfo) |
| wait for cron process to finish | |
| static void * | win_do_cron (void *arg) |
| Do the cron action and wait for result exit value. | |
| static void | set_cron_timer (void) |
| Set the timer for cron for the next wake up. | |
| void | wsvc_cron_cb (void *arg) |
| windows cron timer callback handler | |
| void | wsvc_setup_worker (struct worker *worker) |
| Setup lead worker events. | |
| void | wsvc_desetup_worker (struct worker *worker) |
| Desetup lead worker events. | |
Variables | |
| static SERVICE_STATUS | service_status |
| global service status | |
| static SERVICE_STATUS_HANDLE | service_status_handle |
| global service status handle | |
| static WSAEVENT | service_stop_event = NULL |
| global service stop event | |
| static struct ub_event * | service_stop_ev = NULL |
| event struct for stop callbacks | |
| static int | service_stop_shutdown = 0 |
| if stop even means shutdown or restart | |
| static char * | service_cfgfile = CONFIGFILE |
| config file to open. | |
| static int | service_cmdline_verbose = 0 |
| commandline verbosity. | |
| static struct comm_timer * | service_cron = NULL |
| the cron callback | |
| static ub_thread_type | cron_thread = NULL |
| the cron thread | |
| static int | cron_was_quick = 0 |
| if cron has already done its quick check | |
This file contains functions to integrate with the windows services API.
This means it handles the commandline switches to install and remove the service (via CreateService and DeleteService), it handles the ServiceMain() main service entry point when started as a service, and it handles the Handler[_ex]() to process requests to the service (such as start and stop and status).
| #define ATTR_UNUSED | ( | x | ) |
|
static |
Report current service status to service control manager.
| state | current state |
| exitcode | error code (when stopped) |
| wait | pending operation estimated time in milliseconds. |
References report_status(), service_status, and service_status_handle.
Referenced by call_root_update(), hdlr(), report_status(), service_init(), service_main(), and waitforubanchor().
|
static |
Service control handler.
Called by serviceControlManager when a control code is sent to the service (with ControlService).
| ctrl | control code |
References hdlr(), log_err(), report_status(), service_status, service_stop_event, and service_stop_shutdown.
Referenced by hdlr(), and service_main().
|
static |
report event to system event log For use during startup and shutdown.
| str | the error |
References MSG_GENERIC_ERR, reportev(), SERVICE_NAME, and wsvc_err2str().
Referenced by lookup_reg_int(), lookup_reg_str(), reportev(), service_main(), and service_start().
|
static |
Obtain registry string (if it exists).
| key | key string |
| name | name of value to fetch. |
References lookup_reg_str(), and reportev().
Referenced by call_root_update(), lookup_reg_str(), service_init(), and win_do_cron().
|
static |
Obtain registry integer (if it exists).
| key | key string |
| name | name of value to fetch. |
References lookup_reg_int(), and reportev().
Referenced by lookup_reg_int(), and set_cron_timer().
|
static |
wait for unbound-anchor process to finish
References log_err(), log_info(), report_status(), VERB_ALGO, verbose(), and waitforubanchor().
Referenced by call_root_update(), and waitforubanchor().
|
static |
Perform root anchor update if so configured, by calling that process.
References call_root_update(), log_err(), lookup_reg_str(), report_status(), VERB_ALGO, verbose(), and waitforubanchor().
Referenced by call_root_update(), and service_main().
|
static |
Init service.
Keeps calling status pending to tell service control manager that this process is not hanging.
| r | restart, true on restart |
| d | daemon returned here. |
| c | config file returned here. |
References daemon::cfg, cfg_has_https(), cfg_has_quic(), daemon::chroot, config_file::chrootdir, config_auto_slab_values(), config_create(), config_delete(), config_read(), daemon::connect_dot_sslctx, connect_sslctx_create(), daemon_apply_cfg(), daemon_delete(), daemon_init(), daemon_open_shared_ports(), daemon_privileged(), daemon_remote_create(), config_file::directory, fatal_exit(), config_strlist_head::first, daemon::listen_doh_sslctx, daemon::listen_dot_sslctx, daemon::listen_quic_sslctx, listen_sslctx_create(), log_err(), log_init(), log_warn(), config_file::logfile, lookup_reg_str(), daemon::rc, report_status(), service_cfgfile, service_cmdline_verbose, service_init(), config_file::ssl_service_key, config_file::ssl_service_pem, config_strlist::str, config_file::tls_cert_bundle, config_file::tls_ciphers, config_file::tls_ciphersuites, config_file::tls_protocols, config_file::tls_session_ticket_keys, config_file::tls_win_cert, config_file::use_syslog, VERB_QUERY, verbose(), config_file::verbosity, and verbosity.
Referenced by service_init(), and service_main().
|
static |
Deinit the service.
References daemon::cfg, config_delete(), daemon_cleanup(), daemon_delete(), and service_deinit().
Referenced by service_deinit(), and service_main().
|
static |
The main function for the service.
Called by the services API when starting unbound on windows in background. Arguments could have been present in the string 'path'.
| argc | nr args |
| argv | arg text. |
References call_root_update(), daemon::cfg, config_delete(), daemon_cleanup(), daemon_fork(), hdlr(), log_err(), report_status(), reportev(), service_cfgfile, service_deinit(), service_init(), service_main(), SERVICE_NAME, service_status, service_status_handle, service_stop_event, service_stop_shutdown, VERB_ALGO, VERB_QUERY, and verbose().
Referenced by service_main(), and service_start().
|
static |
start the service
References daemon::cfgfile, fatal_exit(), log_init(), reportev(), service_cfgfile, service_cmdline_verbose, service_main(), SERVICE_NAME, service_start(), VERB_QUERY, verbose(), and verbosity.
Referenced by service_start(), and wsvc_command_option().
| void wsvc_command_option | ( | const char * | wopt, |
| const char * | cfgfile, | ||
| int | v, | ||
| int | c ) |
Handle commandline service for windows.
| wopt | windows option string (install, remove, service). |
| cfgfile | configfile to open (default or passed with -c). |
| v | amount of commandline verbosity added with -v. |
| c | true if cfgfile was set by commandline -c option. |
References daemon::cfgfile, fatal_exit(), service_start(), wsvc_command_option(), wsvc_install(), wsvc_rc_start(), wsvc_rc_stop(), and wsvc_remove().
Referenced by main(), and wsvc_command_option().
| void worker_win_stop_cb | ( | int | fd, |
| short | ev, | ||
| void * | arg ) |
windows worker stop event callback handler
References worker::base, comm_base_exit(), worker::need_to_exit, VERB_QUERY, verbose(), and worker_win_stop_cb().
Referenced by fptr_whitelist_event(), worker_win_stop_cb(), and wsvc_setup_worker().
|
static |
wait for cron process to finish
References log_err(), service_stop_event, VERB_ALGO, verbose(), and waitforit().
Referenced by waitforit(), and win_do_cron().
|
static |
Do the cron action and wait for result exit value.
References cron_thread, log_err(), log_thread_set(), lookup_reg_str(), VERB_ALGO, verbose(), waitforit(), and win_do_cron().
Referenced by win_do_cron(), and wsvc_cron_cb().
|
static |
Set the timer for cron for the next wake up.
References comm_timer_set(), cron_was_quick, lookup_reg_int(), service_cron, and set_cron_timer().
Referenced by set_cron_timer(), wsvc_cron_cb(), and wsvc_setup_worker().
| void wsvc_cron_cb | ( | void * | arg | ) |
windows cron timer callback handler
References cron_thread, set_cron_timer(), VERB_ALGO, verbose(), win_do_cron(), and wsvc_cron_cb().
Referenced by fptr_whitelist_comm_timer(), wsvc_cron_cb(), and wsvc_setup_worker().
| void wsvc_setup_worker | ( | struct worker * | worker | ) |
Setup lead worker events.
| worker | the worker |
References worker::base, comm_timer_create(), fatal_exit(), service_cron, service_stop_ev, service_stop_event, set_cron_timer(), ub_winsock_register_wsaevent(), worker_win_stop_cb(), wsvc_cron_cb(), and wsvc_setup_worker().
Referenced by worker_init(), and wsvc_setup_worker().
| void wsvc_desetup_worker | ( | struct worker * | worker | ) |
Desetup lead worker events.
| worker | the worker |
References comm_timer_delete(), service_cron, and wsvc_desetup_worker().
Referenced by worker_delete(), and wsvc_desetup_worker().
|
static |
global service status
Referenced by hdlr(), report_status(), and service_main().
|
static |
global service status handle
Referenced by report_status(), and service_main().
|
static |
global service stop event
Referenced by hdlr(), service_main(), waitforit(), and wsvc_setup_worker().
|
static |
event struct for stop callbacks
Referenced by wsvc_setup_worker().
|
static |
if stop even means shutdown or restart
Referenced by hdlr(), and service_main().
|
static |
config file to open.
global communication to service_main()
Referenced by service_init(), service_main(), and service_start().
|
static |
commandline verbosity.
global communication to service_main()
Referenced by service_init(), and service_start().
|
static |
the cron callback
Referenced by set_cron_timer(), wsvc_desetup_worker(), and wsvc_setup_worker().
|
static |
the cron thread
Referenced by win_do_cron(), and wsvc_cron_cb().
|
static |
if cron has already done its quick check
Referenced by set_cron_timer().