X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Flogin%2Flogind-user.c;h=4af0e90c2232d36d9c790085151d5765166eb09f;hb=020d59000f86b3d98be763eaee6a2671f0427e46;hp=441e0860d9500f1e658ed5f566c6bc93863194e6;hpb=63966da86d8e71b1f3f2b57d5448770d526421f9;p=elogind.git diff --git a/src/login/logind-user.c b/src/login/logind-user.c index 441e0860d..4af0e90c2 100644 --- a/src/login/logind-user.c +++ b/src/login/logind-user.c @@ -145,10 +145,10 @@ int user_save(User *u) { if (dual_timestamp_is_set(&u->timestamp)) fprintf(f, - "REALTIME=%llu\n" - "MONOTONIC=%llu\n", - (unsigned long long) u->timestamp.realtime, - (unsigned long long) u->timestamp.monotonic); + "REALTIME="USEC_FMT"\n" + "MONOTONIC="USEC_FMT"\n", + u->timestamp.realtime, + u->timestamp.monotonic); if (u->sessions) { Session *i; @@ -247,7 +247,7 @@ int user_save(User *u) { finish: if (r < 0) - log_error("Failed to save user data for %s: %s", u->name, strerror(-r)); + log_error("Failed to save user data %s: %s", u->state_file, strerror(-r)); return r; } @@ -494,13 +494,19 @@ static int user_remove_runtime_path(User *u) { return r; } -int user_stop(User *u) { +int user_stop(User *u, bool force) { Session *s; int r = 0, k; assert(u); + /* Stop jobs have already been queued */ + if (u->stopping) { + user_save(u); + return r; + } + LIST_FOREACH(sessions_by_user, s, u->sessions) { - k = session_stop(s); + k = session_stop(s, force); if (k < 0) r = k; } @@ -515,6 +521,8 @@ int user_stop(User *u) { if (k < 0) r = k; + u->stopping = true; + user_save(u); return r; @@ -633,25 +641,30 @@ void user_add_to_gc_queue(User *u) { UserState user_get_state(User *u) { Session *i; - bool all_closing = true; assert(u); - if (u->closing) + if (u->stopping) return USER_CLOSING; if (u->slice_job || u->service_job) return USER_OPENING; - LIST_FOREACH(sessions_by_user, i, u->sessions) { - if (session_is_active(i)) - return USER_ACTIVE; - if (session_get_state(i) != SESSION_CLOSING) - all_closing = false; - } + if (u->sessions) { + bool all_closing = true; + + LIST_FOREACH(sessions_by_user, i, u->sessions) { + SessionState state; + + state = session_get_state(i); + if (state == SESSION_ACTIVE) + return USER_ACTIVE; + if (state != SESSION_CLOSING) + all_closing = false; + } - if (u->sessions) return all_closing ? USER_CLOSING : USER_ONLINE; + } if (user_check_linger_file(u) > 0) return USER_LINGERING;