syslog-ng source
gprocess.c File Reference
#include "gprocess.h"
#include "userdb.h"
#include "messages.h"
#include "reloc.h"
#include "console.h"
#include "stackdump.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <time.h>
#include <sys/resource.h>
#include <sys/wait.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>
#include <signal.h>
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <pwd.h>
#include <grp.h>
Include dependency graph for gprocess.c:

Macros

#define SAFE_STRING(x)   ((x) ? (x) : "NULL")
 
#define G_PROCESS_FD_LIMIT_RESERVE   64
 
#define G_PROCESS_FAILURE_NOTIFICATION   SYSLOG_NG_PATH_PREFIX "/sbin/syslog-ng-failure"
 
#define inherit_systemd_activation()
 

Enumerations

enum  GProcessKind { G_PK_STARTUP , G_PK_SUPERVISOR , G_PK_DAEMON }
 

Functions

void g_process_set_mode (GProcessMode mode)
 
GProcessMode g_process_get_mode (void)
 

Variables

char ** environ
 

: the name of the process to be reported as program name

g_process_set_name:

This function should be called by the daemon to set the program name which is present in various error message and might influence the PID file if not overridden by g_process_set_pidfile().

#define SPT_PADCHAR   '\0'
 
#define PROC_TITLE_SPACE   1024
 
void g_process_set_name (const gchar *name)
 
void g_process_set_user (const gchar *user)
 
void g_process_set_group (const gchar *group)
 
void g_process_set_chroot (const gchar *chroot_dir)
 
void g_process_set_pidfile (const gchar *pidfile)
 
void g_process_set_pidfile_dir (const gchar *pidfile_dir)
 
void g_process_set_working_dir (const gchar *cwd)
 
void g_process_set_caps (const gchar *caps)
 
void g_process_set_argv_space (gint argc, gchar **argv)
 
void g_process_set_check (gint check_period, gboolean(*check_fn)(void))
 
void g_process_start (void)
 
void g_process_startup_failed (guint ret_num, gboolean may_exit)
 
void g_process_startup_ok (void)
 
void g_process_finish (void)
 
void g_process_disable_caps (void)
 
void g_process_add_option_group (GOptionContext *ctx)
 

Macro Definition Documentation

◆ G_PROCESS_FAILURE_NOTIFICATION

#define G_PROCESS_FAILURE_NOTIFICATION   SYSLOG_NG_PATH_PREFIX "/sbin/syslog-ng-failure"

◆ G_PROCESS_FD_LIMIT_RESERVE

#define G_PROCESS_FD_LIMIT_RESERVE   64

◆ inherit_systemd_activation

#define inherit_systemd_activation ( )

◆ PROC_TITLE_SPACE

#define PROC_TITLE_SPACE   1024

◆ SAFE_STRING

#define SAFE_STRING (   x)    ((x) ? (x) : "NULL")

◆ SPT_PADCHAR

#define SPT_PADCHAR   '\0'

Enumeration Type Documentation

◆ GProcessKind

Enumerator
G_PK_STARTUP 
G_PK_SUPERVISOR 
G_PK_DAEMON 

Function Documentation

◆ g_process_add_option_group()

void g_process_add_option_group ( GOptionContext *  ctx)

◆ g_process_disable_caps()

void g_process_disable_caps ( void  )

◆ g_process_finish()

void g_process_finish ( void  )

g_process_finish:

This is a public API function to be called by the user code when the daemon exits after properly initialized (e.g. when it terminates because of SIGTERM). This function currently only removes the PID file.

There is a memory leak for **environ and elements that should be freed here theoretically.

The reason why environ is copied during g_process_set_argv_space so to be able to overwrite process title in ps/top commands to supervisor. In bsd there is setproctitle call which solve this, but currently it is not available for linux.

The problem is that modules can add their own env variables to the list, which must not be freed here, otherwise it would result double free (e.g some version of Oracle Java). One might also would try to track which environment variables are added by syslog-ng, and free only those. There is still a problem with this, **environ itself cannot be freed in some cases. For example libcurl registers an atexit function which needs an environment variable, that would be freed here before at_exit is called, resulting in invalid read.

As this leak does not cause any real problem like accumulating over time, it is safe to leave it as it is.

◆ g_process_get_mode()

