Tor 0.4.9.0-alpha-dev
Data Structures | Macros | Functions | Variables
subsysmgr.c File Reference

Manager for Tor's subsystems. More...

#include "orconfig.h"
#include "app/main/subsysmgr.h"
#include "lib/confmgt/confmgt.h"
#include "lib/dispatch/dispatch_naming.h"
#include "lib/dispatch/msgtypes.h"
#include "lib/err/torerr.h"
#include "lib/log/log.h"
#include "lib/log/util_bug.h"
#include "lib/malloc/malloc.h"
#include "lib/pubsub/pubsub_build.h"
#include "lib/pubsub/pubsub_connect.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

Go to the source code of this file.

Data Structures

struct  subsys_status_t
 

Macros

#define IDX_NONE   (-1)
 
#define N_SYS_STATUS   128
 

Functions

static void subsys_status_clear (subsys_status_t *status)
 
static void check_and_setup (void)
 
int subsystems_init (void)
 
int subsystems_init_upto (int target_level)
 
int subsystems_add_pubsub_upto (pubsub_builder_t *builder, int target_level)
 
int subsystems_add_pubsub (pubsub_builder_t *builder)
 
void subsystems_shutdown (void)
 
void subsystems_shutdown_downto (int target_level)
 
void subsystems_prefork (void)
 
void subsystems_postfork (void)
 
void subsystems_thread_cleanup (void)
 
void subsystems_dump_list (void)
 
int subsystems_register_options_formats (config_mgr_t *mgr)
 
int subsystems_register_state_formats (config_mgr_t *mgr)
 
int subsystems_set_options (const config_mgr_t *mgr, struct or_options_t *options)
 
int subsystems_set_state (const config_mgr_t *mgr, struct or_state_t *state)
 
int subsystems_flush_state (const config_mgr_t *mgr, struct or_state_t *state)
 

Variables

static bool subsystem_array_validated = false
 
static subsys_status_t sys_status [N_SYS_STATUS]
 

Detailed Description

Manager for Tor's subsystems.

This code is responsible for initializing, configuring, and shutting down all of Tor's individual subsystems.

Definition in file subsysmgr.c.

Macro Definition Documentation

◆ IDX_NONE

#define IDX_NONE   (-1)

Index value indicating that a subsystem has no options/state object, and so that object does not have an index.

Definition at line 38 of file subsysmgr.c.

◆ N_SYS_STATUS

#define N_SYS_STATUS   128

An overestimate of the number of subsystems.

Definition at line 53 of file subsysmgr.c.

Function Documentation

◆ check_and_setup()

static void check_and_setup ( void  )
static

Exit with a raw assertion if the subsystems list is inconsistent; initialize the subsystem_initialized array.

Definition at line 78 of file subsysmgr.c.

Referenced by subsystems_init_upto(), subsystems_postfork(), subsystems_prefork(), subsystems_register_options_formats(), subsystems_register_state_formats(), subsystems_shutdown_downto(), and subsystems_thread_cleanup().

◆ subsys_status_clear()

static void subsys_status_clear ( subsys_status_t status)
static

Set status to a default (not set-up) state.

Definition at line 63 of file subsysmgr.c.

◆ subsystems_add_pubsub()

int subsystems_add_pubsub ( pubsub_builder_t builder)

Add publish/subscribe relationships to builder for all initialized subsystems.

Definition at line 195 of file subsysmgr.c.

Referenced by pubsub_install().

◆ subsystems_add_pubsub_upto()

int subsystems_add_pubsub_upto ( pubsub_builder_t builder,
int  target_level 
)

Add publish/subscribe relationships to builder for all initialized subsystems of level no more than target_level.

Definition at line 160 of file subsysmgr.c.

Referenced by subsystems_add_pubsub().

◆ subsystems_dump_list()

void subsystems_dump_list ( void  )

Dump a human- and machine-readable list of all the subsystems to stdout, in their initialization order, prefixed with their level.

Definition at line 301 of file subsysmgr.c.

Referenced by options_init_from_torrc().

◆ subsystems_flush_state()

int subsystems_flush_state ( const config_mgr_t mgr,
struct or_state_t state 
)

Call all appropriate flush_state() methods to tell the various subsystems to update the state objects in state. Return 0 on success, -1 on failure.

Definition at line 461 of file subsysmgr.c.

◆ subsystems_init()

int subsystems_init ( void  )

Initialize all the subsystems; exit on failure.

Definition at line 114 of file subsysmgr.c.

Referenced by tor_run_main().

◆ subsystems_init_upto()

int subsystems_init_upto ( int  target_level)

Initialize all the subsystems whose level is less than or equal to target_level; exit on failure.

Definition at line 124 of file subsysmgr.c.

Referenced by subsystems_init().

◆ subsystems_postfork()

void subsystems_postfork ( void  )

Run post-fork code on all subsystems that declare any

Definition at line 258 of file subsysmgr.c.

Referenced by options_act_once_on_startup().

◆ subsystems_prefork()

void subsystems_prefork ( void  )

Run pre-fork code on all subsystems that declare any

Definition at line 237 of file subsysmgr.c.

Referenced by options_act_once_on_startup().

◆ subsystems_register_options_formats()

int subsystems_register_options_formats ( config_mgr_t mgr)

Register all subsystem-declared options formats in mgr.

Return 0 on success, -1 on failure.

Definition at line 316 of file subsysmgr.c.

◆ subsystems_register_state_formats()

int subsystems_register_state_formats ( config_mgr_t mgr)

Register all subsystem-declared state formats in mgr.

Return 0 on success, -1 on failure.

Definition at line 339 of file subsysmgr.c.

◆ subsystems_set_options()

int subsystems_set_options ( const config_mgr_t mgr,
struct or_options_t options 
)

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.

Definition at line 410 of file subsysmgr.c.

Referenced by set_options().

◆ subsystems_set_state()

int subsystems_set_state ( const config_mgr_t mgr,
struct or_state_t state 
)

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.

Definition at line 437 of file subsysmgr.c.

◆ subsystems_shutdown()

void subsystems_shutdown ( void  )

Shut down all the subsystems.

Definition at line 204 of file subsysmgr.c.

◆ subsystems_shutdown_downto()

void subsystems_shutdown_downto ( int  target_level)

Shut down all the subsystems whose level is above target_level.

Definition at line 213 of file subsysmgr.c.

Referenced by subsystems_shutdown().

◆ subsystems_thread_cleanup()

void subsystems_thread_cleanup ( void  )

Run thread-cleanup code on all subsystems that declare any

Definition at line 279 of file subsysmgr.c.

Variable Documentation

◆ subsystem_array_validated

bool subsystem_array_validated = false
static

True iff we have checked tor_subsystems for consistency.

Definition at line 34 of file subsysmgr.c.

Referenced by check_and_setup().

◆ sys_status

subsys_status_t sys_status[N_SYS_STATUS]
static

True if a given subsystem is initialized. Expand this array if there are more than this number of subsystems. (We'd rather not dynamically allocate in this module.)

Definition at line 59 of file subsysmgr.c.