From 2bcfdb01e2272e25d0d1ecc384ea431630f4faf5 Mon Sep 17 00:00:00 2001
From: g0dil <g0dil@wiback.org>
Date: Tue, 13 Nov 2007 16:41:12 +0000
Subject: [PATCH] Daemon class moved to Utils/Daemon into libUtils_Daemon
 library

---
 {Scheduler => Utils/Daemon}/Daemon.cc         |  4 +-
 {Scheduler => Utils/Daemon}/Daemon.hh         |  0
 {Scheduler => Utils/Daemon}/Daemon.ih         |  2 +-
 {Scheduler => Utils/Daemon}/Daemon.test.cc    |  0
 Utils/Daemon/Doxyfile                         |  5 +
 Utils/Daemon/SConscript                       | 17 ++++
 Utils/{DaemonTools.cc => Daemon/main.test.cc} | 44 +++------
 Utils/DaemonTools.hh                          | 92 -------------------
 8 files changed, 36 insertions(+), 128 deletions(-)
 rename {Scheduler => Utils/Daemon}/Daemon.cc (99%)
 rename {Scheduler => Utils/Daemon}/Daemon.hh (100%)
 rename {Scheduler => Utils/Daemon}/Daemon.ih (98%)
 rename {Scheduler => Utils/Daemon}/Daemon.test.cc (100%)
 create mode 100644 Utils/Daemon/Doxyfile
 create mode 100644 Utils/Daemon/SConscript
 rename Utils/{DaemonTools.cc => Daemon/main.test.cc} (52%)
 delete mode 100644 Utils/DaemonTools.hh

diff --git a/Scheduler/Daemon.cc b/Utils/Daemon/Daemon.cc
similarity index 99%
rename from Scheduler/Daemon.cc
rename to Utils/Daemon/Daemon.cc
index 378297441..34f476a1b 100644
--- a/Scheduler/Daemon.cc
+++ b/Utils/Daemon/Daemon.cc
@@ -38,8 +38,8 @@
 #include <algorithm>
 #include <boost/algorithm/string/predicate.hpp>
 #include <boost/algorithm/string/trim.hpp>
-#include "../Utils/Exception.hh"
-#include "../Utils/membind.hh"
+#include "../Exception.hh"
+#include "../membind.hh"
 
 //#include "Daemon.mpp"
 #define prefix_
diff --git a/Scheduler/Daemon.hh b/Utils/Daemon/Daemon.hh
similarity index 100%
rename from Scheduler/Daemon.hh
rename to Utils/Daemon/Daemon.hh
diff --git a/Scheduler/Daemon.ih b/Utils/Daemon/Daemon.ih
similarity index 98%
rename from Scheduler/Daemon.ih
rename to Utils/Daemon/Daemon.ih
index 5988bca99..ce8b7e3ab 100644
--- a/Scheduler/Daemon.ih
+++ b/Utils/Daemon/Daemon.ih
@@ -31,7 +31,7 @@
 #include <list>
 #include <boost/utility.hpp>
 #include <boost/function.hpp>
-#include "../Scheduler/Scheduler.hh"
+#include "../../Scheduler/Scheduler.hh"
 
 ///////////////////////////////ih.p////////////////////////////////////////
 
diff --git a/Scheduler/Daemon.test.cc b/Utils/Daemon/Daemon.test.cc
similarity index 100%
rename from Scheduler/Daemon.test.cc
rename to Utils/Daemon/Daemon.test.cc
diff --git a/Utils/Daemon/Doxyfile b/Utils/Daemon/Doxyfile
new file mode 100644
index 000000000..86ac1b942
--- /dev/null
+++ b/Utils/Daemon/Doxyfile
@@ -0,0 +1,5 @@
+@INCLUDE = "$(TOPDIR)/doclib/Doxyfile.global"
+
+PROJECT_NAME = libUtils_Daemon
+GENERATE_TAGFILE = doc/Daemon.tag
+ALPHABETICAL_INDEX = NO
diff --git a/Utils/Daemon/SConscript b/Utils/Daemon/SConscript
new file mode 100644
index 000000000..d7d458674
--- /dev/null
+++ b/Utils/Daemon/SConscript
@@ -0,0 +1,17 @@
+# -*- python -*-
+
+Import('env')
+import SENFSCons, glob
+
+###########################################################################
+
+SENFSCons.StandardTargets(env)
+
+sources = SENFSCons.GlobSources()
+
+SENFSCons.Lib( env,
+               library = 'Utils_Daemon',
+               sources = sources,
+               LIBS = [ 'Scheduler', 'Utils' ] )
+
+SENFSCons.Doxygen(env)
diff --git a/Utils/DaemonTools.cc b/Utils/Daemon/main.test.cc
similarity index 52%
rename from Utils/DaemonTools.cc
rename to Utils/Daemon/main.test.cc
index 1d33a6ea1..d3f3be2fd 100644
--- a/Utils/DaemonTools.cc
+++ b/Utils/Daemon/main.test.cc
@@ -1,6 +1,9 @@
-// $Id$
+// $Id: main.test.cc 369 2007-08-01 07:51:36Z tho $
 //
