type
stringclasses
5 values
content
stringlengths
9
163k
defines
#define ROMSTAGE_RAM_STACK_SIZE 0x5000
functions
void reset_system(void) { hard_reset(); halt(); }
functions
long choose_top_of_stack(void) { unsigned long stack_top; /* cbmem_add() does a find() before add(). */ stack_top = (unsigned long)cbmem_add(CBMEM_ID_ROMSTAGE_RAM_STACK, ROMSTAGE_RAM_STACK_SIZE); stack_top += ROMSTAGE_RAM_STACK_SIZE; return stack_top; }
functions
asmlinkage romstage_main(unsigned long bist) { int i; void *romstage_stack_after_car; const int num_guards = 4; const u32 stack_guard = 0xdeadbeef; u32 *stack_base = (void *)(CONFIG_DCACHE_RAM_BASE + CONFIG_DCACHE_RAM_SIZE - CONFIG_DCACHE_RAM_ROMSTAGE_STACK_SIZE); printk(BIOS_DEBUG, "Setting up stack guards.\n"); for (i = 0; i < num_guards; i++) stack_base[i] = stack_guard; mainboard_romstage_entry(bist); /* Check the stack. */ for (i = 0; i < num_guards; i++) { if (stack_base[i] == stack_guard) continue; printk(BIOS_DEBUG, "Smashed stack detected in romstage!\n"); }
functions
void romstage_common(const struct romstage_params *params) { int boot_mode; int wake_from_s3; struct romstage_handoff *handoff; timestamp_init(get_initial_timestamp()); timestamp_add_now(TS_START_ROMSTAGE); if (params->bist == 0) enable_lapic(); wake_from_s3 = early_pch_init(params->gpio_map, params->rcba_config); #if CONFIG_EC_GOOGLE_CHROMEEC /* Ensure the EC is in the right mode for recovery */ google_chromeec_early_init(); #endif /* Halt if there was a built in self test failure */ report_bist_failure(params->bist); /* Perform some early chipset initialization required * before RAM initialization can work */ haswell_early_initialization(HASWELL_MOBILE); printk(BIOS_DEBUG, "Back from haswell_early_initialization()\n"); if (wake_from_s3) { #if CONFIG_HAVE_ACPI_RESUME printk(BIOS_DEBUG, "Resume from S3 detected.\n"); #else printk(BIOS_DEBUG, "Resume from S3 detected, but disabled.\n"); wake_from_s3 = 0; #endif }
functions
void prepare_for_resume(struct romstage_handoff *handoff) { /* Only need to save memory when ramstage isn't relocatable. */ #if !CONFIG_RELOCATABLE_RAMSTAGE #if CONFIG_HAVE_ACPI_RESUME /* Back up the OS-controlled memory where ramstage will be loaded. */ if (handoff != NULL && handoff->s3_resume) { void *src = (void *)CONFIG_RAMBASE; void *dest = cbmem_find(CBMEM_ID_RESUME); if (dest != NULL) memcpy(dest, src, HIGH_MEMORY_SAVE); }
functions
void romstage_after_car(void) { struct romstage_handoff *handoff; handoff = romstage_handoff_find_or_add(); prepare_for_resume(handoff); /* Load the ramstage. */ copy_and_run(); }
functions
void stage_cache_external_region(void **base, size_t *size) { /* The ramstage cache lives in the TSEG region at RESERVED_SMM_OFFSET. * The top of ram is defined to be the TSEG base address. */ *size = RESERVED_SMM_SIZE; *base = (void *)((uint32_t)cbmem_top() + RESERVED_SMM_OFFSET); }
functions
void ramstage_cache_invalid(void) { #if CONFIG_RESET_ON_INVALID_RAMSTAGE_CACHE reset_system(); #endif }
structs
struct WMcursor { int unused; };
functions
void VGL_FreeWMCursor(_THIS, WMcursor *cursor) { return; }
functions
int VGL_ShowWMCursor(_THIS, WMcursor *cursor) { return(0); }
functions
void VGL_WarpWMCursor(_THIS, Uint16 x, Uint16 y) { SDL_PrivateMouseMotion(0, 0, x, y); }
includes
#include <errno.h>
includes
#include <stdlib.h>
includes
#include <string.h>
includes
#include <sys/stat.h>
includes
#include <unistd.h>
functions
bool unit_has_name(Unit *u, const char *name) { assert(u); assert(name); return !!set_get(u->names, (char*) name); }
functions
void unit_init(Unit *u) { CGroupContext *cc; ExecContext *ec; KillContext *kc; assert(u); assert(u->manager); assert(u->type >= 0); cc = unit_get_cgroup_context(u); if (cc) { cgroup_context_init(cc); /* Copy in the manager defaults into the cgroup * context, _before_ the rest of the settings have * been initialized */ cc->cpu_accounting = u->manager->default_cpu_accounting; cc->blockio_accounting = u->manager->default_blockio_accounting; cc->memory_accounting = u->manager->default_memory_accounting; cc->tasks_accounting = u->manager->default_tasks_accounting; }
functions
int unit_add_name(Unit *u, const char *text) { _cleanup_free_ char *s = NULL, *i = NULL; UnitType t; int r; assert(u); assert(text); if (unit_name_is_valid(text, UNIT_NAME_TEMPLATE)) { if (!u->instance) return -EINVAL; r = unit_name_replace_instance(text, u->instance, &s); if (r < 0) return r; }
functions
int unit_choose_id(Unit *u, const char *name) { _cleanup_free_ char *t = NULL; char *s, *i; int r; assert(u); assert(name); if (unit_name_is_valid(name, UNIT_NAME_TEMPLATE)) { if (!u->instance) return -EINVAL; r = unit_name_replace_instance(name, u->instance, &t); if (r < 0) return r; name = t; }
functions
int unit_set_description(Unit *u, const char *description) { char *s; assert(u); if (isempty(description)) s = NULL; else { s = strdup(description); if (!s) return -ENOMEM; }
functions
bool unit_check_gc(Unit *u) { UnitActiveState state; assert(u); if (u->job) return true; if (u->nop_job) return true; state = unit_active_state(u); /* If the unit is inactive and failed and no job is queued for * it, then release its runtime resources */ if (UNIT_IS_INACTIVE_OR_FAILED(state) && UNIT_VTABLE(u)->release_resources) UNIT_VTABLE(u)->release_resources(u); /* But we keep the unit object around for longer when it is * referenced or configured to not be gc'ed */ if (state != UNIT_INACTIVE) return true; if (UNIT_VTABLE(u)->no_gc) return true; if (u->no_gc) return true; if (u->refs) return true; if (UNIT_VTABLE(u)->check_gc) if (UNIT_VTABLE(u)->check_gc(u)) return true; return false; }
functions
void unit_add_to_load_queue(Unit *u) { assert(u); assert(u->type != _UNIT_TYPE_INVALID); if (u->load_state != UNIT_STUB || u->in_load_queue) return; LIST_PREPEND(load_queue, u->manager->load_queue, u); u->in_load_queue = true; }
functions
void unit_add_to_cleanup_queue(Unit *u) { assert(u); if (u->in_cleanup_queue) return; LIST_PREPEND(cleanup_queue, u->manager->cleanup_queue, u); u->in_cleanup_queue = true; }
functions
void unit_add_to_gc_queue(Unit *u) { assert(u); if (u->in_gc_queue || u->in_cleanup_queue) return; if (unit_check_gc(u)) return; LIST_PREPEND(gc_queue, u->manager->gc_queue, u); u->in_gc_queue = true; u->manager->n_in_gc_queue ++; }
functions
void unit_add_to_dbus_queue(Unit *u) { assert(u); assert(u->type != _UNIT_TYPE_INVALID); if (u->load_state == UNIT_STUB || u->in_dbus_queue) return; /* Shortcut things if nobody cares */ if (sd_bus_track_count(u->manager->subscribed) <= 0 && set_isempty(u->manager->private_buses)) { u->sent_dbus_new_signal = true; return; }
functions
void bidi_set_free(Unit *u, Set *s) { Iterator i; Unit *other; assert(u); /* Frees the set and makes sure we are dropped from the * inverse pointers */ SET_FOREACH(other, s, i) { UnitDependency d; for (d = 0; d < _UNIT_DEPENDENCY_MAX; d++) set_remove(other->dependencies[d], u); unit_add_to_gc_queue(other); }
functions
void unit_remove_transient(Unit *u) { char **i; assert(u); if (!u->transient) return; if (u->fragment_path) (void) unlink(u->fragment_path); STRV_FOREACH(i, u->dropin_paths) { _cleanup_free_ char *p = NULL; (void) unlink(*i); p = dirname_malloc(*i); if (p) (void) rmdir(p); }
functions
void unit_free_requires_mounts_for(Unit *u) { char **j; STRV_FOREACH(j, u->requires_mounts_for) { char s[strlen(*j) + 1]; PATH_FOREACH_PREFIX_MORE(s, *j) { char *y; Set *x; x = hashmap_get2(u->manager->units_requiring_mounts_for, s, (void**) &y); if (!x) continue; set_remove(x, u); if (set_isempty(x)) { hashmap_remove(u->manager->units_requiring_mounts_for, y); free(y); set_free(x); }
functions
void unit_done(Unit *u) { ExecContext *ec; CGroupContext *cc; int r; assert(u); if (u->type < 0) return; if (UNIT_VTABLE(u)->done) UNIT_VTABLE(u)->done(u); ec = unit_get_exec_context(u); if (ec) exec_context_done(ec); cc = unit_get_cgroup_context(u); if (cc) cgroup_context_done(cc); r = unit_remove_from_netclass_cgroup(u); if (r < 0) log_warning_errno(r, "Unable to remove unit from netclass group: %m"); }
functions
void unit_free(Unit *u) { UnitDependency d; Iterator i; char *t; assert(u); if (u->manager->n_reloading <= 0) unit_remove_transient(u); bus_unit_send_removed_signal(u); unit_done(u); sd_bus_slot_unref(u->match_bus_slot); unit_free_requires_mounts_for(u); SET_FOREACH(t, u->names, i) hashmap_remove_value(u->manager->units, t, u); if (u->job) { Job *j = u->job; job_uninstall(j); job_free(j); }
functions
UnitActiveState unit_active_state(Unit *u) { assert(u); if (u->load_state == UNIT_MERGED) return unit_active_state(unit_follow_merge(u)); /* After a reload it might happen that a unit is not correctly * loaded but still has a process around. That's why we won't * shortcut failed loading to UNIT_INACTIVE_FAILED. */ return UNIT_VTABLE(u)->active_state(u); }
functions
int complete_move(Set **s, Set **other) { int r; assert(s); assert(other); if (!*other) return 0; if (*s) { r = set_move(*s, *other); if (r < 0) return r; }
functions
int merge_names(Unit *u, Unit *other) { char *t; Iterator i; int r; assert(u); assert(other); r = complete_move(&u->names, &other->names); if (r < 0) return r; set_free_free(other->names); other->names = NULL; other->id = NULL; SET_FOREACH(t, u->names, i) assert_se(hashmap_replace(u->manager->units, t, u) == 0); return 0; }
functions
int reserve_dependencies(Unit *u, Unit *other, UnitDependency d) { unsigned n_reserve; assert(u); assert(other); assert(d < _UNIT_DEPENDENCY_MAX); /* * If u does not have this dependency set allocated, there is no need * to reserve anything. In that case other's set will be transferred * as a whole to u by complete_move(). */ if (!u->dependencies[d]) return 0; /* merge_dependencies() will skip a u-on-u dependency */ n_reserve = set_size(other->dependencies[d]) - !!set_get(other->dependencies[d], u); return set_reserve(u->dependencies[d], n_reserve); }
functions
void merge_dependencies(Unit *u, Unit *other, const char *other_id, UnitDependency d) { Iterator i; Unit *back; int r; assert(u); assert(other); assert(d < _UNIT_DEPENDENCY_MAX); /* Fix backwards pointers */ SET_FOREACH(back, other->dependencies[d], i) { UnitDependency k; for (k = 0; k < _UNIT_DEPENDENCY_MAX; k++) { /* Do not add dependencies between u and itself */ if (back == u) { if (set_remove(back->dependencies[k], other)) maybe_warn_about_dependency(u, other_id, k); }
functions
int unit_merge(Unit *u, Unit *other) { UnitDependency d; const char *other_id = NULL; int r; assert(u); assert(other); assert(u->manager == other->manager); assert(u->type != _UNIT_TYPE_INVALID); other = unit_follow_merge(other); if (other == u) return 0; if (u->type != other->type) return -EINVAL; if (!u->instance != !other->instance) return -EINVAL; if (other->load_state != UNIT_STUB && other->load_state != UNIT_NOT_FOUND) return -EEXIST; if (other->job) return -EEXIST; if (other->nop_job) return -EEXIST; if (!UNIT_IS_INACTIVE_OR_FAILED(unit_active_state(other))) return -EEXIST; if (other->id) other_id = strdupa(other->id); /* Make reservations to ensure merge_dependencies() won't fail */ for (d = 0; d < _UNIT_DEPENDENCY_MAX; d++) { r = reserve_dependencies(u, other, d); /* * We don't rollback reservations if we fail. We don't have * a way to undo reservations. A reservation is not a leak. */ if (r < 0) return r; }
functions
int unit_merge_by_name(Unit *u, const char *name) { Unit *other; int r; _cleanup_free_ char *s = NULL; assert(u); assert(name); if (unit_name_is_valid(name, UNIT_NAME_TEMPLATE)) { if (!u->instance) return -EINVAL; r = unit_name_replace_instance(name, u->instance, &s); if (r < 0) return r; name = s; }
functions
int unit_add_exec_dependencies(Unit *u, ExecContext *c) { int r; assert(u); assert(c); if (c->working_directory) { r = unit_require_mounts_for(u, c->working_directory); if (r < 0) return r; }
functions
void unit_dump(Unit *u, FILE *f, const char *prefix) { char *t, **j; UnitDependency d; Iterator i; const char *prefix2; char timestamp1[FORMAT_TIMESTAMP_MAX], timestamp2[FORMAT_TIMESTAMP_MAX], timestamp3[FORMAT_TIMESTAMP_MAX], timestamp4[FORMAT_TIMESTAMP_MAX], timespan[FORMAT_TIMESPAN_MAX]; Unit *following; _cleanup_set_free_ Set *following_set = NULL; int r; assert(u); assert(u->type >= 0); prefix = strempty(prefix); prefix2 = strjoina(prefix, "\t"); fprintf(f, "%s-> Unit %s:\n" "%s\tDescription: %s\n" "%s\tInstance: %s\n" "%s\tUnit Load State: %s\n" "%s\tUnit Active State: %s\n" "%s\tInactive Exit Timestamp: %s\n" "%s\tActive Enter Timestamp: %s\n" "%s\tActive Exit Timestamp: %s\n" "%s\tInactive Enter Timestamp: %s\n" "%s\tGC Check Good: %s\n" "%s\tNeed Daemon Reload: %s\n" "%s\tTransient: %s\n" "%s\tSlice: %s\n" "%s\tCGroup: %s\n" "%s\tCGroup realized: %s\n" "%s\tCGroup mask: 0x%x\n" "%s\tCGroup members mask: 0x%x\n", prefix, u->id, prefix, unit_description(u), prefix, strna(u->instance), prefix, unit_load_state_to_string(u->load_state), prefix, unit_active_state_to_string(unit_active_state(u)), prefix, strna(format_timestamp(timestamp1, sizeof(timestamp1), u->inactive_exit_timestamp.realtime)), prefix, strna(format_timestamp(timestamp2, sizeof(timestamp2), u->active_enter_timestamp.realtime)), prefix, strna(format_timestamp(timestamp3, sizeof(timestamp3), u->active_exit_timestamp.realtime)), prefix, strna(format_timestamp(timestamp4, sizeof(timestamp4), u->inactive_enter_timestamp.realtime)), prefix, yes_no(unit_check_gc(u)), prefix, yes_no(unit_need_daemon_reload(u)), prefix, yes_no(u->transient), prefix, strna(unit_slice_name(u)), prefix, strna(u->cgroup_path), prefix, yes_no(u->cgroup_realized), prefix, u->cgroup_realized_mask, prefix, u->cgroup_members_mask); SET_FOREACH(t, u->names, i) fprintf(f, "%s\tName: %s\n", prefix, t); STRV_FOREACH(j, u->documentation) fprintf(f, "%s\tDocumentation: %s\n", prefix, *j); following = unit_following(u); if (following) fprintf(f, "%s\tFollowing: %s\n", prefix, following->id); r = unit_following_set(u, &following_set); if (r >= 0) { Unit *other; SET_FOREACH(other, following_set, i) fprintf(f, "%s\tFollowing Set Member: %s\n", prefix, other->id); }
functions
int unit_load_fragment_and_dropin(Unit *u) { int r; assert(u); /* Load a .{service,socket,...}
functions
int unit_load_fragment_and_dropin_optional(Unit *u) { int r; assert(u); /* Same as unit_load_fragment_and_dropin(), but whether * something can be loaded or not doesn't matter. */ /* Load a .service file */ r = unit_load_fragment(u); if (r < 0) return r; if (u->load_state == UNIT_STUB) u->load_state = UNIT_LOADED; /* Load drop-in directory data */ r = unit_load_dropin(unit_follow_merge(u)); if (r < 0) return r; return 0; }
functions
int unit_add_default_target_dependency(Unit *u, Unit *target) { assert(u); assert(target); if (target->type != UNIT_TARGET) return 0; /* Only add the dependency if both units are loaded, so that * that loop check below is reliable */ if (u->load_state != UNIT_LOADED || target->load_state != UNIT_LOADED) return 0; /* If either side wants no automatic dependencies, then let's * skip this */ if (!u->default_dependencies || !target->default_dependencies) return 0; /* Don't create loops */ if (set_get(target->dependencies[UNIT_BEFORE], u)) return 0; return unit_add_dependency(target, UNIT_AFTER, u, true); }
functions
int unit_add_target_dependencies(Unit *u) { static const UnitDependency deps[] = { UNIT_REQUIRED_BY, UNIT_REQUISITE_OF, UNIT_WANTED_BY, UNIT_BOUND_BY }
functions
int unit_add_slice_dependencies(Unit *u) { assert(u); if (!UNIT_HAS_CGROUP_CONTEXT(u)) return 0; if (UNIT_ISSET(u->slice)) return unit_add_two_dependencies(u, UNIT_AFTER, UNIT_REQUIRES, UNIT_DEREF(u->slice), true); if (unit_has_name(u, SPECIAL_ROOT_SLICE)) return 0; return unit_add_two_dependencies_by_name(u, UNIT_AFTER, UNIT_REQUIRES, SPECIAL_ROOT_SLICE, NULL, true); }
functions
int unit_add_mount_dependencies(Unit *u) { char **i; int r; assert(u); STRV_FOREACH(i, u->requires_mounts_for) { char prefix[strlen(*i) + 1]; PATH_FOREACH_PREFIX_MORE(prefix, *i) { _cleanup_free_ char *p = NULL; Unit *m; r = unit_name_from_path(prefix, ".mount", &p); if (r < 0) return r; m = manager_get_unit(u->manager, p); if (!m) { /* Make sure to load the mount unit if * it exists. If so the dependencies * on this unit will be added later * during the loading of the mount * unit. */ (void) manager_load_unit_prepare(u->manager, p, NULL, NULL, &m); continue; }
functions
int unit_add_startup_units(Unit *u) { CGroupContext *c; int r; c = unit_get_cgroup_context(u); if (!c) return 0; if (c->startup_cpu_shares == CGROUP_CPU_SHARES_INVALID && c->startup_blockio_weight == CGROUP_BLKIO_WEIGHT_INVALID) return 0; r = set_ensure_allocated(&u->manager->startup_units, NULL); if (r < 0) return r; return set_put(u->manager->startup_units, u); }
functions
int unit_load(Unit *u) { int r; assert(u); if (u->in_load_queue) { LIST_REMOVE(load_queue, u->manager->load_queue, u); u->in_load_queue = false; }
functions
bool unit_condition_test(Unit *u) { assert(u); dual_timestamp_get(&u->condition_timestamp); u->condition_result = unit_condition_test_list(u, u->conditions, condition_type_to_string); return u->condition_result; }
functions
bool unit_assert_test(Unit *u) { assert(u); dual_timestamp_get(&u->assert_timestamp); u->assert_result = unit_condition_test_list(u, u->asserts, assert_type_to_string); return u->assert_result; }
functions
void unit_status_print_starting_stopping(Unit *u, JobType t) { const char *format; assert(u); format = unit_get_status_message_format(u, t); DISABLE_WARNING_FORMAT_NONLITERAL; unit_status_printf(u, "", format); REENABLE_WARNING; }
functions
void unit_status_log_starting_stopping_reloading(Unit *u, JobType t) { const char *format; char buf[LINE_MAX]; sd_id128_t mid; assert(u); if (t != JOB_START && t != JOB_STOP && t != JOB_RELOAD) return; if (log_on_console()) return; /* We log status messages for all units and all operations. */ format = unit_get_status_message_format(u, t); DISABLE_WARNING_FORMAT_NONLITERAL; snprintf(buf, sizeof(buf), format, unit_description(u)); REENABLE_WARNING; mid = t == JOB_START ? SD_MESSAGE_UNIT_STARTING : t == JOB_STOP ? SD_MESSAGE_UNIT_STOPPING : SD_MESSAGE_UNIT_RELOADING; /* Note that we deliberately use LOG_MESSAGE() instead of * LOG_UNIT_MESSAGE() here, since this is supposed to mimic * closely what is written to screen using the status output, * which is supposed the highest level, friendliest output * possible, which means we should avoid the low-level unit * name. */ log_struct(LOG_INFO, LOG_MESSAGE_ID(mid), LOG_UNIT_ID(u), LOG_MESSAGE("%s", buf), NULL); }
functions
void unit_status_emit_starting_stopping_reloading(Unit *u, JobType t) { unit_status_log_starting_stopping_reloading(u, t); /* Reload status messages have traditionally not been printed to console. */ if (t != JOB_RELOAD) unit_status_print_starting_stopping(u, t); }
functions
int unit_start(Unit *u) { UnitActiveState state; Unit *following; assert(u); /* Units that aren't loaded cannot be started */ if (u->load_state != UNIT_LOADED) return -EINVAL; /* If this is already started, then this will succeed. Note * that this will even succeed if this unit is not startable * by the user. This is relied on to detect when we need to * wait for units and when waiting is finished. */ state = unit_active_state(u); if (UNIT_IS_ACTIVE_OR_RELOADING(state)) return -EALREADY; /* If the conditions failed, don't do anything at all. If we * already are activating this call might still be useful to * speed up activation in case there is some hold-off time, * but we don't want to recheck the condition in that case. */ if (state != UNIT_ACTIVATING && !unit_condition_test(u)) { log_unit_debug(u, "Starting requested but condition failed. Not starting unit."); return -EALREADY; }
functions
bool unit_can_start(Unit *u) { assert(u); if (u->load_state != UNIT_LOADED) return false; if (!unit_supported(u)) return false; return !!UNIT_VTABLE(u)->start; }
functions
bool unit_can_isolate(Unit *u) { assert(u); return unit_can_start(u) && u->allow_isolate; }
functions
int unit_stop(Unit *u) { UnitActiveState state; Unit *following; assert(u); state = unit_active_state(u); if (UNIT_IS_INACTIVE_OR_FAILED(state)) return -EALREADY; following = unit_following(u); if (following) { log_unit_debug(u, "Redirecting stop request from %s to %s.", u->id, following->id); return unit_stop(following); }
functions
int unit_reload(Unit *u) { UnitActiveState state; Unit *following; assert(u); if (u->load_state != UNIT_LOADED) return -EINVAL; if (!unit_can_reload(u)) return -EBADR; state = unit_active_state(u); if (state == UNIT_RELOADING) return -EALREADY; if (state != UNIT_ACTIVE) { log_unit_warning(u, "Unit cannot be reloaded because it is inactive."); return -ENOEXEC; }
functions
bool unit_can_reload(Unit *u) { assert(u); if (!UNIT_VTABLE(u)->reload) return false; if (!UNIT_VTABLE(u)->can_reload) return true; return UNIT_VTABLE(u)->can_reload(u); }
functions
void unit_check_unneeded(Unit *u) { _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; static const UnitDependency needed_dependencies[] = { UNIT_REQUIRED_BY, UNIT_REQUISITE_OF, UNIT_WANTED_BY, UNIT_BOUND_BY, }
functions
void unit_check_binds_to(Unit *u) { _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; bool stop = false; Unit *other; Iterator i; int r; assert(u); if (u->job) return; if (unit_active_state(u) != UNIT_ACTIVE) return; SET_FOREACH(other, u->dependencies[UNIT_BINDS_TO], i) { if (other->job) continue; if (!UNIT_IS_INACTIVE_OR_FAILED(unit_active_state(other))) continue; stop = true; break; }
functions
void retroactively_start_dependencies(Unit *u) { Iterator i; Unit *other; assert(u); assert(UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(u))); SET_FOREACH(other, u->dependencies[UNIT_REQUIRES], i) if (!set_get(u->dependencies[UNIT_AFTER], other) && !UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(other))) manager_add_job(u->manager, JOB_START, other, JOB_REPLACE, NULL, NULL); SET_FOREACH(other, u->dependencies[UNIT_BINDS_TO], i) if (!set_get(u->dependencies[UNIT_AFTER], other) && !UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(other))) manager_add_job(u->manager, JOB_START, other, JOB_REPLACE, NULL, NULL); SET_FOREACH(other, u->dependencies[UNIT_WANTS], i) if (!set_get(u->dependencies[UNIT_AFTER], other) && !UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(other))) manager_add_job(u->manager, JOB_START, other, JOB_FAIL, NULL, NULL); SET_FOREACH(other, u->dependencies[UNIT_CONFLICTS], i) if (!UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(other))) manager_add_job(u->manager, JOB_STOP, other, JOB_REPLACE, NULL, NULL); SET_FOREACH(other, u->dependencies[UNIT_CONFLICTED_BY], i) if (!UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(other))) manager_add_job(u->manager, JOB_STOP, other, JOB_REPLACE, NULL, NULL); }
functions
void retroactively_stop_dependencies(Unit *u) { Iterator i; Unit *other; assert(u); assert(UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(u))); /* Pull down units which are bound to us recursively if enabled */ SET_FOREACH(other, u->dependencies[UNIT_BOUND_BY], i) if (!UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(other))) manager_add_job(u->manager, JOB_STOP, other, JOB_REPLACE, NULL, NULL); }
functions
void check_unneeded_dependencies(Unit *u) { Iterator i; Unit *other; assert(u); assert(UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(u))); /* Garbage collect services that might not be needed anymore, if enabled */ SET_FOREACH(other, u->dependencies[UNIT_REQUIRES], i) if (!UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(other))) unit_check_unneeded(other); SET_FOREACH(other, u->dependencies[UNIT_WANTS], i) if (!UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(other))) unit_check_unneeded(other); SET_FOREACH(other, u->dependencies[UNIT_REQUISITE], i) if (!UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(other))) unit_check_unneeded(other); SET_FOREACH(other, u->dependencies[UNIT_BINDS_TO], i) if (!UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(other))) unit_check_unneeded(other); }
functions
void unit_start_on_failure(Unit *u) { Unit *other; Iterator i; assert(u); if (set_size(u->dependencies[UNIT_ON_FAILURE]) <= 0) return; log_unit_info(u, "Triggering OnFailure= dependencies."); SET_FOREACH(other, u->dependencies[UNIT_ON_FAILURE], i) { int r; r = manager_add_job(u->manager, JOB_START, other, u->on_failure_job_mode, NULL, NULL); if (r < 0) log_unit_error_errno(u, r, "Failed to enqueue OnFailure= job: %m"); }
functions
void unit_trigger_notify(Unit *u) { Unit *other; Iterator i; assert(u); SET_FOREACH(other, u->dependencies[UNIT_TRIGGERED_BY], i) if (UNIT_VTABLE(other)->trigger_notify) UNIT_VTABLE(other)->trigger_notify(other, u); }
functions
void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, bool reload_success) { Manager *m; bool unexpected; assert(u); assert(os < _UNIT_ACTIVE_STATE_MAX); assert(ns < _UNIT_ACTIVE_STATE_MAX); /* Note that this is called for all low-level state changes, * even if they might map to the same high-level * UnitActiveState! That means that ns == os is an expected * behavior here. For example: if a mount point is remounted * this function will be called too! */ m = u->manager; /* Update timestamps for state changes */ if (m->n_reloading <= 0) { dual_timestamp ts; dual_timestamp_get(&ts); if (UNIT_IS_INACTIVE_OR_FAILED(os) && !UNIT_IS_INACTIVE_OR_FAILED(ns)) u->inactive_exit_timestamp = ts; else if (!UNIT_IS_INACTIVE_OR_FAILED(os) && UNIT_IS_INACTIVE_OR_FAILED(ns)) u->inactive_enter_timestamp = ts; if (!UNIT_IS_ACTIVE_OR_RELOADING(os) && UNIT_IS_ACTIVE_OR_RELOADING(ns)) u->active_enter_timestamp = ts; else if (UNIT_IS_ACTIVE_OR_RELOADING(os) && !UNIT_IS_ACTIVE_OR_RELOADING(ns)) u->active_exit_timestamp = ts; }
functions
else if (u->job->state == JOB_RUNNING && ns != UNIT_ACTIVATING) { unexpected = true; if (UNIT_IS_INACTIVE_OR_FAILED(ns)) job_finish_and_invalidate(u->job, ns == UNIT_FAILED ? JOB_FAILED : JOB_DONE, true); }
functions
else if (ns != UNIT_ACTIVATING && ns != UNIT_RELOADING) { unexpected = true; if (UNIT_IS_INACTIVE_OR_FAILED(ns)) job_finish_and_invalidate(u->job, ns == UNIT_FAILED ? JOB_FAILED : JOB_DONE, true); }
functions
else if (u->job->state == JOB_RUNNING && ns != UNIT_DEACTIVATING) { unexpected = true; job_finish_and_invalidate(u->job, JOB_FAILED, true); }
functions
int unit_watch_pid(Unit *u, pid_t pid) { int q, r; assert(u); assert(pid >= 1); /* Watch a specific PID. We only support one or two units * watching each PID for now, not more. */ r = set_ensure_allocated(&u->pids, NULL); if (r < 0) return r; r = hashmap_ensure_allocated(&u->manager->watch_pids1, NULL); if (r < 0) return r; r = hashmap_put(u->manager->watch_pids1, PID_TO_PTR(pid), u); if (r == -EEXIST) { r = hashmap_ensure_allocated(&u->manager->watch_pids2, NULL); if (r < 0) return r; r = hashmap_put(u->manager->watch_pids2, PID_TO_PTR(pid), u); }
functions
void unit_unwatch_pid(Unit *u, pid_t pid) { assert(u); assert(pid >= 1); (void) hashmap_remove_value(u->manager->watch_pids1, PID_TO_PTR(pid), u); (void) hashmap_remove_value(u->manager->watch_pids2, PID_TO_PTR(pid), u); (void) set_remove(u->pids, PID_TO_PTR(pid)); }
functions
void unit_unwatch_all_pids(Unit *u) { assert(u); while (!set_isempty(u->pids)) unit_unwatch_pid(u, PTR_TO_PID(set_first(u->pids))); u->pids = set_free(u->pids); }
functions
void unit_tidy_watch_pids(Unit *u, pid_t except1, pid_t except2) { Iterator i; void *e; assert(u); /* Cleans dead PIDs from our list */ SET_FOREACH(e, u->pids, i) { pid_t pid = PTR_TO_PID(e); if (pid == except1 || pid == except2) continue; if (!pid_is_unwaited(pid)) unit_unwatch_pid(u, pid); }
functions
bool unit_job_is_applicable(Unit *u, JobType j) { assert(u); assert(j >= 0 && j < _JOB_TYPE_MAX); switch (j) { case JOB_VERIFY_ACTIVE: case JOB_START: case JOB_STOP: case JOB_NOP: return true; case JOB_RESTART: case JOB_TRY_RESTART: return unit_can_start(u); case JOB_RELOAD: return unit_can_reload(u); case JOB_RELOAD_OR_START: return unit_can_reload(u) && unit_can_start(u); default: assert_not_reached("Invalid job type"); }
functions
void maybe_warn_about_dependency(Unit *u, const char *other, UnitDependency dependency) { assert(u); /* Only warn about some unit types */ if (!IN_SET(dependency, UNIT_CONFLICTS, UNIT_CONFLICTED_BY, UNIT_BEFORE, UNIT_AFTER, UNIT_ON_FAILURE, UNIT_TRIGGERS, UNIT_TRIGGERED_BY)) return; if (streq_ptr(u->id, other)) log_unit_warning(u, "Dependency %s=%s dropped", unit_dependency_to_string(dependency), u->id); else log_unit_warning(u, "Dependency %s=%s dropped, merged into %s", unit_dependency_to_string(dependency), strna(other), u->id); }
functions
int unit_add_dependency(Unit *u, UnitDependency d, Unit *other, bool add_reference) { static const UnitDependency inverse_table[_UNIT_DEPENDENCY_MAX] = { [UNIT_REQUIRES] = UNIT_REQUIRED_BY, [UNIT_WANTS] = UNIT_WANTED_BY, [UNIT_REQUISITE] = UNIT_REQUISITE_OF, [UNIT_BINDS_TO] = UNIT_BOUND_BY, [UNIT_PART_OF] = UNIT_CONSISTS_OF, [UNIT_REQUIRED_BY] = UNIT_REQUIRES, [UNIT_REQUISITE_OF] = UNIT_REQUISITE, [UNIT_WANTED_BY] = UNIT_WANTS, [UNIT_BOUND_BY] = UNIT_BINDS_TO, [UNIT_CONSISTS_OF] = UNIT_PART_OF, [UNIT_CONFLICTS] = UNIT_CONFLICTED_BY, [UNIT_CONFLICTED_BY] = UNIT_CONFLICTS, [UNIT_BEFORE] = UNIT_AFTER, [UNIT_AFTER] = UNIT_BEFORE, [UNIT_ON_FAILURE] = _UNIT_DEPENDENCY_INVALID, [UNIT_REFERENCES] = UNIT_REFERENCED_BY, [UNIT_REFERENCED_BY] = UNIT_REFERENCES, [UNIT_TRIGGERS] = UNIT_TRIGGERED_BY, [UNIT_TRIGGERED_BY] = UNIT_TRIGGERS, [UNIT_PROPAGATES_RELOAD_TO] = UNIT_RELOAD_PROPAGATED_FROM, [UNIT_RELOAD_PROPAGATED_FROM] = UNIT_PROPAGATES_RELOAD_TO, [UNIT_JOINS_NAMESPACE_OF] = UNIT_JOINS_NAMESPACE_OF, }
functions
int unit_add_two_dependencies(Unit *u, UnitDependency d, UnitDependency e, Unit *other, bool add_reference) { int r; assert(u); r = unit_add_dependency(u, d, other, add_reference); if (r < 0) return r; return unit_add_dependency(u, e, other, add_reference); }
functions
int resolve_template(Unit *u, const char *name, const char*path, char **buf, const char **ret) { int r; assert(u); assert(name || path); assert(buf); assert(ret); if (!name) name = basename(path); if (!unit_name_is_valid(name, UNIT_NAME_TEMPLATE)) { *buf = NULL; *ret = name; return 0; }
functions
int unit_add_dependency_by_name(Unit *u, UnitDependency d, const char *name, const char *path, bool add_reference) { _cleanup_free_ char *buf = NULL; Unit *other; int r; assert(u); assert(name || path); r = resolve_template(u, name, path, &buf, &name); if (r < 0) return r; r = manager_load_unit(u->manager, name, path, NULL, &other); if (r < 0) return r; return unit_add_dependency(u, d, other, add_reference); }
functions
int unit_add_two_dependencies_by_name(Unit *u, UnitDependency d, UnitDependency e, const char *name, const char *path, bool add_reference) { _cleanup_free_ char *buf = NULL; Unit *other; int r; assert(u); assert(name || path); r = resolve_template(u, name, path, &buf, &name); if (r < 0) return r; r = manager_load_unit(u->manager, name, path, NULL, &other); if (r < 0) return r; return unit_add_two_dependencies(u, d, e, other, add_reference); }
functions
int set_unit_path(const char *p) { /* This is mostly for debug purposes */ if (setenv("SYSTEMD_UNIT_PATH", p, 1) < 0) return -errno; return 0; }
functions
int unit_set_slice(Unit *u, Unit *slice) { assert(u); assert(slice); /* Sets the unit slice if it has not been set before. Is extra * careful, to only allow this for units that actually have a * cgroup context. Also, we don't allow to set this for slices * (since the parent slice is derived from the name). Make * sure the unit we set is actually a slice. */ if (!UNIT_HAS_CGROUP_CONTEXT(u)) return -EOPNOTSUPP; if (u->type == UNIT_SLICE) return -EINVAL; if (unit_active_state(u) != UNIT_INACTIVE) return -EBUSY; if (slice->type != UNIT_SLICE) return -EINVAL; if (unit_has_name(u, SPECIAL_INIT_SCOPE) && !unit_has_name(slice, SPECIAL_ROOT_SLICE)) return -EPERM; if (UNIT_DEREF(u->slice) == slice) return 0; if (UNIT_ISSET(u->slice)) return -EBUSY; unit_ref_set(&u->slice, slice); return 1; }
functions
int unit_set_default_slice(Unit *u) { _cleanup_free_ char *b = NULL; const char *slice_name; Unit *slice; int r; assert(u); if (UNIT_ISSET(u->slice)) return 0; if (u->instance) { _cleanup_free_ char *prefix = NULL, *escaped = NULL; /* Implicitly place all instantiated units in their * own per-template slice */ r = unit_name_to_prefix(u->id, &prefix); if (r < 0) return r; /* The prefix is already escaped, but it might include * "-" which has a special meaning for slice units, * hence escape it here extra. */ escaped = unit_name_escape(prefix); if (!escaped) return -ENOMEM; if (u->manager->running_as == MANAGER_SYSTEM) b = strjoin("system-", escaped, ".slice", NULL); else b = strappend(escaped, ".slice"); if (!b) return -ENOMEM; slice_name = b; }
functions
int unit_load_related_unit(Unit *u, const char *type, Unit **_found) { _cleanup_free_ char *t = NULL; int r; assert(u); assert(type); assert(_found); r = unit_name_change_suffix(u->id, type, &t); if (r < 0) return r; if (unit_has_name(u, t)) return -EINVAL; r = manager_load_unit(u->manager, t, NULL, NULL, _found); assert(r < 0 || *_found != u); return r; }
functions
int signal_name_owner_changed(sd_bus_message *message, void *userdata, sd_bus_error *error) { const char *name, *old_owner, *new_owner; Unit *u = userdata; int r; assert(message); assert(u); r = sd_bus_message_read(message, "sss", &name, &old_owner, &new_owner); if (r < 0) { bus_log_parse_error(r); return 0; }
functions
int unit_install_bus_match(Unit *u, sd_bus *bus, const char *name) { const char *match; assert(u); assert(bus); assert(name); if (u->match_bus_slot) return -EBUSY; match = strjoina("type='signal'," "sender='org.freedesktop.DBus'," "path='/org/freedesktop/DBus'," "interface='org.freedesktop.DBus'," "member='NameOwnerChanged'," "arg0='", name, "'", NULL); return sd_bus_add_match(bus, &u->match_bus_slot, match, signal_name_owner_changed, u); }
functions
int unit_watch_bus_name(Unit *u, const char *name) { int r; assert(u); assert(name); /* Watch a specific name on the bus. We only support one unit * watching each name for now. */ if (u->manager->api_bus) { /* If the bus is already available, install the match directly. * Otherwise, just put the name in the list. bus_setup_api() will take care later. */ r = unit_install_bus_match(u, u->manager->api_bus, name); if (r < 0) return log_warning_errno(r, "Failed to subscribe to NameOwnerChanged signal for '%s': %m", name); }
functions
void unit_unwatch_bus_name(Unit *u, const char *name) { assert(u); assert(name); hashmap_remove_value(u->manager->watch_bus, name, u); u->match_bus_slot = sd_bus_slot_unref(u->match_bus_slot); }
functions
bool unit_can_serialize(Unit *u) { assert(u); return UNIT_VTABLE(u)->serialize && UNIT_VTABLE(u)->deserialize_item; }
functions
int unit_serialize(Unit *u, FILE *f, FDSet *fds, bool serialize_jobs) { int r; assert(u); assert(f); assert(fds); if (unit_can_serialize(u)) { ExecRuntime *rt; r = UNIT_VTABLE(u)->serialize(u, f, fds); if (r < 0) return r; rt = unit_get_exec_runtime(u); if (rt) { r = exec_runtime_serialize(u, rt, f, fds); if (r < 0) return r; }
functions
int unit_serialize_item(Unit *u, FILE *f, const char *key, const char *value) { assert(u); assert(f); assert(key); if (!value) return 0; fputs(key, f); fputc('=', f); fputs(value, f); fputc('\n', f); return 1; }
functions
int unit_serialize_item_escaped(Unit *u, FILE *f, const char *key, const char *value) { _cleanup_free_ char *c = NULL; assert(u); assert(f); assert(key); if (!value) return 0; c = cescape(value); if (!c) return -ENOMEM; fputs(key, f); fputc('=', f); fputs(c, f); fputc('\n', f); return 1; }
functions
int unit_serialize_item_fd(Unit *u, FILE *f, FDSet *fds, const char *key, int fd) { int copy; assert(u); assert(f); assert(key); if (fd < 0) return 0; copy = fdset_put_dup(fds, fd); if (copy < 0) return copy; fprintf(f, "%s=%i\n", key, copy); return 1; }
functions
void unit_serialize_item_format(Unit *u, FILE *f, const char *key, const char *format, ...) { va_list ap; assert(u); assert(f); assert(key); assert(format); fputs(key, f); fputc('=', f); va_start(ap, format); vfprintf(f, format, ap); va_end(ap); fputc('\n', f); }
functions
int unit_deserialize(Unit *u, FILE *f, FDSet *fds) { ExecRuntime **rt = NULL; size_t offset; int r; assert(u); assert(f); assert(fds); offset = UNIT_VTABLE(u)->exec_runtime_offset; if (offset > 0) rt = (ExecRuntime**) ((uint8_t*) u + offset); for (;;) { char line[LINE_MAX], *l, *v; size_t k; if (!fgets(line, sizeof(line), f)) { if (feof(f)) return 0; return -errno; }
functions
int unit_add_node_link(Unit *u, const char *what, bool wants) { Unit *device; _cleanup_free_ char *e = NULL; int r; assert(u); /* Adds in links to the device node that this unit is based on */ if (isempty(what)) return 0; if (!is_device_path(what)) return 0; /* When device units aren't supported (such as in a * container), don't create dependencies on them. */ if (!unit_type_supported(UNIT_DEVICE)) return 0; r = unit_name_from_path(what, ".device", &e); if (r < 0) return r; r = manager_load_unit(u->manager, e, NULL, NULL, &device); if (r < 0) return r; r = unit_add_two_dependencies(u, UNIT_AFTER, u->manager->running_as == MANAGER_SYSTEM ? UNIT_BINDS_TO : UNIT_WANTS, device, true); if (r < 0) return r; if (wants) { r = unit_add_dependency(device, UNIT_WANTS, u, false); if (r < 0) return r; }
functions
int unit_coldplug(Unit *u) { int r = 0, q = 0; assert(u); /* Make sure we don't enter a loop, when coldplugging * recursively. */ if (u->coldplugged) return 0; u->coldplugged = true; if (UNIT_VTABLE(u)->coldplug) r = UNIT_VTABLE(u)->coldplug(u); if (u->job) q = job_coldplug(u->job); if (r < 0) return r; if (q < 0) return q; return 0; }