X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Flogin%2Flogind-user.c;h=f8b896552a34dba7983e6a019563d302a32adb90;hb=2027bfc6205de5f5313609fe0ca7e0649640219b;hp=ecc61080a322a6f321f723e6a222113d5bf6f0e1;hpb=da4b83e77bc603745cf4a365d7f013301ef7fa89;p=elogind.git diff --git a/src/login/logind-user.c b/src/login/logind-user.c index ecc61080a..f8b896552 100644 --- a/src/login/logind-user.c +++ b/src/login/logind-user.c @@ -1,5 +1,3 @@ -/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ - /*** This file is part of systemd. @@ -122,11 +120,11 @@ User *user_free(User *u) { hashmap_remove_value(u->manager->users, UID_TO_PTR(u->uid), u); -/// elogind neither supports slice nor service jobs. -#if 0 +#if 0 /// elogind neither supports slice nor service jobs. u->slice_job = mfree(u->slice_job); u->service_job = mfree(u->service_job); #endif // 0 + u->service = mfree(u->service); u->slice = mfree(u->slice); u->runtime_path = mfree(u->runtime_path); @@ -165,8 +163,7 @@ static int user_save_internal(User *u) { if (u->runtime_path) fprintf(f, "RUNTIME=%s\n", u->runtime_path); -/// elogind neither supports service nor slice jobs -#if 0 +#if 0 /// elogind neither supports service nor slice jobs if (u->service_job) fprintf(f, "SERVICE_JOB=%s\n", u->service_job); @@ -308,8 +305,7 @@ int user_load(User *u) { assert(u); r = parse_env_file(u->state_file, NEWLINE, -/// elogind neither supports service nor slice jobs -#if 0 +#if 0 /// elogind neither supports service nor slice jobs "SERVICE_JOB", &u->service_job, "SLICE_JOB", &u->slice_job, #endif // 0 @@ -331,17 +327,10 @@ int user_load(User *u) { if (s && s->display && display_is_local(s->display)) u->display = s; - if (realtime) { - unsigned long long l; - if (sscanf(realtime, "%llu", &l) > 0) - u->timestamp.realtime = l; - } - - if (monotonic) { - unsigned long long l; - if (sscanf(monotonic, "%llu", &l) > 0) - u->timestamp.monotonic = l; - } + if (realtime) + timestamp_deserialize(realtime, &u->timestamp.realtime); + if (monotonic) + timestamp_deserialize(monotonic, &u->timestamp.monotonic); return r; } @@ -395,15 +384,14 @@ static int user_mkdir_runtime_path(User *u) { return 0; fail: - /* Try to clean up, but ignore errors */ + /* Try to clean up, but ignore errors */ (void) rmdir(u->runtime_path); return r; } static int user_start_slice(User *u) { -/// elogind can not ask systemd via dbus to start user services -#if 0 - _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; +#if 0 /// elogind can not ask systemd via dbus to start user services + _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; const char *description; char *job; int r; @@ -422,13 +410,12 @@ static int user_start_slice(User *u) { u->manager->user_tasks_max, &error, &job); - if (r < 0) { + if (r >= 0) + u->slice_job = job; + else if (!sd_bus_error_has_name(&error, BUS_ERROR_UNIT_EXISTS)) /* we don't fail due to this, let's try to continue */ - if (!sd_bus_error_has_name(&error, BUS_ERROR_UNIT_EXISTS)) - log_error_errno(r, "Failed to start user slice %s, ignoring: %s (%s)", u->slice, bus_error_message(&error, r), error.name); - } else { - u->slice_job = job; - } + log_error_errno(r, "Failed to start user slice %s, ignoring: %s (%s)", + u->slice, bus_error_message(&error, r), error.name); #else assert(u); @@ -439,9 +426,8 @@ static int user_start_slice(User *u) { } static int user_start_service(User *u) { -/// elogind can not ask systemd via dbus to start user services -#if 0 - _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; +#if 0 /// elogind can not ask systemd via dbus to start user services + _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; char *job; int r; @@ -454,11 +440,11 @@ static int user_start_service(User *u) { u->service, &error, &job); - if (r < 0) { + if (r < 0) { /* we don't fail due to this, let's try to continue */ log_error_errno(r, "Failed to start user service, ignoring: %s", bus_error_message(&error, r)); - } else { - u->service_job = job; + } else { + u->service_job = job; } #else assert(u); @@ -530,10 +516,9 @@ int user_start(User *u) { return 0; } -/// UNNEEDED by elogind -#if 0 +#if 0 /// UNNEEDED by elogind static int user_stop_slice(User *u) { - _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; + _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; char *job; int r; @@ -552,7 +537,7 @@ static int user_stop_slice(User *u) { } static int user_stop_service(User *u) { - _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; + _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; char *job; int r; @@ -612,8 +597,7 @@ int user_stop(User *u, bool force) { } /* Kill systemd */ -/// elogind does not support service or slice jobs -#if 0 +#if 0 /// elogind does not support service or slice jobs k = user_stop_service(u); if (k < 0) r = k; @@ -730,8 +714,7 @@ bool user_check_gc(User *u, bool drop_not_started) { if (user_check_linger_file(u) > 0) return true; -/// elogind neither supports service nor slice jobs -#if 0 +#if 0 /// elogind neither supports service nor slice jobs if (u->slice_job && manager_job_is_active(u->manager, u->slice_job)) return true; @@ -760,8 +743,7 @@ UserState user_get_state(User *u) { if (u->stopping) return USER_CLOSING; -/// elogind neither supports service nor slice jobs. -#if 0 +#if 0 /// elogind neither supports service nor slice jobs. if (!u->started || u->slice_job || u->service_job) #else if (!u->started) @@ -791,8 +773,7 @@ UserState user_get_state(User *u) { } int user_kill(User *u, int signo) { -/// Without systemd unit support, elogind has to rely on its session system -#if 0 +#if 0 /// Without systemd unit support, elogind has to rely on its session system assert(u); return manager_kill_unit(u->manager, u->slice, KILL_ALL, signo, NULL); @@ -905,7 +886,6 @@ int config_parse_tmpfs_size( void *userdata) { size_t *sz = data; - const char *e; int r; assert(filename); @@ -913,29 +893,17 @@ int config_parse_tmpfs_size( assert(rvalue); assert(data); - e = endswith(rvalue, "%"); - if (e) { - unsigned long ul; - char *f; - - errno = 0; - ul = strtoul(rvalue, &f, 10); - if (errno != 0 || f != e) { - log_syntax(unit, LOG_ERR, filename, line, errno, "Failed to parse percentage value, ignoring: %s", rvalue); - return 0; - } - - if (ul <= 0 || ul >= 100) { - log_syntax(unit, LOG_ERR, filename, line, 0, "Percentage value out of range, ignoring: %s", rvalue); - return 0; - } - - *sz = PAGE_ALIGN((size_t) ((physical_memory() * (uint64_t) ul) / (uint64_t) 100)); - } else { + /* First, try to parse as percentage */ + r = parse_percent(rvalue); + if (r > 0 && r < 100) + *sz = physical_memory_scale(r, 100U); + else { uint64_t k; + /* If the passed argument was not a percentage, or out of range, parse as byte size */ + r = parse_size(rvalue, 1024, &k); - if (r < 0 || (uint64_t) (size_t) k != k) { + if (r < 0 || k <= 0 || (uint64_t) (size_t) k != k) { log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse size value, ignoring: %s", rvalue); return 0; }