SHA256
1
0
forked from pool/systemd
systemd/fix-write-user-state-file.patch

100 lines
3.6 KiB
Diff
Raw Normal View History

From 0753f9b016f144a6ebe11cd8a2c377e5a0345443 Mon Sep 17 00:00:00 2001
From: Lennart Poettering <lennart@poettering.net>
Date: Tue, 22 May 2012 16:46:11 +0200
Subject: [PATCH] logind: fix write out of user state file
---
src/login/logind-user.c | 65 ++++++++++++++++++++++++++++++----------------
1 files changed, 42 insertions(+), 23 deletions(-)
diff --git a/src/login/logind-user.c b/src/login/logind-user.c
index 717f0e2..b7f579c 100644
--- a/src/login/logind-user.c
+++ b/src/login/logind-user.c
@@ -136,40 +136,59 @@ int user_save(User *u) {
if (u->sessions) {
Session *i;
+ bool first;
fputs("SESSIONS=", f);
+ first = true;
LIST_FOREACH(sessions_by_user, i, u->sessions) {
- fprintf(f,
- "%s%c",
- i->id,
- i->sessions_by_user_next ? ' ' : '\n');
+ if (first)
+ first = false;
+ else
+ fputc(' ', f);
+
+ fputs(i->id, f);
}
- fputs("SEATS=", f);
+ fputs("\nSEATS=", f);
+ first = true;
LIST_FOREACH(sessions_by_user, i, u->sessions) {
- if (i->seat)
- fprintf(f,
- "%s%c",
- i->seat->id,
- i->sessions_by_user_next ? ' ' : '\n');
+ if (!i->seat)
+ continue;
+
+ if (first)
+ first = false;
+ else
+ fputc(' ', f);
+
+ fputs(i->seat->id, f);
}
- fputs("ACTIVE_SESSIONS=", f);
- LIST_FOREACH(sessions_by_user, i, u->sessions)
- if (session_is_active(i))
- fprintf(f,
- "%lu%c",
- (unsigned long) i->user->uid,
- i->sessions_by_user_next ? ' ' : '\n');
+ fputs("\nACTIVE_SESSIONS=", f);
+ first = true;
+ LIST_FOREACH(sessions_by_user, i, u->sessions) {
+ if (!session_is_active(i))
+ continue;
+
+ if (first)
+ first = false;
+ else
+ fputc(' ', f);
+
+ fputs(i->id, f);
+ }
- fputs("ACTIVE_SEATS=", f);
+ fputs("\nACTIVE_SEATS=", f);
+ first = true;
LIST_FOREACH(sessions_by_user, i, u->sessions) {
- if (session_is_active(i) && i->seat)
- fprintf(f,
- "%s%c",
- i->seat->id,
- i->sessions_by_user_next ? ' ' : '\n');
+ if (!session_is_active(i) || !i->seat)
+ continue;
+
+ if (first)
+ first = false;
+ else
+ fputs(i->seat->id, f);
}
+ fputc('\n', f);
}
fflush(f);
--
1.7.7