|
The Assimilation Monitoring Project
|
Miscellaneous library functions - doing varied interesting things. More...
#include <projectcommon.h>#include <stdlib.h>#include <errno.h>#include <string.h>#include <fcntl.h>#include <sys/types.h>#include <sys/stat.h>#include <sys/time.h>#include <sys/resource.h>#include <signal.h>#include <misc.h>
Go to the source code of this file.
Macros | |
| #define | SEP '/' |
| #define | PROCSELFEXE "/proc/self/exe" |
| #define | PROCOTHEREXE "/proc/%d/exe" |
| #define | MAXPIDLEN 16 |
| #define | MAXPATH 256 |
| #define | GETPID getpid() |
Functions | |
| void | assimilation_logger (const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer user_data) |
| FSTATIC void | catch_pid_signal (int signum) |
| Should be overridden with the name to appear in the logs. More... | |
| void | daemonize_me (gboolean stay_in_foreground, const char *dirtorunin, char *pidfile) |
| Function to get system name (uname -n in UNIX terms) More... | |
| void | assimilation_openlog (const char *logname) |
| Open logs in our style (syslog) More... | |
| PidRunningStat | are_we_already_running (const char *pidfile, int *pidarg) |
| See if the pid file suggests we are already running or not. More... | |
| gboolean | create_pid_file (const char *pidfile) |
| Create a pid file for the current process. More... | |
| char * | get_default_pid_fileName (const char *procname) |
| get default pid file name More... | |
| void | remove_pid_file (const char *pidfile) |
| Remove the pid file that goes with this service iff we created one during this invocation. More... | |
| int | kill_pid_service (const char *pidfile, int signal) |
| kill the service that goes with our current pid file - return negative iff pidfile pid is running and kill fails More... | |
| void | rmpid_and_exit_on_signal (const char *pidfile, int signal_in) |
| Remove PID file and exit when a signal is received. More... | |
| guint | pidrunningstat_to_status (PidRunningStat stat) |
| Convert PidRunningStat to an exit code for status. More... | |
| WINEXPORT gchar ** | assim_merge_environ (const gchar *const *env, ConfigContext *update) |
| Merge ConfigContext into possibly NULL current environment, returning a new environment. More... | |
| WINEXPORT void | assim_free_environ (gchar **env) |
| Free the result of assim_merge_env. More... | |
Variables | |
| const char * | assim_syslogid = "assim" |
Miscellaneous library functions - doing varied interesting things.
These include:
This file is part of the Assimilation Project.
The Assimilation software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with the Assimilation Project software. If not, see http://www.gnu.org/licenses/
Definition in file misc.c.
| #define GETPID getpid() |
Referenced by create_pid_file().
| #define MAXPATH 256 |
Definition at line 287 of file misc.c.
Referenced by are_we_already_running().
| #define PROCOTHEREXE "/proc/%d/exe" |
Definition at line 284 of file misc.c.
Referenced by are_we_already_running().
| #define PROCSELFEXE "/proc/self/exe" |
Definition at line 283 of file misc.c.
Referenced by are_we_already_running().
| #define SEP '/' |
Definition at line 282 of file misc.c.
Referenced by are_we_already_running().
| PidRunningStat are_we_already_running | ( | const char * | pidfile, |
| int * | pidarg | ||
| ) |
See if the pid file suggests we are already running or not.
Determine service status.
| pidfile | The pathname of our expected pid file |
| pidarg | Pid of the process (if running) |
Definition at line 293 of file misc.c.
References __FUNCTION__, MAXPATH, PID_DEAD, PID_NOTRUNNING, PID_NOTUS, PID_RUNNING, PROCOTHEREXE, PROCSELFEXE, and SEP.
Referenced by create_pid_file(), daemonize_me(), kill_pid_service(), and main().

| WINEXPORT void assim_free_environ | ( | gchar ** | env | ) |
Free the result of assim_merge_env.
Free environment created by assim_merge_environ.
| env | The result of assim_merge_environ – to be freed |
Definition at line 649 of file misc.c.
Referenced by childprocess_new().

