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