GProcessMode g_process_get_mode ( void  )

g_process_get_mode:

Return the processing mode applied to the daemon.

◆ g_process_set_argv_space()

void g_process_set_argv_space ( gint  argc,
gchar **  argv 
)

g_process_set_argv_space: @argc: Original argc, as received by the main function in it's first parameter @argv: Original argv, as received by the main function in it's second parameter

This function should be called by the daemon if it wants to enable process title manipulation in the supervisor process.

◆ g_process_set_caps()

void g_process_set_caps ( const gchar *  caps)

g_process_set_caps: @caps: capability specification in text form

This function should be called by the daemon to set the initial capability set. The process will change its capabilities to this value during startup, provided it has enough permissions to do so.

◆ g_process_set_check()

void g_process_set_check ( gint  check_period,
gboolean(*)(void)  check_fn 
)

g_process_set_check: @check_period: check period in seconds @check_fn: checker function

Installs a checker function that is called at the specified rate. The checked process is allowed to run as long as this function returns TRUE.

◆ g_process_set_chroot()

void g_process_set_chroot ( const gchar *  chroot_dir)

g_process_set_chroot: @chroot_dir: the name of the chroot directory the process should switch to during startup

This function should be called by the daemon to set the chroot directory

◆ g_process_set_group()

void g_process_set_group ( const gchar *  group)

g_process_set_group: @group: the name of the group the process should switch to during startup

This function should be called by the daemon to set the group name.

◆ g_process_set_mode()

void g_process_set_mode ( GProcessMode  mode)

g_process_set_mode: @mode: an element from ZProcessMode

This function should be called by the daemon to set the processing mode as specified by @mode.

◆ g_process_set_name()

void g_process_set_name ( const gchar *  name)

◆ g_process_set_pidfile()

void g_process_set_pidfile ( const gchar *  pidfile)

g_process_set_pidfile: @pidfile: the name of the complete pid file with full path

This function should be called by the daemon to set the PID file name to store the pid of the process. This value will be used as the pidfile directly, neither name nor pidfile_dir influences the pidfile location if this is set.

◆ g_process_set_pidfile_dir()

void g_process_set_pidfile_dir ( const gchar *  pidfile_dir)

g_process_set_pidfile_dir: @pidfile_dir: name of the pidfile directory

This function should be called by the daemon to set the PID file directory. This value is not used if set_pidfile() was called.

◆ g_process_set_user()

void g_process_set_user ( const gchar *  user)

g_process_set_user: @user: the name of the user the process should switch to during startup

This function should be called by the daemon to set the user name.

◆ g_process_set_working_dir()

void g_process_set_working_dir ( const gchar *  cwd)

g_process_set_working_dir: @working_dir: name of the working directory

This function should be called by the daemon to set the working directory. The process will change its current directory to this value or to pidfile_dir if it is unset.

◆ g_process_start()

void g_process_start ( void  )

g_process_start:

Start the process as directed by the options set by various g_process_set_*() functions.

◆ g_process_startup_failed()

void g_process_startup_failed ( guint  ret_num,
gboolean  may_exit 
)

g_process_startup_failed: @ret_num: exit code @may_exit: whether to exit the process

This is a public API function to be called by the user code when initialization failed.

◆ g_process_startup_ok()

void g_process_startup_ok ( void  )

g_process_startup_ok:

This is a public API function to be called by the user code when initialization was successful, we can report back to the user.

Variable Documentation

◆ argc

gint argc

◆ argv

gchar** argv

◆ argv_env_len

size_t argv_env_len

◆ argv_orig

gchar* argv_orig

◆ argv_start

gchar* argv_start

◆ caps

const gchar* caps

◆ check_fn

gboolean(* check_fn) (void) ( void  )

◆ check_period

gint check_period

◆ chroot_dir

const gchar* chroot_dir

◆ core

gboolean core

◆ cwd

const gchar* cwd

◆ enable_caps

gboolean enable_caps

◆ environ

char** environ
extern

◆ fd_limit_min

gint fd_limit_min

◆ gid

gint gid

◆ group

const gchar* group

◆ mode

◆ name

const gchar* name

◆ pidfile

const gchar* pidfile

◆ pidfile_dir

const gchar* pidfile_dir

◆ uid

gint uid

◆ user

const gchar* user