mirror of
https://github.com/openvswitch/ovs
synced 2025-09-04 16:25:17 +00:00
daemon: Cleanup some functions.
Some functions are unused and some functions can be declared as static. Signed-off-by: Gurucharan Shetty <gshetty@nicira.com> Acked-by: Ben Pfaff <blp@nicira.com>
This commit is contained in:
45
lib/daemon.c
45
lib/daemon.c
@@ -69,10 +69,13 @@ static bool save_fds[3];
|
|||||||
|
|
||||||
static void check_already_running(void);
|
static void check_already_running(void);
|
||||||
static int lock_pidfile(FILE *, int command);
|
static int lock_pidfile(FILE *, int command);
|
||||||
|
static char *make_pidfile_name(const char *name);
|
||||||
|
static pid_t fork_and_clean_up(void);
|
||||||
|
static void daemonize_post_detach(void);
|
||||||
|
|
||||||
/* Returns the file name that would be used for a pidfile if 'name' were
|
/* Returns the file name that would be used for a pidfile if 'name' were
|
||||||
* provided to set_pidfile(). The caller must free the returned string. */
|
* provided to set_pidfile(). The caller must free the returned string. */
|
||||||
char *
|
static char *
|
||||||
make_pidfile_name(const char *name)
|
make_pidfile_name(const char *name)
|
||||||
{
|
{
|
||||||
return (!name
|
return (!name
|
||||||
@@ -94,15 +97,6 @@ set_pidfile(const char *name)
|
|||||||
pidfile = make_pidfile_name(name);
|
pidfile = make_pidfile_name(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Returns an absolute path to the configured pidfile, or a null pointer if no
|
|
||||||
* pidfile is configured. The caller must not modify or free the returned
|
|
||||||
* string. */
|
|
||||||
const char *
|
|
||||||
get_pidfile(void)
|
|
||||||
{
|
|
||||||
return pidfile;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Sets that we do not chdir to "/". */
|
/* Sets that we do not chdir to "/". */
|
||||||
void
|
void
|
||||||
set_no_chdir(void)
|
set_no_chdir(void)
|
||||||
@@ -110,13 +104,6 @@ set_no_chdir(void)
|
|||||||
chdir_ = false;
|
chdir_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Will we chdir to "/" as part of daemonizing? */
|
|
||||||
bool
|
|
||||||
is_chdir_enabled(void)
|
|
||||||
{
|
|
||||||
return chdir_;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Normally, daemonize() or damonize_start() will terminate the program with a
|
/* Normally, daemonize() or damonize_start() will terminate the program with a
|
||||||
* message if a locked pidfile already exists. If this function is called, an
|
* message if a locked pidfile already exists. If this function is called, an
|
||||||
* existing pidfile will be replaced, with a warning. */
|
* existing pidfile will be replaced, with a warning. */
|
||||||
@@ -165,26 +152,6 @@ daemon_save_fd(int fd)
|
|||||||
save_fds[fd] = true;
|
save_fds[fd] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Unregisters pidfile from being unlinked when the program terminates via
|
|
||||||
* exit() or a fatal signal. */
|
|
||||||
void
|
|
||||||
remove_pidfile_from_unlink(void)
|
|
||||||
{
|
|
||||||
if (pidfile) {
|
|
||||||
fatal_signal_remove_file_to_unlink(pidfile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Registers pidfile to be unlinked when the program terminates via exit() or a
|
|
||||||
* fatal signal. */
|
|
||||||
void
|
|
||||||
add_pidfile_to_unlink(void)
|
|
||||||
{
|
|
||||||
if (pidfile) {
|
|
||||||
fatal_signal_add_file_to_unlink(pidfile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If a pidfile has been configured, creates it and stores the running
|
/* If a pidfile has been configured, creates it and stores the running
|
||||||
* process's pid in it. Ensures that the pidfile will be deleted when the
|
* process's pid in it. Ensures that the pidfile will be deleted when the
|
||||||
* process exits. */
|
* process exits. */
|
||||||
@@ -280,7 +247,7 @@ daemonize(void)
|
|||||||
* Post-fork, but before returning, this function calls a few other functions
|
* Post-fork, but before returning, this function calls a few other functions
|
||||||
* that are generally useful if the child isn't planning to exec a new
|
* that are generally useful if the child isn't planning to exec a new
|
||||||
* process. */
|
* process. */
|
||||||
pid_t
|
static pid_t
|
||||||
fork_and_clean_up(void)
|
fork_and_clean_up(void)
|
||||||
{
|
{
|
||||||
pid_t pid = xfork();
|
pid_t pid = xfork();
|
||||||
@@ -570,7 +537,7 @@ daemonize_complete(void)
|
|||||||
* It only makes sense to call this function as part of an implementation of a
|
* It only makes sense to call this function as part of an implementation of a
|
||||||
* special daemon subprocess. A normal daemon should just call
|
* special daemon subprocess. A normal daemon should just call
|
||||||
* daemonize_complete(). */
|
* daemonize_complete(). */
|
||||||
void
|
static void
|
||||||
daemonize_post_detach(void)
|
daemonize_post_detach(void)
|
||||||
{
|
{
|
||||||
if (detach) {
|
if (detach) {
|
||||||
|
@@ -56,26 +56,17 @@
|
|||||||
daemon_set_monitor(); \
|
daemon_set_monitor(); \
|
||||||
break;
|
break;
|
||||||
|
|
||||||
char *make_pidfile_name(const char *name);
|
|
||||||
void set_pidfile(const char *name);
|
void set_pidfile(const char *name);
|
||||||
const char *get_pidfile(void);
|
|
||||||
void set_no_chdir(void);
|
void set_no_chdir(void);
|
||||||
bool is_chdir_enabled(void);
|
|
||||||
void set_detach(void);
|
void set_detach(void);
|
||||||
bool get_detach(void);
|
bool get_detach(void);
|
||||||
void daemon_set_monitor(void);
|
void daemon_set_monitor(void);
|
||||||
void daemon_save_fd(int fd);
|
void daemon_save_fd(int fd);
|
||||||
void remove_pidfile_from_unlink(void);
|
|
||||||
void add_pidfile_to_unlink(void);
|
|
||||||
void daemonize(void);
|
void daemonize(void);
|
||||||
void daemonize_start(void);
|
void daemonize_start(void);
|
||||||
void daemonize_complete(void);
|
void daemonize_complete(void);
|
||||||
void ignore_existing_pidfile(void);
|
void ignore_existing_pidfile(void);
|
||||||
void daemon_usage(void);
|
void daemon_usage(void);
|
||||||
pid_t read_pidfile(const char *name);
|
pid_t read_pidfile(const char *name);
|
||||||
pid_t read_pidfile_if_exists(const char *name);
|
|
||||||
|
|
||||||
pid_t fork_and_clean_up(void);
|
|
||||||
void daemonize_post_detach(void);
|
|
||||||
|
|
||||||
#endif /* daemon.h */
|
#endif /* daemon.h */
|
||||||
|
@@ -78,23 +78,12 @@ def set_pidfile(name):
|
|||||||
_pidfile = make_pidfile_name(name)
|
_pidfile = make_pidfile_name(name)
|
||||||
|
|
||||||
|
|
||||||
def get_pidfile():
|
|
||||||
"""Returns an absolute path to the configured pidfile, or None if no
|
|
||||||
pidfile is configured."""
|
|
||||||
return _pidfile
|
|
||||||
|
|
||||||
|
|
||||||
def set_no_chdir():
|
def set_no_chdir():
|
||||||
"""Sets that we do not chdir to "/"."""
|
"""Sets that we do not chdir to "/"."""
|
||||||
global _chdir
|
global _chdir
|
||||||
_chdir = False
|
_chdir = False
|
||||||
|
|
||||||
|
|
||||||
def is_chdir_enabled():
|
|
||||||
"""Will we chdir to "/" as part of daemonizing?"""
|
|
||||||
return _chdir
|
|
||||||
|
|
||||||
|
|
||||||
def ignore_existing_pidfile():
|
def ignore_existing_pidfile():
|
||||||
"""Normally, daemonize() or daemonize_start() will terminate the program
|
"""Normally, daemonize() or daemonize_start() will terminate the program
|
||||||
with a message if a locked pidfile already exists. If this function is
|
with a message if a locked pidfile already exists. If this function is
|
||||||
|
Reference in New Issue
Block a user