1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * Modified for OpenSSH by Kevin Steves 3*0Sstevel@tonic-gate * October 2000 4*0Sstevel@tonic-gate */ 5*0Sstevel@tonic-gate 6*0Sstevel@tonic-gate /* 7*0Sstevel@tonic-gate * Copyright (c) 1994, 1995 Christopher G. Demetriou 8*0Sstevel@tonic-gate * All rights reserved. 9*0Sstevel@tonic-gate * 10*0Sstevel@tonic-gate * Redistribution and use in source and binary forms, with or without 11*0Sstevel@tonic-gate * modification, are permitted provided that the following conditions 12*0Sstevel@tonic-gate * are met: 13*0Sstevel@tonic-gate * 1. Redistributions of source code must retain the above copyright 14*0Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer. 15*0Sstevel@tonic-gate * 2. Redistributions in binary form must reproduce the above copyright 16*0Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer in the 17*0Sstevel@tonic-gate * documentation and/or other materials provided with the distribution. 18*0Sstevel@tonic-gate * 3. All advertising materials mentioning features or use of this software 19*0Sstevel@tonic-gate * must display the following acknowledgement: 20*0Sstevel@tonic-gate * This product includes software developed by Christopher G. Demetriou 21*0Sstevel@tonic-gate * for the NetBSD Project. 22*0Sstevel@tonic-gate * 4. The name of the author may not be used to endorse or promote products 23*0Sstevel@tonic-gate * derived from this software without specific prior written permission 24*0Sstevel@tonic-gate * 25*0Sstevel@tonic-gate * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 26*0Sstevel@tonic-gate * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 27*0Sstevel@tonic-gate * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 28*0Sstevel@tonic-gate * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 29*0Sstevel@tonic-gate * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 30*0Sstevel@tonic-gate * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31*0Sstevel@tonic-gate * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32*0Sstevel@tonic-gate * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33*0Sstevel@tonic-gate * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 34*0Sstevel@tonic-gate * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35*0Sstevel@tonic-gate */ 36*0Sstevel@tonic-gate 37*0Sstevel@tonic-gate #if defined(LIBC_SCCS) && !defined(lint) 38*0Sstevel@tonic-gate static char rcsid[] = "$OpenBSD: setproctitle.c,v 1.8 2001/11/06 19:21:40 art Exp $"; 39*0Sstevel@tonic-gate #endif /* LIBC_SCCS and not lint */ 40*0Sstevel@tonic-gate 41*0Sstevel@tonic-gate #include "includes.h" 42*0Sstevel@tonic-gate 43*0Sstevel@tonic-gate #ifndef HAVE_SETPROCTITLE 44*0Sstevel@tonic-gate 45*0Sstevel@tonic-gate #define SPT_NONE 0 46*0Sstevel@tonic-gate #define SPT_PSTAT 1 47*0Sstevel@tonic-gate 48*0Sstevel@tonic-gate #ifndef SPT_TYPE 49*0Sstevel@tonic-gate #define SPT_TYPE SPT_NONE 50*0Sstevel@tonic-gate #endif 51*0Sstevel@tonic-gate 52*0Sstevel@tonic-gate #if SPT_TYPE == SPT_PSTAT 53*0Sstevel@tonic-gate #include <sys/param.h> 54*0Sstevel@tonic-gate #include <sys/pstat.h> 55*0Sstevel@tonic-gate #endif /* SPT_TYPE == SPT_PSTAT */ 56*0Sstevel@tonic-gate 57*0Sstevel@tonic-gate #define MAX_PROCTITLE 2048 58*0Sstevel@tonic-gate 59*0Sstevel@tonic-gate extern char *__progname; 60*0Sstevel@tonic-gate 61*0Sstevel@tonic-gate /* 62*0Sstevel@tonic-gate * Set Process Title (SPT) defines. Modeled after sendmail's 63*0Sstevel@tonic-gate * SPT type definition strategy. 64*0Sstevel@tonic-gate * 65*0Sstevel@tonic-gate * SPT_TYPE: 66*0Sstevel@tonic-gate * 67*0Sstevel@tonic-gate * SPT_NONE: Don't set the process title. Default. 68*0Sstevel@tonic-gate * SPT_PSTAT: Use pstat(PSTAT_SETCMD). HP-UX specific. 69*0Sstevel@tonic-gate */ 70*0Sstevel@tonic-gate 71*0Sstevel@tonic-gate void 72*0Sstevel@tonic-gate setproctitle(const char *fmt, ...) 73*0Sstevel@tonic-gate { 74*0Sstevel@tonic-gate #if SPT_TYPE != SPT_NONE 75*0Sstevel@tonic-gate va_list ap; 76*0Sstevel@tonic-gate 77*0Sstevel@tonic-gate char buf[MAX_PROCTITLE]; 78*0Sstevel@tonic-gate size_t used; 79*0Sstevel@tonic-gate 80*0Sstevel@tonic-gate #if SPT_TYPE == SPT_PSTAT 81*0Sstevel@tonic-gate union pstun pst; 82*0Sstevel@tonic-gate #endif /* SPT_TYPE == SPT_PSTAT */ 83*0Sstevel@tonic-gate 84*0Sstevel@tonic-gate va_start(ap, fmt); 85*0Sstevel@tonic-gate if (fmt != NULL) { 86*0Sstevel@tonic-gate used = snprintf(buf, MAX_PROCTITLE, "%s: ", __progname); 87*0Sstevel@tonic-gate if (used >= MAX_PROCTITLE) 88*0Sstevel@tonic-gate used = MAX_PROCTITLE - 1; 89*0Sstevel@tonic-gate (void)vsnprintf(buf + used, MAX_PROCTITLE - used, fmt, ap); 90*0Sstevel@tonic-gate } else 91*0Sstevel@tonic-gate (void)snprintf(buf, MAX_PROCTITLE, "%s", __progname); 92*0Sstevel@tonic-gate va_end(ap); 93*0Sstevel@tonic-gate used = strlen(buf); 94*0Sstevel@tonic-gate 95*0Sstevel@tonic-gate #if SPT_TYPE == SPT_PSTAT 96*0Sstevel@tonic-gate pst.pst_command = buf; 97*0Sstevel@tonic-gate pstat(PSTAT_SETCMD, pst, used, 0, 0); 98*0Sstevel@tonic-gate #endif /* SPT_TYPE == SPT_PSTAT */ 99*0Sstevel@tonic-gate 100*0Sstevel@tonic-gate #endif /* SPT_TYPE != SPT_NONE */ 101*0Sstevel@tonic-gate } 102*0Sstevel@tonic-gate #endif /* HAVE_SETPROCTITLE */ 103*0Sstevel@tonic-gate 104*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 105