37 #define compat_init_setproctitle ruby_init_setproctitle 40 #ifndef HAVE_SETPROCTITLE 47 #ifdef HAVE_SYS_PSTAT_H 48 #include <sys/pstat.h> 52 #if defined(__APPLE__) 53 # ifdef HAVE_CRT_EXTERNS_H 56 # define environ (*_NSGetEnviron()) 64 #define SPT_REUSEARGV 2 67 # define SPT_TYPE SPT_NONE 71 # define SPT_PADCHAR '\0' 74 #if SPT_TYPE == SPT_REUSEARGV 75 static char *argv_start =
NULL;
76 static size_t argv_env_len = 0;
77 static size_t argv_len = 0;
78 static char **argv1_addr =
NULL;
86 #if defined(SPT_TYPE) && SPT_TYPE == SPT_REUSEARGV 88 char *lastargv =
NULL;
89 char *lastenvp =
NULL;
99 if (argc == 0 || argv[0] ==
NULL)
103 for (i = 0; envp[i] !=
NULL; i++)
105 if ((environ =
calloc(i + 1,
sizeof(*environ))) ==
NULL) {
114 for (i = 0; i <
argc; i++) {
115 if (lastargv ==
NULL || lastargv + 1 == argv[i])
116 lastargv = argv[i] +
strlen(argv[i]);
119 for (i = 0; envp[i] !=
NULL; i++) {
120 if (lastenvp + 1 == envp[i])
121 lastenvp = envp[i] +
strlen(envp[i]);
126 argv1_addr = &argv[1];
127 argv_start = argv[0];
128 argv_len = lastargv - argv[0];
129 argv_env_len = lastenvp - argv[0];
131 for (i = 0; envp[i] !=
NULL; i++)
137 #ifndef HAVE_SETPROCTITLE 141 #if SPT_TYPE != SPT_NONE 146 #if SPT_TYPE == SPT_PSTAT 150 #if SPT_TYPE == SPT_REUSEARGV 151 if (argv_env_len <= 0)
157 vsnprintf(ptitle,
sizeof(ptitle) , fmt, ap);
161 #if SPT_TYPE == SPT_PSTAT 162 pst.pst_command = ptitle;
163 pstat(PSTAT_SETCMD, pst,
strlen(ptitle), 0, 0);
164 #elif SPT_TYPE == SPT_REUSEARGV 165 len =
strlcpy(argv_start, ptitle, argv_env_len);
166 argvlen = len > argv_len ? argv_env_len : argv_len;
167 for(; len < argvlen; len++)
size_t strlen(const char *)
RUBY_FUNC_EXPORTED void ruby_init_setproctitle(int argc, char *argv[])
char * ruby_strdup(const char *)
#define RUBY_FUNC_EXPORTED
#define compat_init_setproctitle
RUBY_EXTERN size_t strlcpy(char *, const char *, size_t)
void setproctitle(const char *fmt,...)
register unsigned int len