Date: Wed, 6 Jan 2010 20:39:57 +0000 (UTC) From: Ed Schouten <ed@FreeBSD.org> To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r201666 - user/ed/utmpx/lib/libulog Message-ID: <201001062039.o06KdvA5033349@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: ed Date: Wed Jan 6 20:39:57 2010 New Revision: 201666 URL: http://svn.freebsd.org/changeset/base/201666 Log: Let libulog use ut_id properly, now we have it. Modified: user/ed/utmpx/lib/libulog/ulog_login.c Modified: user/ed/utmpx/lib/libulog/ulog_login.c ============================================================================== --- user/ed/utmpx/lib/libulog/ulog_login.c Wed Jan 6 20:28:47 2010 (r201665) +++ user/ed/utmpx/lib/libulog/ulog_login.c Wed Jan 6 20:39:57 2010 (r201666) @@ -30,9 +30,27 @@ __FBSDID("$FreeBSD$"); #include <sys/time.h> #include <paths.h> #include <string.h> +#include <unistd.h> #include <utmpx.h> #include "ulog.h" +static void +ulog_genid(struct utmpx *utx, const char *line) +{ + size_t s, d; + + /* + * Generate an ut_id based on the TTY name. Use a reverse order + * to prevent the limited space we have to be wasted on prefixes + * like "tty" and "pts/". It also makes sure aliasing because + * of cropping of "pts/1000" and "pts/1001" is less likely. + * Prepend an 'u' to indicate it was done by libulog. + */ + utx->ut_id[0] = 'u'; + for (s = strlen(line), d = 1; s > 0 && d <= sizeof utx->ut_id; s--, d++) + utx->ut_id[d] = line[s - 1]; +} + void ulog_login(const char *line, const char *user, const char *host) { @@ -44,8 +62,9 @@ ulog_login(const char *line, const char memset(&utx, 0, sizeof utx); - /* XXX: ut_id, ut_pid missing. */ utx.ut_type = USER_PROCESS; + utx.ut_pid = getpid(); + ulog_genid(&utx, line); strncpy(utx.ut_line, line, sizeof utx.ut_line); strncpy(utx.ut_user, user, sizeof utx.ut_user); if (host != NULL) @@ -66,9 +85,8 @@ ulog_logout(const char *line) memset(&utx, 0, sizeof utx); - /* XXX: ut_id, ut_pid missing. ut_line not needed */ utx.ut_type = DEAD_PROCESS; - strncpy(utx.ut_line, line, sizeof utx.ut_line); + ulog_genid(&utx, line); gettimeofday(&utx.ut_tv, NULL); pututxline(&utx);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201001062039.o06KdvA5033349>