Skip to content

Commit

Permalink
[Fix] Another try to fix setproctitle
Browse files Browse the repository at this point in the history
  • Loading branch information
vstakhov committed Nov 13, 2023
1 parent b661260 commit 3e29be1
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 31 deletions.
6 changes: 3 additions & 3 deletions src/libserver/worker_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
31 changes: 22 additions & 9 deletions src/libutil/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 2 additions & 7 deletions src/libutil/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
/*
Expand Down
10 changes: 5 additions & 5 deletions src/lua/lua_worker.c
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/rspamadm/rspamadm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions src/rspamd.c
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 3e29be1

Please sign in to comment.