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