[hackers] [ubase] Add lastlog to README || sin
commit 0fbd4280f8e8daa6dbf2d4fe6f7807dd43904b22 Author: sin Date: Mon Aug 18 22:32:58 2014 +0100 Add lastlog to README diff --git a/README b/README index efa5107..c414c10 100644 --- a/README +++ b/README @@ -23,6 +23,7 @@ hwclock id insmod killall5 +lastlog login lsmod lsusb
[hackers] [ubase] Use agetline() in lastlog(8) || sin
commit ef78f20dd8dfbe9c72e0477fc620c31ec852d7e1 Author: sin Date: Mon Aug 18 22:02:22 2014 +0100 Use agetline() in lastlog(8) Some other minor changes as well. diff --git a/lastlog.c b/lastlog.c index 1a27ae4..c9f0949 100644 --- a/lastlog.c +++ b/lastlog.c @@ -8,6 +8,7 @@ #include #include +#include "text.h" #include "util.h" #define PASSWD "/etc/passwd" @@ -34,7 +35,7 @@ lastlog(char *user) fread(&ll, sizeof(struct lastlog), 1, last); if (ferror(last)) - eprintf("error reading lastlog "); + eprintf("%s: read error:", _PATH_LASTLOG); /* on glibc `ll_time' can be an int32_t with compat32 * avoid compiler warning when calling ctime() */ @@ -47,7 +48,8 @@ int main(int argc, char **argv) { FILE *fp; - char line[512], *p; + char *line = NULL, *p; + size_t sz = 0; if ((last = fopen(_PATH_LASTLOG, "r")) == NULL) eprintf("fopen %s:", _PATH_LASTLOG); @@ -58,17 +60,19 @@ main(int argc, char **argv) } else { if ((fp = fopen(PASSWD, "r")) == NULL) eprintf("fopen %s:", PASSWD); - while ((fgets(line, sizeof(line), fp)) != NULL) { + while (agetline(&line, &sz, fp) != -1) { if ((p = strchr(line, ':')) == NULL) eprintf("invalid passwd entry "); *p = '
[hackers] [ubase] Convert lastlog(8) to {w,}eprintf() || sin
commit 1aaec6250a5ca8949e30147259f9316d87eb93b5 Author: sin Date: Mon Aug 18 21:55:38 2014 +0100 Convert lastlog(8) to {w,}eprintf() diff --git a/lastlog.c b/lastlog.c index 0c3cefa..1a27ae4 100644 --- a/lastlog.c +++ b/lastlog.c @@ -1,4 +1,5 @@ /* See LICENSE file for copyright and license details. */ +#include #include #include #include @@ -7,6 +8,8 @@ #include #include +#include "util.h" + #define PASSWD "/etc/passwd" static FILE *last; @@ -18,18 +21,20 @@ lastlog(char *user) struct lastlog ll; time_t lltime; + errno = 0; if ((pwd = getpwnam(user)) == NULL) { - fprintf(stderr, "unknown user: %s ", user); + if (errno) + weprintf("getpwnam %s:", user); + else + weprintf("unknown user: %s ", user); return; } fseek(last, pwd->pw_uid * sizeof(struct lastlog), 0); fread(&ll, sizeof(struct lastlog), 1, last); - if (ferror(last)) { - perror("error reading lastlog"); - exit(EXIT_FAILURE); - } + if (ferror(last)) + eprintf("error reading lastlog "); /* on glibc `ll_time' can be an int32_t with compat32 * avoid compiler warning when calling ctime() */ @@ -44,29 +49,23 @@ main(int argc, char **argv) FILE *fp; char line[512], *p; - if ((last = fopen(_PATH_LASTLOG, "r")) == NULL) { - perror(_PATH_LASTLOG); - exit(EXIT_FAILURE); - } + if ((last = fopen(_PATH_LASTLOG, "r")) == NULL) + eprintf("fopen %s:", _PATH_LASTLOG); if (argc > 1) { while (*++argv) lastlog(*argv); } else { - if ((fp = fopen(PASSWD, "r")) == NULL) { - perror(PASSWD); - exit(EXIT_FAILURE); - } + if ((fp = fopen(PASSWD, "r")) == NULL) + eprintf("fopen %s:", PASSWD); while ((fgets(line, sizeof(line), fp)) != NULL) { - if ((p = strchr(line, ':')) == NULL) { - fputs("incorrect password file", stderr); - exit(-1); - } + if ((p = strchr(line, ':')) == NULL) + eprintf("invalid passwd entry "); *p = '
[hackers] [ubase] Only check errno if getpwnam() fails || sin
commit 6af24e35f954e21bdafd3d0e0f7fb76e92ac93bd Author: sin Date: Mon Aug 18 21:49:22 2014 +0100 Only check errno if getpwnam() fails diff --git a/login.c b/login.c index 51b1f77..fde7ad3 100644 --- a/login.c +++ b/login.c @@ -74,13 +74,15 @@ main(int argc, char *argv[]) if (isatty(STDIN_FILENO) == 0) eprintf("stdin is not a tty "); - errno = 0; user = argv[0]; + errno = 0; pw = getpwnam(user); - if (errno) - eprintf("getpwnam: %s:", user); - else if (!pw) - eprintf("who are you? "); + if (!pw) { + if (errno) + eprintf("getpwnam: %s:", user); + else + eprintf("who are you? "); + } uid = pw->pw_uid; gid = pw->pw_gid;
Re: [hackers] [ubase] Add lastlog(8) || Roberto E. Vargas Caballero
On Mon, Aug 18, 2014 at 10:07:38PM +0200, Roberto E. Vargas Caballero wrote: > I wrote it for personal use, but now that it is going to be part > of ubase maybe is better to use die in some parts of the code, no? Yeah eprintf() etc.
Re: [hackers] [ubase] Add lastlog(8) || Roberto E. Vargas Caballero
I wrote it for personal use, but now that it is going to be part of ubase maybe is better to use die in some parts of the code, no? > + if (ferror(last)) { > + perror("error reading lastlog"); > + exit(EXIT_FAILURE); > + } ... > + if ((last = fopen(_PATH_LASTLOG, "r")) == NULL) { > + perror(_PATH_LASTLOG); > + exit(EXIT_FAILURE); > + } ... > + perror(PASSWD); > + exit(EXIT_FAILURE); > + } > + if ((p = strchr(line, ':')) == NULL) { > + fputs("incorrect password file", stderr); > + exit(-1); > + } > + *p = ' ... -- Roberto E. Vargas Caballero
[hackers] [sinit] Update link to initscripts || sin
commit b15e98850f0fd136a7e370c9287faace4ed97825 Author: sin Date: Mon Aug 18 20:12:36 2014 +0100 Update link to initscripts diff --git a/README b/README index 85d25cb..13642b8 100644 --- a/README +++ b/README @@ -23,4 +23,4 @@ a look at [3]. [1] https://gist.github.com/rofl0r/6168719 [2] http://git.2f30.org/morpheus/ -[3] http://git.2f30.org/fs/ +[3] http://git.2f30.org/ports/tree/fs/
[hackers] [ubase] Add lastlog(8) || Roberto E. Vargas Caballero
commit e4677f290b9fbc6feceda0fbe406d19a8881faae Author: Roberto E. Vargas Caballero Date: Mon Aug 18 18:24:29 2014 +0100 Add lastlog(8) At the moment this does not work with ubase login(1). We should add support to login(1) to write the lastlog entries. Minor modifications by sin. diff --git a/LICENSE b/LICENSE index ed2376d..29531aa 100644 --- a/LICENSE +++ b/LICENSE @@ -8,6 +8,7 @@ MIT/X Consortium License © 2014 Carlos J. Torres © 2014 Hiltjo Posthuma © 2014 Laslo Hunhold +© 2014 Roberto E. Vargas Caballero Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), diff --git a/Makefile b/Makefile index 5a3f0fd..9350306 100644 --- a/Makefile +++ b/Makefile @@ -33,6 +33,7 @@ LIB = \ util/tty.o SRC = \ + lastlog.c \ chvt.c \ clear.c \ ctrlaltdel.c\ @@ -115,6 +116,7 @@ MAN8 = \ hwclock.8 \ insmod.8\ killall5.8 \ + lastlog.8 \ lsmod.8 \ lsusb.8 \ mkswap.8\ diff --git a/lastlog.8 b/lastlog.8 new file mode 100644 index 000..e71f9ea --- /dev/null +++ b/lastlog.8 @@ -0,0 +1,11 @@ +.TH LASTLOG 8 ubase-VERSION +.SH NAME +BlastlogR - Show last login of users +.SH SYPNOSIS +BlastlogI [user ...] +.SH DESCRIPTION +BlastlogR Show time, tty, and host (if it was a remote +connection) of last login of users. If some user names are passed +as parameter then information about last login of these users is +shown, otherwise is shown for all the users in /etc/passwd in the +order they appear in it. diff --git a/lastlog.c b/lastlog.c new file mode 100644 index 000..0c3cefa --- /dev/null +++ b/lastlog.c @@ -0,0 +1,75 @@ +/* See LICENSE file for copyright and license details. */ +#include +#include +#include +#include +#include +#include +#include + +#define PASSWD "/etc/passwd" + +static FILE *last; + +static void +lastlog(char *user) +{ + struct passwd *pwd; + struct lastlog ll; + time_t lltime; + + if ((pwd = getpwnam(user)) == NULL) { + fprintf(stderr, "unknown user: %s ", user); + return; + } + + fseek(last, pwd->pw_uid * sizeof(struct lastlog), 0); + fread(&ll, sizeof(struct lastlog), 1, last); + + if (ferror(last)) { + perror("error reading lastlog"); + exit(EXIT_FAILURE); + } + + /* on glibc `ll_time' can be an int32_t with compat32 +* avoid compiler warning when calling ctime() */ + lltime = ll.ll_time; + printf("%-8.8s %-8.8s %-16.16s %s", + user, ll.ll_line, ll.ll_host, ctime(&lltime)); +} + +int +main(int argc, char **argv) +{ + FILE *fp; + char line[512], *p; + + if ((last = fopen(_PATH_LASTLOG, "r")) == NULL) { + perror(_PATH_LASTLOG); + exit(EXIT_FAILURE); + } + + if (argc > 1) { + while (*++argv) + lastlog(*argv); + } else { + if ((fp = fopen(PASSWD, "r")) == NULL) { + perror(PASSWD); + exit(EXIT_FAILURE); + } + while ((fgets(line, sizeof(line), fp)) != NULL) { + if ((p = strchr(line, ':')) == NULL) { + fputs("incorrect password file", stderr); + exit(-1); + } + *p = '
[hackers] [st] Simplify README || Alexander Huemer
commit 1926305318cf020e20732461293d3e8c1c201734 Author: Alexander Huemer Date: Mon Aug 18 01:52:53 2014 +0200 Simplify README The term 'virtual terminal emulator' was broken. There is nothing virtual about it, it's a terminal emulator. Signed-off-by: Alexander Huemer Signed-off-by: Roberto E. Vargas Caballero diff --git a/README b/README index 25606a2..b38c88b 100644 --- a/README +++ b/README @@ -1,6 +1,6 @@ st - simple terminal -st is a simple virtual terminal emulator for X which sucks less. +st is a simple terminal emulator for X which sucks less. Requirements
[hackers] [st] Fix man page and usage() || Roberto E. Vargas Caballero
commit 8f3e6a577d0d9733d356c0b691fea7b523d8ade7 Author: Roberto E. Vargas Caballero Date: Sun Aug 17 20:49:33 2014 +0200 Fix man page and usage() Man page was repeating -f option, the second time instead of -i, and this option was lost in usage() message. This patch also indent the output of usage(). diff --git a/st.1 b/st.1 index 7174da2..e655530 100644 --- a/st.1 +++ b/st.1 @@ -42,7 +42,7 @@ The form is [=][{xX}][{+-}{+-}]. See .BR XParseGeometry (3) for further details. .TP -.B \-f +.B \-i will fixate the position given with the -g option. .TP .BI \-o " file" diff --git a/st.c b/st.c index 6e5953a..8f19018 100644 --- a/st.c +++ b/st.c @@ -3870,8 +3870,8 @@ run(void) { void usage(void) { die("%s " VERSION " (c) 2010-2014 st engineers " \ - "usage: st [-a] [-v] [-c class] [-f font] [-g geometry] [-o file]" \ - " [-t title] [-w windowid] [-e command ...] ", argv0); + "usage: st [-a] [-v] [-c class] [-f font] [-g geometry] [-o file] " + " [-i] [-t title] [-w windowid] [-e command ...] ", argv0); } int