-# $Id: configure.ac,v 1.98 2003/01/09 22:53:12 djm Exp $
+# $Id: configure.ac,v 1.99 2003/01/12 23:04:59 djm Exp $
 
 AC_INIT
 AC_CONFIG_SRCDIR([ssh.c])
        dnl AIX handles lastlog as part of its login message
        AC_DEFINE(DISABLE_LASTLOG)
        AC_DEFINE(LOGIN_NEEDS_UTMPX)
+       AC_DEFINE(SETPROCTITLE_STRATEGY,PS_USE_CLOBBER_ARGV)
+       AC_DEFINE(SETPROCTITLE_PS_PADDING, '\0')
        ;;
 *-*-cygwin*)
        LIBS="$LIBS /usr/lib/textmode.o"
        AC_DEFINE(LOGIN_NEEDS_UTMPX)
        AC_DEFINE(DISABLE_SHADOW)
        AC_DEFINE(DISABLE_UTMP)
-       AC_DEFINE(SPT_TYPE,SPT_PSTAT)
+       AC_DEFINE(SETPROCTITLE_STRATEGY,PS_USE_PSTAT)
        LIBS="$LIBS -lsec -lsecpw"
        AC_CHECK_LIB(xnet, t_error, ,AC_MSG_ERROR([*** -lxnet needed on HP-UX - check config.log ***]))
        disable_ptmx_check=yes
        AC_DEFINE(LOGIN_NEEDS_UTMPX)
        AC_DEFINE(DISABLE_SHADOW)
        AC_DEFINE(DISABLE_UTMP)
-       AC_DEFINE(SPT_TYPE,SPT_PSTAT)
+       AC_DEFINE(SETPROCTITLE_STRATEGY,PS_USE_PSTAT)
        LIBS="$LIBS -lsec"
        AC_CHECK_LIB(xnet, t_error, ,AC_MSG_ERROR([*** -lxnet needed on HP-UX - check config.log ***]))
        ;;
        AC_DEFINE(LOGIN_NEEDS_UTMPX)
        AC_DEFINE(DISABLE_SHADOW)
        AC_DEFINE(DISABLE_UTMP)
-       AC_DEFINE(SPT_TYPE,SPT_PSTAT)
+       AC_DEFINE(SETPROCTITLE_STRATEGY,PS_USE_PSTAT)
        LIBS="$LIBS -lsec"
        AC_CHECK_LIB(xnet, t_error, ,AC_MSG_ERROR([*** -lxnet needed on HP-UX - check config.log ***]))
        ;;
        check_for_libcrypt_later=1
        AC_DEFINE(DONT_TRY_OTHER_AF)
        AC_DEFINE(PAM_TTY_KLUDGE)
+       AC_DEFINE(SETPROCTITLE_STRATEGY,PS_USE_CLOBBER_ARGV)
+       AC_DEFINE(SETPROCTITLE_PS_PADDING, '\0')
        inet6_default_4in6=yes
        ;;
 mips-sony-bsd|mips-sony-newsos4)
 
  * to contain some useful information. Mechanism differs wildly across
  * platforms.
  *
- * $Header: /var/cvs/openssh/openbsd-compat/setproctitle.c,v 1.3 2003/01/09 22:53:13 djm Exp $
+ * $Header: /var/cvs/openssh/openbsd-compat/setproctitle.c,v 1.4 2003/01/12 23:04:59 djm Exp $
  *
  * Copyright 2000 by PostgreSQL Global Development Group
  * various details abducted from various places
 /*------
  * Alternative ways of updating ps display:
  *
- * PS_USE_PSTAT
+ * SETPROCTITLE_STRATEGY == PS_USE_PSTAT
  *        use the pstat(PSTAT_SETCMD, )
  *        (HPUX)
- * PS_USE_PS_STRINGS
+ * SETPROCTITLE_STRATEGY == PS_USE_PS_STRINGS
  *        assign PS_STRINGS->ps_argvstr = "string"
  *        (some BSD systems)
- * PS_USE_CHANGE_ARGV
+ * SETPROCTITLE_STRATEGY == PS_USE_CHANGE_ARGV
  *        assign argv[0] = "string"
  *        (some other BSD systems)
- * PS_USE_CLOBBER_ARGV
+ * SETPROCTITLE_STRATEGY == PS_USE_CLOBBER_ARGV
  *        write over the argv and environment area
  *        (most SysV-like systems)
- * PS_USE_NONE
+ * SETPROCTITLE_STRATEGY == PS_USE_NONE
  *        don't update ps display
  *        (This is the default, as it is safest.)
  */
