分类: LINUX
2009-11-24 16:33:06
/* proctitle code - we know this to work only on linux... */
/*
** SETPROCTITLE -- set process title for ps (from sendmail)
**
** Parameters:
** fmt -- a printf style format string.
**
** Returns:
** none.
**
** Side Effects:
** Clobbers argv of our main procedure so ps(1) will
** display the title.
*/
# <.>
# <.>
# <.>
# <.>
# "setproctitle.h"
#
# 2048
#
extern char** ;
static char** ;
static int ;
void
(int , char **) {
int ;
char ** = ;
/*
* 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 ( = 0; [] != ; ++)
continue;
= (char **) (sizeof(char *) * ( + 1));
if ( == )
return;
for ( = 0; [] != ; ++)
if (([] = ([])) == )
return;
[] = ;
= ;
if ( > 0)
= [-1] + ([-1]) - [0];
else
= [-1] + ([-1]) - [0];
}
#if 0
/* Nice code, but many places do not know about vsnprintf ... */
void
(const char *,...) {
int ;
char [];
;
if (!)
return;
(, );
(void) (, , , );
();
= ();
if ( > - 2) {
= - 2;
[] = '\0';
}
([0], '\0', ); /* clear the memory area */
(void) ([0], );
[1] = ;
}
#else
void
(const char *, const char *) {
int ;
char [];
if (!)
return;
if (() + () + 5 > )
return;
(void) (, "%s -- %s", , );
= ();
if ( > - 2) {
= - 2;
[] = '\0';
}
([0], '\0', ); /* clear the memory area */
(void) ([0], );
[1] = ;
}
#