struct sd_bus

  1. struct sd_bus {
  2. unsigned n_ref; =-1
  3. enum bus_state state; =BUS_OPENING
  4. int input_fd, output_fd; =-1
  5. int inotify_fd; =-1
  6. int message_version; =1
  7. int message_endian;
  8. bool can_fds:1;
  9. bool bus_client:1;
  10. bool ucred_valid:1;
  11. bool is_server:1;
  12. bool anonymous_auth:1;
  13. bool prefer_readv:1;
  14. bool prefer_writev:1;
  15. bool match_callbacks_modified:1;
  16. bool filter_callbacks_modified:1;
  17. bool nodes_modified:1;
  18. bool trusted:1;
  19. bool manual_peer_interface:1;
  20. bool is_system:1;
  21. bool is_user:1;
  22. bool allow_interactive_authorization:1;
  23. bool exit_on_disconnect:1;
  24. bool exited:1;
  25. bool exit_triggered:1;
  26. bool is_local:1; =true
  27. bool watch_bind:1;
  28. bool is_monitor:1;
  29. bool accept_fd:1;
  30. bool attach_timestamp:1;
  31. bool connected_signal:1;
  32. bool close_on_exit:1;
  33. signed int use_memfd:2;
  34. void *rbuffer;
  35. size_t rbuffer_size;
  36. sd_bus_message **rqueue;
  37. size_t rqueue_size;
  38. size_t rqueue_allocated;
  39. sd_bus_message **wqueue;
  40. size_t wqueue_size;
  41. size_t windex;
  42. size_t wqueue_allocated;
  43. uint64_t cookie;
  44. uint64_t read_counter; /* A counter for each incoming msg */
  45. char *unique_name;
  46. uint64_t unique_id;
  47. struct bus_match_node match_callbacks;
  48. Prioq *reply_callbacks_prioq;
  49. OrderedHashmap *reply_callbacks;
  50. LIST_HEAD(struct filter_callback, filter_callbacks);
  51. Hashmap *nodes;
  52. Hashmap *vtable_methods;
  53. Hashmap *vtable_properties;
  54. union sockaddr_union sockaddr; sockaddr.family = AF_UNIX
  55. socklen_t sockaddr_size;
  56. pid_t nspid;
  57. char *machine;
  58. sd_id128_t server_id;
  59. char *address; =unix:path=/run/systemd/private
  60. unsigned address_index;
  61. int last_connect_error;
  62. enum bus_auth auth;
  63. unsigned auth_index;
  64. struct iovec auth_iovec[3];
  65. size_t auth_rbegin;
  66. char *auth_buffer;
  67. usec_t auth_timeout;
  68. struct ucred ucred;
  69. char *label;
  70. gid_t *groups;
  71. size_t n_groups;
  72. uint64_t creds_mask;=SD_BUS_CREDS_WELL_KNOWN_NAMES|SD_BUS_CREDS_UNIQUE_NAME
  73. int *fds;
  74. size_t n_fds;
  75. char *exec_path;
  76. char **exec_argv;
  77. /* We do locking around the memfd cache, since we want to
  78. * allow people to process a sd_bus_message in a different
  79. * thread then it was generated on and free it there. Since
  80. * adding something to the memfd cache might happen when a
  81. * message is released, we hence need to protect this bit with
  82. * a mutex. */
  83. pthread_mutex_t memfd_cache_mutex;
  84. struct memfd_cache memfd_cache[MEMFD_CACHE_MAX];
  85. unsigned n_memfd_cache;
  86. pid_t original_pid;
  87. pid_t busexec_pid;
  88. unsigned iteration_counter;
  89. sd_event_source *input_io_event_source;
  90. sd_event_source *output_io_event_source;
  91. sd_event_source *time_event_source;
  92. sd_event_source *quit_event_source;
  93. sd_event_source *inotify_event_source;
  94. sd_event *event;
  95. int event_priority;
  96. pid_t tid;
  97. sd_bus_message *current_message;
  98. sd_bus_slot *current_slot;
  99. sd_bus_message_handler_t current_handler;
  100. void *current_userdata;
  101. sd_bus **default_bus_ptr;
  102. char *description;
  103. char *patch_sender;
  104. sd_bus_track *track_queue;
  105. LIST_HEAD(sd_bus_slot, slots);
  106. LIST_HEAD(sd_bus_track, tracks);
  107. int *inotify_watches;
  108. size_t n_inotify_watches;
  109. /* zero means use value specified by $SYSTEMD_BUS_TIMEOUT= environment variable or built-in default */
  110. usec_t method_call_timeout;
  111. };

