#include "lib/util/blocking.h"
#include "lib/util/dlinklist.h"
#include "lib/util/tevent_unix.h"
+#include "lib/util/become_daemon.h"
#include "common/logging.h"
#include "common/reqid.h"
int sock_daemon_setup(TALLOC_CTX *mem_ctx, const char *daemon_name,
const char *logging, const char *debug_level,
- const char *pidfile,
struct sock_daemon_funcs *funcs,
void *private_data,
struct sock_daemon_context **out)
return ret;
}
- if (pidfile != NULL) {
- ret = pidfile_create(sockd, pidfile, &sockd->pid_ctx);
- if (ret != 0) {
- talloc_free(sockd);
- return EEXIST;
- }
- }
-
*out = sockd;
return 0;
}
struct tevent_req *sock_daemon_run_send(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
struct sock_daemon_context *sockd,
+ const char *pidfile,
+ bool do_fork, bool create_session,
pid_t pid_watch)
{
struct tevent_req *req, *subreq;
return NULL;
}
+ become_daemon(do_fork, !create_session, false);
+
+ if (pidfile != NULL) {
+ int ret = pidfile_context_create(sockd, pidfile,
+ &sockd->pid_ctx);
+ if (ret != 0) {
+ tevent_req_error(req, EEXIST);
+ return tevent_req_post(req, ev);
+ }
+ }
+
state->ev = ev;
state->sockd = sockd;
state->pid_watch = pid_watch;
int sock_daemon_run(struct tevent_context *ev,
struct sock_daemon_context *sockd,
+ const char *pidfile,
+ bool do_fork, bool create_session,
pid_t pid_watch)
{
struct tevent_req *req;
int ret;
bool status;
- req = sock_daemon_run_send(ev, ev, sockd, pid_watch);
+ req = sock_daemon_run_send(ev, ev, sockd,
+ pidfile, do_fork, create_session, pid_watch);
if (req == NULL) {
return ENOMEM;
}