]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Another try to fix setproctitle
authorVsevolod Stakhov <vsevolod@rspamd.com>
Mon, 13 Nov 2023 16:03:36 +0000 (16:03 +0000)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Mon, 13 Nov 2023 16:03:36 +0000 (16:03 +0000)
src/libserver/worker_util.c
src/libutil/util.c
src/libutil/util.h
src/lua/lua_worker.c
src/rspamadm/rspamadm.c
src/rspamd.c

index 8edfe0cdb3566bb924b4826eff775e10aeb16b5e..74a3cf887530d9552818d98d8d4d913bd0d0068a 100644 (file)
@@ -1120,11 +1120,11 @@ rspamd_handle_child_fork(struct rspamd_worker *wrk,
        setrlimit(RLIMIT_STACK, &rlim);
 
        if (cf->bind_conf) {
-               setproctitle("%s process (%s)", cf->worker->name,
-                                        cf->bind_conf->bind_line);
+               rspamd_setproctitle("%s process (%s)", cf->worker->name,
+                                                       cf->bind_conf->bind_line);
        }
        else {
-               setproctitle("%s process", cf->worker->name);
+               rspamd_setproctitle("%s process", cf->worker->name);
        }
 
        if (rspamd_main->pfh) {
index f7e22e1bd3551ccfbc7dfb26a2acc96ede246b16..1c644c2ccc2f05eb1c1dda3552aa49c28e02ddf2 100644 (file)
@@ -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);
index 4842b890ecf300a9888edc20250799a05e6a7fe6..17956acb758f88a1694da8af43180746ddbdc124 100644 (file)
@@ -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
 /*
index 47f27ca07e42d0b4639f8d4d2eb5c9c7407caa89..025b97ba1a240df5f27053ed6e5dbccdf49996a7 100644 (file)
@@ -1,11 +1,11 @@
-/*-
- * Copyright 2019 Vsevolod Stakhov
+/*
+ * Copyright 2023 Vsevolod Stakhov
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- *   http://www.apache.org/licenses/LICENSE-2.0
+ *    http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
@@ -828,10 +828,10 @@ lua_worker_spawn_process(lua_State *L)
                ev_loop_destroy(cbdata->event_loop);
 
                if (proctitle) {
-                       setproctitle("lua process: %s", proctitle);
+                       rspamd_setproctitle("lua process: %s", proctitle);
                }
                else {
-                       setproctitle("lua process: unnamed");
+                       rspamd_setproctitle("lua process: unnamed");
                }
 
                cbdata->event_loop = ev_loop_new(EVFLAG_SIGNALFD);
index 58f2da3088da6a7b988f1ea8e20f34286f676970..0e38dc326b9bcb1794668420cf5cde4266c83f5a 100644 (file)
@@ -470,7 +470,7 @@ gint main(gint argc, gchar **argv, gchar **env)
        cfg->compiled_modules = modules;
        cfg->compiled_workers = workers;
 
-       setproctitle("rspamdadm");
+       rspamd_setproctitle("rspamdadm");
 
        L = cfg->lua_state;
        rspamd_lua_set_path(L, NULL, ucl_vars);
index 58a3f87834adcad186a663f4a3c3142cdd774806..df08f54104eb88d944bfc27615d2540823fa13c2 100644 (file)
@@ -1,11 +1,11 @@
-/*-
- * Copyright 2016 Vsevolod Stakhov
+/*
+ * Copyright 2023 Vsevolod Stakhov
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- *   http://www.apache.org/licenses/LICENSE-2.0
+ *    http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
@@ -1125,7 +1125,7 @@ rspamd_stat_update_handler(struct ev_loop *loop, ev_timer *w, int revents)
                                                (new_spam - old_spam) / w->repeat,
                                                (new_ham - old_ham) / w->repeat,
                                                cnt > 0 ? sum / cnt : 0);
-               setproctitle("%s", proctitle);
+               rspamd_setproctitle("%s", proctitle);
        }
 
        memcpy(&old_stat, &cur_stat, sizeof(cur_stat));
@@ -1439,7 +1439,7 @@ gint main(gint argc, gchar **argv, gchar **env)
        }
 
 #ifndef HAVE_SETPROCTITLE
-       init_title(rspamd_main->server_pool, argc, argv, env);
+       rspamd_init_title(rspamd_main->server_pool, argc, argv, env);
 #endif
 
        rspamd_main->cfg->libs_ctx = rspamd_init_libs();
@@ -1584,7 +1584,7 @@ gint main(gint argc, gchar **argv, gchar **env)
        sigprocmask(SIG_BLOCK, &signals.sa_mask, NULL);
 
        /* Set title */
-       setproctitle("main process");
+       rspamd_setproctitle("main process");
 
        /* Open control socket if needed */
        control_fd = -1;