]> andersk Git - gssapi-openssh.git/blobdiff - openssh/openbsd-compat/setproctitle.c
Import of OpenSSH 5.1p1
[gssapi-openssh.git] / openssh / openbsd-compat / setproctitle.c
index b41100fc6b41ebf833d513790ae104d4dc1a4abf..2965f689e702f9545bc2401fe5add5f2bbd43405 100644 (file)
 
 #ifndef HAVE_SETPROCTITLE
 
+#include <stdarg.h>
+#include <stdlib.h>
 #include <unistd.h>
 #ifdef HAVE_SYS_PSTAT_H
 #include <sys/pstat.h>
 #endif
+#include <string.h>
+
+#include <vis.h>
 
 #define SPT_NONE       0       /* don't use it at all */
-#define SPT_PSTAT      1       /* cover argv with title information */
-#define SPT_REUSEARGV  2       /* use pstat(PSTAT_SETCMD, ...) */
+#define SPT_PSTAT      1       /* use pstat(PSTAT_SETCMD, ...) */
+#define SPT_REUSEARGV  2       /* cover argv with title information */
 
 #ifndef SPT_TYPE
 # define SPT_TYPE      SPT_NONE
@@ -80,7 +85,7 @@ compat_init_setproctitle(int argc, char *argv[])
        /* Fail if we can't allocate room for the new environment */
        for (i = 0; envp[i] != NULL; i++)
                ;
-       if ((environ = malloc(sizeof(*environ) * (i + 1))) == NULL) {
+       if ((environ = calloc(i + 1, sizeof(*environ))) == NULL) {
                environ = envp; /* put it back */
                return;
        }
@@ -118,7 +123,7 @@ setproctitle(const char *fmt, ...)
 {
 #if SPT_TYPE != SPT_NONE
        va_list ap;
-       char buf[1024];
+       char buf[1024], ptitle[1024];
        size_t len;
        extern char *__progname;
 #if SPT_TYPE == SPT_PSTAT
@@ -139,14 +144,16 @@ setproctitle(const char *fmt, ...)
                        vsnprintf(buf + len, sizeof(buf) - len , fmt, ap);
        }
        va_end(ap);
+       strnvis(ptitle, buf, sizeof(ptitle),
+           VIS_CSTYLE|VIS_NL|VIS_TAB|VIS_OCTAL);
 
 #if SPT_TYPE == SPT_PSTAT
-       pst.pst_command = buf;
-       pstat(PSTAT_SETCMD, pst, strlen(buf), 0, 0);
+       pst.pst_command = ptitle;
+       pstat(PSTAT_SETCMD, pst, strlen(ptitle), 0, 0);
 #elif SPT_TYPE == SPT_REUSEARGV
 /*     debug("setproctitle: copy \"%s\" into len %d", 
            buf, argv_env_len); */
-       len = strlcpy(argv_start, buf, argv_env_len);
+       len = strlcpy(argv_start, ptitle, argv_env_len);
        for(; len < argv_env_len; len++)
                argv_start[len] = SPT_PADCHAR;
 #endif
This page took 0.189083 seconds and 4 git commands to generate.