]> mj.ucw.cz Git - libucw.git/blobdiff - ucw/daemon.h
Heap: Interface cleanup
[libucw.git] / ucw / daemon.h
index dc2fd746eb39342287293041b31c76f9a15f67be..c5beacc060ca8186171e91fad6a9ef3b3878dffa 100644 (file)
@@ -30,6 +30,7 @@ struct daemon_params {
 /** Flags passed to the daemon helper. **/
 enum daemon_flags {
   DAEMON_FLAG_PRESERVE_CWD = 1,                // Skip chdir("/")
 /** Flags passed to the daemon helper. **/
 enum daemon_flags {
   DAEMON_FLAG_PRESERVE_CWD = 1,                // Skip chdir("/")
+  DAEMON_FLAG_SIMULATE = 2,            // Simulate daemonization (avoid fork etc.)
 };
 
 /**
 };
 
 /**
@@ -44,6 +45,9 @@ void daemon_init(struct daemon_params *dp);
  * a new process and does all necessary setup. Inside the new process, it calls
  * @body (and when it returns, it exits the process). In the original process, it writes
  * the PID file and returns.
  * a new process and does all necessary setup. Inside the new process, it calls
  * @body (and when it returns, it exits the process). In the original process, it writes
  * the PID file and returns.
+ *
+ * When `DAEMON_FLAG_SIMULATE` is set, it justs calls @body. This is useful
+ * for running of daemons in a debugger.
  **/
 void daemon_run(struct daemon_params *dp, void (*body)(struct daemon_params *dp));
 
  **/
 void daemon_run(struct daemon_params *dp, void (*body)(struct daemon_params *dp));
 
@@ -65,7 +69,7 @@ struct daemon_control_params {
 };
 
 enum daemon_control_action {
 };
 
 enum daemon_control_action {
-  DAEMON_CONTROL_CHECK,
+  DAEMON_CONTROL_CHECK = 1,
   DAEMON_CONTROL_START,
   DAEMON_CONTROL_STOP,
   DAEMON_CONTROL_SIGNAL,
   DAEMON_CONTROL_START,
   DAEMON_CONTROL_STOP,
   DAEMON_CONTROL_SIGNAL,
@@ -77,7 +81,7 @@ enum daemon_control_action {
  * * `DAEMON_CONTROL_START` to start the daemon
  * * `DAEMON_CONTROL_STOP` to stop the daemon (send `SIGTERM` or `dc->signal` if non-zero)
  * * `DAEMON_CONTROL_CHECK` to check that the daemon is running
  * * `DAEMON_CONTROL_START` to start the daemon
  * * `DAEMON_CONTROL_STOP` to stop the daemon (send `SIGTERM` or `dc->signal` if non-zero)
  * * `DAEMON_CONTROL_CHECK` to check that the daemon is running
- * * `DAEMON_CONTROL_SIGNAL` to send a signal to the daemon
+ * * `DAEMON_CONTROL_SIGNAL` to send a signal to the daemon (send `SIGHUP` or `dc->signal` if non-zero)
  *
  * The function returns a status code:
  *
  *
  * The function returns a status code:
  *
@@ -86,14 +90,18 @@ enum daemon_control_action {
  * * `DAEMON_STATUS_NOT_RUNNING` if the action failed, because the daemon is not running
  * * `DAEMON_STATUS_ERROR` if the action failed for some other reason (in this case,
  *   `dc->error_msg` contains a full error message)
  * * `DAEMON_STATUS_NOT_RUNNING` if the action failed, because the daemon is not running
  * * `DAEMON_STATUS_ERROR` if the action failed for some other reason (in this case,
  *   `dc->error_msg` contains a full error message)
+ * * `DAEMON_STATUS_STALE` if the daemon was in an undefined state (e.g., a stale PID file);
+ *   for `DAEMON_CONTROL_START`, it means success
  **/
 enum daemon_control_status daemon_control(struct daemon_control_params *dc);
 
  **/
 enum daemon_control_status daemon_control(struct daemon_control_params *dc);
 
+// XXX: Also used as exit codes of the daemon-control utility.
 enum daemon_control_status {
   DAEMON_STATUS_OK = 0,
   DAEMON_STATUS_ALREADY_DONE = 100,
   DAEMON_STATUS_NOT_RUNNING = 101,
   DAEMON_STATUS_ERROR = 102,
 enum daemon_control_status {
   DAEMON_STATUS_OK = 0,
   DAEMON_STATUS_ALREADY_DONE = 100,
   DAEMON_STATUS_NOT_RUNNING = 101,
   DAEMON_STATUS_ERROR = 102,
+  DAEMON_STATUS_STALE = 103,
 };
 
 #endif
 };
 
 #endif