iov.iov_base = mbuf;
iov.iov_len = mbufsize;
+
#if defined(USE_SYSTEMD) && HAVE_DECL_SD_SESSION_GET_USERNAME == 1
if (sd_booted() > 0) {
char **sessions_list;
sessions = sd_get_sessions(&sessions_list);
if (sessions < 0)
errx(EXIT_FAILURE, _("error getting sessions: %s"),
- strerror(-sessions));
+ strerror(-sessions));
for (int i = 0; i < sessions; i++) {
char *name, *tty;
free(sessions_list[i]);
}
free(sessions_list);
- } else {
+ } else
#endif
- while((utmpptr = getutxent())) {
- if (!utmpptr->ut_user[0])
- continue;
+ {
+ while ((utmpptr = getutxent())) {
+ if (!utmpptr->ut_user[0])
+ continue;
#ifdef USER_PROCESS
- if (utmpptr->ut_type != USER_PROCESS)
- continue;
+ if (utmpptr->ut_type != USER_PROCESS)
+ continue;
#endif
- /* Joey Hess reports that use-sessreg in /etc/X11/wdm/ produces
- * ut_line entries like :0, and a write to /dev/:0 fails.
- *
- * It also seems that some login manager may produce empty ut_line.
- */
- if (!*utmpptr->ut_line || *utmpptr->ut_line == ':')
- continue;
+ /* Joey Hess reports that use-sessreg in /etc/X11/wdm/ produces
+ * ut_line entries like :0, and a write to /dev/:0 fails.
+ *
+ * It also seems that some login manager may produce empty ut_line.
+ */
+ if (!*utmpptr->ut_line || *utmpptr->ut_line == ':')
+ continue;
- if (group_buf && !is_gr_member(utmpptr->ut_user, group_buf))
- continue;
+ if (group_buf && !is_gr_member(utmpptr->ut_user, group_buf))
+ continue;
- mem2strcpy(line, utmpptr->ut_line, sizeof(utmpptr->ut_line), sizeof(line));
- if ((p = ttymsg(&iov, 1, line, timeout)) != NULL)
- warnx("%s", p);
- }
- endutxent();
-#if defined(USE_SYSTEMD) && HAVE_DECL_SD_SESSION_GET_USERNAME == 1
+ mem2strcpy(line, utmpptr->ut_line, sizeof(utmpptr->ut_line), sizeof(line));
+ if ((p = ttymsg(&iov, 1, line, timeout)) != NULL)
+ warnx("%s", p);
+ }
+ endutxent();
}
-#endif
+
free(mbuf);
free_group_workspace(group_buf);
exit(EXIT_SUCCESS);
for (int i = 0; i < sessions; i++)
free(sessions_list[i]);
free(sessions_list);
- } else {
+ } else
#endif
- char path[sizeof(u->ut_line) + 6];
-
- utmpxname(_PATH_UTMP);
- setutxent();
-
- while ((u = getutxent())) {
- if (strncmp(ctl->dst_login, u->ut_user, sizeof(u->ut_user)) != 0)
- continue;
- num_ttys++;
- snprintf(path, sizeof(path), "/dev/%s", u->ut_line);
- if (check_tty(path, &tty_writeable, &tty_atime, 0))
- /* bad term? skip */
- continue;
- if (ctl->src_uid && !tty_writeable)
- /* skip ttys with msgs off */
- continue;
- if (memcmp(u->ut_line, ctl->src_tty_name, strlen(ctl->src_tty_name) + 1) == 0) {
- user_is_me = 1;
- /* don't write to yourself */
- continue;
- }
- if (u->ut_type != USER_PROCESS)
- /* it's not a valid entry */
- continue;
- valid_ttys++;
- if (best_atime < tty_atime) {
- best_atime = tty_atime;
- free(ctl->dst_tty_path);
- ctl->dst_tty_path = xstrdup(path);
- ctl->dst_tty_name = ctl->dst_tty_path + 5;
+ {
+ char path[sizeof(u->ut_line) + 6];
+
+ utmpxname(_PATH_UTMP);
+ setutxent();
+
+ while ((u = getutxent())) {
+ if (strncmp(ctl->dst_login, u->ut_user, sizeof(u->ut_user)) != 0)
+ continue;
+ num_ttys++;
+ snprintf(path, sizeof(path), "/dev/%s", u->ut_line);
+ if (check_tty(path, &tty_writeable, &tty_atime, 0))
+ /* bad term? skip */
+ continue;
+ if (ctl->src_uid && !tty_writeable)
+ /* skip ttys with msgs off */
+ continue;
+ if (memcmp(u->ut_line, ctl->src_tty_name, strlen(ctl->src_tty_name) + 1) == 0) {
+ user_is_me = 1;
+ /* don't write to yourself */
+ continue;
+ }
+ if (u->ut_type != USER_PROCESS)
+ /* it's not a valid entry */
+ continue;
+ valid_ttys++;
+ if (best_atime < tty_atime) {
+ best_atime = tty_atime;
+ free(ctl->dst_tty_path);
+ ctl->dst_tty_path = xstrdup(path);
+ ctl->dst_tty_name = ctl->dst_tty_path + 5;
+ }
}
- }
- endutxent();
-#if defined(USE_SYSTEMD) && HAVE_DECL_SD_SESSION_GET_USERNAME == 1
+ endutxent();
}
-#endif
+
if (num_ttys == 0)
errx(EXIT_FAILURE, _("%s is not logged in"), ctl->dst_login);
if (valid_ttys == 0) {