2
I don't know if it's a good thing to do NXArgc or NXArgv,
3
but it makes finding the beginning a few steps simpler and
4
resetting their values might be a good thing for WindowServer
11
#include "setproctitle.h"
12
void setproctitle(const char *fmt, ...)
16
size_t bufSize=sizeof(kp);
17
static char newargs[SPT_BUFSIZE];
18
char *p1,*minpos,*endorig;
21
/* write out the formatted string, or quit */
24
newargs[sizeof(newargs)-1] = 0;
25
(void)vsnprintf(newargs,sizeof(newargs),fmt,ap);
31
if (sysctl(mib,4,&kp,&bufSize,NULL,0)) { printf("setproctitle: i dont know my own pid!\n"); return; }
32
strcpy(newargs,kp.kp_proc.p_comm);
36
/* find the end of the original string cause we're stackbackwards! */
37
endorig = NXArgv[NXArgc-1]+strlen(NXArgv[NXArgc-1]);
39
/* kill the original */
40
bzero(NXArgv[0],(unsigned int)(endorig-NXArgv[0]));
41
for (p1=NXArgv[0]-2;*p1;--p1) *p1=0;
43
/* new length (all args) */
47
minpos = endorig-olen;
50
/* copy the new string to the old place */
51
strcpy(NXArgv[0],newargs);
53
/* search for spaces, replace with nulls and increment the argc */
55
for (p1=NXArgv[0];*p1;++p1)
56
if (*p1==' ') { *p1=0; NXArgv[NXArgc++] = p1+1; }
59
/* why this is here or what for is beyond me.. theres a copy of the executable name before NXArgv[0] */
60
strcpy(NXArgv[0]-strlen(NXArgv[0])-2,NXArgv[0]);
62
/* is this even necessary? */
65
while (++p1<(char *)(USRSTACK-4)) if (!*p1) NXArgv[++olen]=p1+1;