Hi all, I've attached five patches for sessreg:
[PATCH 1/5] Correct whitespace and indentation. [PATCH 2/5] Fix typo in function name check. [PATCH 3/5] Only split off /dev/ instead trimming to last /. [PATCH 4/5] Use Autoconf to check for utmp field existence. [PATCH 5/5] Get rid of bzero() calls. Replace them by memset(). Greetings, -- Ed Schouten <e...@80386.nl> WWW: http://80386.nl/
From 7a3763b5b101c64c67851a18dc53f4c306776a1f Mon Sep 17 00:00:00 2001 From: Ed Schouten <e...@80386.nl> Date: Wed, 22 Jun 2011 00:09:59 +0200 Subject: [PATCH 1/5] Correct whitespace and indentation. Signed-off-by: Ed Schouten <e...@80386.nl> --- sessreg.c | 184 ++++++++++++++++++++++++++++++------------------------------ sessreg.h | 6 +- 2 files changed, 95 insertions(+), 95 deletions(-) diff --git a/sessreg.c b/sessreg.c index 40ec450..08da1ab 100644 --- a/sessreg.c +++ b/sessreg.c @@ -6,10 +6,10 @@ * the above copyright notice appear in all copies and that both that * copyright notice and this permission notice appear in supporting * documentation. - * + * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. @@ -17,7 +17,7 @@ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. - * + * * Except as contained in this notice, the name of The Open Group shall * not be used in advertising or otherwise to promote the sale, use or * other dealings in this Software without prior written authorization @@ -65,7 +65,7 @@ * [ -h <host-name> ] / BSD only * [ -s <slot-number> ] [ -x Xservers-file ] / BSD only * [ -t <ttys-file> ] / BSD only - * [ -a ] [ -d ] user-name + * [ -a ] [ -d ] user-name * * one of -a or -d must be specified */ @@ -189,9 +189,9 @@ main (int argc, char **argv) int utmp; #endif char *line_tmp; -#ifndef USE_UTMPX +#ifndef USE_UTMPX int wtmp; -#endif +#endif Time_t current_time; #ifdef USE_UTMP struct utmp utmp_entry; @@ -304,24 +304,24 @@ main (int argc, char **argv) UtmpxIdOpen to work */ # ifdef HAVE_UTMPXNAME if (utmpx_file != NULL) { - utmpxname (utmpx_file); + utmpxname (utmpx_file); } # endif set_utmpx (&utmpx_entry, line, user_name, host_name, current_time, aflag); -#endif +#endif if (!utmp_none) { #ifdef USE_UTMPX # ifdef HAVE_UTMPX_NAME - if (utmpx_file != NULL) + if (utmpx_file != NULL) # endif - { - setutxent (); - (void) getutxid (&utmpx_entry); - pututxline (&utmpx_entry); - endutxent (); - } + { + setutxent (); + (void) getutxid (&utmpx_entry); + pututxline (&utmpx_entry); + endutxent (); + } #endif #ifdef USE_UTMP # ifdef SYSV @@ -335,7 +335,7 @@ main (int argc, char **argv) if (utmp != -1) { syserr ((int) lseek (utmp, (long) slot_number * sizeof (struct utmp), 0), "lseek"); sysnerr (write (utmp, (char *) &utmp_entry, sizeof (utmp_entry)) - == sizeof (utmp_entry), "write utmp entry"); + == sizeof (utmp_entry), "write utmp entry"); close (utmp); } # endif @@ -352,24 +352,24 @@ main (int argc, char **argv) wtmp = open (wtmp_file, O_WRONLY|O_APPEND); if (wtmp != -1) { sysnerr (write (wtmp, (char *) &utmp_entry, sizeof (utmp_entry)) - == sizeof (utmp_entry), "write wtmp entry"); + == sizeof (utmp_entry), "write wtmp entry"); close (wtmp); } -#endif +#endif } #ifndef NO_LASTLOG if (aflag && !llog_none) { - int llog; - struct passwd *pwd = getpwnam(user_name); + int llog; + struct passwd *pwd = getpwnam(user_name); - sysnerr( pwd != NULL, "get user id"); - llog = open (llog_file, O_RDWR); + sysnerr( pwd != NULL, "get user id"); + llog = open (llog_file, O_RDWR); if (llog != -1) { struct lastlog ll; sysnerr (lseek(llog, (long) pwd->pw_uid*sizeof(ll), 0) - != -1, "seeking lastlog entry"); + != -1, "seeking lastlog entry"); bzero((char *)&ll, sizeof(ll)); ll.ll_time = current_time; if (line) @@ -378,7 +378,7 @@ main (int argc, char **argv) (void) strncpy (ll.ll_host, host_name, sizeof (ll.ll_host)); sysnerr (write (llog, (char *) &ll, sizeof (ll)) - == sizeof (ll), "write lastlog entry"); + == sizeof (ll), "write lastlog entry"); close (llog); } } @@ -447,17 +447,17 @@ UtmpxIdOpen( char *utmpId ) int status = 1; /* return code */ setutxent(); - + while ( (u = getutxent()) != NULL ) { - + if ( (strncmp(u->ut_id, utmpId, 4) == 0 ) && u->ut_type != DEAD_PROCESS ) { - + status = 0; break; } } - + endutxent(); return (status); } @@ -469,77 +469,77 @@ set_utmpx (struct utmpx *u, const char *line, const char *user, static const char letters[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; - if (line) + if (line) { - if(strcmp(line, ":0") == 0) - (void) strcpy(u->ut_line, "console"); - else - (void) strncpy (u->ut_line, line, sizeof (u->ut_line)); + if(strcmp(line, ":0") == 0) + (void) strcpy(u->ut_line, "console"); + else + (void) strncpy (u->ut_line, line, sizeof (u->ut_line)); strncpy(u->ut_host, line, sizeof(u->ut_host)); #ifdef HAVE_STRUCT_UTMPX_UT_SYSLEN - u->ut_syslen = strlen(line); + u->ut_syslen = strlen(line); #endif } - else - bzero (u->ut_line, sizeof (u->ut_line)); - if (addp && user) - (void) strncpy (u->ut_user, user, sizeof (u->ut_user)); - else - bzero (u->ut_user, sizeof (u->ut_user)); - - if (line) { - int i; - /* - * this is a bit crufty, but - * follows the apparent conventions in - * the ttys file. ut_id is only 4 bytes - * long, and the last 4 bytes of the line - * name are written into it, left justified. - */ - i = strlen (line); - if (i >= sizeof (u->ut_id)) - i -= sizeof (u->ut_id); - else - i = 0; - (void) strncpy (u->ut_id, line + i, sizeof (u->ut_id)); + else + bzero (u->ut_line, sizeof (u->ut_line)); + if (addp && user) + (void) strncpy (u->ut_user, user, sizeof (u->ut_user)); + else + bzero (u->ut_user, sizeof (u->ut_user)); + + if (line) { + int i; + /* + * this is a bit crufty, but + * follows the apparent conventions in + * the ttys file. ut_id is only 4 bytes + * long, and the last 4 bytes of the line + * name are written into it, left justified. + */ + i = strlen (line); + if (i >= sizeof (u->ut_id)) + i -= sizeof (u->ut_id); + else + i = 0; + (void) strncpy (u->ut_id, line + i, sizeof (u->ut_id)); /* make sure there is no entry using identical ut_id */ if (!UtmpxIdOpen(u->ut_id) && addp) { - int limit = sizeof(letters) - 1; - int t = 0; - - u->ut_id[1] = line[i]; - u->ut_id[2] = line[i+1]; - u->ut_id[3] = line[i+2]; - do { - u->ut_id[0] = letters[t]; - t++; - } while (!UtmpxIdOpen(u->ut_id) && (t < limit)); - } - if (!addp && strstr(line, ":") != NULL) { - struct utmpx *tmpu; - - while ( (tmpu = getutxent()) != NULL ) { - if ( (strcmp(tmpu->ut_host, line) == 0 ) && - tmpu->ut_type != DEAD_PROCESS ) { - strncpy(u->ut_id, tmpu->ut_id, + int limit = sizeof(letters) - 1; + int t = 0; + + u->ut_id[1] = line[i]; + u->ut_id[2] = line[i+1]; + u->ut_id[3] = line[i+2]; + do { + u->ut_id[0] = letters[t]; + t++; + } while (!UtmpxIdOpen(u->ut_id) && (t < limit)); + } + if (!addp && strstr(line, ":") != NULL) { + struct utmpx *tmpu; + + while ( (tmpu = getutxent()) != NULL ) { + if ( (strcmp(tmpu->ut_host, line) == 0 ) && + tmpu->ut_type != DEAD_PROCESS ) { + strncpy(u->ut_id, tmpu->ut_id, sizeof(u->ut_id)); - break; - } - } - endutxent(); - } - } else - bzero (u->ut_id, sizeof (u->ut_id)); - - if (addp) { - u->ut_pid = getppid (); - u->ut_type = USER_PROCESS; - } else { - u->ut_pid = 0; - u->ut_type = DEAD_PROCESS; - } + break; + } + } + endutxent(); + } + } else + bzero (u->ut_id, sizeof (u->ut_id)); + + if (addp) { + u->ut_pid = getppid (); + u->ut_type = USER_PROCESS; + } else { + u->ut_pid = 0; + u->ut_type = DEAD_PROCESS; + } u->ut_tv.tv_sec = date; u->ut_tv.tv_usec = 0; } @@ -636,13 +636,13 @@ findslot (char *line_name, char *host_name, int addp, int slot) while (read (utmp, (char *) &entry, sizeof (entry)) == sizeof (entry)) { if (strncmp(entry.ut_line, line_name, - sizeof(entry.ut_line)) == 0 + sizeof(entry.ut_line)) == 0 #ifndef __QNX__ - && + && strncmp(entry.ut_host, host_name, sizeof(entry.ut_host)) == 0 #endif - ) { + ) { found = 1; break; } diff --git a/sessreg.h b/sessreg.h index fe4f573..cf721c8 100644 --- a/sessreg.h +++ b/sessreg.h @@ -6,10 +6,10 @@ * the above copyright notice appear in all copies and that both that * copyright notice and this permission notice appear in supporting * documentation. - * + * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. @@ -17,7 +17,7 @@ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. - * + * * Except as contained in this notice, the name of The Open Group shall * not be used in advertising or otherwise to promote the sale, use or * other dealings in this Software without prior written authorization -- 1.7.4.2
From 17f09cc4b3ddb403f9ae5fda0572606fc8818c8e Mon Sep 17 00:00:00 2001 From: Ed Schouten <e...@80386.nl> Date: Wed, 22 Jun 2011 00:10:17 +0200 Subject: [PATCH 2/5] Fix typo in function name check. Signed-off-by: Ed Schouten <e...@80386.nl> --- sessreg.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/sessreg.c b/sessreg.c index 08da1ab..5b0fb87 100644 --- a/sessreg.c +++ b/sessreg.c @@ -313,7 +313,7 @@ main (int argc, char **argv) if (!utmp_none) { #ifdef USE_UTMPX -# ifdef HAVE_UTMPX_NAME +# ifdef HAVE_UTMPXNAME if (utmpx_file != NULL) # endif { -- 1.7.4.2
From 102be027d1be60e89f828022b0d5bf38cf56ff9a Mon Sep 17 00:00:00 2001 From: Ed Schouten <e...@80386.nl> Date: Wed, 22 Jun 2011 00:36:41 +0200 Subject: [PATCH 3/5] Only split off /dev/ instead trimming to last /. This prevents pseudo-terminals with names like /dev/pts/0 from getting trimmed to just 0 instead of pts/0. Signed-off-by: Ed Schouten <e...@80386.nl> --- sessreg.c | 10 +++------- 1 files changed, 3 insertions(+), 7 deletions(-) diff --git a/sessreg.c b/sessreg.c index 5b0fb87..6bd593a 100644 --- a/sessreg.c +++ b/sessreg.c @@ -188,7 +188,6 @@ main (int argc, char **argv) #if defined(USE_UTMP) && !defined(SYSV) int utmp; #endif - char *line_tmp; #ifndef USE_UTMPX int wtmp; #endif @@ -287,12 +286,9 @@ main (int argc, char **argv) } #endif if (!lflag) { - sysnerr ((line_tmp = ttyname (0)) != NULL, "ttyname"); - line = strrchr(line_tmp, '/'); - if (line) - line = line + 1; - else - line = line_tmp; + sysnerr ((line = ttyname (0)) != NULL, "ttyname"); + if (strncmp(line, "/dev/", 5) == 0) + line += 5; } time (¤t_time); #ifdef USE_UTMP -- 1.7.4.2
From b49e5bb33f780695bf384dcb48047dfd225d3c23 Mon Sep 17 00:00:00 2001 From: Ed Schouten <e...@80386.nl> Date: Fri, 24 Jun 2011 15:46:43 +0200 Subject: [PATCH 4/5] Use Autoconf to check for utmp field existence. Don't use the quirky SYSV and __QNX__ definitions to determine whether the utmp fields exist. Signed-off-by: Ed Schouten <e...@80386.nl> --- configure.ac | 5 +++++ sessreg.c | 19 ++++++++++++------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/configure.ac b/configure.ac index c7e5e90..be90cf3 100644 --- a/configure.ac +++ b/configure.ac @@ -44,6 +44,11 @@ XORG_WITH_LINT AC_CHECK_HEADERS([lastlog.h utmp.h utmpx.h sys/param.h]) # Checks for typedefs, structures, and compiler characteristics. +AC_CHECK_MEMBERS([ + struct utmp.ut_host, + struct utmp.ut_id, + struct utmp.ut_pid, + struct utmp.ut_type], [], [], [#include <utmp.h>]) AC_CHECK_MEMBERS([struct utmpx.ut_syslen], [], [], [#include <utmpx.h>]) # Checks for library functions. diff --git a/sessreg.c b/sessreg.c index 6bd593a..9ce4653 100644 --- a/sessreg.c +++ b/sessreg.c @@ -399,7 +399,7 @@ set_utmp (struct utmp *u, char *line, char *user, char *host, Time_t date, int a (void) strncpy (u->ut_name, user, sizeof (u->ut_name)); else bzero (u->ut_name, sizeof (u->ut_name)); -#ifdef SYSV +#ifdef HAVE_STRUCT_UTMP_UT_ID if (line) { int i; /* @@ -417,15 +417,20 @@ set_utmp (struct utmp *u, char *line, char *user, char *host, Time_t date, int a (void) strncpy (u->ut_id, line + i, sizeof (u->ut_id)); } else bzero (u->ut_id, sizeof (u->ut_id)); - if (addp) { +#endif +#ifdef HAVE_STRUCT_UTMP_UT_PID + if (addp) u->ut_pid = getppid (); - u->ut_type = USER_PROCESS; - } else { + else u->ut_pid = 0; +#endif +#ifdef HAVE_STRUCT_UTMP_UT_TYPE + if (addp) + u->ut_type = USER_PROCESS; + else u->ut_type = DEAD_PROCESS; - } #endif -#if (!defined(SYSV) && !defined(__QNX__)) || defined(linux) +#ifdef HAVE_STRUCT_UTMP_UT_HOST if (addp && host) (void) strncpy (u->ut_host, host, sizeof (u->ut_host)); else @@ -633,7 +638,7 @@ findslot (char *line_name, char *host_name, int addp, int slot) while (read (utmp, (char *) &entry, sizeof (entry)) == sizeof (entry)) { if (strncmp(entry.ut_line, line_name, sizeof(entry.ut_line)) == 0 -#ifndef __QNX__ +#ifdef HAVE_STRUCT_UTMP_UT_HOST && strncmp(entry.ut_host, host_name, sizeof(entry.ut_host)) == 0 -- 1.7.4.2
From 8804899782045d4ac7d8be49b10c928128556c0a Mon Sep 17 00:00:00 2001 From: Ed Schouten <e...@80386.nl> Date: Fri, 24 Jun 2011 15:52:18 +0200 Subject: [PATCH 5/5] Get rid of bzero() calls. Replace them by memset(). bzero() is not part of POSIX; memset() is. Signed-off-by: Ed Schouten <e...@80386.nl> --- sessreg.c | 18 +++++++++--------- 1 files changed, 9 insertions(+), 9 deletions(-) diff --git a/sessreg.c b/sessreg.c index 9ce4653..7bce6ef 100644 --- a/sessreg.c +++ b/sessreg.c @@ -366,7 +366,7 @@ main (int argc, char **argv) sysnerr (lseek(llog, (long) pwd->pw_uid*sizeof(ll), 0) != -1, "seeking lastlog entry"); - bzero((char *)&ll, sizeof(ll)); + memset(&ll, 0, sizeof(ll)); ll.ll_time = current_time; if (line) (void) strncpy (ll.ll_line, line, sizeof (ll.ll_line)); @@ -390,15 +390,15 @@ main (int argc, char **argv) static void set_utmp (struct utmp *u, char *line, char *user, char *host, Time_t date, int addp) { - bzero (u, sizeof (*u)); + memset (u, 0, sizeof (*u)); if (line) (void) strncpy (u->ut_line, line, sizeof (u->ut_line)); else - bzero (u->ut_line, sizeof (u->ut_line)); + memset (u->ut_line, 0, sizeof (u->ut_line)); if (addp && user) (void) strncpy (u->ut_name, user, sizeof (u->ut_name)); else - bzero (u->ut_name, sizeof (u->ut_name)); + memset (u->ut_name, 0, sizeof (u->ut_name)); #ifdef HAVE_STRUCT_UTMP_UT_ID if (line) { int i; @@ -416,7 +416,7 @@ set_utmp (struct utmp *u, char *line, char *user, char *host, Time_t date, int a i = 0; (void) strncpy (u->ut_id, line + i, sizeof (u->ut_id)); } else - bzero (u->ut_id, sizeof (u->ut_id)); + memset (u->ut_id, 0, sizeof (u->ut_id)); #endif #ifdef HAVE_STRUCT_UTMP_UT_PID if (addp) @@ -434,7 +434,7 @@ set_utmp (struct utmp *u, char *line, char *user, char *host, Time_t date, int a if (addp && host) (void) strncpy (u->ut_host, host, sizeof (u->ut_host)); else - bzero (u->ut_host, sizeof (u->ut_host)); + memset (u->ut_host, 0, sizeof (u->ut_host)); #endif u->ut_time = date; } @@ -483,11 +483,11 @@ set_utmpx (struct utmpx *u, const char *line, const char *user, #endif } else - bzero (u->ut_line, sizeof (u->ut_line)); + memset (u->ut_line, 0, sizeof (u->ut_line)); if (addp && user) (void) strncpy (u->ut_user, user, sizeof (u->ut_user)); else - bzero (u->ut_user, sizeof (u->ut_user)); + memset (u->ut_user, 0, sizeof (u->ut_user)); if (line) { int i; @@ -532,7 +532,7 @@ set_utmpx (struct utmpx *u, const char *line, const char *user, endutxent(); } } else - bzero (u->ut_id, sizeof (u->ut_id)); + memset (u->ut_id, 0, sizeof (u->ut_id)); if (addp) { u->ut_pid = getppid (); -- 1.7.4.2
pgpg7L4Hr9l7A.pgp
Description: PGP signature
_______________________________________________ xorg-devel@lists.x.org: X.Org development Archives: http://lists.x.org/archives/xorg-devel Info: http://lists.x.org/mailman/listinfo/xorg-devel