-#if defined(HAVE_PSTAT) && defined(PSTAT_SETCMD)
-#define PS_USE_PSTAT
-#elif defined(HAVE_PS_STRINGS)
-#define PS_USE_PS_STRINGS
-#elif defined(BSD) || defined(__bsdi__) || defined(__hurd__)
-#define PS_USE_CHANGE_ARGV
-#elif defined(__linux__) || defined(_AIX)
-#define PS_USE_CLOBBER_ARGV
-#else
-#define PS_USE_NONE
+
+#define PS_USE_NONE                    0
+#define PS_USE_PSTAT                   1
+#define PS_USE_PS_STRINGS              2
+#define PS_USE_CHANGE_ARGV             3
+#define PS_USE_CLOBBER_ARGV            4
+
+#ifndef SETPROCTITLE_STRATEGY
+# define SETPROCTITLE_STRATEGY PS_USE_NONE 
 #endif
 
-/* Different systems want the buffer padded differently */
-#if defined(_AIX) || defined(__linux__) || defined(__QNX__) || defined(__svr4__)
-#define PS_PADDING '\0'
-#else
-#define PS_PADDING ' '
+#ifndef SETPROCTITLE_PS_PADDING
+# define SETPROCTITLE_PS_PADDING       ' '
 #endif
 
 /*
  * argv clobbering uses existing argv space, all other methods need a buffer
  */
-#ifndef PS_USE_CLOBBER_ARGV
+#if SETPROCTITLE_STRATEGY != PS_USE_CLOBBER_ARGV
 static char ps_buffer[256];
 static const size_t ps_buffer_size = sizeof(ps_buffer);
-#else /* PS_USE_CLOBBER_ARGV */
+#else
 static char *ps_buffer;                        /* will point to argv area */
 static size_t ps_buffer_size;          /* space determined at run time */
-#endif   /* PS_USE_CLOBBER_ARGV */
+#endif
 
 /* save the original argv[] location here */
 static int     save_argc;
 void
 setproctitle(const char *fmt, ...)
 {
-#ifdef PS_USE_PSTAT
+#if SETPROCTITLE_STRATEGY == PS_USE_PSTAT
        union pstun pst;
 #endif
-#ifndef PS_USE_NONE
+#if SETPROCTITLE_STRATEGY != PS_USE_NONE
        ssize_t used;
        va_list ap;
 
        /* no ps display if you didn't call save_ps_display_args() */
        if (save_argv == NULL)
                return;
-#ifdef PS_USE_CLOBBER_ARGV
+#if SETPROCTITLE_STRATEGY == PS_USE_CLOBBER_ARGV
        /* If ps_buffer is a pointer, it might still be null */
        if (ps_buffer == NULL)
                return;
        /*
         * Overwrite argv[] to point at appropriate space, if needed
         */
-#ifdef PS_USE_CHANGE_ARGV
+#if SETPROCTITLE_STRATEGY == PS_USE_CHANGE_ARGV
        save_argv[0] = ps_buffer;
        save_argv[1] = NULL;
 #endif /* PS_USE_CHANGE_ARGV */
 
-#ifdef PS_USE_CLOBBER_ARGV
+#if SETPROCTITLE_STRATEGY == PS_USE_CLOBBER_ARGV
        save_argv[1] = NULL;
 #endif /* PS_USE_CLOBBER_ARGV */
 
        }
        va_end(ap);
 
-#if 0
-       error("XXXXXXXXX %s", __progname);
-       error("XXXXXXXXX %d", ps_buffer_size);
-       error("XXXXXXXXX %s", ps_buffer);
-#endif
-
-#ifdef PS_USE_PSTAT
+#if SETPROCTITLE_STRATEGY == PS_USE_PSTAT
        pst.pst_command = ps_buffer;
        pstat(PSTAT_SETCMD, pst, strlen(ps_buffer), 0, 0);
 #endif   /* PS_USE_PSTAT */
 
-#ifdef PS_USE_PS_STRINGS
+#if SETPROCTITLE_STRATEGY == PS_USE_PS_STRINGS
        PS_STRINGS->ps_nargvstr = 1;
        PS_STRINGS->ps_argvstr = ps_buffer;
 #endif   /* PS_USE_PS_STRINGS */
 
-#ifdef PS_USE_CLOBBER_ARGV
+#if SETPROCTITLE_STRATEGY == PS_USE_CLOBBER_ARGV
        /* pad unused memory */
        used = strlen(ps_buffer);
-       memset(ps_buffer + used, PS_PADDING, ps_buffer_size - used);
+       memset(ps_buffer + used, SETPROCTITLE_PS_PADDING, 
+           ps_buffer_size - used);
 #endif   /* PS_USE_CLOBBER_ARGV */
 
 #endif /* PS_USE_NONE */
 void
 compat_init_setproctitle(int argc, char *argv[])
 {
-#ifdef PS_USE_CLOBBER_ARGV
+#if SETPROCTITLE_STRATEGY == PS_USE_CLOBBER_ARGV
        char *end_of_area = NULL;
        char **new_environ;
        int i;
        save_argc = argc;
        save_argv = argv;
 
-#ifdef PS_USE_CLOBBER_ARGV
+#if SETPROCTITLE_STRATEGY == PS_USE_CLOBBER_ARGV
        /*
         * If we're going to overwrite the argv area, count the available
         * space.  Also move the environment to make additional room.