Skip to content

Commit

Permalink
Refactor: move from gvm-lib proctitle-set to libbsd setproctitle
Browse files Browse the repository at this point in the history
To be less dependenct on gvm-libs and have more robust way to set
proctitle this commit switches from gvm-libs proctitle-set to
setproctitle of libbsd.
  • Loading branch information
nichtsfrei authored and bjoernricks committed May 3, 2022
1 parent 2005540 commit 98b5370
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 81 deletions.
17 changes: 9 additions & 8 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pkg_check_modules (LIBGVM_OSP REQUIRED libgvm_osp>=22.4)
pkg_check_modules (LIBGVM_GMP REQUIRED libgvm_gmp>=22.4)
pkg_check_modules (GNUTLS REQUIRED gnutls>=3.2.15)
pkg_check_modules (GLIB REQUIRED glib-2.0>=2.42)
pkg_check_modules (LIBBSD REQUIRED libbsd)
pkg_check_modules (LIBICAL REQUIRED libical>=1.00)

message (STATUS "Looking for PostgreSQL...")
Expand Down Expand Up @@ -95,7 +96,7 @@ endif (WITH_LIBTHEIA)

include_directories (${LIBGVM_GMP_INCLUDE_DIRS}
${LIBGVM_BASE_INCLUDE_DIRS} ${LIBGVM_UTIL_INCLUDE_DIRS}
${LIBGVM_OSP_INCLUDE_DIRS} ${GLIB_INCLUDE_DIRS})
${LIBGVM_OSP_INCLUDE_DIRS} ${LIBBSD_INCLUDE_DIRS} ${GLIB_INCLUDE_DIRS})

