17 #include "setproctitle.h"
29 #include <sys/ioctl.h>
30 #include <sys/param.h>
38 # define _PATH_KMEM "/dev/kmem"
41 #define SPACELEFT(buf, ptr) (sizeof buf - ((ptr) - buf))
60 #define SPT_REUSEARGV 1
63 #define SPT_PSSTRINGS 4
66 #define SPT_CHANGEARGV 7
69 # define SPT_TYPE SPT_REUSEARGV
72 #if SPT_TYPE != SPT_NONE && SPT_TYPE != SPT_BUILTIN
74 # if SPT_TYPE == SPT_PSTAT
75 # include <sys/pstat.h>
77 # if SPT_TYPE == SPT_PSSTRINGS
78 # include <machine/vmparam.h>
79 # ifdef HAVE_SYS_EXEC_H
80 # include <sys/exec.h>
84 # define SPT_TYPE SPT_REUSEARGV
88 typedef unsigned int *pt_entry_t;
93 # if SPT_TYPE == SPT_PSSTRINGS || SPT_TYPE == SPT_CHANGEARGV
94 # define SETPROC_STATIC static
96 # define SETPROC_STATIC
99 # if SPT_TYPE == SPT_SYSMIPS
100 # include <sys/sysmips.h>
101 # include <sys/sysnews.h>
104 # if SPT_TYPE == SPT_SCO
105 # include <sys/immu.h>
106 # include <sys/dir.h>
107 # include <sys/user.h>
108 # include <sys/fs/s5param.h>
109 # if PSARGSZ > MAXLINE
110 # define SPT_BUFSIZE PSARGSZ
116 # define SPT_PADCHAR '\0'
118 # define SPT_PADCHAR ' '
125 # define SPT_BUFSIZE 2048
134 char *LastArgv = NULL;
137 tdeinit_initsetproctitle(
int argc,
char **argv,
char **envp)
140 #if !defined(HAVE_NSGETENVIRON) || !defined(HAVE_CRT_EXTERNS_H)
141 extern char **environ;
149 for (i = 0; envp[i] != NULL; i++)
150 envpsize += strlen(envp[i]) + 1;
151 environ = (
char **) malloc(
sizeof (
char *) * (i + 1));
155 for (i = 0; envp[i] != NULL; i++)
156 environ[i] = strdup(envp[i]);
169 for (i = 0; i < argc; i++)
171 if (i==0 || LastArgv + 1 == argv[i])
172 LastArgv = argv[i] + strlen(argv[i]);
185 for (i=0; envp[i] != NULL; i++)
187 if (LastArgv + 1 == envp[i])
188 LastArgv = envp[i] + strlen(envp[i]);
195 #if SPT_TYPE != SPT_BUILTIN
199 setproctitle(
const char *fmt, ...)
201 # if SPT_TYPE != SPT_NONE
204 SETPROC_STATIC
char buf[SPT_BUFSIZE];
206 # if SPT_TYPE == SPT_PSTAT
209 # if SPT_TYPE == SPT_SCO
211 static int kmem = -1;
212 #warning (rikkus) kmempid is declared as int, should be long
213 static int kmempid = -1;
221 (void) vsnprintf(p, SPACELEFT(buf, p), fmt, ap);
226 # if SPT_TYPE == SPT_PSTAT
227 pst.pst_command = buf;
228 pstat(PSTAT_SETCMD, pst, i, 0, 0);
230 # if SPT_TYPE == SPT_PSSTRINGS
231 PS_STRINGS->ps_nargvstr = 1;
232 PS_STRINGS->ps_argvstr = buf;
234 # if SPT_TYPE == SPT_SYSMIPS
235 sysmips(SONY_SYSNEWS, NEWS_SETPSARGS, buf);
237 # if SPT_TYPE == SPT_SCO
238 if (kmem < 0 || kmempid != getpid())
242 kmem = open(_PATH_KMEM, O_RDWR, 0);
245 (void) fcntl(kmem, F_SETFD, 1);
248 buf[PSARGSZ - 1] =
'\0';
249 seek_off = UVUBLK + (off_t) u.u_psargs - (off_t) &u;
250 if (lseek(kmem, (off_t) seek_off, SEEK_SET) == seek_off)
251 (
void) write(kmem, buf, PSARGSZ);
253 # if SPT_TYPE == SPT_REUSEARGV
254 if (i > LastArgv - Argv[0] - 2)
256 i = LastArgv - Argv[0] - 2;
259 (void) strcpy(Argv[0], buf);
265 # if SPT_TYPE == SPT_CHANGEARGV
290 tdeinit_setproctitle(
const char *fmt, ...)
292 char buf[SPT_BUFSIZE];
297 (void) vsnprintf(buf, SPT_BUFSIZE, fmt, ap);
300 setproctitle(
"%s", buf);