On Sat, Mar 3, 2012 at 10:32, Jim Warner <james.warner@xxxxxxxxxxx> wrote: Hi Jim & Craig, > Your fsf-address-update.patch is a duplicate of the one I sent to Craig. > Mine was in git am format preserving Jaromir's original commit. Yes, your patch is better. > Your w-utmp.patch does not apply cleanly. You are right again. That, and FIXME item are fixed in my 2012wk9 branch. The following changes since commit 7e1657db4864e138a04de1ac5b720adb71716693: Increase library revision number (2012-03-03 18:47:40 +1100) are available in the git repository at: git://gitorious.org/~kerolasa/procps/sami-procps-ng.git 2012wk9 for you to fetch changes up to 5d20ed6545424433603be6a23e76f7ab7e64ef12: w: make date string abbreviations nls aware (2012-03-03 12:03:40 +0100) ---------------------------------------------------------------- Sami Kerola (2): w: use utmp system header size definitions w: make date string abbreviations nls aware w.c | 53 +++++++++++++++++++++++------------------------------ 1 file changed, 23 insertions(+), 30 deletions(-) diff --git a/w.c b/w.c index 39a530d..8c1c80a 100644 --- a/w.c +++ b/w.c @@ -67,13 +67,6 @@ typedef struct utmp utmp_t; # define FROM_STRING "off" #endif -/* Uh... same thing as UT_NAMESIZE */ -#define USERSZ (sizeof u->ut_user) - -/* Arbitary setting, not too big for the screen, max host size */ -#define HOSTSZ 40 - - /* * This routine is careful since some programs leave utmp strings * unprintable. Always outputs at least 16 chars padded with @@ -156,14 +149,11 @@ static time_t idletime(const char *restrict const tty) static void print_logintime(time_t logt, FILE * fout) { - /* FIXME: make use of locale, remember strftime() */ - char weekday[][4] = { - "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" - }; - char month[][4] = { - "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", - "Sep", "Oct", "Nov", "Dec" - }; + + /* Abbreviated of weekday can be longer than 3 characters, + * see for instance hu_HU. Using 16 is few bytes more than + * enough. */ + char time_str[16]; time_t curt; struct tm *logtm, *curtm; int today; @@ -174,12 +164,15 @@ static void print_logintime(time_t logt, FILE * fout) today = curtm->tm_yday; logtm = localtime(&logt); 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, - month[logtm->tm_mon], logtm->tm_year % 100); - else - fprintf(fout, " %3s%02d ", weekday[logtm->tm_wday], + time_str, logtm->tm_year % 100); + } else { + strftime(time_str, sizeof(time_str), "%a", logtm); + fprintf(fout, " %3s%02d ", time_str, logtm->tm_hour); + } } else { fprintf(fout, " %02d:%02d ", logtm->tm_hour, logtm->tm_min); } @@ -249,10 +242,10 @@ static void showinfo(utmp_t * u, int formtype, int maxcmd, int from, unsigned long long jcpu; int ut_pid_found; unsigned i; - char uname[USERSZ + 1] = "", tty[5 + sizeof u->ut_line + 1] = "/dev/"; + char uname[UT_NAMESIZE + 1] = "", tty[5 + UT_LINESIZE + 1] = "/dev/"; 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 */ if (isalnum(u->ut_line[i]) || (u->ut_line[i] == '/')) tty[i + 5] = u->ut_line[i]; @@ -271,12 +264,12 @@ static void showinfo(utmp_t * u, int formtype, int maxcmd, int from, return; /* force NUL term for printf */ - strncpy(uname, u->ut_user, USERSZ); + strncpy(uname, u->ut_user, UT_NAMESIZE); if (formtype) { printf("%-*.*s%-9.8s", userlen + 1, userlen, uname, u->ut_line); 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); if (*u->ut_line == ':') /* idle unknown for xdm logins */ @@ -296,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, u->ut_line); if (from) - print_host(u->ut_host, sizeof u->ut_host, fromlen); + print_host(u->ut_host, UT_HOSTSIZE, fromlen); if (*u->ut_line == ':') /* idle unknown for xdm logins */ printf(" ?xdm? "); @@ -404,20 +397,20 @@ int main(int argc, char **argv) /* Get user field length from environment */ if ((env_var = getenv("PROCPS_USERLEN")) != NULL) { userlen = atoi(env_var); - if (userlen < 8 || userlen > USERSZ) { + if (userlen < 8 || UT_NAMESIZE < userlen) { xwarnx - (_("User length environment PROCPS_USERLEN must be between 8 and %zu, ignoring.\n"), - USERSZ); + (_("User length environment PROCPS_USERLEN must be between 8 and %d, ignoring.\n"), + UT_NAMESIZE); userlen = 8; } } /* Get from field length from environment */ if ((env_var = getenv("PROCPS_FROMLEN")) != NULL) { fromlen = atoi(env_var); - if (fromlen < 8 || fromlen > HOSTSZ) { + if (fromlen < 8 || UT_HOSTSIZE < fromlen) { xwarnx (_("from length environment PROCPS_FROMLEN must be between 8 and %d, ignoring\n"), - HOSTSZ); + UT_HOSTSIZE); fromlen = 16; } } @@ -459,7 +452,7 @@ int main(int argc, char **argv) break; if (u->ut_type != USER_PROCESS) continue; - if (!strncmp(u->ut_user, user, USERSZ)) + if (!strncmp(u->ut_user, user, UT_NAMESIZE)) showinfo(u, longform, maxcmd, from, userlen, fromlen); } -- Sami Kerola http://www.iki.fi/kerolasa/