From: Steve Dickson <SteveD@redhat.com>
To: nfs@lists.sourceforge.net
Subject: [PATCH] nfs-utils - 2 of 6 - statd - creates a pid file
Date: Wed, 18 Jun 2003 13:40:35 -0400 [thread overview]
Message-ID: <3EF0A413.3090602@RedHat.com> (raw)
[-- 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);
reply other threads:[~2003-06-18 17:39 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3EF0A413.3090602@RedHat.com \
--to=steved@redhat.com \
--cc=nfs@lists.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox