if (sd_booted() > 0) {
char **sessions_list;
int sessions = sd_get_sessions(&sessions_list);
+
if (sessions < 0)
- errx(EXIT_FAILURE, _("error getting sessions: %s"),
- strerror(-sessions));
+ goto utmp;
for (int i = 0; i < sessions; i++) {
char *name, *tty;
- int r;
- if ((r = sd_session_get_username(sessions_list[i], &name)) < 0)
- errx(EXIT_FAILURE, _("get user name failed: %s"), strerror (-r));
+ if (sd_session_get_username(sessions_list[i], &name) < 0)
+ continue;
if (sd_session_get_tty(sessions_list[i], &tty) < 0) {
free(name);
continue;
for (int i = 0; i < sessions; i++)
free(sessions_list[i]);
free(sessions_list);
- } else {
+
+ if (res == 0)
+ return res;
+ }
+utmp:
#endif
- utmpxname(_PATH_UTMP);
- setutxent();
+ utmpxname(_PATH_UTMP);
+ setutxent();
- while ((u = getutxent())) {
- if (strncmp(ctl->dst_login, u->ut_user, sizeof(u->ut_user)) == 0 &&
- strncmp(ctl->dst_tty_name, u->ut_line, sizeof(u->ut_line)) == 0) {
- res = 0;
- break;
- }
+ while ((u = getutxent())) {
+ if (strncmp(ctl->dst_login, u->ut_user, sizeof(u->ut_user)) == 0 &&
+ strncmp(ctl->dst_tty_name, u->ut_line, sizeof(u->ut_line)) == 0) {
+ res = 0;
+ break;
}
-
- endutxent();
-#if defined(USE_SYSTEMD) && HAVE_DECL_SD_SESSION_GET_USERNAME == 1
}
-#endif
+
+ endutxent();
return res;
}
char path[256];
char **sessions_list;
int sessions = sd_get_sessions(&sessions_list);
+
if (sessions < 0)
- errx(EXIT_FAILURE, _("error getting sessions: %s"),
- strerror(-sessions));
+ goto utmp;
for (int i = 0; i < sessions; i++) {
char *name, *tty;
- int r;
- if ((r = sd_session_get_username(sessions_list[i], &name)) < 0)
- errx(EXIT_FAILURE, _("get user name failed: %s"), strerror (-r));
+ if (sd_session_get_username(sessions_list[i], &name) < 0)
+ continue;
if (strcmp(ctl->dst_login, name) != 0) {
free(name);
for (int i = 0; i < sessions; i++)
free(sessions_list[i]);
free(sessions_list);
- } else
+ }
+utmp:
#endif
{
char path[sizeof(u->ut_line) + 6];