summaryrefslogtreecommitdiff
path: root/openbsd-compat/setproctitle.c
diff options
context:
space:
mode:
Diffstat (limited to 'openbsd-compat/setproctitle.c')
-rw-r--r--openbsd-compat/setproctitle.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/openbsd-compat/setproctitle.c b/openbsd-compat/setproctitle.c
index 2965f689e..9f7ca14c2 100644
--- a/openbsd-compat/setproctitle.c
+++ b/openbsd-compat/setproctitle.c
@@ -67,7 +67,8 @@ static size_t argv_env_len = 0;
67void 67void
68compat_init_setproctitle(int argc, char *argv[]) 68compat_init_setproctitle(int argc, char *argv[])
69{ 69{
70#if defined(SPT_TYPE) && SPT_TYPE == SPT_REUSEARGV 70#if !defined(HAVE_SETPROCTITLE) && \
71 defined(SPT_TYPE) && SPT_TYPE == SPT_REUSEARGV
71 extern char **environ; 72 extern char **environ;
72 char *lastargv = NULL; 73 char *lastargv = NULL;
73 char **envp = environ; 74 char **envp = environ;
@@ -125,6 +126,7 @@ setproctitle(const char *fmt, ...)
125 va_list ap; 126 va_list ap;
126 char buf[1024], ptitle[1024]; 127 char buf[1024], ptitle[1024];
127 size_t len; 128 size_t len;
129 int r;
128 extern char *__progname; 130 extern char *__progname;
129#if SPT_TYPE == SPT_PSTAT 131#if SPT_TYPE == SPT_PSTAT
130 union pstun pst; 132 union pstun pst;
@@ -137,13 +139,16 @@ setproctitle(const char *fmt, ...)
137 139
138 strlcpy(buf, __progname, sizeof(buf)); 140 strlcpy(buf, __progname, sizeof(buf));
139 141
142 r = -1;
140 va_start(ap, fmt); 143 va_start(ap, fmt);
141 if (fmt != NULL) { 144 if (fmt != NULL) {
142 len = strlcat(buf, ": ", sizeof(buf)); 145 len = strlcat(buf, ": ", sizeof(buf));
143 if (len < sizeof(buf)) 146 if (len < sizeof(buf))
144 vsnprintf(buf + len, sizeof(buf) - len , fmt, ap); 147 r = vsnprintf(buf + len, sizeof(buf) - len , fmt, ap);
145 } 148 }
146 va_end(ap); 149 va_end(ap);
150 if (r == -1 || (size_t)r >= sizeof(buf) - len)
151 return;
147 strnvis(ptitle, buf, sizeof(ptitle), 152 strnvis(ptitle, buf, sizeof(ptitle),
148 VIS_CSTYLE|VIS_NL|VIS_TAB|VIS_OCTAL); 153 VIS_CSTYLE|VIS_NL|VIS_TAB|VIS_OCTAL);
149 154