All of lore.kernel.org
 help / color / mirror / Atom feed
From: Petr Rockai <mornfall@fedoraproject.org>
To: lvm-devel@redhat.com
Subject: dev-mornfall-lvmcache - libdaemon: Print a diagnostic when we fail to lock the pidfile.
Date: Wed,  5 Jun 2013 12:01:02 +0000 (UTC)	[thread overview]
Message-ID: <20130605120102.592F26140D@fedorahosted.org> (raw)

Gitweb:        http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=dce8d06af7e5a14a1507bea0e64e6cc27556cbc7
Commit:        dce8d06af7e5a14a1507bea0e64e6cc27556cbc7
Parent:        9495a3d807b890f7a639e5761b2b37ba495b5d9b
Author:        Petr Rockai <prockai@redhat.com>
AuthorDate:    Mon Apr 15 09:43:30 2013 +0200
Committer:     Petr Rockai <prockai@redhat.com>
CommitterDate: Mon Apr 15 16:07:07 2013 +0200

libdaemon: Print a diagnostic when we fail to lock the pidfile.

---
 libdaemon/server/daemon-server.c |   18 +++++++++++++-----
 1 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/libdaemon/server/daemon-server.c b/libdaemon/server/daemon-server.c
index 735a0ea..1db7ca7 100644
--- a/libdaemon/server/daemon-server.c
+++ b/libdaemon/server/daemon-server.c
@@ -52,6 +52,8 @@ static void _exit_handler(int sig __attribute__((unused)))
 	_shutdown_requested = 1;
 }
 
+#define EXIT_ALREADYRUNNING 13
+
 #ifdef linux
 
 #include <stddef.h>
@@ -261,7 +263,7 @@ static void remove_lockfile(const char *file)
 		perror("unlink failed");
 }
 
-static void _daemonise(void)
+static void _daemonise(daemon_state s)
 {
 	int child_status;
 	int fd;
@@ -296,8 +298,14 @@ static void _daemonise(void)
 		if (_shutdown_requested) /* Child has signaled it is ok - we can exit now */
 			exit(0);
 
-		/* Problem with child.  Determine what it is by exit code */
-		fprintf(stderr, "Child exited with code %d\n", WEXITSTATUS(child_status));
+		switch (WEXITSTATUS(child_status)) {
+		case EXIT_ALREADYRUNNING:
+			fprintf(stderr, "Failed to acquire lock on %s. Already running?\n", s.pidfile);
+			break;
+		default:
+			/* Problem with child.  Determine what it is by exit code */
+			fprintf(stderr, "Child exited with code %d\n", WEXITSTATUS(child_status));
+		}
 		exit(WEXITSTATUS(child_status));
 	}
 
@@ -464,7 +472,7 @@ void daemon_start(daemon_state s)
 #endif
 
 	if (!s.foreground)
-		_daemonise();
+		_daemonise(s);
 
 	s.log = &_log;
 	s.log->name = s.name;
@@ -481,7 +489,7 @@ void daemon_start(daemon_state s)
 		 * after this point.
 		 */
 		if (dm_create_lockfile(s.pidfile) == 0)
-			exit(1);
+			exit(EXIT_ALREADYRUNNING);
 
 		(void) dm_prepare_selinux_context(NULL, 0);
 	}



                 reply	other threads:[~2013-06-05 12:01 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=20130605120102.592F26140D@fedorahosted.org \
    --to=mornfall@fedoraproject.org \
    --cc=lvm-devel@redhat.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.