| * set process title for ps (from sendmail) |
| * Clobbers argv of our main procedure so ps(1) will display the title. |
| #include "setproctitle.h" |
| # define SPT_BUFSIZE 2048 |
| void initproctitle (int argc, char **argv) |
| * Move the environment so we can reuse the memory. |
| * (Code borrowed from sendmail.) |
| * WARNING: ugly assumptions on memory layout here; |
| * if this ever causes problems, #undef DO_PS_FIDDLING |
| for (i = 0; envp[i] != NULL; i++) |
| environ = (char **) malloc(sizeof(char *) * (i + 1)); |
| for (i = 0; envp[i] != NULL; i++) |
| if ((environ[i] = strdup(envp[i])) == NULL) |
| argv_lth = envp[i-1] + strlen(envp[i-1]) - argv0[0]; |
| argv_lth = argv0[argc-1] + strlen(argv0[argc-1]) - argv0[0]; |
| void setproctitle (const char *prog, const char *txt) |
| if (strlen(prog) + strlen(txt) + 5 > SPT_BUFSIZE) |
| sprintf(buf, "%s -- %s", prog, txt); |
| memset(argv0[0], '\0', argv_lth); /* clear the memory area */ |