~ubuntu-branches/ubuntu/saucy/procps/saucy

« back to all changes in this revision

Viewing changes to debian/patches/w_envlength.patch

  • Committer: Package Import Robot
  • Author(s): Oliver Grawert
  • Date: 2012-06-20 13:12:40 UTC
  • mfrom: (2.1.21 sid)
  • Revision ID: package-import@ubuntu.com-20120620131240-923p0d8q88bmk3ac
Tags: 1:3.3.3-2ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - debian/sysctl.d (Ubuntu-specific):
    + 10-console-messages.conf: stop low-level kernel messages on console.
    + 10-kernel-hardening.conf: add the kptr_restrict setting
    + 10-keyboard.conf.powerpc: mouse button emulation on PowerPC.
    + 10-network-security.conf: enable rp_filter and SYN-flood protection.
    + 10-ptrace.conf: describe new PTRACE setting.
    + 10-zeropage.conf: safe mmap_min_addr value for graceful fall-back.
    + README: describe how this directory is supposed to work.
  - debian/upstart (Ubuntu-specific): upstart configuration to replace old
    style sysv init script

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
Description: Use environment to set user and from/host column widths
2
 
Author: Craig Small <csmall@debian.org>
3
 
Bug-Debian: http://bugs.debian.org/396423
4
 
Bug-Debian: http://bugs.debian.org/341439
5
 
Index: b/w.1
6
 
===================================================================
7
 
--- a/w.1       2009-11-24 21:00:42.000000000 +1100
8
 
+++ b/w.1       2009-11-24 21:00:44.000000000 +1100
9
 
@@ -1,6 +1,6 @@
10
 
 .\"             -*-Nroff-*-
11
 
 .\"
12
 
-.TH W 1 "8 Dec 1993 " " " "Linux User's Manual"
13
 
+.TH W 1 "5 October 2009 " " " "Linux User's Manual"
14
 
 .SH NAME
15
 
 w \- Show who is logged on and what they are doing.
16
 
 .SH SYNOPSIS
17
 
@@ -61,6 +61,14 @@
18
 
 .B "user "
19
 
 Show information about the specified user only.
20
 
 
21
 
+.SH ENVIRONMENT
22
 
+.TP
23
 
+PROCPS_USERLEN
24
 
+Override the default width of the username column. Defaults to 8.
25
 
+.TP
26
 
+PROCPS_FROMLEN
27
 
+Override the default width of the from column. Defaults to 16.
28
 
+
29
 
 .SH FILES
30
 
 .TP
31
 
 .I /var/run/utmp
32
 
Index: b/w.c
33
 
===================================================================
34
 
--- a/w.c       2009-11-24 21:00:43.000000000 +1100
35
 
+++ b/w.c       2009-11-24 21:00:44.000000000 +1100
36
 
@@ -44,20 +44,19 @@
37
 
 /* Uh... same thing as UT_NAMESIZE */
38
 
 #define USERSZ (sizeof u->ut_user)
39
 
 
40
 
+/* Arbitary setting, not too big for the screen, max host size */
41
 
+#define HOSTSZ 40
42
 
+
43
 
 
44
 
 /* This routine is careful since some programs leave utmp strings
45
 
- * unprintable.  Always outputs at least 16 chars padded with spaces
46
 
+ * unprintable.  Always outputs at least fromlen chars padded with spaces
47
 
  * on the right if necessary.
48
 
  */
49
 