struct manager

  1. struct Manager {
  2. /* Note that the set of units we know of is allowed to be
  3. * inconsistent. However the subset of it that is loaded may
  4. * not, and the list of jobs may neither. */
  5. /* Active jobs and units */
  6. Hashmap *units; /* name string => Unit object n:1 */
  7. Hashmap *units_by_invocation_id;
  8. Hashmap *jobs; /* job id => Job object 1:1 */
  9. /* To make it easy to iterate through the units of a specific
  10. * type we maintain a per type linked list */
  11. LIST_HEAD(Unit, units_by_type[_UNIT_TYPE_MAX]);
  12. /* Units that need to be loaded */
  13. LIST_HEAD(Unit, load_queue); /* this is actually more a stack than a queue, but uh. */
  14. /* Jobs that need to be run */
  15. struct Prioq *run_queue;
  16. /* Units and jobs that have not yet been announced via
  17. * D-Bus. When something about a job changes it is added here
  18. * if it is not in there yet. This allows easy coalescing of
  19. * D-Bus change signals. */
  20. LIST_HEAD(Unit, dbus_unit_queue);
  21. LIST_HEAD(Job, dbus_job_queue);
  22. /* Units to remove */
  23. LIST_HEAD(Unit, cleanup_queue);
  24. /* Units and jobs to check when doing GC */
  25. LIST_HEAD(Unit, gc_unit_queue);
  26. LIST_HEAD(Job, gc_job_queue);
  27. /* Units that should be realized */
  28. LIST_HEAD(Unit, cgroup_realize_queue);
  29. /* Units whose cgroup ran empty */
  30. LIST_HEAD(Unit, cgroup_empty_queue);
  31. /* Units whose memory.event fired */
  32. LIST_HEAD(Unit, cgroup_oom_queue);
  33. /* Target units whose default target dependencies haven't been set yet */
  34. LIST_HEAD(Unit, target_deps_queue);
  35. /* Units that might be subject to StopWhenUnneeded= clean-up */
  36. LIST_HEAD(Unit, stop_when_unneeded_queue);
  37. sd_event *event;
  38. /* This maps PIDs we care about to units that are interested in. We allow multiple units to he interested in
  39. * the same PID and multiple PIDs to be relevant to the same unit. Since in most cases only a single unit will
  40. * be interested in the same PID we use a somewhat special encoding here: the first unit interested in a PID is
  41. * stored directly in the hashmap, keyed by the PID unmodified. If there are other units interested too they'll
  42. * be stored in a NULL-terminated array, and keyed by the negative PID. This is safe as pid_t is signed and
  43. * negative PIDs are not used for regular processes but process groups, which we don't care about in this
  44. * context, but this allows us to use the negative range for our own purposes. */
  45. Hashmap *watch_pids; /* pid => unit as well as -pid => array of units */
  46. /* A set contains all units which cgroup should be refreshed after startup */
  47. Set *startup_units;
  48. /* A set which contains all currently failed units */
  49. Set *failed_units;
  50. sd_event_source *run_queue_event_source;
  51. char *notify_socket;
  52. int notify_fd;
  53. sd_event_source *notify_event_source;
  54. int cgroups_agent_fd;
  55. sd_event_source *cgroups_agent_event_source;
  56. int signal_fd;
  57. sd_event_source *signal_event_source;
  58. sd_event_source *sigchld_event_source;
  59. int time_change_fd;
  60. sd_event_source *time_change_event_source;
  61. sd_event_source *timezone_change_event_source;
  62. sd_event_source *jobs_in_progress_event_source;
  63. int user_lookup_fds[2];
  64. sd_event_source *user_lookup_event_source;
  65. sd_event_source *sync_bus_names_event_source;
  66. UnitFileScope unit_file_scope; // == UNIT_FILE_SYSTEM. setup by manager_new()
  67. LookupPaths lookup_paths;
  68. Hashmap *unit_id_map;
  69. Hashmap *unit_name_map;
  70. Set *unit_path_cache;
  71. usec_t unit_cache_mtime;
  72. char **transient_environment; /* The environment, as determined from config files, kernel cmdline and environment generators */
  73. char **client_environment; /* Environment variables created by clients through the bus API */
  74. usec_t runtime_watchdog;
  75. usec_t reboot_watchdog;
  76. usec_t kexec_watchdog;
  77. dual_timestamp timestamps[_MANAGER_TIMESTAMP_MAX];
  78. /* Data specific to the device subsystem */
  79. sd_device_monitor *device_monitor;
  80. Hashmap *devices_by_sysfs;
  81. /* Data specific to the mount subsystem */
  82. struct libmnt_monitor *mount_monitor;
  83. sd_event_source *mount_event_source;
  84. /* Data specific to the swap filesystem */
  85. FILE *proc_swaps;
  86. sd_event_source *swap_event_source;
  87. Hashmap *swaps_by_devnode;
  88. /* Data specific to the D-Bus subsystem */
  89. sd_bus *api_bus, *system_bus;
  90. Set *private_buses;
  91. int private_listen_fd;
  92. sd_event_source *private_listen_event_source;
  93. /* Contains all the clients that are subscribed to signals via
  94. the API bus. Note that private bus connections are always
  95. considered subscribes, since they last for very short only,
  96. and it is much simpler that way. */
  97. sd_bus_track *subscribed;
  98. char **deserialized_subscribed;
  99. /* This is used during reloading: before the reload we queue
  100. * the reply message here, and afterwards we send it */
  101. sd_bus_message *pending_reload_message;
  102. Hashmap *watch_bus; /* D-Bus names => Unit object n:1 */
  103. bool send_reloading_done;
  104. uint32_t current_job_id;
  105. uint32_t default_unit_job_id;
  106. /* Data specific to the Automount subsystem */
  107. int dev_autofs_fd;
  108. /* Data specific to the cgroup subsystem */
  109. Hashmap *cgroup_unit;
  110. CGroupMask cgroup_supported;
  111. char *cgroup_root;
  112. /* Notifications from cgroups, when the unified hierarchy is used is done via inotify. */
  113. int cgroup_inotify_fd;
  114. sd_event_source *cgroup_inotify_event_source;
  115. /* Maps for finding the unit for each inotify watch descriptor for the cgroup.events and
  116. * memory.events cgroupv2 attributes. */
  117. Hashmap *cgroup_control_inotify_wd_unit;
  118. Hashmap *cgroup_memory_inotify_wd_unit;
  119. /* A defer event for handling cgroup empty events and processing them after SIGCHLD in all cases. */
  120. sd_event_source *cgroup_empty_event_source;
  121. sd_event_source *cgroup_oom_event_source;
  122. /* Make sure the user cannot accidentally unmount our cgroup
  123. * file system */
  124. int pin_cgroupfs_fd;
  125. unsigned gc_marker;
  126. /* The stat() data the last time we saw /etc/localtime */
  127. usec_t etc_localtime_mtime;
  128. bool etc_localtime_accessible:1;
  129. ManagerObjective objective:5; //= _MANAGER_OBJECTIVE_INVALID. setup by manager_new()
  130. /* Flags */
  131. bool dispatching_load_queue:1;
  132. bool taint_usr:1;
  133. /* Have we already sent out the READY=1 notification? */
  134. bool ready_sent:1;
  135. /* Have we already printed the taint line if necessary? */
  136. bool taint_logged:1;
  137. /* Have we ever changed the "kernel.pid_max" sysctl? */
  138. bool sysctl_pid_max_changed:1;
  139. ManagerTestRunFlags test_run_flags:8;
  140. /* If non-zero, exit with the following value when the systemd
  141. * process terminate. Useful for containers: systemd-nspawn could get
  142. * the return value. */
  143. uint8_t return_value;
  144. ShowStatus show_status;
  145. StatusUnitFormat status_unit_format; //= STATUS_UNIT_FORMAT_DEFAULT. setup by manager_new()
  146. char *confirm_spawn;
  147. bool no_console_output;
  148. bool service_watchdogs;
  149. ExecOutput default_std_output, default_std_error;
  150. usec_t default_restart_usec, default_timeout_start_usec, default_timeout_stop_usec;
  151. usec_t default_timeout_abort_usec;
  152. bool default_timeout_abort_set;
  153. usec_t default_start_limit_interval;
  154. unsigned default_start_limit_burst;
  155. bool default_cpu_accounting;
  156. bool default_memory_accounting;
  157. bool default_io_accounting;
  158. bool default_blockio_accounting;
  159. bool default_tasks_accounting;
  160. bool default_ip_accounting;
  161. uint64_t default_tasks_max;
  162. usec_t default_timer_accuracy_usec;
  163. OOMPolicy default_oom_policy;
  164. int original_log_level;
  165. LogTarget original_log_target;
  166. bool log_level_overridden:1;
  167. bool log_target_overridden:1;
  168. struct rlimit *rlimit[_RLIMIT_MAX];
  169. /* non-zero if we are reloading or reexecuting, */
  170. int n_reloading;
  171. unsigned n_installed_jobs;
  172. unsigned n_failed_jobs;
  173. /* Jobs in progress watching */
  174. unsigned n_running_jobs;
  175. unsigned n_on_console;
  176. unsigned jobs_in_progress_iteration;
  177. /* Do we have any outstanding password prompts? */
  178. int have_ask_password;
  179. int ask_password_inotify_fd;
  180. sd_event_source *ask_password_event_source;
  181. /* Type=idle pipes */
  182. int idle_pipe[4];
  183. sd_event_source *idle_pipe_event_source;
  184. char *switch_root;
  185. char *switch_root_init;
  186. /* This maps all possible path prefixes to the units needing
  187. * them. It's a hashmap with a path string as key and a Set as
  188. * value where Unit objects are contained. */
  189. Hashmap *units_requiring_mounts_for;
  190. /* Used for processing polkit authorization responses */
  191. Hashmap *polkit_registry;
  192. /* Dynamic users/groups, indexed by their name */
  193. Hashmap *dynamic_users;
  194. /* Keep track of all UIDs and GIDs any of our services currently use. This is useful for the RemoveIPC= logic. */
  195. Hashmap *uid_refs;
  196. Hashmap *gid_refs;
  197. /* ExecRuntime, indexed by their owner unit id */
  198. Hashmap *exec_runtime_by_id;
  199. /* When the user hits C-A-D more than 7 times per 2s, do something immediately... */
  200. RateLimit ctrl_alt_del_ratelimit;
  201. EmergencyAction cad_burst_action;
  202. const char *unit_log_field;
  203. const char *unit_log_format_string;
  204. const char *invocation_log_field;
  205. const char *invocation_log_format_string;
  206. int first_boot; /* tri-state */
  207. /* Prefixes of e.g. RuntimeDirectory= */
  208. char *prefix[_EXEC_DIRECTORY_TYPE_MAX];
  209. /* Used in the SIGCHLD and sd_notify() message invocation logic to avoid that we dispatch the same event
  210. * multiple times on the same unit. */
  211. unsigned sigchldgen;
  212. unsigned notifygen;
  213. bool honor_device_enumeration;
  214. };