On Fri, Feb 12, 1999 at 04:02:31PM +0100, Niels M=F6ller wrote:
> Rafal Maszkowski <[EMAIL PROTECTED]> writes:
> > After a break I am trying to run version 1999-01-28 now. All proble=
ms except
> > the one with -z option are fixed. I was able to connect lsh to lshd=
 on Solaris.
> > One of he strange problems I've met is ignoring '\n' by tr so I hav=
e changed it
> > like
> > -AC_DEFINE_UNQUOTED(PTY_BSD_SCHEME_FIRST_CHARS, "`ls /dev/pty* | cu=
t -c 9-9 | uniq | tr -d '\n'`")
> > -AC_DEFINE_UNQUOTED(PTY_BSD_SCHEME_SECOND_CHARS, "`ls /dev/pty* | c=
ut -c 10-10 | sort | uniq | tr -d '\n'`")
> > +AC_DEFINE_UNQUOTED(PTY_BSD_SCHEME_FIRST_CHARS, "`ls /dev/pty* | cu=
t -c 9-9 | uniq | /usr/xpg4/bin/tr -d '\n'`")
> > +AC_DEFINE_UNQUOTED(PTY_BSD_SCHEME_SECOND_CHARS, "`ls /dev/pty* | c=
ut -c 10-10 | sort | uniq | /usr/xpg4/bin/tr -d '\n'`")
> > in configure.in .
> Thanks, I should change these tests. Is there any particular reason
> why you are using absolute paths for tr?

There are at least three (!) different trs on Solaris:

rzm@galera:~/lsh,0> lt /usr/ucb/tr /usr/xpg4/bin/tr /usr/bin/tr
-r-xr-xr-x   1 bin         14480 May  3  1996 /usr/xpg4/bin/tr
-r-xr-xr-x   1 bin         15108 May  3  1996 /usr/bin/tr
-rwxr-xr-x   1 bin          4676 May  3  1996 /usr/ucb/tr

and not all understand '\n'. But I have found a better solution - use '=
\012'
instead of '\n'. It will not break anything on Linux and doesn't need
additional checking.

> > - steal [v]snprintf from glibc-2.1 and put tests into configure.in
> That would be good. Currently, there are only two uses of snprintf,
> though (in server_pty.c).

I used the one advised by emarshal - http://www.theos.com/deraadt/snpri=
ntf.c, I
only removed space from between roundup and '(' in roundup() define bec=
ause gcc
didn't like it (I am using v. 2.8.1 here).


Relevant diffs (better change for broken Solaris tr handling and privat=
e
[v]snprintf; cfmakeraw will be in another mail):

diff -ru lsh-snapshot-1999-01-28.orig/configure.in lsh-snapshot-1999-01=
-28/configure.in
--- lsh-snapshot-1999-01-28.orig/configure.in   Thu Jan 28 08:55:06 1999
+++ lsh-snapshot-1999-01-28/configure.in        Sun Feb 14 04:49:02 1999
@@ -178,7 +178,8 @@
 AC_FUNC_VPRINTF
 AC_CHECK_FUNCS(select socket strerror strtol)
 AC_CHECK_FUNCS(getspnam)
-AC_CHECK_FUNCS(vsnprintf inet_aton)
+AC_CHECK_FUNCS(inet_aton)
+AC_CHECK_FUNCS(snprintf,,[LIBOBJS=3D"snprintf.o $LIBOBJS"])
 AC_CHECK_FUNCS(openpty)
 AC_CHECK_FUNCS(poll,,[LIBOBJS=3D"jpoll.o $LIBOBJS"])
=20
@@ -291,8 +292,8 @@
 fi
=20
 AC_MSG_CHECKING(for BSD pty names)
-AC_DEFINE_UNQUOTED(PTY_BSD_SCHEME_FIRST_CHARS, "`ls /dev/pty* | cut -c=
 9-9 | uniq | tr -d '\n'`")
-AC_DEFINE_UNQUOTED(PTY_BSD_SCHEME_SECOND_CHARS, "`ls /dev/pty* | cut -=
c 10-10 | sort | uniq | tr -d '\n'`")
+AC_DEFINE_UNQUOTED(PTY_BSD_SCHEME_FIRST_CHARS, "`ls /dev/pty* | cut -c=
 9-9 | uniq | tr -d '\012'`")
+AC_DEFINE_UNQUOTED(PTY_BSD_SCHEME_SECOND_CHARS, "`ls /dev/pty* | cut -=
c 10-10 | sort | uniq | tr -d '\012'`")
 AC_DEFINE(PTY_BSD_SCHEME)
 AC_MSG_RESULT([done])
=20
diff -ru lsh-snapshot-1999-01-28.orig/src/werror.c lsh-snapshot-1999-01=
-28/src/werror.c
--- lsh-snapshot-1999-01-28.orig/src/werror.c   Thu Jan 28 10:00:06 1999
+++ lsh-snapshot-1999-01-28/src/werror.c        Sun Feb 14 04:52:42 1999
@@ -97,7 +97,6 @@
     }
 }
=20
-#ifdef HAVE_VSNPRINTF
 /* FIXME: Too bad we can't create a custom FILE * using werror_putc to
  * output each character. */
 static void w_vnprintf(unsigned size, const char *format, va_list args=
)
@@ -123,16 +122,6 @@
       WERROR(size, s);
     }
 }
-#else /* !HAVE_VSNPRINTF */
-
-#warning No vsnprintf. Some output to stderr will be lost.
-
-static void w_vnprintf(unsigned size, const char *format, va_list args=
)
-{
-  /* NOTE: This loses the interesting parts of the messages. */
-  wwrite(format);
-}
-#endif /* !HAVE_VSNPRINTF */
=20
 static void w_nprintf(UINT32 size, const char *format, ...)
 {



I am including the http://www.theos.com/deraadt/snprintf.c as an attach=
ment. I
wonder if the license is OK for lsh:

/*
 * Revision 12: http://theos.com/~deraadt/snprintf.c
 *
 * Copyright (c) 1997 Theo de Raadt
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in t=
he
 *    documentation and/or other materials provided with the distributi=
on.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRA=
NTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIM=
ED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,=
 BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF=
 USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON AN=
Y
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE US=
E OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

what means that hypotetic lsh....rpm has to have at least above lines i=
n
/usr/doc/lsh../snprintf.disclaimer or maybe whole snprintf.c there - it=
 is only
3+ KB.

R.
/*
 * Revision 12: http://theos.com/~deraadt/snprintf.c
 *
 * Copyright (c) 1997 Theo de Raadt
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in t=
he
 *    documentation and/or other materials provided with the distributi=
on.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRA=
NTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIM=
ED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,=
 BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF=
 USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON AN=
Y
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE US=
E OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include <sys/param.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <signal.h>
#include <stdio.h>
#if __STDC__
#include <stdarg.h>
#include <stdlib.h>
#else
#include <varargs.h>
#endif
#include <setjmp.h>

#ifndef roundup
#define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
#endif

static int pgsize;
static char *curobj;
static int caught;
static sigjmp_buf bail;

#define EXTRABYTES      2       /* XXX: why 2? you don't want to know */

static char *
msetup(str, n)
        char *str;
        size_t n;
{
        char *e;

        if (n =3D=3D 0)
                return NULL;
        if (pgsize =3D=3D 0)
                pgsize =3D getpagesize();
        curobj =3D (char *)malloc(n + EXTRABYTES + pgsize * 2);
        if (curobj =3D=3D NULL)
                return NULL;
        e =3D curobj + n + EXTRABYTES;
        e =3D (char *)roundup((unsigned long)e, pgsize);
        if (mprotect(e, pgsize, PROT_NONE) =3D=3D -1) {
                free(curobj);
                curobj =3D NULL;
                return NULL;
        }
        e =3D e - n - EXTRABYTES;
        *e =3D '\0';
        return (e);
}

static void
mcatch()
{
        siglongjmp(bail, 1);
}

static void
mcleanup(str, n, p)
        char *str;
        size_t n;
        char *p;
{
        strncpy(str, p, n-1);
        str[n-1] =3D '\0';
        if (mprotect((caddr_t)(p + n + EXTRABYTES), pgsize,
            PROT_READ|PROT_WRITE|PROT_EXEC) =3D=3D -1)
                mprotect((caddr_t)(p + n + EXTRABYTES), pgsize,
                    PROT_READ|PROT_WRITE);
        free(curobj);
}

int
#if __STDC__
snprintf(char *str, size_t n, char const *fmt, ...)
#else
snprintf(str, n, fmt, va_alist)
        char *str;
        size_t n;
        char *fmt;
        va_dcl
#endif
{
        va_list ap;
#if __STDC__
        va_start(ap, fmt);
#else
        va_start(ap);
#endif

        return (vsnprintf(str, n, fmt, ap));
        va_end(ap);
}

int
vsnprintf(str, n, fmt, ap)
        char *str;
        size_t n;
        char *fmt;
        char *ap;
{
        struct sigaction osa, nsa;
        char *p;
        int ret =3D n + 1;      /* if we bail, indicated we overflowed */

        memset(&nsa, 0, sizeof nsa);
        nsa.sa_handler =3D mcatch;
        sigemptyset(&nsa.sa_mask);

        p =3D msetup(str, n);
        if (p =3D=3D NULL) {
                *str =3D '\0';
                return 0;
        }
        if (sigsetjmp(bail, 1) =3D=3D 0) {
                if (sigaction(SIGSEGV, &nsa, &osa) =3D=3D -1) {
                        mcleanup(str, n, p);
                        return (0);
                }
                ret =3D vsprintf(p, fmt, ap);
        }
        mcleanup(str, n, p);
        (void) sigaction(SIGSEGV, &osa, NULL);
        return (ret);
}

Reply via email to