aboutsummaryrefslogtreecommitdiffstats
path: root/src/libutil
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rspamd.com>2023-11-13 16:03:36 +0000
committerVsevolod Stakhov <vsevolod@rspamd.com>2023-11-13 16:03:36 +0000
commit3e29be1422ae7e5303e2fda47ff93d1a458a9f75 (patch)
treef3b44483ef019cc3eea2562174c92ba592494288 /src/libutil
parentb6612604aa2b06ef7b12c2aaf24a4175dcea67e5 (diff)
downloadrspamd-3e29be1422ae7e5303e2fda47ff93d1a458a9f75.tar.gz
rspamd-3e29be1422ae7e5303e2fda47ff93d1a458a9f75.zip
[Fix] Another try to fix setproctitle
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/util.c31
-rw-r--r--src/libutil/util.h9
2 files changed, 24 insertions, 16 deletions
diff --git a/src/libutil/util.c b/src/libutil/util.c
index f7e22e1bd..1c644c2cc 100644
--- a/src/libutil/util.c
+++ b/src/libutil/util.c
@@ -533,9 +533,7 @@ void rspamd_signals_init(struct sigaction *signals, void (*sig_handler)(gint))
static gchar *title_buffer = NULL;
static size_t title_buffer_size = 0;
static gchar *title_progname, *title_progname_full;
-#endif
-#ifdef LINUX
static void
rspamd_title_dtor(gpointer d)
{
@@ -548,12 +546,14 @@ rspamd_title_dtor(gpointer d)
g_free(env);
}
-#endif
+#endif /* ifdef LINUX */
+
+#endif /* ifndef HAVE_SETPROCTITLE */
-gint init_title(rspamd_mempool_t *pool,
- gint argc, gchar *argv[], gchar *envp[])
+gint rspamd_init_title(rspamd_mempool_t *pool,
+ gint argc, gchar *argv[], gchar *envp[])
{
-#ifdef LINUX
+#if defined(LINUX) && !defined(HAVE_SETPROCTITLE)
gchar *begin_of_buffer = 0, *end_of_buffer = 0;
gint i;
@@ -614,8 +614,20 @@ gint init_title(rspamd_mempool_t *pool,
return 0;
}
-gint setproctitle(const gchar *fmt, ...)
+gint rspamd_setproctitle(const gchar *fmt, ...)
{
+#ifdef HAVE_SETPROCTITLE
+ if (fmt) {
+ static char titlebuf[4096];
+ va_list ap;
+
+ va_start(ap, fmt);
+ rspamd_vsnprintf(titlebuf, sizeof(titlebuf), fmt, ap);
+ va_end(ap);
+
+ setproctitle("%s", titlebuf);
+ }
+#else
#if defined(LINUX)
if (!title_buffer || !title_buffer_size) {
errno = ENOMEM;
@@ -669,11 +681,12 @@ gint setproctitle(const gchar *fmt, ...)
g_set_prgname(dest->str);
g_string_free(dest, TRUE);
-#endif
+#endif /* defined(LINUX) */
+
+#endif /* HAVE_SETPROCTITLE */
return 0;
}
-#endif
#ifndef HAVE_PIDFILE
static gint _rspamd_pidfile_remove(rspamd_pidfh_t *pfh, gint freeit);
diff --git a/src/libutil/util.h b/src/libutil/util.h
index 4842b890e..17956acb7 100644
--- a/src/libutil/util.h
+++ b/src/libutil/util.h
@@ -126,16 +126,11 @@ void rspamd_signals_init(struct sigaction *sa, void (*sig_handler)(gint,
void rspamd_signals_init(struct sigaction *sa, void (*sig_handler)(gint));
#endif
-#ifndef HAVE_SETPROCTITLE
-
/*
* Process title utility functions
*/
-gint init_title(rspamd_mempool_t *pool, gint argc, gchar *argv[], gchar *envp[]);
-
-gint setproctitle(const gchar *fmt, ...);
-
-#endif
+gint rspamd_init_title(rspamd_mempool_t *pool, gint argc, gchar *argv[], gchar *envp[]);
+gint rspamd_setproctitle(const gchar *fmt, ...);
#ifndef HAVE_PIDFILE
/*