setproctitle can be implemented on Linux too, following code
is adopted from sendmail:
static char **Argv = NULL;
static char *LastArgv = NULL;
static void
init_setproctitle(int argc, char *argv[], char *envp[])
{
extern char **environ;
int i, envpsize;
char **p;
for (i = envpsize = 0; envp[i] != ((void *) 0); i++)
envpsize += strlen(envp[i]) + 1;
if ((p = (char **) malloc((i + 1) * sizeof (char *))) != ((void *) 0)) {
environ = p;
for (i = 0; envp[i] != ((void *) 0); i++) {
if ((environ[i] =
malloc(strlen(envp[i]) + 1)) != ((void *) 0))
strcpy(environ[i], envp[i]);
}
environ[i] = ((void *) 0);
}
Argv = argv;
for (i = 0; i < argc; i++) {
if (!i || (LastArgv + 1 == argv[i]))
LastArgv = argv[i] + strlen(argv[i]);
}
for (i = 0; envp[i] != ((void *) 0); i++) {
if ((LastArgv + 1) == envp[i])
LastArgv = envp[i] + strlen(envp[i]);
}
}
void
setproctitle(char *fmt, ...)
{
va_list msg;
static char statbuf[8192];
char *p;
int i, maxlen = (LastArgv - Argv[0]) - 2;
va_start((msg), fmt);
memset(statbuf, 0, sizeof (statbuf));
vsnprintf(statbuf, sizeof (statbuf), fmt, msg);
va_end(msg);
i = strlen(statbuf);
snprintf(Argv[0], maxlen, "%s", statbuf);
p = &Argv[0][i];
while (p < LastArgv)
*p++ = '\0';
Argv[1] = ((void *) 0);
}
【 在 quickmouse.bbs@bbs.sjtu.edu.cn (碰猫死翘翘) 的大作中提到: 】
: 同dang~~
: jieer啊,ft,不要拿专用的函数过来吧 :)
: 把大家搞晕了
--
修改:bigheadmonst FROM 211.66.128.204
FROM 211.66.128.204