add_library (gvm-pg-server SHARED
manage_pg_server.c manage_utils.c)
Expand Down Expand Up @@ -268,35 +269,35 @@ add_executable (gvmd

target_link_libraries (gvmd m
${GNUTLS_LDFLAGS} ${GPGME_LDFLAGS} ${CMAKE_THREAD_LIBS_INIT} ${LINKER_HARDENING_FLAGS} ${LINKER_DEBUG_FLAGS}
${PostgreSQL_LIBRARIES} ${GLIB_LDFLAGS} ${GTHREAD_LDFLAGS}
${PostgreSQL_LIBRARIES} ${LIBBSD_LDFLAGS} ${GLIB_LDFLAGS} ${GTHREAD_LDFLAGS}
${LIBGVM_BASE_LDFLAGS} ${LIBGVM_UTIL_LDFLAGS} ${LIBGVM_OSP_LDFLAGS} ${LIBGVM_GMP_LDFLAGS}
${LIBICAL_LDFLAGS} ${LINKER_HARDENING_FLAGS} ${OPT_THEIA_TGT})
target_link_libraries (manage-test cgreen m
${GNUTLS_LDFLAGS} ${GPGME_LDFLAGS} ${CMAKE_THREAD_LIBS_INIT} ${LINKER_HARDENING_FLAGS} ${LINKER_DEBUG_FLAGS}
${PostgreSQL_LIBRARIES} ${GLIB_LDFLAGS} ${GTHREAD_LDFLAGS}
${PostgreSQL_LIBRARIES} ${LIBBSD_LDFLAGS} ${GLIB_LDFLAGS} ${GTHREAD_LDFLAGS}
${LIBGVM_BASE_LDFLAGS} ${LIBGVM_UTIL_LDFLAGS} ${LIBGVM_OSP_LDFLAGS} ${LIBGVM_GMP_LDFLAGS}
${LIBICAL_LDFLAGS} ${LINKER_HARDENING_FLAGS} ${OPT_THEIA_TGT})
target_link_libraries (manage-sql-test cgreen m
${GNUTLS_LDFLAGS} ${GPGME_LDFLAGS} ${CMAKE_THREAD_LIBS_INIT} ${LINKER_HARDENING_FLAGS} ${LINKER_DEBUG_FLAGS}
${PostgreSQL_LIBRARIES} ${GLIB_LDFLAGS} ${GTHREAD_LDFLAGS}
${PostgreSQL_LIBRARIES} ${LIBBSD_LDFLAGS} ${GLIB_LDFLAGS} ${GTHREAD_LDFLAGS}
${LIBGVM_BASE_LDFLAGS} ${LIBGVM_UTIL_LDFLAGS} ${LIBGVM_OSP_LDFLAGS} ${LIBGVM_GMP_LDFLAGS}
${LIBICAL_LDFLAGS} ${LINKER_HARDENING_FLAGS} ${OPT_THEIA_TGT})
target_link_libraries (manage-utils-test cgreen m
${GNUTLS_LDFLAGS} ${GPGME_LDFLAGS} ${CMAKE_THREAD_LIBS_INIT} ${LINKER_HARDENING_FLAGS} ${LINKER_DEBUG_FLAGS}
${PostgreSQL_LIBRARIES} ${GLIB_LDFLAGS} ${GTHREAD_LDFLAGS}
${PostgreSQL_LIBRARIES} ${LIBBSD_LDFLAGS} ${GLIB_LDFLAGS} ${GTHREAD_LDFLAGS}
${LIBGVM_BASE_LDFLAGS} ${LIBGVM_UTIL_LDFLAGS} ${LIBGVM_OSP_LDFLAGS} ${LIBGVM_GMP_LDFLAGS}
${LIBICAL_LDFLAGS} ${LINKER_HARDENING_FLAGS} ${OPT_THEIA_TGT})
target_link_libraries (gmp-tickets-test cgreen m
${GNUTLS_LDFLAGS} ${GPGME_LDFLAGS} ${CMAKE_THREAD_LIBS_INIT} ${LINKER_HARDENING_FLAGS} ${LINKER_DEBUG_FLAGS}
${PostgreSQL_LIBRARIES} ${GLIB_LDFLAGS} ${GTHREAD_LDFLAGS}
${PostgreSQL_LIBRARIES} ${LIBBSD_LDFLAGS} ${GLIB_LDFLAGS} ${GTHREAD_LDFLAGS}
${LIBGVM_BASE_LDFLAGS} ${LIBGVM_UTIL_LDFLAGS} ${LIBGVM_OSP_LDFLAGS} ${LIBGVM_GMP_LDFLAGS}
${LIBICAL_LDFLAGS} ${LINKER_HARDENING_FLAGS} ${OPT_THEIA_TGT})
target_link_libraries (utils-test cgreen m
${GNUTLS_LDFLAGS} ${GPGME_LDFLAGS} ${CMAKE_THREAD_LIBS_INIT} ${LINKER_HARDENING_FLAGS} ${LINKER_DEBUG_FLAGS}
${PostgreSQL_LIBRARIES} ${GLIB_LDFLAGS} ${GTHREAD_LDFLAGS}
${PostgreSQL_LIBRARIES} ${LIBBSD_LDFLAGS} ${GLIB_LDFLAGS} ${GTHREAD_LDFLAGS}
${LIBGVM_BASE_LDFLAGS} ${LIBGVM_UTIL_LDFLAGS} ${LIBGVM_OSP_LDFLAGS} ${LIBGVM_GMP_LDFLAGS}
${LIBICAL_LDFLAGS} ${LINKER_HARDENING_FLAGS} ${OPT_THEIA_TGT})
target_link_libraries (gvm-pg-server ${GLIB_LDFLAGS} ${GTHREAD_LDFLAGS} ${LIBGVM_BASE_LDFLAGS} ${LIBGVM_UTIL_LDFLAGS} ${LIBICAL_LDFLAGS} ${LINKER_HARDENING_FLAGS})
target_link_libraries (gvm-pg-server ${LIBBSD_LDFLAGS} ${GLIB_LDFLAGS} ${GTHREAD_LDFLAGS} ${LIBGVM_BASE_LDFLAGS} ${LIBGVM_UTIL_LDFLAGS} ${LIBICAL_LDFLAGS} ${LINKER_HARDENING_FLAGS})

set_target_properties (gvmd PROPERTIES LINKER_LANGUAGE C)
set_target_properties (manage-test PROPERTIES LINKER_LANGUAGE C)
Expand Down
64 changes: 32 additions & 32 deletions src/gvmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
#include <gvm/base/pidfile.h>
#include <gvm/base/pwpolicy.h>
#include <gvm/base/logging.h>
#include <gvm/base/proctitle.h>
#include <bsd/unistd.h>
#include <gvm/base/gvm_sentry.h>
#include <gvm/util/fileutils.h>
#include <gvm/util/serverutils.h>
Expand Down Expand Up @@ -600,7 +600,7 @@ accept_and_maybe_fork (int server_socket, sigset_t *sigmask_current)
init_sentry ();
is_parent = 0;

proctitle_set ("gvmd: Serving client");
setproctitle ("gvmd: Serving client");

/* Restore the sigmask that was blanked for pselect. */
pthread_sigmask (SIG_SETMASK, sigmask_current, NULL);
Expand Down Expand Up @@ -736,7 +736,7 @@ fork_connection_internal (gvm_connection_t *client_connection,
/* Child. Serve the scheduler GMP, then exit. */

init_sentry ();
proctitle_set ("gvmd: Serving GMP internally");
setproctitle ("gvmd: Serving GMP internally");

parent_client_socket = sockets[0];

Expand Down Expand Up @@ -834,7 +834,7 @@ fork_connection_internal (gvm_connection_t *client_connection,

g_debug ("%s: %i forked %i", __func__, getpid (), pid);

proctitle_set ("gvmd: Requesting GMP internally");
setproctitle ("gvmd: Requesting GMP internally");

/* This process is returned as the child of
* fork_connection_for_scheduler so that the returned parent can wait
Expand Down Expand Up @@ -1105,7 +1105,7 @@ handle_sigabrt_simple (int signal)
static int
update_nvt_cache_osp (const gchar *update_socket)
{
proctitle_set ("gvmd: OSP: Updating NVT cache");
setproctitle ("gvmd: OSP: Updating NVT cache");

return manage_update_nvts_osp (update_socket);
}
Expand All @@ -1121,7 +1121,7 @@ update_nvt_cache_osp (const gchar *update_socket)
static int
update_nvt_cache_retry ()
{
proctitle_set ("gvmd: Reloading NVTs");
setproctitle ("gvmd: Reloading NVTs");

/* Don't ignore SIGCHLD, in order to wait for child process. */
setup_signal_handler (SIGCHLD, SIG_DFL, 0);
Expand Down Expand Up @@ -1216,7 +1216,7 @@ fork_update_nvt_cache ()
/* Child. */

init_sentry ();
proctitle_set ("gvmd: Updating NVT cache");
setproctitle ("gvmd: Updating NVT cache");

/* Clean up the process. */

Expand Down Expand Up @@ -1327,7 +1327,7 @@ fork_feed_sync ()
/* Child. */

init_sentry ();
proctitle_set ("gvmd: Synchronizing feed data");
setproctitle ("gvmd: Synchronizing feed data");

/* Clean up the process. */

Expand Down Expand Up @@ -1818,7 +1818,7 @@ parse_authentication_goption_arg (const gchar *opt, const gchar *arg,
* @return EXIT_SUCCESS on success, EXIT_FAILURE on failure.
*/
int
gvmd (int argc, char** argv)
gvmd (int argc, char** argv, char *env[])
{
/* Process options. */

Expand Down Expand Up @@ -2326,8 +2326,8 @@ gvmd (int argc, char** argv)

/* Set process title. */

proctitle_init (argc, argv);
proctitle_set ("gvmd: Initializing");
setproctitle_init (argc, argv, env);
setproctitle ("gvmd: Initializing");

/* Setup initial signal handlers. */

Expand Down Expand Up @@ -2511,7 +2511,7 @@ gvmd (int argc, char** argv)
return EXIT_FAILURE;
}

proctitle_set ("gvmd: Migrating database");
setproctitle ("gvmd: Migrating database");

g_info (" Migrating database.");

Expand Down Expand Up @@ -2596,7 +2596,7 @@ gvmd (int argc, char** argv)
{
int ret;

proctitle_set ("gvmd: Optimizing");
setproctitle ("gvmd: Optimizing");

if (option_lock (&lockfile_checking))
return EXIT_FAILURE;
Expand All @@ -2612,7 +2612,7 @@ gvmd (int argc, char** argv)
{
int ret;

proctitle_set ("gvmd: --rebuild");
setproctitle ("gvmd: --rebuild");

if (option_lock (&lockfile_checking))
return EXIT_FAILURE;
Expand All @@ -2634,7 +2634,7 @@ gvmd (int argc, char** argv)

error_msg = NULL;

proctitle_set ("gvmd: --rebuild-gvmd-data");
setproctitle ("gvmd: --rebuild-gvmd-data");

if (option_lock (&lockfile_checking))
return EXIT_FAILURE;
Expand All @@ -2659,7 +2659,7 @@ gvmd (int argc, char** argv)
{
int ret;

proctitle_set ("gvmd: --rebuild-scap");
setproctitle ("gvmd: --rebuild-scap");

if (option_lock (&lockfile_checking))
return EXIT_FAILURE;
Expand All @@ -2678,7 +2678,7 @@ gvmd (int argc, char** argv)
{
int ret;

proctitle_set ("gvmd: --dump-vt-verification");
setproctitle ("gvmd: --dump-vt-verification");

if (option_lock (&lockfile_checking))
return EXIT_FAILURE;
Expand All @@ -2701,7 +2701,7 @@ gvmd (int argc, char** argv)

/* Create the scanner and then exit. */

proctitle_set ("gvmd: Creating scanner");
setproctitle ("gvmd: Creating scanner");

if (option_lock (&lockfile_checking))
return EXIT_FAILURE;
Expand Down Expand Up @@ -2753,7 +2753,7 @@ gvmd (int argc, char** argv)

/* Modify the scanner and then exit. */

proctitle_set ("gvmd: Modifying scanner");
setproctitle ("gvmd: Modifying scanner");

if (option_lock (&lockfile_checking))
return EXIT_FAILURE;
Expand Down Expand Up @@ -2797,7 +2797,7 @@ gvmd (int argc, char** argv)
{
int ret;

proctitle_set ("gvmd: Checking alerts");
setproctitle ("gvmd: Checking alerts");

if (option_lock (&lockfile_checking))
return EXIT_FAILURE;
Expand All @@ -2813,7 +2813,7 @@ gvmd (int argc, char** argv)
{
int ret;

proctitle_set ("gvmd: Creating user");
setproctitle ("gvmd: Creating user");

if (option_lock (&lockfile_checking))
return EXIT_FAILURE;
Expand All @@ -2830,7 +2830,7 @@ gvmd (int argc, char** argv)
{
int ret;

proctitle_set ("gvmd: Deleting user");
setproctitle ("gvmd: Deleting user");

if (option_lock (&lockfile_checking))
return EXIT_FAILURE;
Expand All @@ -2846,7 +2846,7 @@ gvmd (int argc, char** argv)
{
int ret;

proctitle_set ("gvmd: Getting roles");
setproctitle ("gvmd: Getting roles");

if (option_lock (&lockfile_checking))
return EXIT_FAILURE;
Expand All @@ -2862,7 +2862,7 @@ gvmd (int argc, char** argv)
{
int ret;

proctitle_set ("gvmd: Getting users");
setproctitle ("gvmd: Getting users");

if (option_lock (&lockfile_checking))
return EXIT_FAILURE;
Expand All @@ -2878,7 +2878,7 @@ gvmd (int argc, char** argv)
{
int ret;

proctitle_set ("gvmd: Getting scanners");
setproctitle ("gvmd: Getting scanners");

if (option_lock (&lockfile_checking))
return EXIT_FAILURE;
Expand All @@ -2894,7 +2894,7 @@ gvmd (int argc, char** argv)
{
int ret;

proctitle_set ("gvmd: Deleting scanner");
setproctitle ("gvmd: Deleting scanner");

if (option_lock (&lockfile_checking))
return EXIT_FAILURE;
Expand All @@ -2910,7 +2910,7 @@ gvmd (int argc, char** argv)
{
int ret;

proctitle_set ("gvmd: Verifying scanner");
setproctitle ("gvmd: Verifying scanner");

if (option_lock (&lockfile_checking))
return EXIT_FAILURE;
Expand All @@ -2926,7 +2926,7 @@ gvmd (int argc, char** argv)
{
int ret;

proctitle_set ("gvmd: Modifying user password");
setproctitle ("gvmd: Modifying user password");

if (option_lock (&lockfile_checking))
return EXIT_FAILURE;
Expand All @@ -2942,7 +2942,7 @@ gvmd (int argc, char** argv)
{
int ret;

proctitle_set ("gvmd: Modifying setting");
setproctitle ("gvmd: Modifying setting");

if (option_lock (&lockfile_checking))
return EXIT_FAILURE;
Expand All @@ -2959,7 +2959,7 @@ gvmd (int argc, char** argv)
{
int ret;

proctitle_set ("gvmd: Encrypting all credentials");
setproctitle ("gvmd: Encrypting all credentials");

if (option_lock (&lockfile_checking))
return EXIT_FAILURE;
Expand All @@ -2975,7 +2975,7 @@ gvmd (int argc, char** argv)
{
int ret;

proctitle_set ("gvmd: Decrypting all credentials");
setproctitle ("gvmd: Decrypting all credentials");

if (option_lock (&lockfile_checking))
return EXIT_FAILURE;
Expand Down Expand Up @@ -3226,7 +3226,7 @@ gvmd (int argc, char** argv)

/* Enter the main forever-loop. */

proctitle_set ("gvmd: Waiting for incoming connections");
setproctitle ("gvmd: Waiting for incoming connections");
serve_and_schedule ();

gvm_close_sentry ();
Expand Down
2 changes: 1 addition & 1 deletion src/gvmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
#define _GVMD_H

int
gvmd (int, char **);
gvmd (int, char **, char **);

#endif /* not _GVMD_H */
4 changes: 2 additions & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* @return EXIT_SUCCESS on success, EXIT_FAILURE on failure.
*/
int
main (int argc, char **argv)
main (int argc, char **argv, char *env[])
{
return gvmd (argc, argv);
return gvmd (argc, argv, env);
}
Loading

0 comments on commit 98b5370

Please sign in to comment.