-// Copyright (C) 2006 Stefan Bund <g0dil@senf.berlios.de>
+// Copyright (C) 2006
+// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
+// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
+//     Stefan Bund <stefan.bund@fokus.fraunhofer.de>
 //
 // This program is free software; you can redistribute it and/or modify
 // it under the terms of the GNU General Public License as published by
@@ -17,47 +20,22 @@
 // Free Software Foundation, Inc.,
 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
-/** \file
-    \brief DaemonTools  non-inline non-template implementation */
+// Definition of non-inline non-template functions
 
-#include "DaemonTools.hh"
-//#include "DaemonTools.ih"
+//#include "test.hh"
+//#include "test.ih"
 
 // Custom includes
-#include <errno.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <fcntl.h>
-#include "Exception.hh"
+#define BOOST_AUTO_TEST_MAIN
+#include "../../Utils/auto_unit_test.hh"
+#include <boost/test/test_tools.hpp>
 
-//#include "DaemonTools.mpp"
 #define prefix_
 ///////////////////////////////cc.p////////////////////////////////////////
 
-prefix_ void senf::daemonize()
-{
-    int pid = fork();
-    if (pid < 0)
-        throw senf::SystemException("fork",errno);
-    if (pid > 0)
-        ::_exit(0);
-    if (::setsid() < 0)
-        throw senf::SystemException("setsid",errno);
-}
-
-prefix_ void senf::redirect_stdio(std::string const & path)
-{
-    int fd = ::open(path.c_str(),O_RDWR);
-    if (fd < 0) throw senf::SystemException("open",errno);
-    if (dup2(fd,0) < 0) throw senf::SystemException("dup2",errno);
-    if (dup2(fd,1) < 0) throw senf::SystemException("dup2",errno);
-    if (dup2(fd,2) < 0) throw senf::SystemException("dup2",errno);
-    if (::close(fd) < 0) throw senf::SystemException("close",errno);
-}
 
 ///////////////////////////////cc.e////////////////////////////////////////
 #undef prefix_
-//#include "DaemonTools.mpp"
 
 
 // Local Variables:
diff --git a/Utils/DaemonTools.hh b/Utils/DaemonTools.hh
deleted file mode 100644
index 466e5920d..000000000
--- a/Utils/DaemonTools.hh
+++ /dev/null
@@ -1,92 +0,0 @@
-// $Id$
-//
-// Copyright (C) 2006 Stefan Bund <g0dil@senf.berlios.de>
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the
-// Free Software Foundation, Inc.,
-// 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
-
-/** \file
-    \brief DaemonTools public header */
-
-/** \defgroup process Process Management
-
-    Future features:
-
-    \li Daemon manager watching the real daemon. Auto-restart, when the daemon fails
-
-    \li Provide access to the config console indirectly via the daemon manager. This allows to
-        connect to the daemon manager console even if the app is not running
-    
-    \li For this to be efficient, the daemon manager must be it's own executable (e.g. senf-launch)
-
-    \li auto-detect whether called from senf-launch or not
-
-    \li when daemon is running, the console is transparently forwarded to the daemon. The daemon
-        however can still access the daemon manager as a subgroup
-    
-    \li No idea, whether this is sensible: Make the daemon manager completely self-contained (not
-        dependent on any external OS support) by providing our own log-file rotation support.
-
-    This collection of utilities provides help in managing daemon processes.
-
-    \idea A closeall()/closemost() function which is useful when starting child processes. We'll use
-        getrlimit to now the biggest filehandle and close all of em. closemost() takes a number of
-        file handles as arg and will keep those open.
-
-    \idea We might want to add other oft used utitlities: chroot(), setreuid(), pipes() / IPC ...
- */
-
-#ifndef HH_DaemonTools_
-#define HH_DaemonTools_ 1
-
-// Custom includes
-#include <string>
-
-//#include "DaemonTools.mpp"
-///////////////////////////////hh.p////////////////////////////////////////
-
-namespace senf {
-
-    /// \addtogroup process
-    /// @{
-
-    void daemonize();                   ///< Make the current process a daemon process
-                                        /**< daemonize() will fork, detach from the controlling
-                                             terminal and start a new process group. */
-    void redirect_stdio(std::string const & path = "/dev/null"); ///< Redirect STDIN, STDOUT and STDERR
-                                        /**< All standard file-descriptors will be redirected to the
-                                             given path defaulting to <tt>/dev/null</tt>
-                                             \param[in] path path to redirect to */
-
-    /// @}
-}
-
-///////////////////////////////hh.e////////////////////////////////////////
-//#include "DaemonTools.cci"
-//#include "DaemonTools.ct"
-//#include "DaemonTools.cti"
-//#include "DaemonTools.mpp"
-#endif
-
-
-// Local Variables:
-// mode: c++
-// fill-column: 100
-// c-file-style: "senf"
-// indent-tabs-mode: nil
-// ispell-local-dictionary: "american"
-// compile-command: "scons -u test"
-// comment-column: 40
-// End:
-- 
GitLab