summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimo Sorce <simo@redhat.com>2013-03-22 09:05:06 -0400
committerSimo Sorce <simo@redhat.com>2013-03-22 11:34:42 -0400
commit1955a2d57d6d6ff3d4aa6dcdbc890d9c44417f7f (patch)
tree87a56d0ebb1e1e733a20528541fb8937ef31ccf3
parente9623f5f05053f215c71dbf37d034ae98f1f1c36 (diff)
downloadgss-proxy-1955a2d57d6d6ff3d4aa6dcdbc890d9c44417f7f.tar.gz
gss-proxy-1955a2d57d6d6ff3d4aa6dcdbc890d9c44417f7f.tar.xz
gss-proxy-1955a2d57d6d6ff3d4aa6dcdbc890d9c44417f7f.zip
Write pid file at startup.
-rw-r--r--proxy/conf_macros.m434
-rw-r--r--proxy/configure.ac2
-rw-r--r--proxy/src/gp_common.h1
-rw-r--r--proxy/src/gp_init.c33
-rw-r--r--proxy/src/gp_proxy.h1
-rw-r--r--proxy/src/gssproxy.c2
6 files changed, 55 insertions, 18 deletions
diff --git a/proxy/conf_macros.m4 b/proxy/conf_macros.m4
index 27b89ed..f2d3755 100644
--- a/proxy/conf_macros.m4
+++ b/proxy/conf_macros.m4
@@ -9,23 +9,6 @@ AC_DEFUN([WITH_DISTRO_VERSION],
[Distro version number])
])
-AC_DEFUN([WITH_PID_PATH],
- [ AC_ARG_WITH([pid-path],
- [AC_HELP_STRING([--with-pid-path=PATH],
- [Where to store pid files for gssproxy [/var/run]]
- )
- ]
- )
- config_pidpath="\"VARDIR\"/run"
- pidpath="${localstatedir}/run"
- if test x"$with_pid_path" != x; then
- config_pidpath=$with_pid_path
- pidpath=$with_pid_path
- fi
- AC_SUBST(pidpath)
- AC_DEFINE_UNQUOTED(PID_PATH, "$config_pidpath", [Where to store pid files for gssproxy])
- ])
-
AC_DEFUN([WITH_LOG_PATH],
[ AC_ARG_WITH([log-path],
[AC_HELP_STRING([--with-log-path=PATH],
@@ -77,6 +60,23 @@ AC_DEFUN([WITH_SOCKET_NAME],
AC_DEFINE_UNQUOTED(GP_SOCKET_NAME, "$gp_socket_name", [The name of the GSS Proxy socket file])
])
+AC_DEFUN([WITH_PID_FILE],
+ [ AC_ARG_WITH([pid-file],
+ [AC_HELP_STRING([--with-id-file=PATH],
+ [Name of the GSS Proxy pid file [/var/run/gssproxy.pid]]
+ )
+ ]
+ )
+ gp_pid_file="\"VARDIR\"/run/gssproxy.pid"
+ pidfile="${localstatedir}/run/gssproxy.pid"
+ if test x"$with_pid_file" != x; then
+ gp_pid_file=$with_pid_file
+ pidfile=$with_pid_file
+ fi
+ AC_SUBST(pidfile)
+ AC_DEFINE_UNQUOTED(GP_PID_FILE, "$gp_pid_file", [The name of the GSS Proxy pid file])
+ ])
+
AC_DEFUN([WITH_INITSCRIPT],
[ AC_ARG_WITH([initscript],
[AC_HELP_STRING([--with-initscript=INITSCRIPT_TYPE],
diff --git a/proxy/configure.ac b/proxy/configure.ac
index ec8a115..d108d69 100644
--- a/proxy/configure.ac
+++ b/proxy/configure.ac
@@ -55,11 +55,11 @@ m4_include([external/platform.m4])
m4_include(conf_macros.m4)
WITH_DISTRO_VERSION
-WITH_PID_PATH
WITH_CC_PATH
WITH_LOG_PATH
WITH_PUBCONF_PATH
WITH_SOCKET_NAME
+WITH_PID_FILE
WITH_INIT_DIR
WITH_TEST_DIR
WITH_MANPAGES
diff --git a/proxy/src/gp_common.h b/proxy/src/gp_common.h
index 0de698c..ad68e55 100644
--- a/proxy/src/gp_common.h
+++ b/proxy/src/gp_common.h
@@ -26,6 +26,7 @@
#ifndef _GP_COMMON_H_
#define _GP_COMMON_H_
+#include "config.h"
#include "gp_debug.h"
#include "gp_log.h"
diff --git a/proxy/src/gp_init.c b/proxy/src/gp_init.c
index 8d0ebd8..c364edc 100644
--- a/proxy/src/gp_init.c
+++ b/proxy/src/gp_init.c
@@ -31,6 +31,8 @@
#include <fcntl.h>
#include <errno.h>
#include <string.h>
+#include <unistd.h>
+#include <stdio.h>
#include "gp_proxy.h"
void init_server(bool daemonize)
@@ -176,3 +178,34 @@ void init_proc_nfsd(struct gp_config *cfg)
return;
}
}
+
+void write_pid(void)
+{
+ pid_t pid;
+ FILE *f;
+ int ret;
+
+ pid = getpid();
+
+ f = fopen(GP_PID_FILE, "w");
+ if (!f) {
+ ret = errno;
+ GPDEBUG("Failed to open %s: %d (%s)\n",
+ GP_PID_FILE, ret, strerror(ret));
+ return;
+ }
+
+ ret = fprintf(f, "%d\n", pid);
+ if (ret < 0) {
+ GPDEBUG("Failed to write pid to %s\n", GP_PID_FILE);
+ fclose(f);
+ return;
+ }
+
+ ret = fclose(f);
+ if (ret != 0) {
+ GPDEBUG("Failed to close %s: %d (%s)\n"
+ GP_PID_FILE, ret, strerror(ret));
+ return;
+ }
+}
diff --git a/proxy/src/gp_proxy.h b/proxy/src/gp_proxy.h
index beddf61..25f8a43 100644
--- a/proxy/src/gp_proxy.h
+++ b/proxy/src/gp_proxy.h
@@ -88,6 +88,7 @@ void init_server(bool daemonize);
void fini_server(void);
verto_ctx *init_event_loop(void);
void init_proc_nfsd(struct gp_config *cfg);
+void write_pid(void);
/* from gp_socket.c */
int init_unix_socket(const char *file_name);
diff --git a/proxy/src/gssproxy.c b/proxy/src/gssproxy.c
index f1f0d13..4dd0094 100644
--- a/proxy/src/gssproxy.c
+++ b/proxy/src/gssproxy.c
@@ -106,6 +106,8 @@ int main(int argc, const char *argv[])
/* special call to tell the Linux kernel gss-proxy is available */
init_proc_nfsd(gpctx->config);
+ write_pid();
+
vctx = init_event_loop();
if (!vctx) {
return 1;