OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
daemon.cc File Reference
#include <unistd.h>
#include <grp.h>
#include <pwd.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <ctype.h>
#include <signal.h>
#include <fstream>
#include <iostream>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdlib>
#include <cerrno>
#include "config.h"
#include "ServerExitConditions.h"
#include "SocketListener.h"
#include "TcpSocket.h"
#include "UnixSocket.h"
#include "PPTServer.h"
#include "BESModuleApp.h"
#include "DaemonCommandHandler.h"
#include "BESServerUtils.h"
#include "BESScrub.h"
#include "BESError.h"
#include "BESDebug.h"
#include "TheBESKeys.h"
#include "BESLog.h"
#include "BESDaemonConstants.h"
Include dependency graph for daemon.cc:

Go to the source code of this file.

Macros

#define BES_SERVER   "/beslistener"
 
#define BES_SERVER_PID   "/bes.pid"
 
#define DAEMON_PORT_STR   "BES.DaemonPort"
 
#define DAEMON_UNIX_SOCK_STR   "BES.DaemonUnixSocket"
 

Typedefs

typedef map< string, string > arg_map
 

Functions

void block_signals ()
 For code that must use signals to stop and start the master listener, block signals being delivered to this process. More...
 
int main (int argc, char *argv[])
 Run the daemon. More...
 
int start_master_beslistener ()
 Start the 'master beslistener' and return its PID. More...
 
bool stop_all_beslisteners (int sig)
 Stop all of the listeners (both the master listener and all of the child listeners that actually process requests). More...
 
void unblock_signals ()
 See block_signals() More...
 
char ** update_beslistener_args ()
 Update the arguments passed to the master beslistener so that changes in the debug/log contexts set in the besdaemon will also be set in the beslisteners. More...
 

Variables

volatile int master_beslistener_status = BESLISTENER_STOPPED
 
volatile int num_children = 0
 

Macro Definition Documentation

#define BES_SERVER   "/beslistener"

Definition at line 76 of file daemon.cc.

#define BES_SERVER_PID   "/bes.pid"

Definition at line 77 of file daemon.cc.

#define DAEMON_PORT_STR   "BES.DaemonPort"

Definition at line 78 of file daemon.cc.

#define DAEMON_UNIX_SOCK_STR   "BES.DaemonUnixSocket"

Definition at line 79 of file daemon.cc.

Typedef Documentation

typedef map<string,string> arg_map

Definition at line 98 of file daemon.cc.

Function Documentation

void block_signals ( )

For code that must use signals to stop and start the master listener, block signals being delivered to this process.

The code must call the companion unblock_signals() when it is done.

Definition at line 177 of file daemon.cc.

Referenced by ServerApp::run(), and stop_all_beslisteners().

int start_master_beslistener ( )

Start the 'master beslistener' and return its PID.

This function also sets the global 'master_beslistener_pid' so that other code in this file (like the signal handlers) can have access to it. It starts the beslistener using the global 'arguments' that is a copy of the arguments passed to this daemon.

Note
The globals 'arguments' and 'master_beslistener_pid' are used here (but not passed in) so that they can be kept local to this file. A poor-man's version of encapsulation.
Returns
0 for an error or the PID of the master beslistener

Definition at line 314 of file daemon.cc.

References BESDEBUG, BESLISTENER_PIPE_FD, BESLISTENER_RUNNING, PPTServer::closeConnection(), master_beslistener_status, and update_beslistener_args().

Referenced by main().

Here is the call graph for this function:

bool stop_all_beslisteners ( int  sig)

Stop all of the listeners (both the master listener and all of the child listeners that actually process requests).

A test version of this used the master beslistener's exit status to determine if the daemon should try to restart the master beslistener. That feature is retained so that the daemon can start without listening on the BESDaemonPort, thus eliminating a security issue for sites without a firewall.

Uses the master bestistener's process group to send 'sig' to all of the beslisteners.

Parameters
sigSignal to send to all beslisteners.
Returns
true if the master beslistener status was caught, false otherwise

Definition at line 217 of file daemon.cc.

References BESDEBUG, block_signals(), master_beslistener_status, and unblock_signals().

Here is the call graph for this function:

void unblock_signals ( )

See block_signals()

Definition at line 191 of file daemon.cc.

Referenced by ServerApp::run(), and stop_all_beslisteners().

char** update_beslistener_args ( )

Update the arguments passed to the master beslistener so that changes in the debug/log contexts set in the besdaemon will also be set in the beslisteners.

Note
The arguments are held in a static global variable - use this function to alter that array.

Definition at line 269 of file daemon.cc.

References BESDEBUG, and BESDebug::GetOptionsString().

Referenced by start_master_beslistener().

Here is the call graph for this function:

Variable Documentation

volatile int master_beslistener_status = BESLISTENER_STOPPED

Definition at line 94 of file daemon.cc.

Referenced by main(), start_master_beslistener(), and stop_all_beslisteners().

volatile int num_children = 0

Definition at line 95 of file daemon.cc.