From b899bfc9ba231fa6f2465f19f167377588c7efd7 Mon Sep 17 00:00:00 2001 From: Rafal Wojtczuk Date: Fri, 4 Mar 2011 17:38:59 +0100 Subject: [PATCH] Daemonize qrexec_daemon. --- qrexec/qrexec_daemon.c | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/qrexec/qrexec_daemon.c b/qrexec/qrexec_daemon.c index ef6ec05f..508b164c 100644 --- a/qrexec/qrexec_daemon.c +++ b/qrexec/qrexec_daemon.c @@ -25,6 +25,8 @@ #include #include #include +#include +#include #include "qrexec.h" #include "buffer.h" #include "glue.h" @@ -49,10 +51,37 @@ int server_fd; void init(int xid) { + char dbg_log[256]; + int logfd; + if (xid <= 0) { fprintf(stderr, "domain id=0?\n"); exit(1); } + switch (fork()) { + case -1: + perror("fork"); + exit(1); + case 0: + break; + default: + exit(0); + } + close(0); + snprintf(dbg_log, sizeof(dbg_log), + "/var/log/qubes/qrexec.%d.log", xid); + umask(0007); + logfd = open(dbg_log, O_WRONLY | O_CREAT | O_TRUNC, 0640); + umask(0077); + dup2(logfd, 1); + dup2(logfd, 2); + + chdir("/var/run/qubes"); + if (setsid() < 0) { + perror("setsid()"); + exit(1); + } + server_fd = get_server_socket(xid); peer_client_init(xid, REXEC_PORT); setuid(getuid()); @@ -209,8 +238,8 @@ void handle_agent_data() struct server_header s_hdr; read_all_vchan_ext(&s_hdr, sizeof s_hdr); -// fprintf(stderr, "got %x %x %x\n", s_hdr.type, s_hdr.clid, -// s_hdr.len); +// fprintf(stderr, "got %x %x %x\n", s_hdr.type, s_hdr.clid, +// s_hdr.len); if (s_hdr.clid >= MAX_FDS || s_hdr.clid < 0) { fprintf(stderr, "from agent: clid=%d\n", s_hdr.clid);