[Openvas-commits] r5664 - in trunk/openvas-libraries: . base
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Wed Oct 21 20:54:09 CEST 2009
Author: jan
Date: 2009-10-21 20:54:08 +0200 (Wed, 21 Oct 2009)
New Revision: 5664
Added:
trunk/openvas-libraries/base/pidfile.c
trunk/openvas-libraries/base/pidfile.h
Modified:
trunk/openvas-libraries/ChangeLog
trunk/openvas-libraries/MANIFEST
trunk/openvas-libraries/Makefile
trunk/openvas-libraries/base/CMakeLists.txt
Log:
* base/pidfile.c, base/pidfile.h: New.
* base/CMakeLists.txt: Added handling for pidfile.c.
* Makefile: Install pidfile.h.
* MANIFEST: Updated.
Modified: trunk/openvas-libraries/ChangeLog
===================================================================
--- trunk/openvas-libraries/ChangeLog 2009-10-21 18:53:03 UTC (rev 5663)
+++ trunk/openvas-libraries/ChangeLog 2009-10-21 18:54:08 UTC (rev 5664)
@@ -1,3 +1,13 @@
+2009-10-21 Jan-Oliver Wagner <jan-oliver.wagner at greenbone.net>
+
+ * base/pidfile.c, base/pidfile.h: New.
+
+ * base/CMakeLists.txt: Added handling for pidfile.c.
+
+ * Makefile: Install pidfile.h.
+
+ * MANIFEST: Updated.
+
2009-10-20 Jan-Oliver Wagner <jan-oliver.wagner at greenbone.net>
* misc/otp.h: Changed author and copyright because
Modified: trunk/openvas-libraries/MANIFEST
===================================================================
--- trunk/openvas-libraries/MANIFEST 2009-10-21 18:53:03 UTC (rev 5663)
+++ trunk/openvas-libraries/MANIFEST 2009-10-21 18:54:08 UTC (rev 5664)
@@ -13,6 +13,8 @@
base/openvas_certificate_file.h
base/openvas_string.c
base/openvas_string.h
+base/pidfile.c
+base/pidfile.h
base/README.txt
base/severity_filter.c
base/severity_filter.h
Modified: trunk/openvas-libraries/Makefile
===================================================================
--- trunk/openvas-libraries/Makefile 2009-10-21 18:53:03 UTC (rev 5663)
+++ trunk/openvas-libraries/Makefile 2009-10-21 18:54:08 UTC (rev 5664)
@@ -84,6 +84,7 @@
$(INSTALL) -m 0444 base/nvti.h $(DESTDIR)${includedir}/openvas/base
$(INSTALL) -m 0444 base/openvas_certificate_file.h $(DESTDIR)${includedir}/openvas/base
$(INSTALL) -m 0444 base/openvas_string.h $(DESTDIR)${includedir}/openvas/base
+ $(INSTALL) -m 0444 base/pidfile.h $(DESTDIR)${includedir}/openvas/base
$(INSTALL) -m 0444 base/severity_filter.h $(DESTDIR)${includedir}/openvas/base
$(INSTALL) -m 0444 omp/omp.h $(DESTDIR)${includedir}/openvas/omp
$(INSTALL) -m 0444 omp/xml.h $(DESTDIR)${includedir}/openvas/omp
Modified: trunk/openvas-libraries/base/CMakeLists.txt
===================================================================
--- trunk/openvas-libraries/base/CMakeLists.txt 2009-10-21 18:53:03 UTC (rev 5663)
+++ trunk/openvas-libraries/base/CMakeLists.txt 2009-10-21 18:54:08 UTC (rev 5664)
@@ -133,7 +133,7 @@
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
set (FILES certificate.c hash_table_util.c nvti.c nvticache.c
-openvas_certificate_file.c openvas_string.c severity_filter.c)
+openvas_certificate_file.c openvas_string.c pidfile.c severity_filter.c)
add_library (openvas_base_static STATIC ${FILES})
set_target_properties (openvas_base_static PROPERTIES COMPILE_FLAGS "${GLIB_CFLAGS}")
@@ -147,6 +147,10 @@
set_target_properties (openvas_base_shared PROPERTIES SOVERSION "${CPACK_PACKAGE_VERSION_MAJOR}")
set_target_properties (openvas_base_shared PROPERTIES VERSION "${CPACK_PACKAGE_VERSION}")
+if (OPENVAS_PID_DIR)
+ add_definitions (-DOPENVAS_PID_DIR=\\\"${OPENVAS_PID_DIR}\\\")
+endif (OPENVAS_PID_DIR)
+
## Install
install (TARGETS openvas_base_static openvas_base_shared
Added: trunk/openvas-libraries/base/pidfile.c
===================================================================
--- trunk/openvas-libraries/base/pidfile.c 2009-10-21 18:53:03 UTC (rev 5663)
+++ trunk/openvas-libraries/base/pidfile.c 2009-10-21 18:54:08 UTC (rev 5664)
@@ -0,0 +1,95 @@
+/* openvas-libraries/base
+ * $Id$
+ * Description: PID-file management.
+ *
+ * Authors:
+ * Jan-Oliver Wagner <jan-oliver.wagner at greenbone.net>
+ *
+ * Copyright:
+ * Copyright (C) 2009 Greenbone Networks GmbH
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2,
+ * or, at your option, any later version as published by the Free
+ * Software Foundation
+ *
+ * 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+/**
+ * @file pidfile.c
+ * @brief PID-file management.
+ */
+
+#include <glib.h>
+#include <glib/gstdio.h> /* for g_fopen */
+
+#include <stdio.h> /* for FILE */
+#include <string.h> /* for strerror */
+#include <errno.h> /* for errno */
+#include <unistd.h> /* for getpid */
+
+/**
+ * @brief GLib log domain.
+ */
+#undef G_LOG_DOMAIN
+#define G_LOG_DOMAIN "base pidfile"
+
+/**
+ * @brief Create a PID-file.
+ *
+ * A standard PID file will be created for the
+ * given daemon name.
+ *
+ * @param[in] daemon_name The name of the daemon (e.g. "openvasmd")
+ *
+ * @return 0 for success, anything else indicates an error.
+ */
+int
+pidfile_create (gchar * daemon_name)
+{
+ gchar *name_pid = g_strconcat (daemon_name, ".pid", NULL);
+ gchar *pidfile_name = g_build_filename (OPENVAS_PID_DIR, name_pid);
+ FILE *pidfile = g_fopen (pidfile_name, "w");
+
+ g_free(name_pid);
+
+ if (pidfile == NULL)
+ {
+ g_critical ("%s: failed to open pidfile: %s\n",
+ __FUNCTION__,
+ strerror (errno));
+ return 1;
+ }
+ else
+ {
+ g_fprintf (pidfile, "%d\n", getpid());
+ fclose (pidfile);
+ g_free (pidfile_name);
+ }
+ return 0;
+}
+
+/**
+ * @brief Remove PID file.
+ *
+ * @param[in] daemon_name The name of the daemon (e.g. "openvasmd")
+ */
+void
+pidfile_remove (gchar * daemon_name)
+{
+ gchar *name_pid = g_strconcat (daemon_name, ".pid", NULL);
+ gchar *pidfile_name = g_build_filename (OPENVAS_PID_DIR, name_pid);
+
+ g_free(name_pid);
+
+ g_unlink (pidfile_name);
+ g_free (pidfile_name);
+}
Added: trunk/openvas-libraries/base/pidfile.h
===================================================================
--- trunk/openvas-libraries/base/pidfile.h 2009-10-21 18:53:03 UTC (rev 5663)
+++ trunk/openvas-libraries/base/pidfile.h 2009-10-21 18:54:08 UTC (rev 5664)
@@ -0,0 +1,34 @@
+/* openvas-libraries/base
+ * $Id$
+ * Description: PID-file management.
+ *
+ * Authors:
+ * Jan-Oliver Wagner <jan-oliver.wagner at greenbone.net>
+ *
+ * Copyright:
+ * Copyright (C) 2009 Greenbone Networks GmbH
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2,
+ * or, at your option, any later version as published by the Free
+ * Software Foundation
+ *
+ * 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef _OPENVAS_LIBRARIES_BASE_PIDFILE_H
+#define _OPENVAS_LIBRARIES_BASE_PIDFILE_H
+
+#include <glib.h>
+
+int pidfile_create (gchar *);
+void pidfile_remove (gchar *);
+
+#endif /* not _OPENVAS_LIBRARIES_BASE_PIDFILE_H */
More information about the Openvas-commits
mailing list