Takefumi Iseki
2001-Jun-29 02:30 UTC
wtmpx problem on Solaris 8 sparcv9 (64bit) environment
Hello When I was using OpenSSH-2.9p2 in Solaris 8 sparcv9 (64bit) environment, I found some trouble that wtmpx has broken. The size of utmpx structure object becomes larger than 32 bit environment in sparcv9 environment.Therefore, instead of using utmpx structure object, using futmpx structure object is better. In sparcv9 environment, futmpx structure object is used instead of utmpx structure object. The system is as follows. OpenSSH Version: 2.9p2 OS: % uname -a SunOS foo 5.8 Generic_108528-06 sun4u sparc SUNW,UltraSPARC-IIi-cEngine % isainfo -v 64-bit sparcv9 applications 32-bit sparc applications Please look at reference. % cat utmptest.c #include <stdio.h> #include <utmp.h> #include <utmpx.h> main () { struct utmp utmp; struct futmp futmp; struct utmpx utmpx; struct futmpx futmpx; printf("utmp: %d, futmp: %d / utmpx: %d, futmpx: %d\n", sizeof(utmp), sizeof(futmp), sizeof(utmpx), sizeof(futmpx)); return(1); } % cc utmptest.c % ./a.out utmp: 36, futmp: 36 / utmpx: 372, futmpx: 372 % cc -xarch=v9 utmptest.c % ./a.out utmp: 40, futmp: 36 / utmpx: 384, futmpx: 372 Following are patch for "openssh-2.9p2/loginrec.c" file. diff -Naur openssh-2.9p2.org/loginrec.c openssh-2.9p2.cast/loginrec.c --- openssh-2.9p2.org/loginrec.c Wed May 9 05:34:33 2001 +++ openssh-2.9p2.cast/loginrec.c Thu Jun 28 11:06:22 2001 @@ -887,7 +891,11 @@ /* write a utmpx entry with the system's help (pututxline() and pals) */ # ifdef UTMPX_USE_LIBRARY static int +#ifdef __sparcv9 +utmpx_write_library(struct logininfo *li, struct utmpx *utx) +#else utmpx_write_library(struct logininfo *li, struct utmpx *utx) +#endif { setutxent(); pututxline(utx); @@ -902,7 +910,11 @@ /* write a utmp entry direct to the file */ static int +#ifdef __sparcv9 +utmpx_write_direct(struct logininfo *li, struct futmpx *utx) +#else utmpx_write_direct(struct logininfo *li, struct utmpx *utx) +#endif { log("utmpx_write_direct: not implemented!"); return 0; @@ -1144,7 +1156,11 @@ /* write a wtmpx entry direct to the end of the file */ /* This is a slight modification of code in OpenBSD's logwtmp.c */ static int +#ifdef __sparcv9 +wtmpx_write(struct logininfo *li, struct futmpx *utx) +#else wtmpx_write(struct logininfo *li, struct utmpx *utx) +#endif { struct stat buf; int fd, ret = 1; @@ -1167,6 +1183,24 @@ return ret; } +#ifdef __sparcv9 +void +utmpx_to_futmpx(struct utmpx *utx, struct futmpx *futx) +{ + strncpy(futx->ut_user, utx->ut_user, sizeof(futx->ut_user)); + strncpy(futx->ut_id, utx->ut_id, sizeof(futx->ut_id)); + strncpy(futx->ut_line, utx->ut_line, sizeof(futx->ut_line)); + futx->ut_pid = (pid32_t)utx->ut_pid; + futx->ut_type = (int16_t)utx->ut_type; + futx->ut_exit.e_termination = (int16_t)utx->ut_exit.e_termination; + futx->ut_exit.e_exit = (int16_t)utx->ut_exit.e_exit; + futx->ut_tv.tv_sec = (time32_t)utx->ut_tv.tv_sec; + futx->ut_tv.tv_usec = (int32_t)utx->ut_tv.tv_usec; + futx->ut_session = (int32_t)utx->ut_session; + futx->ut_syslen = (int16_t)utx->ut_syslen; + strncpy(futx->ut_host, utx->ut_host, sizeof(futx->ut_host)); +} +#endif static int wtmpx_perform_login(struct logininfo *li) @@ -1174,7 +1208,15 @@ struct utmpx utx; construct_utmpx(li, &utx); +#ifdef __sparcv9 + { + struct futmpx futx; + utmpx_to_futmpx(&utx , &futx); + return wtmpx_write(li, &futx); + } +#else return wtmpx_write(li, &utx); +#endif } @@ -1184,7 +1226,16 @@ struct utmpx utx; construct_utmpx(li, &utx); - return wtmpx_write(li, &utx); +#ifdef __sparcv9 + { + struct futmpx futx; + utmpx_to_futmpx(&utx , &futx); + return wtmpx_write(li, &futx); + } +#else + return wtmpx_write(li, &utx); +#endif + } @@ -1207,7 +1258,11 @@ /* Return true if this wtmpx entry indicates a login */ static int +#ifdef __sparcv9 +wtmpx_islogin(struct logininfo *li, struct futmpx *utx) +#else wtmpx_islogin(struct logininfo *li, struct utmpx *utx) +#endif { if ( strncmp(li->username, utx->ut_name, MIN_SIZEOF(li->username, utx->ut_name)) == 0 ) { @@ -1226,7 +1281,11 @@ wtmpx_get_entry(struct logininfo *li) { struct stat st; +#ifdef __sparcv9 + struct futmpx utx; +#else struct utmpx utx; +#endif int fd, found=0; /* Clear the time entries */ @@ -1245,7 +1304,11 @@ } /* Seek to the start of the last struct utmpx */ +#ifdef __sparcv9 + if (lseek(fd, (off_t)(0-sizeof(struct futmpx)), SEEK_END) == -1 ) { +#else if (lseek(fd, (off_t)(0-sizeof(struct utmpx)), SEEK_END) == -1 ) { +#endif /* probably a newly rotated wtmpx file */ close(fd); return 0; @@ -1275,7 +1338,11 @@ # endif continue; } +#ifdef __sparcv9 + if (lseek(fd, (off_t)(0-2*sizeof(struct futmpx)), SEEK_CUR) == -1) { +#else if (lseek(fd, (off_t)(0-2*sizeof(struct utmpx)), SEEK_CUR) == -1) { +#endif close (fd); return 0; }
Darren Moffat
2001-Jun-29 15:57 UTC
wtmpx problem on Solaris 8 sparcv9 (64bit) environment
>When I was using OpenSSH-2.9p2 in Solaris 8 sparcv9 (64bit) >environment, I found some trouble that wtmpx has broken.Why are you building 64bit binaries for ssh ? This will gain you nothing and there is no reason to do so. 32bit binaries run just fine on a 64bit kernel (most of Solaris is still 32bit binaries even when running a 64bit kernel). There are currently only 4 reasons to compile userland binaries 64bit rather than 32bit: 1. The process needs greater than 4Gb address space 2. Need for a 64bit time_t ie need to process times past 2038 3. Direct access to kernel memory when runing a 64bit kernel 4. Need to control a 64bit process via /proc (ie you are a debugger). None of the ssh programs fall into these categories. You can do 64bit maths without building a 64bit binary and you can get UltraSPARC performance improvements on 32bit binaries - infact in general 32bit binaries perform better than 64bit ones. If you are compiling with -xarch=v9 in an attempt to gain the performance benifits of the UltraSPARC platfrom then this isn't what you are getting. In fact all it will do is hurt your performance since you will waste valuable cache space - bigger bits does NOT mean faster. -xarch=v9 means build a 64bit binary -xtarget=ultra will give you a 32bit binary optimized for UltraSPARC. I don't believe that this patch is neccessary. -- Darren J Moffat