/* * UCW Library -- Setting of Process Title * * (c) 2001--2006 Martin Mares * * This software may be freely distributed and used according to the terms * of the GNU Lesser General Public License. */ #include #include #include #include #include #include #include static char **spt_argv; static char *spt_start, *spt_end; void setproctitle_init(int argc, char **argv) { #ifdef CONFIG_LINUX int i, len; char **env, **oldenv, *t; spt_argv = argv; /* Create a backup copy of environment */ oldenv = __environ; len = 0; for (i=0; oldenv[i]; i++) len += strlen(oldenv[i]) + 1; __environ = env = xmalloc(sizeof(char *)*(i+1)); t = xmalloc(len); for (i=0; oldenv[i]; i++) { env[i] = t; len = strlen(oldenv[i]) + 1; memcpy(t, oldenv[i], len); t += len; } env[i] = NULL; /* Scan for consecutive free space */ spt_start = spt_end = argv[0]; for (i=0; i spt_start) { n = vsnprintf(buf, sizeof(buf), msg, args); if (n >= (int) sizeof(buf) || n < 0) sprintf(buf, ""); n = spt_end - spt_start; strncpy(spt_start, buf, n); spt_start[n] = 0; spt_argv[0] = spt_start; spt_argv[1] = NULL; } va_end(args); } char * getproctitle(void) { return (spt_start < spt_end) ? spt_start : NULL; }