Hi,

This patch adds -w option to command 'last'

-w     Display full user and domain names in the output.

With this option user and domain names aren't cut in output.

Regards,

Petr
--
Petr Lautrbach, Red Hat, Inc.
From 84b4a8db12287f220b6aa0ee59542877f0dccc55 Mon Sep 17 00:00:00 2001
From: Petr Lautrbach <plaut...@redhat.com>
Date: Thu, 14 Jan 2010 16:18:10 +0100
Subject: [PATCH] add to last command -w option for wide output

---
 man/last.1 |    6 ++++--
 src/last.c |   34 +++++++++++++++++++++-------------
 2 files changed, 25 insertions(+), 15 deletions(-)

diff --git a/man/last.1 b/man/last.1
index d718485..92bacb5 100644
--- a/man/last.1
+++ b/man/last.1
@@ -12,7 +12,7 @@ last, lastb \- show listing of last logged in users
 .RB [ \-R ]
 .RB [ \-\fInum\fP ]
 .RB "[ \-\fBn\fP \fInum\fP ]"
-.RB [ \-adFiox ]
+.RB [ \-adFiowx ]
 .RB "[ \-\fBf\fP \fIfile\fP ]"
 .RB "[ \-\fBt\fP \fIYYYYMMDDHHMMSS\fP ]"
 .RI [ name... ]
@@ -23,7 +23,7 @@ last, lastb \- show listing of last logged in users
 .RB [ \-\fInum\fP ]
 .RB "[ \-\fBn\fP \fInum\fP ]"
 .RB "[ \-\fBf\fP \fIfile\fP ]"
-.RB [ \-adFiox ]
+.RB [ \-adFiowx ]
 .RI [ name... ]
 .RI [ tty... ]
 .\"}}}
@@ -80,6 +80,8 @@ This option is like \fB-d\fP in that it displays the IP 
number of the remote
 host, but it displays the IP number in numbers-and-dots notation.
 .IP \fB\-o\fP
 Read an old-type wtmp file (written by linux-libc5 applications).
+.IP \fB\-w\fP
+Display full user and domain names in the output.
 .IP \fB\-x\fP
 Display the system shutdown entries and run level changes.
 .\"}}}
diff --git a/src/last.c b/src/last.c
index e304a09..06bba47 100644
--- a/src/last.c
+++ b/src/last.c
@@ -71,6 +71,8 @@ int altlist = 0;      /* Show hostname at the end. */
 int usedns = 0;                /* Use DNS to lookup the hostname. */
 int useip = 0;         /* Print IP address in number format */
 int fulltime = 0;      /* Print full dates and times */
+int name_len = 8;      /* Default print 8 characters of name */
+int domain_len = 16;   /* Default print 16 characters of domain */
 int oldfmt = 0;                /* Use old libc5 format? */
 char **show = NULL;    /* What do they want us to show */
 char *ufile;           /* Filename of this file */
@@ -359,7 +361,7 @@ int list(struct utmp *p, time_t t, int what)
        char            logintime[32];
        char            logouttime[32];
        char            length[32];
-       char            final[128];
+       char            final[512];
        char            utline[UT_LINESIZE+1];
        char            domain[256];
        char            *s, **walk;
@@ -469,24 +471,24 @@ int list(struct utmp *p, time_t t, int what)
                if (!altlist) {
                        snprintf(final, sizeof(final),
                                fulltime ?
-                               "%-8.8s %-12.12s %-16.16s %-24.24s %-26.26s 
%-12.12s\n" :
-                               "%-8.8s %-12.12s %-16.16s %-16.16s %-7.7s 
%-12.12s\n",
-                               p->ut_name, utline,
-                               domain, logintime, logouttime, length);
+                               "%-8.*s %-12.12s %-16.*s %-24.24s %-26.26s 
%-12.12s\n" :
+                               "%-8.*s %-12.12s %-16.*s %-16.16s %-7.7s 
%-12.12s\n",
+                               name_len, p->ut_name, utline,
+                               domain_len, domain, logintime, logouttime, 
length);
                } else {
                        snprintf(final, sizeof(final), 
                                fulltime ?
-                               "%-8.8s %-12.12s %-24.24s %-26.26s %-12.12s 
%s\n" :
-                               "%-8.8s %-12.12s %-16.16s %-7.7s %-12.12s %s\n",
-                               p->ut_name, utline,
+                               "%-8.*s %-12.12s %-24.24s %-26.26s %-12.12s 
%s\n" :
+                               "%-8.*s %-12.12s %-16.16s %-7.7s %-12.12s %s\n",
+                               name_len, p->ut_name, utline,
                                logintime, logouttime, length, domain);
                }
        } else
                snprintf(final, sizeof(final),
                        fulltime ?
-                       "%-8.8s %-12.12s %-24.24s %-26.26s %-12.12s\n" :
-                       "%-8.8s %-12.12s %-16.16s %-7.7s %-12.12s\n",
-                       p->ut_name, utline,
+                       "%-8.*s %-12.12s %-24.24s %-26.26s %-12.12s\n" :
+                       "%-8.*s %-12.12s %-16.16s %-7.7s %-12.12s\n",
+                       name_len, p->ut_name, utline,
                        logintime, logouttime, length);
 
        /*
@@ -514,7 +516,7 @@ void usage(char *s)
 {
        fprintf(stderr, "Usage: %s [-num | -n num] [-f file] "
                        "[-t YYYYMMDDHHMMSS] "
-                       "[-R] [-adioxF] [username..] [tty..]\n", s);
+                       "[-R] [-adioxFw] [username..] [tty..]\n", s);
        exit(1);
 }
 
@@ -585,7 +587,7 @@ int main(int argc, char **argv)
   progname = mybasename(argv[0]);
 
   /* Process the arguments. */
-  while((c = getopt(argc, argv, "f:n:RxadFiot:0123456789")) != EOF)
+  while((c = getopt(argc, argv, "f:n:RxadFiot:0123456789w")) != EOF)
     switch(c) {
        case 'R':
                showhost = 0;
@@ -626,6 +628,12 @@ int main(int argc, char **argv)
                        usage(progname);
                }
                break;
+       case 'w':
+               if (UT_NAMESIZE > name_len)
+                       name_len = UT_NAMESIZE;
+               if (UT_HOSTSIZE > domain_len)
+                       domain_len = UT_HOSTSIZE;
+               break;
        case '0': case '1': case '2': case '3': case '4':
        case '5': case '6': case '7': case '8': case '9':
                maxrecs = 10*maxrecs + c - '0';
-- 
1.6.5.2

_______________________________________________
initscripts-ng-devel mailing list
initscripts-ng-devel@lists.alioth.debian.org
http://lists.alioth.debian.org/mailman/listinfo/initscripts-ng-devel

Reply via email to