#include <Daemon.h>
Inheritance diagram for Tools::Daemon:


Public Member Functions | |
| Daemon (void) | |
| virtual String * | name (void) abstract |
| Answer application name. | |
| virtual String * | processIdPath (void) |
| virtual void | processIdPath (String *path) |
| virtual void | redirectStreamsToNull (void) |
| virtual void | changeRootDirectory (void) |
| virtual void | runUnderUser (int id) |
| virtual void | runUnderUserNamed (String *name) |
| virtual void | hookupSignal (int signo) |
| virtual void | hookupTerminateSignal (void) |
| virtual void | hookupInterruptSignal (void) |
| virtual void | signalHandler (int signo) abstract |
| Here you can define how the signals should be handled. | |
| virtual void | run (void) |
Protected Member Functions | |
| virtual Filename * | processIdFilename (void) |
| virtual int | loadProcessId (void) |
| virtual void | saveProcessId (void) |
Protected Attributes | |
| bool | close_std_streams |
| bool | change_current_directory |
| String * | pid_path |
Static Private Member Functions | |
| static void | globalSignalHandler (int signo) |
|
|
Definition at line 41 of file Daemon.cc. References change_current_directory, close_std_streams, and pid_path. 00042 {
00043 close_std_streams = false;
00044 change_current_directory = false;
00045 pid_path = new String("/var/run");
00046 }
|
|
|
Definition at line 64 of file Daemon.cc. References change_current_directory. 00065 {
00066 change_current_directory = true;
00067 }
|
|
|
Definition at line 148 of file Daemon.cc. References Tools::Application::current(). Referenced by hookupSignal(). 00149 {
00150 dynamic_cast<Daemon *>(Application::current())->signalHandler(signo);
00151 }
|
|
|
Definition at line 87 of file Daemon.cc. References hookupSignal(). 00088 {
00089 hookupSignal(SIGINT);
00090 }
|
|
|
Definition at line 82 of file Daemon.cc. References globalSignalHandler(). Referenced by hookupInterruptSignal(), and hookupTerminateSignal(). 00083 {
00084 signal(signo, globalSignalHandler);
00085 }
|
|
|
Definition at line 92 of file Daemon.cc. References hookupSignal(). 00093 {
00094 hookupSignal(SIGTERM);
00095 }
|
|
|
Definition at line 122 of file Daemon.cc. References Core::Stream::close(), Core::Stream::nextLine(), and processIdFilename(). Referenced by run(). 00123 {
00124 Stream *pidfile;
00125 int pid;
00126
00127 try {
00128 pidfile = processIdFilename()->withEncoding("default")->readStream();
00129 pid = dynamic_cast<String *>(pidfile->nextLine())->asNumber()->asLong();
00130 pidfile->close();
00131 return(pid);
00132 }
00133 catch (FileOpenFailed *ex) {
00134 return 0;
00135 }
00136 }
|
|
|
Answer application name. This is used as a part of pid file name. Referenced by processIdFilename(). |
|
|
Definition at line 117 of file Daemon.cc. References name(), and pid_path. Referenced by loadProcessId(), run(), and saveProcessId().
|
|
|
Definition at line 54 of file Daemon.cc. References pid_path. 00055 {
00056 pid_path = path;
00057 }
|
|
|
Definition at line 49 of file Daemon.cc. References pid_path. 00050 {
00051 return pid_path;
00052 }
|
|
|
Definition at line 59 of file Daemon.cc. References close_std_streams. 00060 {
00061 close_std_streams = true;
00062 }
|
|
|
Reimplemented from Tools::Application. Definition at line 98 of file Daemon.cc. References Tools::Application::cerr, change_current_directory, close_std_streams, loadProcessId(), Core::Stream::nextPutAll(), processIdFilename(), Tools::Application::run(), and saveProcessId(). 00099 {
00100 /* Is server already running */
00101 if (loadProcessId()) {
00102 cerr->nextPutAll("One server is already running.\n");
00103 return;
00104 }
00105 if (daemon(change_current_directory ? 0 : 1,
00106 close_std_streams ? 0 : 1) < 0) {
00107 cerr->nextPutAll("Cannot start daemon process.\n");
00108 return;
00109 }
00110 saveProcessId();
00111 Application::run();
00112 /* Delete PID file */
00113 processIdFilename()->erase();
00114 }
|
|
|
Definition at line 69 of file Daemon.cc. Referenced by runUnderUserNamed(). 00070 {
00071 if (uid > 0) setuid(uid);
00072 }
|
|
|
Definition at line 74 of file Daemon.cc. References Core::String::asCString(), and runUnderUser(). 00075 {
00076 struct passwd *pass;
00077 pass = getpwnam(name->asCString());
00078 runUnderUser(pass->pw_uid);
00079 }
|
|
|
Definition at line 138 of file Daemon.cc. References Core::Stream::close(), Core::Stream::lf(), Core::Stream::print(), and processIdFilename(). Referenced by run(). 00139 {
00140 Stream *pidfile;
00141
00142 pidfile = processIdFilename()->withEncoding("default")->writeStream();
00143 pidfile->print((long int) getpid());
00144 pidfile->lf();
00145 pidfile->close();
00146 }
|
|
|
Here you can define how the signals should be handled.
|
|
|
Definition at line 39 of file Daemon.h. Referenced by changeRootDirectory(), Daemon(), and run(). |
|
|
Definition at line 38 of file Daemon.h. Referenced by Daemon(), redirectStreamsToNull(), and run(). |
|
|
Definition at line 40 of file Daemon.h. Referenced by Daemon(), processIdFilename(), and processIdPath(). |
1.4.2