-static void print_host(const char *restrict host, int len) {
50
 
+static void print_host(const char *restrict host, int len, const int fromlen) {
51
 
     const char *last;
52
 
     int width = 0;
53
 
 
54
 
-    /* FIXME: there should really be a way to configure this... */
55
 
-    /* for now, we'll just limit it to the 16 that the libc5 version
56
 
-     * of utmp uses.
57
 
-     */
58
 
-    if (len > 16) len = 16;
59
 
+    if (len > fromlen) len = fromlen;
60
 
     last = host + len;
61
 
     for ( ; host < last ; host++){
62
 
         if (isprint(*host) && *host != ' ') {
63
 
@@ -68,7 +67,8 @@
64
 
        }
65
 
     }
66
 
     // space-fill, and a '-' too if needed to ensure the column exists
67
 
-    if(width < 16) fputs("-               "+width, stdout);
68
 
+       while(width++ < fromlen)
69
 
+         fputc(' ',stdout);
70
 
 }
71
 
 
72
 
 /***** compact 7 char format for time intervals (belongs in libproc?) */
73
 
@@ -180,7 +180,7 @@
74
 
 
75
 
 
76
 
 /***** showinfo */
77
 
-static void showinfo(utmp_t *u, int formtype, int maxcmd, int from) {
78
 
+static void showinfo(utmp_t *u, int formtype, int maxcmd, int from, const int userlen, const int fromlen) {
79
 
     unsigned long long jcpu;
80
 
     int ut_pid_found;
81
 
     unsigned i;
82
 
@@ -205,9 +205,9 @@
83
 
 
84
 
     strncpy(uname, u->ut_user, USERSZ);                /* force NUL term for printf */
85
 
     if (formtype) {
86
 
-       printf("%-9.8s%-9.8s", uname, u->ut_line);
87
 
+       printf("%-*.*s%-9.8s", userlen+1, userlen, uname, u->ut_line);
88
 
        if (from)
89
 
-           print_host(u->ut_host, sizeof u->ut_host);
90
 
+           print_host(u->ut_host, sizeof u->ut_host, fromlen);
91
 
        print_logintime(u->ut_time, stdout);
92
 
        if (*u->ut_line == ':')                 /* idle unknown for xdm logins */
93
 
            printf(" ?xdm? ");
94
 
@@ -220,9 +220,9 @@
95
 
        } else
96
 
            printf("   ?   ");
97
 
     } else {
98
 
-       printf("%-9.8s%-9.8s", u->ut_user, u->ut_line);
99
 
+       printf("%-*.*s%-9.8s", userlen+1, userlen, u->ut_user, u->ut_line);
100
 
        if (from)
101
 
-           print_host(u->ut_host, sizeof u->ut_host);
102
 
+           print_host(u->ut_host, sizeof u->ut_host, fromlen);
103
 
        if (*u->ut_line == ':')                 /* idle unknown for xdm logins */
104
 
            printf(" ?xdm? ");
105
 
        else
106
 
@@ -245,6 +245,9 @@
107
 
     utmp_t *u;
108
 
     struct winsize win;
109
 
     int header=1, longform=1, from=1, args, maxcmd, ch;
110
 
+    int userlen = 8;
111
 
+    int fromlen = 16;
112
 
+       char *env_var;
113
 
 
114
 
 #ifndef W_SHOWFROM
115
 
     from = 0;
116
 
@@ -275,6 +278,22 @@
117
 
     if ((argv[optind]))
118
 
        user = (argv[optind]);
119
 
 
120
 
+       /* Get user field length from environment */
121
 
+       if ( (env_var = getenv("PROCPS_USERLEN")) != NULL) {
122
 
+        userlen = atoi(env_var);
123
 
+        if (userlen < 8 || userlen > USERSZ) {
124
 
+            fprintf(stderr, "User length environment PROCPS_USERLEN must be between 8 and %d, ignoring.\n", USERSZ);
125
 
+                       userlen=8;
126
 
+        }
127
 
+       }
128
 
+       /* Get from field length from environment */
129
 
+       if ( (env_var = getenv("PROCPS_FROMLEN")) != NULL) {
130
 
+        fromlen = atoi(env_var);
131
 
+        if (fromlen < 8 || fromlen > HOSTSZ) {
132
 
+            fprintf(stderr, "From length environment PROCPS_FROMLEN must be between 8 and %d, ignoring.\n", HOSTSZ);
133
 
+                       fromlen=16;
134
 
+        }
135
 
+       }
136
 
     if (ioctl(1, TIOCGWINSZ, &win) != -1 && win.ws_col > 0)
137
 
        maxcmd = win.ws_col;
138
 
     else if (p = getenv("COLUMNS"))
139
 
@@ -285,7 +304,7 @@
140
 
        fprintf(stderr, "%d column window is too narrow\n", maxcmd);
141
 
        exit(1);
142
 
     }
143
 
-    maxcmd -= 29 + (from ? 16 : 0) + (longform ? 20 : 0);
144
 
+    maxcmd -= 21 + userlen + (from ? fromlen : 0) + (longform ? 20 : 0);
145
 
     if (maxcmd < 3)
146
 
        fprintf(stderr, "warning: screen width %d suboptimal.\n", win.ws_col);
147
 
 
148
 
@@ -293,7 +312,7 @@
149
 
 
150
 
     if (header) {                              /* print uptime and headers */
151
 
        print_uptime();
152
 
-       printf("USER     TTY      ");
153
 
+       printf("%-*s TTY      ",userlen,"USER");
154
 
        if (from)
155
 
            printf("FROM            ");
156
 
        if (longform)
157
 
@@ -309,14 +328,14 @@
158
 
            u = getutent();
159
 
            if (unlikely(!u)) break;
160
 
            if (u->ut_type != USER_PROCESS) continue;
161
 
-           if (!strncmp(u->ut_user, user, USERSZ)) showinfo(u, longform, maxcmd, from);
162
 
+           if (!strncmp(u->ut_user, user, USERSZ)) showinfo(u, longform, maxcmd, from, userlen, fromlen);
163
 
        }
164
 
     } else {
165
 
        for (;;) {
166
 
            u = getutent();
167
 
            if (unlikely(!u)) break;
168
 
            if (u->ut_type != USER_PROCESS) continue;
169
 
-           if (*u->ut_user) showinfo(u, longform, maxcmd, from);
170
 
+           if (*u->ut_user) showinfo(u, longform, maxcmd, from, userlen, fromlen);
171
 
        }
172
 
     }
173
 
     endutent();