[hackers] [ubase] Clear utmp entries for the specified tty in getty(8) || sin

From: <git_AT_suckless.org>
Date: Wed, 02 Jul 2014 13:05:48 +0200

commit ae8ca1598bd54db8eea053c04d2b11c294fe0afa
Author: sin <sin_AT_2f30.org>
Date: Wed Jul 2 11:45:10 2014 +0100

    Clear utmp entries for the specified tty in getty(8)

diff --git a/getty.c b/getty.c
index 8673363..e522516 100644
--- a/getty.c
+++ b/getty.c
_AT_@ -10,6 +10,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <utmp.h>
 
 #include "util.h"
 
_AT_@ -25,12 +26,15 @@ static char *defaultterm = "linux";
 int
 main(int argc, char *argv[])
 {
- int fd;
- struct sigaction sa;
         char term[128], logname[LOGIN_NAME_MAX], c;
         char hostname[HOST_NAME_MAX + 1];
+ struct utmp usr;
+ struct sigaction sa;
+ FILE *fp;
+ int fd;
         unsigned int i = 0;
         ssize_t n;
+ long pos;
 
         ARGBEGIN {
         default:
_AT_@ -84,6 +88,27 @@ main(int argc, char *argv[])
         if (fchmod(fd, 0600) < 0)
                 eprintf("chmod %s:", tty);
 
+ /* Clear all utmp entries for this tty */
+ fp = fopen("/var/run/utmp", "r+");
+ if (fp) {
+ do {
+ pos = ftell(fp);
+ if (fread(&usr, sizeof(usr), 1, fp) != 1)
+ break;
+ if (usr.ut_line[0] == '
Received on Wed Jul 02 2014 - 13:05:48 CEST

This archive was generated by hypermail 2.3.0 : Wed Jul 02 2014 - 13:12:12 CEST