HALF ECHO LEARN / REFERENCE COLLECTION
v262.2src/core/unit.h
Git blob: c07588ac1e94eeb89ad73e4215923fd2d8081056
Lines 1001–1279 of 1,279
bool unit_is_bound_by_inactive(Unit *u, Unit **ret_culprit);
PidRef* unit_control_pid(Unit *u);
PidRef* unit_main_pid_full(Unit *u, bool *ret_is_alien);
static inline PidRef* unit_main_pid(Unit *u) {
return unit_main_pid_full(u, NULL);
}
void unit_warn_if_dir_nonempty(Unit *u, const char* where);
int unit_log_noncanonical_mount_path(Unit *u, const char *where);
int unit_fail_if_noncanonical_mount_path(Unit *u, const char* where);
int unit_test_start_limit(Unit *u);
int unit_ref_uid_gid(Unit *u, uid_t uid, gid_t gid);
void unit_unref_uid_gid(Unit *u, bool destroy_now);
void unit_notify_user_lookup(Unit *u, uid_t uid, gid_t gid);
int unit_set_invocation_id(Unit *u, sd_id128_t id);
int unit_acquire_invocation_id(Unit *u);
int unit_set_exec_params(Unit *u, ExecParameters *p);
int unit_fork_helper_process_full(Unit *u, const char *name, bool into_cgroup, ForkFlags flags, PidRef *ret);
int unit_fork_helper_process(Unit *u, const char *name, bool into_cgroup, PidRef *ret);
int unit_fork_and_watch_rm_rf(Unit *u, char **paths, PidRef *ret);
void unit_remove_dependencies(Unit *u, UnitDependencyMask mask);
void unit_export_state_files(Unit *u);
void unit_unlink_state_files(Unit *u);
int unit_set_debug_invocation(Unit *u, bool enable);
int unit_prepare_exec(Unit *u);
int unit_warn_leftover_processes(Unit *u, bool start);
bool unit_needs_console(Unit *u);
int unit_pid_attachable(Unit *unit, PidRef *pid, sd_bus_error *reterr_error);
static inline bool unit_has_job_type(Unit *u, JobType type) {
return u && u->job && u->job->type == type;
}
int unit_get_log_level_max(const Unit *u);
bool unit_log_level_test(const Unit *u, int level);
/* unit_log_skip is for cases like ExecCondition= where a unit is considered "done"
* after some execution, rather than succeeded or failed. */
void unit_log_skip(Unit *u, const char *result);
void unit_log_success(Unit *u);
void unit_log_failure(Unit *u, const char *result);
static inline void unit_log_result(Unit *u, bool success, const char *result) {
if (success)
unit_log_success(u);
else
unit_log_failure(u, result);
}
void unit_log_process_exit(Unit *u, const char *kind, const char *command, bool success, int code, int status);
int unit_exit_status(Unit *u);
int unit_success_action_exit_status(Unit *u);
int unit_failure_action_exit_status(Unit *u);
int unit_test_trigger_loaded(Unit *u);
void unit_destroy_runtime_data(Unit *u, const ExecContext *context, bool destroy_runtime_dir);
int unit_clean(Unit *u, ExecCleanMask mask);
int unit_can_clean(Unit *u, ExecCleanMask *ret_mask);
bool unit_can_start_refuse_manual(Unit *u);
bool unit_can_stop_refuse_manual(Unit *u);
bool unit_can_isolate_refuse_manual(Unit *u);
bool unit_can_freeze(const Unit *u);
int unit_freezer_action(Unit *u, FreezerAction action);
void unit_next_freezer_state(Unit *u, FreezerAction action, FreezerState *ret_next, FreezerState *ret_objective);
void unit_set_freezer_state(Unit *u, FreezerState state);
void unit_freezer_complete(Unit *u, FreezerState kernel_state);
int unit_can_live_mount(Unit *u, sd_bus_error *reterr_error);
int unit_live_mount(
Unit *u,
const char *src,
const char *dst,
sd_bus_message *message,
MountInNamespaceFlags flags,
const MountOptions *options,
sd_bus_error *reterr_error);
Condition *unit_find_failed_condition(Unit *u);
int unit_arm_timer(Unit *u, sd_event_source **source, bool relative, usec_t usec, sd_event_time_handler_t handler);
bool unit_passes_filter(Unit *u, char * const *states, char * const *patterns);
int unit_compare_priority(Unit *a, Unit *b);
const char* unit_log_field(const Unit *u);
const char* unit_invocation_log_field(const Unit *u);
DECLARE_STRING_TABLE_LOOKUP(unit_mount_dependency_type, UnitMountDependencyType);
UnitDependency unit_mount_dependency_type_to_dependency_type(UnitMountDependencyType t) _pure_;
DECLARE_STRING_TABLE_LOOKUP(oom_policy, OOMPolicy);
int unit_queue_job_check_and_mangle_type(Unit *u, JobType *type, bool reload_if_possible, sd_bus_error *reterr_error);
int parse_unit_marker(const char *marker, unsigned *settings, unsigned *mask);
unsigned unit_normalize_markers(unsigned existing_markers, unsigned new_markers);
/* Trying to log with too many fields is going to fail. We need at least also MESSAGE=,
* but we generally log a few extra in most cases. So let's reserve 10. Anything
* above a few would be very unusual, but let's not be overly strict. */
#define LOG_EXTRA_FIELDS_MAX (ENTRY_FIELD_COUNT_MAX - 10)
/* Macros which append UNIT= or USER_UNIT= to the message */
#define log_unit_full_errno_zerook(unit, level, error, ...) \
({ \
const Unit *_u = (unit); \
const int _l = (level); \
LOG_CONTEXT_SET_LOG_LEVEL(unit_get_log_level_max(_u)); \
const ExecContext *_c = _u ? unit_get_exec_context(_u) : NULL; \
LOG_CONTEXT_PUSH_IOV(_c ? _c->log_extra_fields : NULL, \
_c ? _c->n_log_extra_fields : 0); \
_u ? log_object_internal(_l, error, PROJECT_FILE, __LINE__, __func__, unit_log_field(_u), _u->id, unit_invocation_log_field(_u), _u->invocation_id_string, ##__VA_ARGS__) : \
log_internal(_l, error, PROJECT_FILE, __LINE__, __func__, ##__VA_ARGS__); \
})
#define log_unit_full_errno(unit, level, error, ...) \
({ \
int _error = (error); \
ASSERT_NON_ZERO(_error); \
log_unit_full_errno_zerook(unit, level, _error, ##__VA_ARGS__); \
})
#define log_unit_full(unit, level, ...) (void) log_unit_full_errno_zerook(unit, level, 0, __VA_ARGS__)
#define log_unit_debug(unit, ...) log_unit_full(unit, LOG_DEBUG, __VA_ARGS__)
#define log_unit_info(unit, ...) log_unit_full(unit, LOG_INFO, __VA_ARGS__)
#define log_unit_notice(unit, ...) log_unit_full(unit, LOG_NOTICE, __VA_ARGS__)
#define log_unit_warning(unit, ...) log_unit_full(unit, LOG_WARNING, __VA_ARGS__)
#define log_unit_error(unit, ...) log_unit_full(unit, LOG_ERR, __VA_ARGS__)
#define log_unit_debug_errno(unit, error, ...) log_unit_full_errno(unit, LOG_DEBUG, error, __VA_ARGS__)
#define log_unit_info_errno(unit, error, ...) log_unit_full_errno(unit, LOG_INFO, error, __VA_ARGS__)
#define log_unit_notice_errno(unit, error, ...) log_unit_full_errno(unit, LOG_NOTICE, error, __VA_ARGS__)
#define log_unit_warning_errno(unit, error, ...) log_unit_full_errno(unit, LOG_WARNING, error, __VA_ARGS__)
#define log_unit_error_errno(unit, error, ...) log_unit_full_errno(unit, LOG_ERR, error, __VA_ARGS__)
#if LOG_TRACE
# define log_unit_trace(...) log_unit_debug(__VA_ARGS__)
# define log_unit_trace_errno(...) log_unit_debug_errno(__VA_ARGS__)
#else
# define log_unit_trace(...) do {} while (0)
# define log_unit_trace_errno(e, ...) (-ERRNO_VALUE(e))
#endif
#define log_unit_struct_errno(unit, level, error, ...) \
({ \
const Unit *_u = (unit); \
const int _l = (level); \
LOG_CONTEXT_SET_LOG_LEVEL(unit_get_log_level_max(_u)); \
const ExecContext *_c = _u ? unit_get_exec_context(_u) : NULL; \
LOG_CONTEXT_PUSH_IOV(_c ? _c->log_extra_fields : NULL, \
_c ? _c->n_log_extra_fields : 0); \
log_struct_errno(_l, error, __VA_ARGS__, LOG_UNIT_ID(_u)); \
})
#define log_unit_struct(unit, level, ...) log_unit_struct_errno(unit, level, 0, __VA_ARGS__)
#define log_unit_struct_iovec_errno(unit, level, error, iovec, n_iovec) \
({ \
const Unit *_u = (unit); \
const int _l = (level); \
LOG_CONTEXT_SET_LOG_LEVEL(unit_get_log_level_max(_u)); \
const ExecContext *_c = _u ? unit_get_exec_context(_u) : NULL; \
LOG_CONTEXT_PUSH_IOV(_c ? _c->log_extra_fields : NULL, \
_c ? _c->n_log_extra_fields : 0); \
log_struct_iovec_errno(_l, error, iovec, n_iovec); \
})
#define log_unit_struct_iovec(unit, level, iovec, n_iovec) log_unit_struct_iovec_errno(unit, level, 0, iovec, n_iovec)
/* Like LOG_MESSAGE(), but with the unit name prefixed. */
#define LOG_UNIT_MESSAGE(unit, fmt, ...) LOG_MESSAGE("%s: " fmt, (unit)->id, ##__VA_ARGS__)
#define LOG_UNIT_ID(unit) LOG_ITEM("%s%s", unit_log_field((unit)), (unit)->id)
#define LOG_UNIT_INVOCATION_ID(unit) LOG_ITEM("%s%s", unit_invocation_log_field((unit)), (unit)->invocation_id_string)
DECLARE_STRING_TABLE_LOOKUP(collect_mode, CollectMode);
typedef struct UnitForEachDependencyData {
/* Stores state for the FOREACH macro below for iterating through all deps that have any of the
* specified dependency atom bits set */
const Unit *unit;
UnitDependencyAtom match_atom;
Hashmap *by_type, *by_unit;
void *current_type;
Iterator by_type_iterator, by_unit_iterator;
Unit **current_unit;
uint64_t generation;
unsigned n_restart;
bool restart_on_generation_change;
} UnitForEachDependencyData;
/* Let's not restart the loop infinitely. */
#define MAX_FOREACH_DEPENDENCY_RESTART 100000
/* Iterates through all dependencies that have a specific atom in the dependency type set. This tries to be
* smart: if the atom is unique, we'll directly go to right entry. Otherwise we'll iterate through the
* per-dependency type hashmap and match all dep that have the right atom set. */
#define _UNIT_FOREACH_DEPENDENCY(other, u, ma, restart, data) \
for (UnitForEachDependencyData data = { \
.unit = (u), \
.match_atom = (ma), \
.current_unit = &(other), \
.restart_on_generation_change = (restart), \
}; \
({ \
UnitDependency _dt = _UNIT_DEPENDENCY_INVALID; \
bool _found; \
\
if (data.generation == 0 || \
(data.restart_on_generation_change && \
data.generation != data.unit->dependency_generation)) { \
data.generation = data.unit->dependency_generation; \
data.by_type = data.unit->dependencies; \
data.by_type_iterator = ITERATOR_FIRST; \
assert_se(data.n_restart++ < MAX_FOREACH_DEPENDENCY_RESTART); \
} else \
assert(data.generation == data.unit->dependency_generation); \
\
if (data.by_type && ITERATOR_IS_FIRST(data.by_type_iterator)) { \
_dt = unit_dependency_from_unique_atom(data.match_atom); \
if (_dt >= 0) { \
data.by_unit = hashmap_get(data.by_type, UNIT_DEPENDENCY_TO_PTR(_dt)); \
data.current_type = UNIT_DEPENDENCY_TO_PTR(_dt); \
data.by_type = NULL; \
_found = !!data.by_unit; \
} \
} \
if (_dt < 0) \
_found = hashmap_iterate(data.by_type, \
&data.by_type_iterator, \
(void**) &(data.by_unit), \
(const void**) &(data.current_type)); \
_found; \
}); ) \
if ((unit_dependency_to_atom(UNIT_DEPENDENCY_FROM_PTR(data.current_type)) & data.match_atom) != 0) \
for (data.by_unit_iterator = ITERATOR_FIRST; \
data.generation == data.unit->dependency_generation && \
hashmap_iterate(data.by_unit, \
&data.by_unit_iterator, \
NULL, \
(const void**) data.current_unit); )
/* Note: this matches deps that have *any* of the atoms specified in match_atom set */
#define UNIT_FOREACH_DEPENDENCY(other, u, match_atom) \
_UNIT_FOREACH_DEPENDENCY(other, u, match_atom, false, UNIQ_T(data, UNIQ))
#define UNIT_FOREACH_DEPENDENCY_SAFE(other, u, match_atom) \
_UNIT_FOREACH_DEPENDENCY(other, u, match_atom, true, UNIQ_T(data, UNIQ))
#define _LOG_CONTEXT_PUSH_UNIT(unit, u, c) \
const Unit *u = (unit); \
const ExecContext *c = unit_get_exec_context(u); \
LOG_CONTEXT_PUSH_KEY_VALUE(unit_log_field(u), u->id); \
LOG_CONTEXT_PUSH_KEY_VALUE(unit_invocation_log_field(u), u->invocation_id_string); \
LOG_CONTEXT_PUSH_IOV(c ? c->log_extra_fields : NULL, c ? c->n_log_extra_fields : 0); \
LOG_CONTEXT_SET_LOG_LEVEL(unit_get_log_level_max(u))
#define LOG_CONTEXT_PUSH_UNIT(unit) \
_LOG_CONTEXT_PUSH_UNIT(unit, UNIQ_T(u, UNIQ), UNIQ_T(c, UNIQ))