| WINEXPORT gchar** assim_merge_environ | ( | const gchar *const * | env, |
| ConfigContext * | update | ||
| ) |
Merge ConfigContext into possibly NULL current environment, returning a new environment.
Create new env merged from ConfigContext.
| env | Initial environment – or NULL |
| update | Updates to merge into this environment |
Definition at line 538 of file misc.c.
References _NetAddr::baseclass, CFG_BOOL, CFG_EEXIST, CFG_INT64, CFG_NETADDR, CFG_STRING, FMT_64BIT, g_get_environ(), _ConfigContext::getaddr, _ConfigContext::getbool, _ConfigContext::getint, _ConfigContext::getstring, _ConfigContext::gettype, _ConfigContext::keycount, _ConfigContext::keys, and _AssimObj::toString.
Referenced by childprocess_new().


| void assimilation_logger | ( | const gchar * | log_domain, |
| GLogLevelFlags | log_level, | ||
| const gchar * | message, | ||
| gpointer | ignored | ||
| ) |
| log_domain | What domain are we logging to? |
| log_level | What is our log level? |
| message | What should we log |
| ignored | Ignored |
Definition at line 212 of file misc.c.
References assim_syslogid, and assimilation_openlog().
Referenced by assimilation_openlog().


| void assimilation_openlog | ( | const char * | logname | ) |
Open logs in our style (syslog)
Definition at line 187 of file misc.c.
References assim_syslogid, and assimilation_logger().
Referenced by assimilation_logger(), and main().


| FSTATIC void catch_pid_signal | ( | int | signum | ) |
Should be overridden with the name to appear in the logs.
Definition at line 506 of file misc.c.
References g_unlink.
Referenced by rmpid_and_exit_on_signal().

| gboolean create_pid_file | ( | const char * | pidfile | ) |
Create a pid file for the current process.
Create pid file - return TRUE on success.
Definition at line 396 of file misc.c.
References __FUNCTION__, are_we_already_running(), g_unlink, GETPID, PID_DEAD, PID_NOTUS, and PID_RUNNING.
Referenced by daemonize_me().


| void daemonize_me | ( | gboolean | stay_in_foreground, |
| const char * | dirtorunin, | ||
| char * | pidfile | ||
| ) |
Function to get system name (uname -n in UNIX terms)
pathname of pid file, or NULL
Make us into a proper daemon.
| [in] | stay_in_foreground | TRUE to not make a background job |
| [in] | dirtorunin | Directory to cd to or NULL for default (/) |
| [in] | pidfile | Pathname of pidfile or NULL for no pidfile |
Definition at line 85 of file misc.c.
References __FUNCTION__, are_we_already_running(), create_pid_file(), DIMOF, and PID_RUNNING.
Referenced by main().


| char* get_default_pid_fileName | ( | const char * | procname | ) |
get default pid file name
Make a daemon process out of this process.
Definition at line 443 of file misc.c.
References __FUNCTION__, and STD_PID_DIR.
Referenced by main().

| int kill_pid_service | ( | const char * | pidfile, |
| int | signal | ||
| ) |
kill the service that goes with our current pid file - return negative iff pidfile pid is running and kill fails
Issue given signal to the pidfile-indicated running process.
Definition at line 465 of file misc.c.
References are_we_already_running(), g_unlink, and PID_RUNNING.
Referenced by main().


| guint pidrunningstat_to_status | ( | PidRunningStat | stat | ) |
Convert PidRunningStat to an exit code for status.
| stat | Status to convert |
Definition at line 515 of file misc.c.
References PID_DEAD, PID_NOTRUNNING, PID_NOTUS, and PID_RUNNING.
Referenced by main().

| void remove_pid_file | ( | const char * | pidfile | ) |
| void rmpid_and_exit_on_signal | ( | const char * | pidfile, |
| int | signal_in | ||
| ) |
Remove PID file and exit when a signal is received.
Issue given signal to the pidfile-indicated running process.
Definition at line 488 of file misc.c.
References catch_pid_signal(), and signal.

| const char* assim_syslogid = "assim" |
Definition at line 47 of file misc.c.
Referenced by assimilation_logger(), and assimilation_openlog().