initial checkin
authorEnrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
Tue, 21 Oct 2003 13:26:21 +0000 (13:26 +0000)
committerEnrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
Tue, 21 Oct 2003 13:26:21 +0000 (13:26 +0000)
git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@259 94cd875c-1c1d-0410-91d2-eb244daf1a30

util-vserver/m4/ensc_cxxcompiler.m4 [new file with mode: 0644]
util-vserver/m4/ensc_fpicsyscall.m4 [new file with mode: 0644]
util-vserver/src/vserver.cc [new file with mode: 0644]
util-vserver/src/vserver.hh [new file with mode: 0644]

diff --git a/util-vserver/m4/ensc_cxxcompiler.m4 b/util-vserver/m4/ensc_cxxcompiler.m4
new file mode 100644 (file)
index 0000000..cf493bc
--- /dev/null
@@ -0,0 +1,35 @@
+dnl $Id$
+
+dnl Copyright (C) 2002 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+dnl  
+dnl This program is free software; you can redistribute it and/or modify
+dnl it under the terms of the GNU General Public License as published by
+dnl the Free Software Foundation; version 2 of the License.
+dnl  
+dnl This program is distributed in the hope that it will be useful,
+dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
+dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+dnl GNU General Public License for more details.
+dnl  
+dnl You should have received a copy of the GNU General Public License
+dnl along with this program; if not, write to the Free Software
+dnl Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+AC_DEFUN([ENSC_CXXCOMPILER],
+[
+       AC_REQUIRE([AC_PROG_CXX])
+
+       AC_CACHE_CHECK([whether $CXX is a C++ compiler], [ensc_cv_cxx_cxxcompiler],
+        [
+               AC_LANG_PUSH(C++)
+               AC_COMPILE_IFELSE([
+                   #include <ostream>
+                ],
+                [ensc_cv_cxx_cxxcompiler=yes],
+                [ensc_cv_cxx_cxxcompiler=no])
+               AC_LANG_POP(C++)
+        ])
+
+       AM_CONDITIONAL(ENSC_HAVE_CXX_COMPILER,
+                       [test x"$ensc_cv_cxx_cxxcompiler" = xyes])
+])
diff --git a/util-vserver/m4/ensc_fpicsyscall.m4 b/util-vserver/m4/ensc_fpicsyscall.m4
new file mode 100644 (file)
index 0000000..7f3839e
--- /dev/null
@@ -0,0 +1,41 @@
+dnl $Id$
+
+dnl Copyright (C) 2002 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+dnl  
+dnl This program is free software; you can redistribute it and/or modify
+dnl it under the terms of the GNU General Public License as published by
+dnl the Free Software Foundation; version 2 of the License.
+dnl  
+dnl This program is distributed in the hope that it will be useful,
+dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
+dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+dnl GNU General Public License for more details.
+dnl  
+dnl You should have received a copy of the GNU General Public License
+dnl along with this program; if not, write to the Free Software
+dnl Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+AC_DEFUN([ENSC_FPIC_SYSCALL],
+[
+    AC_CACHE_CHECK([whether syscall() allows -fpic], [ensc_cv_c_fpic_syscall],
+    [
+        old_CFLAGS=$CFLAGS
+        CFLAGS="-fPIC -DPIC"
+
+       AC_LANG_PUSH(C)
+        AC_COMPILE_IFELSE([
+            #include <sys/syscall.h>
+            #include <unistd.h>
+            #include <asm/unistd.h>
+            #include <errno.h>
+            
+            #define __NR_dummy 42
+            _syscall3(int, dummy, int, a, int, b, int, c)],
+        [ensc_cv_c_fpic_syscall=yes], [ensc_cv_c_fpic_syscall=no])
+       AC_LANG_PUSH(C)
+
+        CFLAGS=$old_CFLAGS
+    ])
+    
+    AM_CONDITIONAL(ENSC_ALLOW_FPIC_WITH_SYSCALL, [test x"$ensc_cv_c_fpic_syscall" = xyes])
+])
diff --git a/util-vserver/src/vserver.cc b/util-vserver/src/vserver.cc
new file mode 100644 (file)
index 0000000..920ff9c
--- /dev/null
@@ -0,0 +1,75 @@
+// $Id$    --*- c++ -*--
+
+// Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.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; version 2 of the License.
+//  
+// 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.
+
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include "vserver.hh"
+#include "pathconfig.h"
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <fstream>
+#include <iostream>
+
+static bool
+dirExists(std::string const &path)
+{
+  struct stat  st;
+  return (stat(path.c_str(), &st)!=-1 &&
+         S_ISDIR(st.st_mode));
+}
+
+Vserver::Vserver(std::string const &str) :
+  conf_dir_(str), vdir_(str), name_(str)
+{
+  vdir_       += "/.vdir";
+  
+  if (!dirExists(vdir_)) {
+    conf_dir_  = CONFDIR;
+    conf_dir_ += str;
+  }
+
+  rpmdb_path_  = conf_dir_;
+  rpmdb_path_ += "/apps/pkgmgmt/rpmstate";
+
+  if (!dirExists(rpmdb_path_)) {
+    rpmdb_path_  = conf_dir_;
+    rpmdb_path_ += "/apps/pkgmgmt/base/rpm/state";
+  }
+
+  if (!dirExists(rpmdb_path_)) {
+    rpmdb_path_  = vdir_;
+    rpmdb_path_ += "/var/lib/rpm";
+  }
+
+  std::string  tmp = conf_dir_;
+  tmp  += ".name";
+
+  std::ifstream                name_file(tmp.c_str());
+
+  if (name_file.good()) getline(name_file, name_);
+}
+
+std::ostream &
+operator << (std::ostream &lhs, Vserver const &rhs)
+{
+  return lhs << rhs.getName();
+}
diff --git a/util-vserver/src/vserver.hh b/util-vserver/src/vserver.hh
new file mode 100644 (file)
index 0000000..3e8e8a1
--- /dev/null
@@ -0,0 +1,45 @@
+// $Id$    --*- c++ -*--
+
+// Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.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; version 2 of the License.
+//  
+// 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.
+
+
+#ifndef HH_UTIL_VSERVER_SRC_VSERVSER_HH
+#define HH_UTIL_VSERVER_SRC_VSERVSER_HH
+
+#include <string>
+#include <ostream>
+
+class Vserver
+{
+  public:
+    Vserver(std::string const &name);
+
+    std::string const &                getConfDir() const   { return conf_dir_; }
+    std::string const &                getVdir() const      { return vdir_; }
+    std::string const &                getRPMDbPath() const { return rpmdb_path_; }
+    std::string const &                getName() const      { return name_; }
+
+  private:
+    std::string                conf_dir_;
+    std::string                vdir_;
+    std::string                rpmdb_path_;
+    std::string                name_;
+};
+
+std::ostream & operator << (std::ostream &lhs, Vserver const &rhs);
+
+
+#endif //  HH_UTIL_VSERVER_SRC_VSERVSER_HH