1
Author: Dean Gaudet <dean@arctic.org>
2
Description: Adds lastcomm -f - stdin and --forwards support (Closes: #262583).
4
diff -Naurp acct.orig/lastcomm.1 acct/lastcomm.1
5
--- acct.orig/lastcomm.1 2009-06-09 05:00:45.000000000 +0000
6
+++ acct/lastcomm.1 2009-07-06 22:32:01.000000000 +0000
7
@@ -23,6 +23,10 @@ lastcomm \- print out information about
17
.BI \-\-file " filename"
18
@@ -131,11 +135,25 @@ List records for command
23
+Read file forwards instead of backwards. This avoids trying to seek on the file
24
+and can be used to read from a pipe. This must be specified prior to any
28
.BI \-f " filename, " \-\-file " filename"
34
+A filename of "-" will result in reading from stdin. This must either be the
44
Use this flag to tell the program what
45
diff -Naurp acct.orig/lastcomm.c acct/lastcomm.c
46
--- acct.orig/lastcomm.c 2009-06-09 05:00:45.000000000 +0000
47
+++ acct/lastcomm.c 2009-07-06 22:32:01.000000000 +0000
48
@@ -96,12 +96,9 @@ main (int argc, char *argv[])
50
int other_pacct_file_specified = 0; /* nonzero if the user used the
51
`-f' or `--file' flag */
52
+ int backwards = 1; /* default to reading backwards */
54
program_name = argv[0];
56
- /* Tell the pacct reader that we want to do things backwards! */
62
@@ -118,6 +115,7 @@ main (int argc, char *argv[])
63
{ "tty", required_argument, NULL, 8 },
64
{ "command", required_argument, NULL, 9 },
65
{ "ahz", required_argument, NULL, 10 },
66
+ { "forwards", no_argument, NULL, 11 },
68
{ "show-paging", no_argument, NULL, 11 },
70
@@ -146,6 +144,18 @@ main (int argc, char *argv[])
74
+ if (strcmp(optarg, "-") == 0)
76
+ if (backwards && other_pacct_file_specified)
78
+ printf ("%s: -f - must be specified first, or --forwards must precede the first -f\n", program_name);
82
+ optarg = "/proc/self/fd/0";
84
+ if (other_pacct_file_specified == 0)
85
+ pacct_init(backwards);
86
add_pacct_file (optarg);
87
other_pacct_file_specified = 1;
89
@@ -186,6 +196,14 @@ main (int argc, char *argv[])
94
+ if (other_pacct_file_specified)
96
+ printf ("%s: --forwards must come before -f\n", program_name);
103
/* This should fall through to default! */
104
@@ -196,6 +214,9 @@ main (int argc, char *argv[])
108
+ if (other_pacct_file_specified == 0)
109
+ pacct_init(backwards);
111
/* if we get here, we expect everything else to be a username,
112
terminal name, or command name */
114
@@ -275,7 +296,7 @@ give_usage (void)
117
"V] [-f file] [command] ... [user] ... [terminal] ...\n"
118
-" [--file <file>] [--strict-match] [--print-controls]\n"
119
+" [--forwards] [--file <file>] [--strict-match] [--print-controls]\n"
120
" [--user <name>] [--tty <name>] [--command <name>] [--debug]\n"