summaryrefslogtreecommitdiff
path: root/openbsd-compat/setproctitle.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2003-01-13 10:04:58 +1100
committerDamien Miller <djm@mindrot.org>2003-01-13 10:04:58 +1100
commitec201964e4afc9d97b4f11251cb42db0bd4fb062 (patch)
treea6fcb656d85a9f4201e023bc4f221b0fe1fb2fb0 /openbsd-compat/setproctitle.c
parent4790772cda87697a33e54d35c7cc2763914e014a (diff)
- (djm) Rework openbsd-compat/setproctitle.c a bit: move emulation type
detection to configure.ac. Prompted by stevesk@
Diffstat (limited to 'openbsd-compat/setproctitle.c')
-rw-r--r--openbsd-compat/setproctitle.c73
1 files changed, 32 insertions, 41 deletions
diff --git a/openbsd-compat/setproctitle.c b/openbsd-compat/setproctitle.c
index 5439bd07e..14d5d2f3c 100644
--- a/openbsd-compat/setproctitle.c
+++ b/openbsd-compat/setproctitle.c
@@ -31,7 +31,7 @@
31 * to contain some useful information. Mechanism differs wildly across 31 * to contain some useful information. Mechanism differs wildly across
32 * platforms. 32 * platforms.
33 * 33 *
34 * $Header: /var/cvs/openssh/openbsd-compat/setproctitle.c,v 1.3 2003/01/09 22:53:13 djm Exp $ 34 * $Header: /var/cvs/openssh/openbsd-compat/setproctitle.c,v 1.4 2003/01/12 23:04:59 djm Exp $
35 * 35 *
36 * Copyright 2000 by PostgreSQL Global Development Group 36 * Copyright 2000 by PostgreSQL Global Development Group
37 * various details abducted from various places 37 * various details abducted from various places
@@ -56,51 +56,47 @@ extern char **environ;
56/*------ 56/*------
57 * Alternative ways of updating ps display: 57 * Alternative ways of updating ps display:
58 * 58 *
59 * PS_USE_PSTAT 59 * SETPROCTITLE_STRATEGY == PS_USE_PSTAT
60 * use the pstat(PSTAT_SETCMD, ) 60 * use the pstat(PSTAT_SETCMD, )
61 * (HPUX) 61 * (HPUX)
62 * PS_USE_PS_STRINGS 62 * SETPROCTITLE_STRATEGY == PS_USE_PS_STRINGS
63 * assign PS_STRINGS->ps_argvstr = "string" 63 * assign PS_STRINGS->ps_argvstr = "string"
64 * (some BSD systems) 64 * (some BSD systems)
65 * PS_USE_CHANGE_ARGV 65 * SETPROCTITLE_STRATEGY == PS_USE_CHANGE_ARGV
66 * assign argv[0] = "string" 66 * assign argv[0] = "string"
67 * (some other BSD systems) 67 * (some other BSD systems)
68 * PS_USE_CLOBBER_ARGV 68 * SETPROCTITLE_STRATEGY == PS_USE_CLOBBER_ARGV
69 * write over the argv and environment area 69 * write over the argv and environment area
70 * (most SysV-like systems) 70 * (most SysV-like systems)
71 * PS_USE_NONE 71 * SETPROCTITLE_STRATEGY == PS_USE_NONE
72 * don't update ps display 72 * don't update ps display
73 * (This is the default, as it is safest.) 73 * (This is the default, as it is safest.)
74 */ 74 */
75#if defined(HAVE_PSTAT) && defined(PSTAT_SETCMD) 75
76#define PS_USE_PSTAT 76#define PS_USE_NONE 0
77#elif defined(HAVE_PS_STRINGS) 77#define PS_USE_PSTAT 1
78#define PS_USE_PS_STRINGS 78#define PS_USE_PS_STRINGS 2
79#elif defined(BSD) || defined(__bsdi__) || defined(__hurd__) 79#define PS_USE_CHANGE_ARGV 3
80#define PS_USE_CHANGE_ARGV 80#define PS_USE_CLOBBER_ARGV 4
81#elif defined(__linux__) || defined(_AIX) 81
82#define PS_USE_CLOBBER_ARGV 82#ifndef SETPROCTITLE_STRATEGY
83#else 83# define SETPROCTITLE_STRATEGY PS_USE_NONE
84#define PS_USE_NONE
85#endif 84#endif
86 85
87/* Different systems want the buffer padded differently */ 86#ifndef SETPROCTITLE_PS_PADDING
88#if defined(_AIX) || defined(__linux__) || defined(__QNX__) || defined(__svr4__) 87# define SETPROCTITLE_PS_PADDING ' '
89#define PS_PADDING '\0'
90#else
91#define PS_PADDING ' '
92#endif 88#endif
93 89
94/* 90/*
95 * argv clobbering uses existing argv space, all other methods need a buffer 91 * argv clobbering uses existing argv space, all other methods need a buffer
96 */ 92 */
97#ifndef PS_USE_CLOBBER_ARGV 93#if SETPROCTITLE_STRATEGY != PS_USE_CLOBBER_ARGV
98static char ps_buffer[256]; 94static char ps_buffer[256];
99static const size_t ps_buffer_size = sizeof(ps_buffer); 95static const size_t ps_buffer_size = sizeof(ps_buffer);
100#else /* PS_USE_CLOBBER_ARGV */ 96#else
101static char *ps_buffer; /* will point to argv area */ 97static char *ps_buffer; /* will point to argv area */
102static size_t ps_buffer_size; /* space determined at run time */ 98static size_t ps_buffer_size; /* space determined at run time */
103#endif /* PS_USE_CLOBBER_ARGV */ 99#endif
104 100
105/* save the original argv[] location here */ 101/* save the original argv[] location here */
106static int save_argc; 102static int save_argc;
@@ -115,17 +111,17 @@ extern char *__progname;
115void 111void
116setproctitle(const char *fmt, ...) 112setproctitle(const char *fmt, ...)
117{ 113{
118#ifdef PS_USE_PSTAT 114#if SETPROCTITLE_STRATEGY == PS_USE_PSTAT
119 union pstun pst; 115 union pstun pst;
120#endif 116#endif
121#ifndef PS_USE_NONE 117#if SETPROCTITLE_STRATEGY != PS_USE_NONE
122 ssize_t used; 118 ssize_t used;
123 va_list ap; 119 va_list ap;
124 120
125 /* no ps display if you didn't call save_ps_display_args() */ 121 /* no ps display if you didn't call save_ps_display_args() */
126 if (save_argv == NULL) 122 if (save_argv == NULL)
127 return; 123 return;
128#ifdef PS_USE_CLOBBER_ARGV 124#if SETPROCTITLE_STRATEGY == PS_USE_CLOBBER_ARGV
129 /* If ps_buffer is a pointer, it might still be null */ 125 /* If ps_buffer is a pointer, it might still be null */
130 if (ps_buffer == NULL) 126 if (ps_buffer == NULL)
131 return; 127 return;
@@ -134,12 +130,12 @@ setproctitle(const char *fmt, ...)
134 /* 130 /*
135 * Overwrite argv[] to point at appropriate space, if needed 131 * Overwrite argv[] to point at appropriate space, if needed
136 */ 132 */
137#ifdef PS_USE_CHANGE_ARGV 133#if SETPROCTITLE_STRATEGY == PS_USE_CHANGE_ARGV
138 save_argv[0] = ps_buffer; 134 save_argv[0] = ps_buffer;
139 save_argv[1] = NULL; 135 save_argv[1] = NULL;
140#endif /* PS_USE_CHANGE_ARGV */ 136#endif /* PS_USE_CHANGE_ARGV */
141 137
142#ifdef PS_USE_CLOBBER_ARGV 138#if SETPROCTITLE_STRATEGY == PS_USE_CLOBBER_ARGV
143 save_argv[1] = NULL; 139 save_argv[1] = NULL;
144#endif /* PS_USE_CLOBBER_ARGV */ 140#endif /* PS_USE_CLOBBER_ARGV */
145 141
@@ -158,26 +154,21 @@ setproctitle(const char *fmt, ...)
158 } 154 }
159 va_end(ap); 155 va_end(ap);
160 156
161#if 0 157#if SETPROCTITLE_STRATEGY == PS_USE_PSTAT
162 error("XXXXXXXXX %s", __progname);
163 error("XXXXXXXXX %d", ps_buffer_size);
164 error("XXXXXXXXX %s", ps_buffer);
165#endif
166
167#ifdef PS_USE_PSTAT
168 pst.pst_command = ps_buffer; 158 pst.pst_command = ps_buffer;
169 pstat(PSTAT_SETCMD, pst, strlen(ps_buffer), 0, 0); 159 pstat(PSTAT_SETCMD, pst, strlen(ps_buffer), 0, 0);
170#endif /* PS_USE_PSTAT */ 160#endif /* PS_USE_PSTAT */
171 161
172#ifdef PS_USE_PS_STRINGS 162#if SETPROCTITLE_STRATEGY == PS_USE_PS_STRINGS
173 PS_STRINGS->ps_nargvstr = 1; 163 PS_STRINGS->ps_nargvstr = 1;
174 PS_STRINGS->ps_argvstr = ps_buffer; 164 PS_STRINGS->ps_argvstr = ps_buffer;
175#endif /* PS_USE_PS_STRINGS */ 165#endif /* PS_USE_PS_STRINGS */
176 166
177#ifdef PS_USE_CLOBBER_ARGV 167#if SETPROCTITLE_STRATEGY == PS_USE_CLOBBER_ARGV
178 /* pad unused memory */ 168 /* pad unused memory */
179 used = strlen(ps_buffer); 169 used = strlen(ps_buffer);
180 memset(ps_buffer + used, PS_PADDING, ps_buffer_size - used); 170 memset(ps_buffer + used, SETPROCTITLE_PS_PADDING,
171 ps_buffer_size - used);
181#endif /* PS_USE_CLOBBER_ARGV */ 172#endif /* PS_USE_CLOBBER_ARGV */
182 173
183#endif /* PS_USE_NONE */ 174#endif /* PS_USE_NONE */
@@ -196,7 +187,7 @@ setproctitle(const char *fmt, ...)
196void 187void
197compat_init_setproctitle(int argc, char *argv[]) 188compat_init_setproctitle(int argc, char *argv[])
198{ 189{
199#ifdef PS_USE_CLOBBER_ARGV 190#if SETPROCTITLE_STRATEGY == PS_USE_CLOBBER_ARGV
200 char *end_of_area = NULL; 191 char *end_of_area = NULL;
201 char **new_environ; 192 char **new_environ;
202 int i; 193 int i;
@@ -205,7 +196,7 @@ compat_init_setproctitle(int argc, char *argv[])
205 save_argc = argc; 196 save_argc = argc;
206 save_argv = argv; 197 save_argv = argv;
207 198
208#ifdef PS_USE_CLOBBER_ARGV 199#if SETPROCTITLE_STRATEGY == PS_USE_CLOBBER_ARGV
209 /* 200 /*
210 * If we're going to overwrite the argv area, count the available 201 * If we're going to overwrite the argv area, count the available
211 * space. Also move the environment to make additional room. 202 * space. Also move the environment to make additional room.