aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGilles Chehade <gilles@poolp.org>2020-12-01 23:41:34 +0100
committerGilles Chehade <gilles@poolp.org>2020-12-01 23:41:34 +0100
commite94cc12211d1fbbd52bc4c50c3e530342d3e95ee (patch)
tree9ee06132aaa240f8c533b0365dbd52eb6215b6ea
parentRevert "use get_progname() to fix proctitle" (diff)
downloadOpenSMTPD-e94cc12211d1fbbd52bc4c50c3e530342d3e95ee.tar.xz
OpenSMTPD-e94cc12211d1fbbd52bc4c50c3e530342d3e95ee.zip
fix get_progname() and setproctitle() detection
-rw-r--r--configure.ac4
-rw-r--r--openbsd-compat/openbsd-compat.h2
-rw-r--r--openbsd-compat/setproctitle.c5
-rw-r--r--usr.sbin/smtpd/smtpd.c9
4 files changed, 11 insertions, 9 deletions
diff --git a/configure.ac b/configure.ac
index 28f1be1f..d46aeae7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2046,6 +2046,10 @@ AM_CONDITIONAL([NEED_PROGNAME], [test "x$ac_cv_libc_defines___progname" != "xyes
##
+AM_COND_IF([NEED_PROGNAME], [AC_DEFINE([NEED_PROGNAME], [1], [Define to 1 if NEED_PROGNAME])])
+AM_COND_IF([NEED_SETPROCTITLE], [AC_DEFINE([NEED_SETPROCTITLE], [1], [Define to 1 if NEED_SETPROCTITLE])])
+
+
AC_CONFIG_FILES([Makefile
openbsd-compat/Makefile
mk/Makefile
diff --git a/openbsd-compat/openbsd-compat.h b/openbsd-compat/openbsd-compat.h
index ec0ae516..dcb643f1 100644
--- a/openbsd-compat/openbsd-compat.h
+++ b/openbsd-compat/openbsd-compat.h
@@ -96,7 +96,7 @@ const char *inet_ntop(int af, const void *src, char *dst, socklen_t size);
char *strsep(char **stringp, const char *delim);
#endif
-#ifndef HAVE_SETPROCTITLE
+#ifdef NEED_SETPROCTITLE
void setproctitle(const char *fmt, ...);
void compat_init_setproctitle(int argc, char *argv[]);
#endif
diff --git a/openbsd-compat/setproctitle.c b/openbsd-compat/setproctitle.c
index eef70c14..71e1595e 100644
--- a/openbsd-compat/setproctitle.c
+++ b/openbsd-compat/setproctitle.c
@@ -68,8 +68,7 @@ static size_t argv_env_len = 0;
void
compat_init_setproctitle(int argc, char *argv[])
{
-#if !defined(HAVE_SETPROCTITLE) && \
- defined(SPT_TYPE) && SPT_TYPE == SPT_REUSEARGV
+#if defined(SPT_TYPE) && SPT_TYPE == SPT_REUSEARGV
extern char **environ;
char *lastargv = NULL;
char **envp = environ;
@@ -156,8 +155,6 @@ setproctitle(const char *fmt, ...)
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, ptitle, argv_env_len);
for(; len < argv_env_len; len++)
argv_start[len] = SPT_PADCHAR;
diff --git a/usr.sbin/smtpd/smtpd.c b/usr.sbin/smtpd/smtpd.c
index ad0ebdea..9307fc3b 100644
--- a/usr.sbin/smtpd/smtpd.c
+++ b/usr.sbin/smtpd/smtpd.c
@@ -520,11 +520,11 @@ main(int argc, char *argv[])
char *rexec = NULL;
struct smtpd *conf;
-#ifndef HAVE___PROGNAME
- __progname = ssh_get_progname(argv[0]);
+#ifdef NEED_PROGNAME
+ __progname = get_progname(argv[0]);
#endif
+ __progname = xstrdup(__progname);
-#ifndef HAVE_SETPROCTITLE
/* Save argv. Duplicate so setproctitle emulation doesn't clobber it */
saved_argc = argc;
saved_argv = xcalloc(argc + 1, sizeof(*saved_argv));
@@ -532,14 +532,15 @@ main(int argc, char *argv[])
saved_argv[i] = xstrdup(argv[i]);
saved_argv[i] = NULL;
+#ifdef NEED_SETPROCTITLE
/* Prepare for later setproctitle emulation */
compat_init_setproctitle(argc, argv);
argv = saved_argv;
+#endif
/* this is to work around GNU getopt + portable setproctitle() fuckery */
save_argc = saved_argc;
save_argv = saved_argv;
-#endif
if ((conf = config_default()) == NULL)
err(1, NULL);