From: mornfall@sourceware.org <mornfall@sourceware.org>
To: lvm-devel@redhat.com
Subject: LVM2/daemons/common daemon-client.h daemon-ser ...
Date: 15 May 2011 11:02:32 -0000 [thread overview]
Message-ID: <20110515110232.22303.qmail@sourceware.org> (raw)
CVSROOT: /cvs/lvm2
Module name: LVM2
Changes by: mornfall at sourceware.org 2011-05-15 11:02:29
Modified files:
daemons/common : daemon-client.h daemon-server.c daemon-server.h
Log message:
More work on the common daemon framework. Make things compile, too.
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/daemons/common/daemon-client.h.diff?cvsroot=lvm2&r1=1.1&r2=1.2
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/daemons/common/daemon-server.c.diff?cvsroot=lvm2&r1=1.2&r2=1.3
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/daemons/common/daemon-server.h.diff?cvsroot=lvm2&r1=1.3&r2=1.4
--- LVM2/daemons/common/daemon-client.h 2011/05/13 08:07:28 1.1
+++ LVM2/daemons/common/daemon-client.h 2011/05/15 11:02:29 1.2
@@ -32,7 +32,7 @@
} daemon_request;
typedef struct {
- int errno; /* 0 for success */
+ int error; /* 0 for success */
char *reply; /* textual reply */
struct config_tree *cft; /* parsed reply, if available */
} daemon_reply;
@@ -51,7 +51,7 @@
* the daemon is synchronous. The function handles the IO details and parses the
* response, handling common error conditions. See "daemon_reply" for details.
*/
-daemon_reply daemon_request(daemon_handle h, daemon_request r);
+daemon_reply daemon_send(daemon_handle h, daemon_request r);
/* Shut down the communication to the daemon. Compulsory. */
void daemon_close(daemon_handle h);
--- LVM2/daemons/common/daemon-server.c 2011/05/13 09:34:12 1.2
+++ LVM2/daemons/common/daemon-server.c 2011/05/15 11:02:29 1.3
@@ -18,11 +18,16 @@
#include <sys/wait.h>
#include <sys/time.h>
#include <sys/resource.h>
+#include <netinet/in.h>
+#include <sys/un.h>
#include <unistd.h>
#include <signal.h>
#include <syslog.h>
+#include "daemon-server.h"
+#include "libdevmapper.h"
+#if 0
/* Create a device monitoring thread. */
static int _pthread_create(pthread_t *t, void *(*fun)(void *), void *arg, int stacksize)
{
@@ -34,6 +39,7 @@
pthread_attr_setstacksize(&attr, stacksize);
return pthread_create(t, &attr, fun, arg);
}
+#endif
static volatile sig_atomic_t _shutdown_requested = 0;
@@ -44,6 +50,7 @@
#ifdef linux
# define OOM_ADJ_FILE "/proc/self/oom_adj"
+# include <stdio.h>
/* From linux/oom.h */
# define OOM_DISABLE (-17)
@@ -72,7 +79,7 @@
}
fprintf(fp, "%i", val);
- if (dm_fclose(fp))
+ if (fclose(fp))
perror(OOM_ADJ_FILE ": fclose failed");
return 1;
@@ -91,13 +98,13 @@
/* Open local socket */
fd = socket(PF_UNIX, SOCK_STREAM, 0);
if (fd < 0) {
- log_error("Can't create local socket: %m");
+ perror("Can't create local socket.");
goto error;
}
/* Set Close-on-exec & non-blocking */
if (fcntl(fd, F_SETFD, 1))
- DEBUGLOG("setting CLOEXEC on socket fd %d failed: %s\n", fd, strerror(errno));
+ fprintf(stderr, "setting CLOEXEC on socket fd %d failed: %s\n", fd, strerror(errno));
fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK);
memset(&sockaddr, 0, sizeof(sockaddr));
@@ -105,11 +112,11 @@
sockaddr.sun_family = AF_UNIX;
if (bind(fd, (struct sockaddr *) &sockaddr, sizeof(sockaddr))) {
- log_error("can't bind local socket: %m");
+ perror("can't bind local socket.");
goto error;
}
if (listen(fd, 1) != 0) {
- log_error("listen local: %m");
+ perror("listen local");
goto error;
}
@@ -129,7 +136,7 @@
static void remove_lockfile(const char *file)
{
if (unlink(file))
- perror(file ": unlink failed");
+ perror("unlink failed");
}
static void _daemonise(void)
@@ -158,7 +165,7 @@
default:
/* Wait for response from child */
- while (!waitpid(pid, &child_status, WNOHANG) && !_exit_now) {
+ while (!waitpid(pid, &child_status, WNOHANG) && !_shutdown_requested) {
tval.tv_sec = 0;
tval.tv_usec = 250000; /* .25 sec */
select(0, NULL, NULL, NULL, &tval);
@@ -168,16 +175,7 @@
exit(0);
/* Problem with child. Determine what it is by exit code */
- switch (WEXITSTATUS(child_status)) {
- case EXIT_DESC_CLOSE_FAILURE:
- case EXIT_DESC_OPEN_FAILURE:
- case EXIT_FIFO_FAILURE:
- case EXIT_CHDIR_FAILURE:
- default:
- fprintf(stderr, "Child exited with code %d\n", WEXITSTATUS(child_status));
- break;
- }
-
+ fprintf(stderr, "Child exited with code %d\n", WEXITSTATUS(child_status));
exit(WEXITSTATUS(child_status));
}
@@ -200,7 +198,7 @@
setsid();
}
-void daemon_start(daemon_state s, handle_request r)
+void daemon_start(daemon_state s)
{
int failed = 0;
/*
--- LVM2/daemons/common/daemon-server.h 2011/05/13 09:34:12 1.3
+++ LVM2/daemons/common/daemon-server.h 2011/05/15 11:02:29 1.4
@@ -12,8 +12,10 @@
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#ifndef _LVM_DAEMON_COMMON_CLIENT_H
-#define _LVM_DAEMON_COMMON_CLIENT_H
+#include "daemon-client.h"
+
+#ifndef _LVM_DAEMON_COMMON_SERVER_H
+#define _LVM_DAEMON_COMMON_SERVER_H
typedef struct {
int socket_fd; /* the fd we use to talk to the client */
@@ -23,6 +25,26 @@
} client_handle;
typedef struct {
+ struct config_tree *cft;
+} request;
+
+typedef struct {
+ int error;
+ struct config_tree *cft;
+} response;
+
+struct daemon_state;
+
+/*
+ * The callback. Called once per request issued, in the respective client's
+ * thread. It is presented by a parsed request (in the form of a config tree).
+ * The output is a new config tree that is serialised and sent back to the
+ * client. The client blocks until the request processing is done and reply is
+ * sent.
+ */
+typedef response (*handle_request)(struct daemon_state s, client_handle h, request r);
+
+typedef struct daemon_state {
/*
* The maximal stack size for individual daemon threads. This is
* essential for daemons that need to be locked into memory, since
@@ -36,6 +58,9 @@
const char *name;
const char *pidfile;
const char *socket_path;
+ int log_level;
+ handle_request handler;
+ int (*setup_post)(struct daemon_state *st);
/* Global runtime info maintained by the framework. */
int socket_fd;
@@ -43,29 +68,12 @@
void *private; /* the global daemon state */
} daemon_state;
-typedef struct {
- struct config_tree *cft;
-} request;
-
-typedef struct {
- struct config_tree *cft;
-} response;
-
-/*
- * The callback. Called once per request issued, in the respective client's
- * thread. It is presented by a parsed request (in the form of a config tree).
- * The output is a new config tree that is serialised and sent back to the
- * client. The client blocks until the request processing is done and reply is
- * sent.
- */
-typedef response (*handle_request)(daemon_state s, client_handle h, request r);
-
/*
* Start serving the requests. This does all the daemonisation, socket setup
* work and so on. This function takes over the process, and upon failure, it
* will terminate execution. It may be called@most once.
*/
-void daemon_start(daemon_state s, handle_request r);
+void daemon_start(daemon_state s);
/*
* Take over from an already running daemon. This function handles connecting
next reply other threads:[~2011-05-15 11:02 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-15 11:02 mornfall [this message]
-- strict thread matches above, loose matches on Subject: below --
2011-07-18 14:46 LVM2/daemons/common daemon-client.h daemon-ser mornfall
2011-06-14 2:34 mornfall
2011-05-13 8:07 mornfall
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=20110515110232.22303.qmail@sourceware.org \
--to=mornfall@sourceware.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.