diff options
author | Nick Mathewson <nickm@torproject.org> | 2019-10-30 10:29:43 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2019-11-07 07:28:43 -0500 |
commit | 52c0ab4af3ec152c4b78669acf8877ca27d66097 (patch) | |
tree | e8dc14ad0834731fd746bc22d462aae1db18ed3b /src/app/main/subsysmgr.c | |
parent | 7ac4f9d5ec1b31a0d4b76ab62c1afc039c8fe627 (diff) | |
download | tor-52c0ab4af3ec152c4b78669acf8877ca27d66097.tar.gz tor-52c0ab4af3ec152c4b78669acf8877ca27d66097.zip |
Add subsys functions for receiving/flushing states and options.
These functions are in the subsystem, not in the config_format_t,
since they are about how the format is _used_, not about _what it
is_.
Diffstat (limited to 'src/app/main/subsysmgr.c')
-rw-r--r-- | src/app/main/subsysmgr.c | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/src/app/main/subsysmgr.c b/src/app/main/subsysmgr.c index e5c76b8e55..bd9af11444 100644 --- a/src/app/main/subsysmgr.c +++ b/src/app/main/subsysmgr.c @@ -334,3 +334,79 @@ subsystems_register_state_formats(config_mgr_t *mgr) } return 0; } + +/** + * Call all appropriate set_options() methods to tell the various subsystems + * about a new set of torrc options. Return 0 on success, -1 on + * nonrecoverable failure. + **/ +int +subsystems_set_options(const config_mgr_t *mgr, struct or_options_t *options) +{ + /* XXXX This does not yet handle reversible option assignment; I'll + * do that later in this branch. */ + + for (unsigned i = 0; i < n_tor_subsystems; ++i) { + const subsys_fns_t *sys = tor_subsystems[i]; + if (sys_status[i].options_idx >= 0 && sys->set_options) { + void *obj = config_mgr_get_obj_mutable(mgr, options, + sys_status[i].options_idx); + int rv = sys->set_options(obj); + if (rv < 0) { + log_err(LD_CONFIG, "Error when handling option for %s; " + "cannot proceed.", sys->name); + return -1; + } + } + } + return 0; +} + +/** + * Call all appropriate set_state() methods to tell the various subsystems + * about an initial DataDir/state file. Return 0 on success, -1 on + * nonrecoverable failure. + **/ +int +subsystems_set_state(const config_mgr_t *mgr, struct or_state_t *state) +{ + for (unsigned i = 0; i < n_tor_subsystems; ++i) { + const subsys_fns_t *sys = tor_subsystems[i]; + if (sys_status[i].state_idx >= 0 && sys->set_state) { + void *obj = config_mgr_get_obj_mutable(mgr, state, + sys_status[i].state_idx); + int rv = sys->set_state(obj); + if (rv < 0) { + log_err(LD_CONFIG, "Error when handling state for %s; " + "cannot proceed.", sys->name); + return -1; + } + } + } + return 0; +} + +/** + * Call all appropriate flush_state() methods to tell the various subsystems + * to update the state objects in <b>state</b>. Return 0 on success, + * -1 on failure. + **/ +int +subsystems_flush_state(const config_mgr_t *mgr, struct or_state_t *state) +{ + int result = 0; + for (unsigned i = 0; i < n_tor_subsystems; ++i) { + const subsys_fns_t *sys = tor_subsystems[i]; + if (sys_status[i].state_idx >= 0 && sys->flush_state) { + void *obj = config_mgr_get_obj_mutable(mgr, state, + sys_status[i].state_idx); + int rv = sys->flush_state(obj); + if (rv < 0) { + log_warn(LD_CONFIG, "Error when flushing state to state object for %s", + sys->name); + result = -1; + } + } + } + return result; +} |