Merge remote-tracking branch 'sami/2012wk9'
This commit is contained in:
commit
98ebb386c4
55
pmap.c
55
pmap.c
@ -272,10 +272,10 @@ static int one_proc(proc_t * p)
|
|||||||
&end, flags, &file_offset, &dev_major, &dev_minor,
|
&end, flags, &file_offset, &dev_major, &dev_minor,
|
||||||
&inode);
|
&inode);
|
||||||
|
|
||||||
if (start > range_high)
|
if (end - 1 < range_low)
|
||||||
break;
|
|
||||||
if (end < range_low)
|
|
||||||
continue;
|
continue;
|
||||||
|
if (range_high < start)
|
||||||
|
break;
|
||||||
|
|
||||||
tmp = strchr(mapbuf, '\n');
|
tmp = strchr(mapbuf, '\n');
|
||||||
if (tmp)
|
if (tmp)
|
||||||
@ -382,6 +382,28 @@ static int one_proc(proc_t * p)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void range_arguments(char *optarg)
|
||||||
|
{
|
||||||
|
char *arg1;
|
||||||
|
char *arg2;
|
||||||
|
|
||||||
|
arg1 = xstrdup(optarg);
|
||||||
|
arg2 = strchr(arg1, ',');
|
||||||
|
if (arg2)
|
||||||
|
*arg2 = '\0';
|
||||||
|
if (arg2)
|
||||||
|
++arg2;
|
||||||
|
else
|
||||||
|
arg2 = arg1;
|
||||||
|
if (arg1 && *arg1)
|
||||||
|
range_low = STRTOUKL(arg1, &arg1, 16);
|
||||||
|
if (*arg2)
|
||||||
|
range_high = STRTOUKL(arg2, &arg2, 16);
|
||||||
|
if (arg1 && (*arg1 || *arg2))
|
||||||
|
xerrx(EXIT_FAILURE, "%s: '%s'", _("failed to parse argument"),
|
||||||
|
optarg);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
unsigned *pidlist;
|
unsigned *pidlist;
|
||||||
@ -422,32 +444,7 @@ int main(int argc, char **argv)
|
|||||||
q_option = 1;
|
q_option = 1;
|
||||||
break;
|
break;
|
||||||
case 'A':
|
case 'A':
|
||||||
{
|
range_arguments(optarg);
|
||||||
/* FIXME: this should be a function. */
|
|
||||||
char *walk = optarg;
|
|
||||||
char *arg1;
|
|
||||||
char *arg2;
|
|
||||||
if (walk[1]) {
|
|
||||||
arg1 = walk + 1;
|
|
||||||
walk += strlen(walk) - 1;
|
|
||||||
} else {
|
|
||||||
arg1 = *++argv;
|
|
||||||
if (!arg1)
|
|
||||||
usage(stderr);
|
|
||||||
}
|
|
||||||
arg2 = strchr(arg1, ',');
|
|
||||||
if (arg2)
|
|
||||||
*arg2 = '\0';
|
|
||||||
if(arg2) ++arg2;
|
|
||||||
else arg2 = arg1;
|
|
||||||
|
|
||||||
if (arg1 && *arg1)
|
|
||||||
range_low = STRTOUKL(arg1, &arg1, 16);
|
|
||||||
if (*arg2)
|
|
||||||
range_high = STRTOUKL(arg2, &arg2, 16);
|
|
||||||
if (arg1 && (*arg1 || *arg2))
|
|
||||||
usage(stderr);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
usage(stdout);
|
usage(stdout);
|
||||||
|
42
w.c
42
w.c
@ -67,10 +67,6 @@ typedef struct utmp utmp_t;
|
|||||||
# define FROM_STRING "off"
|
# define FROM_STRING "off"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Arbitary setting, not too big for the screen, max host size */
|
|
||||||
#define HOSTSZ 40
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This routine is careful since some programs leave utmp strings
|
* This routine is careful since some programs leave utmp strings
|
||||||
* unprintable. Always outputs at least 16 chars padded with
|
* unprintable. Always outputs at least 16 chars padded with
|
||||||
@ -153,14 +149,11 @@ static time_t idletime(const char *restrict const tty)
|
|||||||
|
|
||||||
static void print_logintime(time_t logt, FILE * fout)
|
static void print_logintime(time_t logt, FILE * fout)
|
||||||
{
|
{
|
||||||
/* FIXME: make use of locale, remember strftime() */
|
|
||||||
char weekday[][4] = {
|
/* Abbreviated of weekday can be longer than 3 characters,
|
||||||
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
|
* see for instance hu_HU. Using 16 is few bytes more than
|
||||||
};
|
* enough. */
|
||||||
char month[][4] = {
|
char time_str[16];
|
||||||
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug",
|
|
||||||
"Sep", "Oct", "Nov", "Dec"
|
|
||||||
};
|
|
||||||
time_t curt;
|
time_t curt;
|
||||||
struct tm *logtm, *curtm;
|
struct tm *logtm, *curtm;
|
||||||
int today;
|
int today;
|
||||||
@ -171,12 +164,15 @@ static void print_logintime(time_t logt, FILE * fout)
|
|||||||
today = curtm->tm_yday;
|
today = curtm->tm_yday;
|
||||||
logtm = localtime(&logt);
|
logtm = localtime(&logt);
|
||||||
if (curt - logt > 12 * 60 * 60 && logtm->tm_yday != today) {
|
if (curt - logt > 12 * 60 * 60 && logtm->tm_yday != today) {
|
||||||
if (curt - logt > 6 * 24 * 60 * 60)
|
if (curt - logt > 6 * 24 * 60 * 60) {
|
||||||
|
strftime(time_str, sizeof(time_str), "%b", logtm);
|
||||||
fprintf(fout, " %02d%3s%02d", logtm->tm_mday,
|
fprintf(fout, " %02d%3s%02d", logtm->tm_mday,
|
||||||
month[logtm->tm_mon], logtm->tm_year % 100);
|
time_str, logtm->tm_year % 100);
|
||||||
else
|
} else {
|
||||||
fprintf(fout, " %3s%02d ", weekday[logtm->tm_wday],
|
strftime(time_str, sizeof(time_str), "%a", logtm);
|
||||||
|
fprintf(fout, " %3s%02d ", time_str,
|
||||||
logtm->tm_hour);
|
logtm->tm_hour);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
fprintf(fout, " %02d:%02d ", logtm->tm_hour, logtm->tm_min);
|
fprintf(fout, " %02d:%02d ", logtm->tm_hour, logtm->tm_min);
|
||||||
}
|
}
|
||||||
@ -249,7 +245,7 @@ static void showinfo(utmp_t * u, int formtype, int maxcmd, int from,
|
|||||||
char uname[UT_NAMESIZE + 1] = "", tty[5 + UT_LINESIZE + 1] = "/dev/";
|
char uname[UT_NAMESIZE + 1] = "", tty[5 + UT_LINESIZE + 1] = "/dev/";
|
||||||
const proc_t *best;
|
const proc_t *best;
|
||||||
|
|
||||||
for (i = 0; i < sizeof(u->ut_line); i++)
|
for (i = 0; i < UT_LINESIZE; i++)
|
||||||
/* clean up tty if garbled */
|
/* clean up tty if garbled */
|
||||||
if (isalnum(u->ut_line[i]) || (u->ut_line[i] == '/'))
|
if (isalnum(u->ut_line[i]) || (u->ut_line[i] == '/'))
|
||||||
tty[i + 5] = u->ut_line[i];
|
tty[i + 5] = u->ut_line[i];
|
||||||
@ -273,7 +269,7 @@ static void showinfo(utmp_t * u, int formtype, int maxcmd, int from,
|
|||||||
if (formtype) {
|
if (formtype) {
|
||||||
printf("%-*.*s%-9.8s", userlen + 1, userlen, uname, u->ut_line);
|
printf("%-*.*s%-9.8s", userlen + 1, userlen, uname, u->ut_line);
|
||||||
if (from)
|
if (from)
|
||||||
print_host(u->ut_host, sizeof u->ut_host, fromlen);
|
print_host(u->ut_host, UT_HOSTSIZE, fromlen);
|
||||||
print_logintime(u->ut_time, stdout);
|
print_logintime(u->ut_time, stdout);
|
||||||
if (*u->ut_line == ':')
|
if (*u->ut_line == ':')
|
||||||
/* idle unknown for xdm logins */
|
/* idle unknown for xdm logins */
|
||||||
@ -293,7 +289,7 @@ static void showinfo(utmp_t * u, int formtype, int maxcmd, int from,
|
|||||||
printf("%-*.*s%-9.8s", userlen + 1, userlen, u->ut_user,
|
printf("%-*.*s%-9.8s", userlen + 1, userlen, u->ut_user,
|
||||||
u->ut_line);
|
u->ut_line);
|
||||||
if (from)
|
if (from)
|
||||||
print_host(u->ut_host, sizeof u->ut_host, fromlen);
|
print_host(u->ut_host, UT_HOSTSIZE, fromlen);
|
||||||
if (*u->ut_line == ':')
|
if (*u->ut_line == ':')
|
||||||
/* idle unknown for xdm logins */
|
/* idle unknown for xdm logins */
|
||||||
printf(" ?xdm? ");
|
printf(" ?xdm? ");
|
||||||
@ -401,7 +397,7 @@ int main(int argc, char **argv)
|
|||||||
/* Get user field length from environment */
|
/* Get user field length from environment */
|
||||||
if ((env_var = getenv("PROCPS_USERLEN")) != NULL) {
|
if ((env_var = getenv("PROCPS_USERLEN")) != NULL) {
|
||||||
userlen = atoi(env_var);
|
userlen = atoi(env_var);
|
||||||
if (userlen < 8 || userlen > UT_NAMESIZE) {
|
if (userlen < 8 || UT_NAMESIZE < userlen) {
|
||||||
xwarnx
|
xwarnx
|
||||||
(_("User length environment PROCPS_USERLEN must be between 8 and %zu, ignoring.\n"),
|
(_("User length environment PROCPS_USERLEN must be between 8 and %zu, ignoring.\n"),
|
||||||
UT_NAMESIZE);
|
UT_NAMESIZE);
|
||||||
@ -411,10 +407,10 @@ int main(int argc, char **argv)
|
|||||||
/* Get from field length from environment */
|
/* Get from field length from environment */
|
||||||
if ((env_var = getenv("PROCPS_FROMLEN")) != NULL) {
|
if ((env_var = getenv("PROCPS_FROMLEN")) != NULL) {
|
||||||
fromlen = atoi(env_var);
|
fromlen = atoi(env_var);
|
||||||
if (fromlen < 8 || fromlen > HOSTSZ) {
|
if (fromlen < 8 || UT_HOSTSIZE < fromlen) {
|
||||||
xwarnx
|
xwarnx
|
||||||
(_("from length environment PROCPS_FROMLEN must be between 8 and %d, ignoring\n"),
|
(_("from length environment PROCPS_FROMLEN must be between 8 and %d, ignoring\n"),
|
||||||
HOSTSZ);
|
UT_HOSTSIZE);
|
||||||
fromlen = 16;
|
fromlen = 16;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -440,7 +436,7 @@ int main(int argc, char **argv)
|
|||||||
* headers. Try to keep alignment intact. */
|
* headers. Try to keep alignment intact. */
|
||||||
printf(_("%-*s TTY "), userlen, _("USER"));
|
printf(_("%-*s TTY "), userlen, _("USER"));
|
||||||
if (from)
|
if (from)
|
||||||
printf(_("FROM "));
|
printf("%-*s", fromlen - 1, _("FROM"));
|
||||||
if (longform)
|
if (longform)
|
||||||
printf(_(" LOGIN@ IDLE JCPU PCPU WHAT\n"));
|
printf(_(" LOGIN@ IDLE JCPU PCPU WHAT\n"));
|
||||||
else
|
else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user