* [PATCH] nfs-utils - 2 of 6 - statd - creates a pid file
@ 2003-06-18 17:40 Steve Dickson
0 siblings, 0 replies; only message in thread
From: Steve Dickson @ 2003-06-18 17:40 UTC (permalink / raw)
To: nfs
[-- Attachment #1: Type: text/plain, Size: 161 bytes --]
This patch added code that will make
statd create a pid file (rpc.statd) in
/var/run. This was need to help our rc
script detect the status of stated.
SteveD.
[-- Attachment #2: nfs-utils-1.0.3-02-statd-pidfile.patch --]
[-- Type: text/plain, Size: 2310 bytes --]
--- ./utils/statd/statd.c.org 2003-06-02 15:17:17.000000000 -0400
+++ ./utils/statd/statd.c 2003-06-02 15:18:36.000000000 -0400
@@ -21,6 +21,9 @@
#include <grp.h>
#include <sys/types.h>
#include <fcntl.h>
+#include <errno.h>
+#include <netdb.h>
+#include <sys/wait.h>
#include "statd.h"
#include "version.h"
@@ -72,6 +75,51 @@ extern void simulator (int, char **);
#endif
/*
+ * Create a pid file
+ */
+static const char *piddir="/var/run/rpc.statd";
+static const char *pidfile="/var/run/rpc.statd/rpc.statd.pid";
+static void
+delete_pidfile(void)
+{
+ if (unlink(pidfile) < 0) {
+ log(L_WARNING,"Unlinking %s failed: errno %d (%s)\n", pidfile,
+ errno, strerror(errno));
+ }
+
+ return;
+}
+static void
+create_pidfile(void)
+{
+ FILE *fp;
+
+ if (access(pidfile, F_OK) == 0) {
+ die("rpc.statd is already running (check PID in %s)\n", pidfile);
+ }
+
+ /*
+ * A directory is need so the pid file can be remove
+ * once the privs have been dropped.
+ */
+ if (mkdir(piddir, 0755) < 0 && errno != EEXIST) {
+ die("Creating %s directory failed: errno %d (%s)\n", pidfile,
+ errno, strerror(errno));
+ }
+ if ((fp = fopen(pidfile, "w")) == NULL) {
+ die("Opening %s failed: errno %d (%s)\n", pidfile,
+ errno, strerror(errno));
+ }
+ fprintf(fp, "%d", getpid());
+ if (fclose(fp) < 0) {
+ log(L_WARNING,"Closing %s failed: errno %d (%s)\n", pidfile,
+ errno, strerror(errno));
+ }
+
+ return;
+}
+
+/*
* Privilege dropper
*/
static void
@@ -94,6 +142,10 @@ drop_privs(void)
die("Cannot start - cannot drop privs: getpwnam()\n");
}
+ if (chown(piddir, pw->pw_uid, pw->pw_gid) < 0) {
+ log(L_WARNING,"Owner change of '%s' to user '%s' failed: errno %d (%s)\n",
+ pidfile, pw->pw_name, errno, strerror(errno));
+ }
initgroups(pw->pw_name, pw->pw_gid);
setgid(pw->pw_gid);
@@ -343,6 +395,8 @@ int main (int argc, char **argv)
}
log_init (name_p, version_p);
+ create_pidfile();
+ atexit(delete_pidfile);
/* Child. */
signal (SIGHUP, killer);
@@ -364,7 +418,7 @@ int main (int argc, char **argv)
die("Startup failed: Please start rpc.statd as root\n");
/* Arm the ****** resolver before chroot() so it doesn't fail
- * trying to open /etc/ for the dozenth time
+ * trying to open /etc/host for the dozenth time
*/
sethostent(1);
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2003-06-18 17:39 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-06-18 17:40 [PATCH] nfs-utils - 2 of 6 - statd - creates a pid file Steve Dickson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox