w: use utmp definitions to determine array sizes
Signed-off-by: Sami Kerola <kerolasa@iki.fi> Conflicts: w.c
This commit is contained in:
parent
0f6b289212
commit
ddd15211e0
13
w.c
13
w.c
@ -67,9 +67,6 @@ typedef struct utmp utmp_t;
|
|||||||
# define FROM_STRING "off"
|
# define FROM_STRING "off"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Uh... same thing as UT_NAMESIZE */
|
|
||||||
#define USERSZ (sizeof u->ut_user)
|
|
||||||
|
|
||||||
/* Arbitary setting, not too big for the screen, max host size */
|
/* Arbitary setting, not too big for the screen, max host size */
|
||||||
#define HOSTSZ 40
|
#define HOSTSZ 40
|
||||||
|
|
||||||
@ -249,7 +246,7 @@ static void showinfo(utmp_t * u, int formtype, int maxcmd, int from,
|
|||||||
unsigned long long jcpu;
|
unsigned long long jcpu;
|
||||||
int ut_pid_found;
|
int ut_pid_found;
|
||||||
unsigned i;
|
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;
|
const proc_t *best;
|
||||||
|
|
||||||
for (i = 0; i < sizeof(u->ut_line); i++)
|
for (i = 0; i < sizeof(u->ut_line); i++)
|
||||||
@ -271,7 +268,7 @@ static void showinfo(utmp_t * u, int formtype, int maxcmd, int from,
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
/* force NUL term for printf */
|
/* force NUL term for printf */
|
||||||
strncpy(uname, u->ut_user, USERSZ);
|
strncpy(uname, u->ut_user, UT_NAMESIZE);
|
||||||
|
|
||||||
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);
|
||||||
@ -404,10 +401,10 @@ 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 > USERSZ) {
|
if (userlen < 8 || userlen > UT_NAMESIZE) {
|
||||||
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"),
|
||||||
USERSZ);
|
UT_NAMESIZE);
|
||||||
userlen = 8;
|
userlen = 8;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -459,7 +456,7 @@ int main(int argc, char **argv)
|
|||||||
break;
|
break;
|
||||||
if (u->ut_type != USER_PROCESS)
|
if (u->ut_type != USER_PROCESS)
|
||||||
continue;
|
continue;
|
||||||
if (!strncmp(u->ut_user, user, USERSZ))
|
if (!strncmp(u->ut_user, user, UT_NAMESIZE))
|
||||||
showinfo(u, longform, maxcmd, from, userlen,
|
showinfo(u, longform, maxcmd, from, userlen,
|
||||||
fromlen);
|
fromlen);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user