From 8848b249ff1f6059271480c4abcedc9a3762f9c6 Mon Sep 17 00:00:00 2001 From: Kevin Steves Date: Wed, 18 Oct 2000 13:11:44 +0000 Subject: - (stevesk) Add initial support for setproctitle(). Current support is for the HP-UX pstat(PSTAT_SETCMD, ...) method. --- ChangeLog | 4 ++ Makefile.in | 2 +- acconfig.h | 4 ++ bsd-misc.c | 7 ---- bsd-misc.h | 4 -- bsd-setproctitle.c | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++++ bsd-setproctitle.h | 10 +++++ configure.in | 2 + openbsd-compat.h | 1 + 9 files changed, 128 insertions(+), 12 deletions(-) create mode 100644 bsd-setproctitle.c create mode 100644 bsd-setproctitle.h diff --git a/ChangeLog b/ChangeLog index 3d3a04a93..8cd8109b6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +20001018 + - (stevesk) Add initial support for setproctitle(). Current + support is for the HP-UX pstat(PSTAT_SETCMD, ...) method. + 20001017 - (djm) Add -lregex to cywin libs from Corinna Vinschen diff --git a/Makefile.in b/Makefile.in index a08b3731b..03c745914 100644 --- a/Makefile.in +++ b/Makefile.in @@ -37,7 +37,7 @@ TARGETS=ssh$(EXEEXT) sshd$(EXEEXT) ssh-add$(EXEEXT) ssh-keygen$(EXEEXT) ssh-agen LIBSSH_OBJS=atomicio.o authfd.o authfile.o bufaux.o buffer.o canohost.o channels.o cipher.o cli.o compat.o compress.o crc32.o cygwin_util.o deattack.o dispatch.o dsa.o hmac.o hostfile.o key.o kex.o log.o match.o mpaux.o nchan.o packet.o radix.o rijndael.o entropy.o readpass.o rsa.o tildexpand.o ttymodes.o uidswap.o util.o uuencode.o xmalloc.o -LIBOPENBSD_COMPAT_OBJS=bsd-arc4random.o bsd-base64.o bsd-bindresvport.o bsd-daemon.o bsd-getcwd.o bsd-inet_aton.o bsd-inet_ntoa.o bsd-misc.o bsd-mktemp.o bsd-realpath.o bsd-rresvport.o bsd-setenv.o bsd-sigaction.o bsd-snprintf.o bsd-strlcat.o bsd-strlcpy.o bsd-strsep.o bsd-strtok.o bsd-vis.o fake-getaddrinfo.o fake-getnameinfo.o next-posix.o +LIBOPENBSD_COMPAT_OBJS=bsd-arc4random.o bsd-base64.o bsd-bindresvport.o bsd-daemon.o bsd-getcwd.o bsd-inet_aton.o bsd-inet_ntoa.o bsd-misc.o bsd-mktemp.o bsd-realpath.o bsd-rresvport.o bsd-setenv.o bsd-sigaction.o bsd-snprintf.o bsd-strlcat.o bsd-strlcpy.o bsd-strsep.o bsd-strtok.o bsd-vis.o bsd-setproctitle.o fake-getaddrinfo.o fake-getnameinfo.o next-posix.o SSHOBJS= ssh.o sshconnect.o sshconnect1.o sshconnect2.o log-client.o readconf.o clientloop.o diff --git a/acconfig.h b/acconfig.h index 0837eb3f4..9e95f426b 100644 --- a/acconfig.h +++ b/acconfig.h @@ -6,6 +6,10 @@ @TOP@ +/* Define to a Set Process Title type if your system is */ +/* supported by bsd-setproctitle.c */ +#undef SPT_TYPE + /* SCO workaround */ #undef BROKEN_SYS_TERMIO_H diff --git a/bsd-misc.c b/bsd-misc.c index 6059f5d39..59814946c 100644 --- a/bsd-misc.c +++ b/bsd-misc.c @@ -26,13 +26,6 @@ #include "xmalloc.h" #include "ssh.h" -#ifndef HAVE_SETPROCTITLE -void setproctitle(const char *fmt, ...) -{ - /* FIXME */ -} -#endif /* !HAVE_SETPROCTITLE */ - #ifndef HAVE_SETLOGIN int setlogin(const char *name) { diff --git a/bsd-misc.h b/bsd-misc.h index 477048b74..0546ef1fe 100644 --- a/bsd-misc.h +++ b/bsd-misc.h @@ -27,10 +27,6 @@ #include "config.h" -#ifndef HAVE_SETPROCTITLE -void setproctitle(const char *fmt, ...); -#endif /* !HAVE_SETPROCTITLE */ - #ifndef HAVE_SETENV int setenv(const char *name, const char *value, int overwrite); #endif /* !HAVE_SETENV */ diff --git a/bsd-setproctitle.c b/bsd-setproctitle.c new file mode 100644 index 000000000..51a642e85 --- /dev/null +++ b/bsd-setproctitle.c @@ -0,0 +1,106 @@ +/* + * Modified for OpenSSH by Kevin Steves + * October 2000 + */ + +/* + * Copyright (c) 1994, 1995 Christopher G. Demetriou + * All rights reserved. + * + * 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 the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Christopher G. Demetriou + * for the NetBSD Project. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * 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 ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char rcsid[] = "$OpenBSD: setproctitle.c,v 1.7 1999/02/25 22:10:12 art Exp $"; +#endif /* LIBC_SCCS and not lint */ + +#ifndef HAVE_SETPROCTITLE + +#include "includes.h" + +#define SPT_NONE 0 +#define SPT_PSTAT 1 + +#ifndef SPT_TYPE +#define SPT_TYPE SPT_NONE +#endif + +#if SPT_TYPE == SPT_PSTAT +#include +#include +#endif /* SPT_TYPE == SPT_PSTAT */ + +#define MAX_PROCTITLE 2048 + +#ifdef HAVE___PROGNAME +extern char *__progname; +#else +static const char *__progname = "sshd"; +#endif /* HAVE___PROGNAME */ + +/* + * Set Process Title (SPT) defines. Modeled after sendmail's + * SPT type definition strategy. + * + * SPT_TYPE: + * + * SPT_NONE: Don't set the process title. Default. + * SPT_PSTAT: Use pstat(PSTAT_SETCMD). HP-UX specific. + */ + +void +setproctitle(const char *fmt, ...) +{ +#if SPT_TYPE != SPT_NONE + va_list ap; + + char buf[MAX_PROCTITLE]; + size_t used; + +#if SPT_TYPE == SPT_PSTAT + union pstun pst; +#endif /* SPT_TYPE == SPT_PSTAT */ + + va_start(ap, fmt); + if (fmt != NULL) { + used = snprintf(buf, MAX_PROCTITLE, "%s: ", __progname); + if (used >= MAX_PROCTITLE) + used = MAX_PROCTITLE - 1; + (void)vsnprintf(buf + used, MAX_PROCTITLE - used, fmt, ap); + } else + (void)snprintf(buf, MAX_PROCTITLE, "%s", __progname); + va_end(ap); + used = strlen(buf); + +#if SPT_TYPE == SPT_PSTAT + pst.pst_command = buf; + pstat(PSTAT_SETCMD, pst, used, 0, 0); +#endif /* SPT_TYPE == SPT_PSTAT */ + +#endif /* SPT_TYPE != SPT_NONE */ +} +#endif /* HAVE_SETPROCTITLE */ diff --git a/bsd-setproctitle.h b/bsd-setproctitle.h new file mode 100644 index 000000000..000689fac --- /dev/null +++ b/bsd-setproctitle.h @@ -0,0 +1,10 @@ +#ifndef _BSD_SETPROCTITLE_H +#define _BSD_SETPROCTITLE_H + +#include "config.h" + +#ifndef HAVE_SETPROCTITLE +void setproctitle(const char *fmt, ...); +#endif + +#endif /* _BSD_SETPROCTITLE_H */ diff --git a/configure.in b/configure.in index 1a57583fa..ed4d05199 100644 --- a/configure.in +++ b/configure.in @@ -78,6 +78,7 @@ case "$host" in AC_DEFINE(USE_PIPES) AC_DEFINE(DISABLE_SHADOW) AC_DEFINE(DISABLE_UTMP) + AC_DEFINE(SPT_TYPE,SPT_PSTAT) LIBS="$LIBS -lsec" MANTYPE='$(CATMAN)' mansubdir=cat @@ -88,6 +89,7 @@ case "$host" in AC_DEFINE(USE_PIPES) AC_DEFINE(DISABLE_SHADOW) AC_DEFINE(DISABLE_UTMP) + AC_DEFINE(SPT_TYPE,SPT_PSTAT) LIBS="$LIBS -lsec" MANTYPE='$(CATMAN)' mansubdir=cat diff --git a/openbsd-compat.h b/openbsd-compat.h index 18c67f088..0d5e7427a 100644 --- a/openbsd-compat.h +++ b/openbsd-compat.h @@ -22,6 +22,7 @@ #include "bsd-strsep.h" #include "bsd-strtok.h" #include "bsd-vis.h" +#include "bsd-setproctitle.h" /* rfc2553 socket API replacements */ #include "fake-getaddrinfo.h" -- cgit v1.2.3