]> mj.ucw.cz Git - libucw.git/blobdiff - ucw/daemon.h
tableprinter: code cleanup
[libucw.git] / ucw / daemon.h
index 6ea383c9b913c42ac71da8453b5eecd3a08f1dac..25a34f8033f3b43690b036892da17a82a4415a30 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *     UCW Library -- Daemonization
  *
- *     (c) 2012 Martin Mares <mj@ucw.cz>
+ *     (c) 2012--2014 Martin Mares <mj@ucw.cz>
  *
  *     This software may be freely distributed and used according to the terms
  *     of the GNU Lesser General Public License.
 #define daemon_control ucw_daemon_control
 #define daemon_exit ucw_daemon_exit
 #define daemon_init ucw_daemon_init
+#define daemon_resolve_ugid ucw_daemon_resolve_ugid
 #define daemon_run ucw_daemon_run
+#define daemon_switch_ugid ucw_daemon_switch_ugid
 #endif
 
 /** Parameters passed to the daemon helper. **/
 struct daemon_params {
-  uns flags;                           // DAEMON_FLAG_xxx
+  uint flags;                          // DAEMON_FLAG_xxx
   const char *pid_file;                        // A path to PID file (optional)
   const char *run_as_user;             // User name or "#uid" (optional)
   const char *run_as_group;            // Group name or "#gid" (optional)
@@ -63,9 +65,24 @@ void daemon_run(struct daemon_params *dp, void (*body)(struct daemon_params *dp)
  **/
 void daemon_exit(struct daemon_params *dp);
 
+/**
+ * Parse `run_as_user` and `run_as_group` and remember the results in internal fields.
+ * This is called automatically by daemon_init(), but also provided as a separate
+ * function in case you want to use daemon_switch_ugid(). Upon parse error, it calls die().
+ **/
+void daemon_resolve_ugid(struct daemon_params *dp);
+
+/**
+ * Switch user and group as specified by the `run_as_user` and `run_as_group`.
+ * This is performed automatically by daemon_run(), but sometimes you might want to
+ * switch the user and group separately. In this case, you have to call daemon_resolve_ugid()
+ * beforehand.
+ **/
+void daemon_switch_ugid(struct daemon_params *dp);
+
 #define DAEMON_ERR_LEN 256
 
-/** Parameters passed to daemon_control() **/
+/** Parameters passed to @daemon_control() **/
 struct daemon_control_params {
   const char *pid_file;                // A path to PID file
   const char *guard_file;      // A path to guard file
@@ -102,7 +119,7 @@ enum daemon_control_action {
  **/
 enum daemon_control_status daemon_control(struct daemon_control_params *dc);
 
-// XXX: Also used as exit codes of the daemon-control utility.
+// XXX: Also used as exit codes of the ucw-daemon-control utility.
 enum daemon_control_status {
   DAEMON_STATUS_OK = 0,
   DAEMON_STATUS_ALREADY_DONE = 100,