log_init(debug);
+ if (!debug) {
+ int pid;
+ char *spid;
+ if (daemon(0, 0) != 0)
+ fatal("failed to detach daemon");
+ if ((pid = open(LLDPD_PID_FILE,
+ O_TRUNC | O_CREAT | O_WRONLY)) == -1)
+ fatal("unable to open pid file " LLDPD_PID_FILE);
+ if (asprintf(&spid, "%d\n", getpid()) == -1)
+ fatal("unable to create pid file " LLDPD_PID_FILE);
+ if (write(pid, spid, strlen(spid)) == -1)
+ fatal("unable to write pid file " LLDPD_PID_FILE);
+ free(spid);
+ close(pid);
+ }
+
priv_init(PRIVSEP_CHROOT);
if (probe == 0) probe = LLDPD_TTL;
TAILQ_INIT(&cfg->g_clients);
gcfg = cfg;
- if (!debug) {
- priv_fork();
- }
if (atexit(lldpd_exit) != 0) {
close(cfg->g_ctl);
priv_ctl_cleanup();
enum {
PRIV_PING,
- PRIV_FORK,
PRIV_CREATE_CTL_SOCKET,
PRIV_DELETE_CTL_SOCKET,
PRIV_GET_HOSTNAME,
LLOG_DEBUG("monitor ready");
}
-/* Proxy for fork */
-void
-priv_fork()
-{
- int cmd, rc;
- cmd = PRIV_FORK;
- must_write(remote, &cmd, sizeof(int));
- must_read(remote, &rc, sizeof(int));
-}
-
/* Proxy for ctl_create, no argument since this is the monitor that decides the
* location of the socket */
int
must_write(remote, &rc, sizeof(int));
}
-void
-asroot_fork()
-{
- int pid;
- char *spid;
- if (daemon(0, 0) != 0)
- fatal("[priv]: failed to detach daemon");
- if ((pid = open(LLDPD_PID_FILE,
- O_TRUNC | O_CREAT | O_WRONLY)) == -1)
- fatal("[priv]: unable to open pid file " LLDPD_PID_FILE);
- if (asprintf(&spid, "%d\n", getpid()) == -1)
- fatal("[priv]: unable to create pid file " LLDPD_PID_FILE);
- if (write(pid, spid, strlen(spid)) == -1)
- fatal("[priv]: unable to write pid file " LLDPD_PID_FILE);
- free(spid);
- close(pid);
-
- /* Ack */
- must_write(remote, &pid, sizeof(int));
-}
-
void
asroot_ctl_create()
{
struct dispatch_actions actions[] = {
{PRIV_PING, asroot_ping},
- {PRIV_FORK, asroot_fork},
{PRIV_CREATE_CTL_SOCKET, asroot_ctl_create},
{PRIV_DELETE_CTL_SOCKET, asroot_ctl_cleanup},
{PRIV_GET_HOSTNAME, asroot_gethostbyname},