chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Handle suspend, shutdown, reboot, etc within elogind
[elogind.git]
/
src
/
login
/
logind-seat.c
diff --git
a/src/login/logind-seat.c
b/src/login/logind-seat.c
index 04909a991a5f1a0de020b09e863ffdc065582ec3..1be8713754c3fec5503c8c8e06a6b8a9273fc3c4 100644
(file)
--- a/
src/login/logind-seat.c
+++ b/
src/login/logind-seat.c
@@
-19,21
+19,18
@@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
-#include <assert.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
-#include <sys/ioctl.h>
-#include <linux/vt.h>
#include <string.h>
#include <string.h>
-#include "sd-id128.h"
#include "sd-messages.h"
#include "logind-seat.h"
#include "logind-acl.h"
#include "util.h"
#include "mkdir.h"
#include "sd-messages.h"
#include "logind-seat.h"
#include "logind-acl.h"
#include "util.h"
#include "mkdir.h"
-#include "path-util.h"
+#include "formats-util.h"
+#include "terminal-util.h"
Seat *seat_new(Manager *m, const char *id) {
Seat *s;
Seat *seat_new(Manager *m, const char *id) {
Seat *s;
@@
-96,11
+93,11
@@
int seat_save(Seat *s) {
r = mkdir_safe_label("/run/systemd/seats", 0755, 0, 0);
if (r < 0)
r = mkdir_safe_label("/run/systemd/seats", 0755, 0, 0);
if (r < 0)
- goto f
inish
;
+ goto f
ail
;
r = fopen_temporary(s->state_file, &f, &temp_path);
if (r < 0)
r = fopen_temporary(s->state_file, &f, &temp_path);
if (r < 0)
- goto f
inish
;
+ goto f
ail
;
fchmod(fileno(f), 0644);
fchmod(fileno(f), 0644);
@@
-144,19
+141,24
@@
int seat_save(Seat *s) {
i->sessions_by_seat_next ? ' ' : '\n');
}
i->sessions_by_seat_next ? ' ' : '\n');
}
- fflush(f);
+ r = fflush_and_check(f);
+ if (r < 0)
+ goto fail;
- if (
ferror(f) ||
rename(temp_path, s->state_file) < 0) {
+ if (rename(temp_path, s->state_file) < 0) {
r = -errno;
r = -errno;
- unlink(s->state_file);
- unlink(temp_path);
+ goto fail;
}
}
-finish:
- if (r < 0)
- log_error_errno(-r, "Failed to save seat data %s: %m", s->state_file);
+ return 0;
- return r;
+fail:
+ (void) unlink(s->state_file);
+
+ if (temp_path)
+ (void) unlink(temp_path);
+
+ return log_error_errno(r, "Failed to save seat data %s: %m", s->state_file);
}
int seat_load(Seat *s) {
}
int seat_load(Seat *s) {
@@
-167,6
+169,8
@@
int seat_load(Seat *s) {
return 0;
}
return 0;
}
+/// UNNEEDED by elogind
+#if 0
static int vt_allocate(unsigned int vtnr) {
char p[sizeof("/dev/tty") + DECIMAL_STR_MAX(unsigned int)];
_cleanup_close_ int fd = -1;
static int vt_allocate(unsigned int vtnr) {
char p[sizeof("/dev/tty") + DECIMAL_STR_MAX(unsigned int)];
_cleanup_close_ int fd = -1;
@@
-201,13
+205,14
@@
int seat_preallocate_vts(Seat *s) {
q = vt_allocate(i);
if (q < 0) {
q = vt_allocate(i);
if (q < 0) {
- log_error_errno(
-q, "Failed to preallocate VT %i
: %m", i);
+ log_error_errno(
q, "Failed to preallocate VT %u
: %m", i);
r = q;
}
}
return r;
}
r = q;
}
}
return r;
}
+#endif // 0
int seat_apply_acls(Seat *s, Session *old_active) {
int r;
int seat_apply_acls(Seat *s, Session *old_active) {
int r;
@@
-221,7
+226,7
@@
int seat_apply_acls(Seat *s, Session *old_active) {
!!s->active, s->active ? s->active->user->uid : 0);
if (r < 0)
!!s->active, s->active ? s->active->user->uid : 0);
if (r < 0)
- log_error_errno(
-
r, "Failed to apply ACLs: %m");
+ log_error_errno(r, "Failed to apply ACLs: %m");
return r;
}
return r;
}
@@
-272,7
+277,7
@@
int seat_set_active(Seat *s, Session *session) {
int seat_switch_to(Seat *s, unsigned int num) {
/* Public session positions skip 0 (there is only F1-F12). Maybe it
* will get reassigned in the future, so return error for now. */
int seat_switch_to(Seat *s, unsigned int num) {
/* Public session positions skip 0 (there is only F1-F12). Maybe it
* will get reassigned in the future, so return error for now. */
- if (
!num
)
+ if (
num == 0
)
return -EINVAL;
if (num >= s->position_count || !s->positions[num]) {
return -EINVAL;
if (num >= s->position_count || !s->positions[num]) {
@@
-289,12
+294,12
@@
int seat_switch_to(Seat *s, unsigned int num) {
int seat_switch_to_next(Seat *s) {
unsigned int start, i;
int seat_switch_to_next(Seat *s) {
unsigned int start, i;
- if (
!s->position_count
)
+ if (
s->position_count == 0
)
return -EINVAL;
start = 1;
return -EINVAL;
start = 1;
- if (s->active && s->active->pos > 0)
- start = s->active->pos;
+ if (s->active && s->active->pos
ition
> 0)
+ start = s->active->pos
ition
;
for (i = start + 1; i < s->position_count; ++i)
if (s->positions[i])
for (i = start + 1; i < s->position_count; ++i)
if (s->positions[i])
@@
-310,12
+315,12
@@
int seat_switch_to_next(Seat *s) {
int seat_switch_to_previous(Seat *s) {
unsigned int start, i;
int seat_switch_to_previous(Seat *s) {
unsigned int start, i;
- if (
!s->position_count
)
+ if (
s->position_count == 0
)
return -EINVAL;
start = 1;
return -EINVAL;
start = 1;
- if (s->active && s->active->pos > 0)
- start = s->active->pos;
+ if (s->active && s->active->pos
ition
> 0)
+ start = s->active->pos
ition
;
for (i = start - 1; i > 0; --i)
if (s->positions[i])
for (i = start - 1; i > 0; --i)
if (s->positions[i])
@@
-340,14
+345,30
@@
int seat_active_vt_changed(Seat *s, unsigned int vtnr) {
log_debug("VT changed to %u", vtnr);
log_debug("VT changed to %u", vtnr);
+ /* we might have earlier closing sessions on the same VT, so try to
+ * find a running one first */
LIST_FOREACH(sessions_by_seat, i, s->sessions)
LIST_FOREACH(sessions_by_seat, i, s->sessions)
- if (i->vtnr == vtnr) {
+ if (i->vtnr == vtnr
&& !i->stopping
) {
new_active = i;
break;
}
new_active = i;
break;
}
+ if (!new_active) {
+ /* no running one? then we can't decide which one is the
+ * active one, let the first one win */
+ LIST_FOREACH(sessions_by_seat, i, s->sessions)
+ if (i->vtnr == vtnr) {
+ new_active = i;
+ break;
+ }
+ }
+
r = seat_set_active(s, new_active);
r = seat_set_active(s, new_active);
+
+/// elogind does not spawn autovt
+#if 0
manager_spawn_autovt(s->manager, vtnr);
manager_spawn_autovt(s->manager, vtnr);
+#endif // 0
return r;
}
return r;
}
@@
-406,7
+427,10
@@
int seat_start(Seat *s) {
NULL);
/* Initialize VT magic stuff */
NULL);
/* Initialize VT magic stuff */
+/// elogind does not support autospawning vts
+#if 0
seat_preallocate_vts(s);
seat_preallocate_vts(s);
+#endif // 0
/* Read current VT */
seat_read_active_vt(s);
/* Read current VT */
seat_read_active_vt(s);
@@
-463,21
+487,21
@@
int seat_stop_sessions(Seat *s, bool force) {
void seat_evict_position(Seat *s, Session *session) {
Session *iter;
void seat_evict_position(Seat *s, Session *session) {
Session *iter;
- unsigned int pos = session->pos;
+ unsigned int pos = session->pos
ition
;
- session->pos = 0;
+ session->pos
ition
= 0;
- if (
!pos
)
+ if (
pos == 0
)
return;
if (pos < s->position_count && s->positions[pos] == session) {
s->positions[pos] = NULL;
/* There might be another session claiming the same
return;
if (pos < s->position_count && s->positions[pos] == session) {
s->positions[pos] = NULL;
/* There might be another session claiming the same
- * position (eg., during gdm->session transition), so lets look
+ * position (eg., during gdm->session transition), so let
'
s look
* for it and set it on the free slot. */
LIST_FOREACH(sessions_by_seat, iter, s->sessions) {
* for it and set it on the free slot. */
LIST_FOREACH(sessions_by_seat, iter, s->sessions) {
- if (iter->pos
== pos
) {
+ if (iter->pos
ition == pos && session_get_state(iter) != SESSION_CLOSING
) {
s->positions[pos] = iter;
break;
}
s->positions[pos] = iter;
break;
}
@@
-495,15
+519,15
@@
void seat_claim_position(Seat *s, Session *session, unsigned int pos) {
seat_evict_position(s, session);
seat_evict_position(s, session);
- session->pos = pos;
- if (pos > 0
&& !s->positions[pos]
)
+ session->pos
ition
= pos;
+ if (pos > 0)
s->positions[pos] = session;
}
static void seat_assign_position(Seat *s, Session *session) {
unsigned int pos;
s->positions[pos] = session;
}
static void seat_assign_position(Seat *s, Session *session) {
unsigned int pos;
- if (session->pos > 0)
+ if (session->pos
ition
> 0)
return;
for (pos = 1; pos < s->position_count; ++pos)
return;
for (pos = 1; pos < s->position_count; ++pos)
@@
-590,7
+614,7
@@
bool seat_can_graphical(Seat *s) {
int seat_get_idle_hint(Seat *s, dual_timestamp *t) {
Session *session;
bool idle_hint = true;
int seat_get_idle_hint(Seat *s, dual_timestamp *t) {
Session *session;
bool idle_hint = true;
- dual_timestamp ts =
{ 0, 0 }
;
+ dual_timestamp ts =
DUAL_TIMESTAMP_NULL
;
assert(s);
assert(s);