src/Makefile | 15 ++++++++++----
src/client_admin.c | 1
src/client_msg.c | 52 +-------------------------------------------------
src/client_msg.h | 34 --------------------------------
src/client_resource.c | 1
src/host_id.c | 3 +-
src/main.c | 32 +++++++++++++++++++++++++++---
src/sanlock_sock.c | 20 +++++++++++++++++++
src/sanlock_sock.h | 46 ++++++++++++++++++++++++++++++++++++++++++++
wdmd/Makefile | 26 +++++++++++++++----------
wdmd/client.c | 35 +--------------------------------
wdmd/main.c | 5 +---
wdmd/wdmd_sock.c | 21 ++++++++++++++++++++
wdmd/wdmd_sock.h | 6 +++++
14 files changed, 159 insertions(+), 138 deletions(-)
New commits:
commit 5f218b4aad41c330f5d33ce59cceab445b72b59e
Author: David Teigland <teigland(a)redhat.com>
Date: Wed Aug 3 11:42:20 2011 -0500
sanlock: new build flags
and move some code around to get it to work
diff --git a/src/Makefile b/src/Makefile
index 66d5fcd..3aadb5d 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -25,7 +25,8 @@ CMD_SOURCE = \
paxos_lease.c \
task.c \
token_manager.c \
- watchdog.c
+ watchdog.c \
+ sanlock_sock.c
LIB_SOURCE = \
client_msg.c \
@@ -37,7 +38,8 @@ LIB_SOURCE = \
paxos_lease.c \
direct.c \
task.c \
- direct_lib.c
+ direct_lib.c \
+ sanlock_sock.c
CFLAGS += -D_GNU_SOURCE -g \
-Wall \
@@ -58,10 +60,15 @@ CFLAGS += -D_GNU_SOURCE -g \
-fexceptions \
-fasynchronous-unwind-tables \
-fdiagnostics-show-option
+# -fPIE -DPIE
-CMD_LDFLAGS = -lpthread -luuid -lrt -laio -lblkid -lsanlock -L../wdmd -lwdmd
-LIB_LDFLAGS = -lpthread -lrt -laio -lblkid -L../wdmd -lwdmd
+CMD_LDFLAGS += -lpthread -luuid -lrt -laio -lblkid -lsanlock -L../wdmd -lwdmd
+CMD_LDFLAGS += -Wl,-z,now -Wl,-z,relro
+#CMD_LDFLAGS += -Wl,-z,now -Wl,-z,relro -pie
+LIB_LDFLAGS += -lpthread -lrt -laio -lblkid -L../wdmd -lwdmd
+LIB_LDFLAGS += -Wl,-z,relro
+#LIB_LDFLAGS += -Wl,-z,relro -pie
all: $(SHLIB_TARGET) $(CMD_TARGET)
diff --git a/src/client_admin.c b/src/client_admin.c
index fc3fa4a..94645ec 100644
--- a/src/client_admin.c
+++ b/src/client_admin.c
@@ -28,6 +28,7 @@
#include <sys/un.h>
#include "sanlock_internal.h"
+#include "sanlock_sock.h"
#include "log.h"
#include "client_msg.h"
#include "sanlock_admin.h"
diff --git a/src/client_msg.c b/src/client_msg.c
index 28c0374..21b18db 100644
--- a/src/client_msg.c
+++ b/src/client_msg.c
@@ -28,57 +28,9 @@
#include <sys/un.h>
#include "sanlock_internal.h"
-#include "log.h"
+#include "sanlock_sock.h"
#include "client_msg.h"
-static int get_socket_address(struct sockaddr_un *addr)
-{
- memset(addr, 0, sizeof(struct sockaddr_un));
- addr->sun_family = AF_LOCAL;
- snprintf(addr->sun_path, sizeof(addr->sun_path) - 1, "%s/%s",
- SANLK_RUN_DIR, SANLK_SOCKET_NAME);
- return 0;
-}
-
-int setup_listener_socket(int *listener_socket,
- uid_t owner, gid_t group, mode_t mode)
-{
- int rv, s;
- struct sockaddr_un addr;
-
- s = socket(AF_LOCAL, SOCK_STREAM, 0);
- if (s < 0)
- return -1;
-
- rv = get_socket_address(&addr);
- if (rv < 0)
- return rv;
-
- unlink(addr.sun_path);
- rv = bind(s, (struct sockaddr *) &addr, sizeof(struct sockaddr_un));
- if (rv < 0)
- goto exit_fail;
-
- rv = chmod(addr.sun_path, mode);
- if (rv < 0)
- goto exit_fail;
-
- rv = chown(addr.sun_path, owner, group);
- if (rv < 0)
- goto exit_fail;
-
- rv = listen(s, 5);
- if (rv < 0)
- goto exit_fail;
-
- *listener_socket = s;
- return 0;
-
- exit_fail:
- close(s);
- return -1;
-}
-
int connect_socket(int *sock_fd)
{
int rv, s;
@@ -88,7 +40,7 @@ int connect_socket(int *sock_fd)
if (s < 0)
return -1;
- rv = get_socket_address(&addr);
+ rv = sanlock_socket_address(&addr);
if (rv < 0)
return rv;
diff --git a/src/client_msg.h b/src/client_msg.h
index dcb943a..b7ab2d5 100644
--- a/src/client_msg.h
+++ b/src/client_msg.h
@@ -9,40 +9,6 @@
#ifndef __CLIENT_MSG_H__
#define __CLIENT_MSG_H__
-#define MAX_CLIENT_MSG (1024 * 1024) /* TODO: this is random */
-
-enum {
- SM_CMD_REGISTER = 1,
- SM_CMD_ADD_LOCKSPACE = 2,
- SM_CMD_REM_LOCKSPACE = 3,
- SM_CMD_SHUTDOWN = 4,
- SM_CMD_STATUS = 5,
- SM_CMD_LOG_DUMP = 6,
- SM_CMD_ACQUIRE = 7,
- SM_CMD_RELEASE = 8,
- SM_CMD_INQUIRE = 9,
- SM_CMD_RESTRICT = 10,
-};
-
-#define SANLK_STATE_MAXSTR 4096
-
-#define SANLK_STATE_DAEMON 1
-#define SANLK_STATE_LOCKSPACE 2
-#define SANLK_STATE_CLIENT 3
-#define SANLK_STATE_RESOURCE 4
-
-struct sanlk_state {
- uint32_t type; /* SANLK_STATE_ */
- uint32_t flags;
- uint32_t data32; /* pid (for client) */
- uint64_t data64;
- char name[SANLK_NAME_LEN]; /* client name or resource name */
- uint32_t str_len;
- char str[0]; /* string of internal state */
-};
-
-int setup_listener_socket(int *listener_socket,
- uid_t owner, gid_t group, mode_t mode);
int connect_socket(int *sock_fd);
int send_header(int sock, int cmd, uint32_t cmd_flags, int datalen,
uint32_t data, uint32_t data2);
diff --git a/src/client_resource.c b/src/client_resource.c
index fd3228a..eeffae4 100644
--- a/src/client_resource.c
+++ b/src/client_resource.c
@@ -28,6 +28,7 @@
#include <sys/un.h>
#include "sanlock_internal.h"
+#include "sanlock_sock.h"
#include "client_msg.h"
#include "sanlock_resource.h"
diff --git a/src/host_id.c b/src/host_id.c
index 142f61b..822e8cb 100644
--- a/src/host_id.c
+++ b/src/host_id.c
@@ -22,15 +22,16 @@
#include <sys/types.h>
#include <sys/time.h>
#include <sys/utsname.h>
+#include <sys/un.h>
#include <uuid/uuid.h>
#include "sanlock_internal.h"
+#include "sanlock_sock.h"
#include "diskio.h"
#include "log.h"
#include "delta_lease.h"
#include "host_id.h"
#include "watchdog.h"
-#include "client_msg.h"
#include "task.h"
static unsigned int space_id_counter = 1;
diff --git a/src/main.c b/src/main.c
index 309d242..b58ecd4 100644
--- a/src/main.c
+++ b/src/main.c
@@ -43,7 +43,7 @@
#include "lockfile.h"
#include "watchdog.h"
#include "task.h"
-#include "client_msg.h"
+#include "sanlock_sock.h"
#include "sanlock_resource.h"
#include "sanlock_admin.h"
@@ -2044,18 +2044,44 @@ static void process_listener(int ci GNUC_UNUSED)
static int setup_listener(void)
{
+ struct sockaddr_un addr;
int rv, fd, ci;
- rv = setup_listener_socket(&fd, com.uid, com.gid, DEFAULT_SOCKET_MODE);
+ rv = sanlock_socket_address(&addr);
if (rv < 0)
return rv;
+ fd = socket(AF_LOCAL, SOCK_STREAM, 0);
+ if (fd < 0)
+ return fd;
+
+ unlink(addr.sun_path);
+ rv = bind(fd, (struct sockaddr *) &addr, sizeof(struct sockaddr_un));
+ if (rv < 0)
+ goto exit_fail;
+
+ rv = chmod(addr.sun_path, DEFAULT_SOCKET_MODE);
+ if (rv < 0)
+ goto exit_fail;
+
+ rv = chown(addr.sun_path, com.uid, com.gid);
+ if (rv < 0)
+ goto exit_fail;
+
+ rv = listen(fd, 5);
+ if (rv < 0)
+ goto exit_fail;
+
ci = client_add(fd, process_listener, NULL);
if (ci < 0)
- return -1;
+ goto exit_fail;
strcpy(client[ci].owner_name, "listener");
return 0;
+
+ exit_fail:
+ close(fd);
+ return -1;
}
static void sigterm_handler(int sig GNUC_UNUSED)
diff --git a/src/sanlock_sock.c b/src/sanlock_sock.c
new file mode 100644
index 0000000..dea7c34
--- /dev/null
+++ b/src/sanlock_sock.c
@@ -0,0 +1,20 @@
+#include <inttypes.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stddef.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+
+#include "sanlock_internal.h"
+#include "sanlock_sock.h"
+
+int sanlock_socket_address(struct sockaddr_un *addr)
+{
+ memset(addr, 0, sizeof(struct sockaddr_un));
+ addr->sun_family = AF_LOCAL;
+ snprintf(addr->sun_path, sizeof(addr->sun_path) - 1, "%s/%s",
+ SANLK_RUN_DIR, SANLK_SOCKET_NAME);
+ return 0;
+}
+
diff --git a/src/sanlock_sock.h b/src/sanlock_sock.h
new file mode 100644
index 0000000..154665a
--- /dev/null
+++ b/src/sanlock_sock.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2010-2011 Red Hat, Inc. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU General Public License v.2.
+ */
+
+#ifndef __SANLOCK_SOCK_H__
+#define __SANLOCK_SOCK_H__
+
+#define MAX_CLIENT_MSG (1024 * 1024) /* TODO: this is random */
+
+enum {
+ SM_CMD_REGISTER = 1,
+ SM_CMD_ADD_LOCKSPACE = 2,
+ SM_CMD_REM_LOCKSPACE = 3,
+ SM_CMD_SHUTDOWN = 4,
+ SM_CMD_STATUS = 5,
+ SM_CMD_LOG_DUMP = 6,
+ SM_CMD_ACQUIRE = 7,
+ SM_CMD_RELEASE = 8,
+ SM_CMD_INQUIRE = 9,
+ SM_CMD_RESTRICT = 10,
+};
+
+#define SANLK_STATE_MAXSTR 4096
+
+#define SANLK_STATE_DAEMON 1
+#define SANLK_STATE_LOCKSPACE 2
+#define SANLK_STATE_CLIENT 3
+#define SANLK_STATE_RESOURCE 4
+
+struct sanlk_state {
+ uint32_t type; /* SANLK_STATE_ */
+ uint32_t flags;
+ uint32_t data32; /* pid (for client) */
+ uint64_t data64;
+ char name[SANLK_NAME_LEN]; /* client name or resource name */
+ uint32_t str_len;
+ char str[0]; /* string of internal state */
+};
+
+int sanlock_socket_address(struct sockaddr_un *addr);
+
+#endif
commit f85b7c11453129fec7819128f6dd340b8e531ace
Author: David Teigland <teigland(a)redhat.com>
Date: Wed Aug 3 10:41:50 2011 -0500
wdmd: new build flags
and move socket address function into a c
file that both lib and cmd can share
diff --git a/wdmd/Makefile b/wdmd/Makefile
index bc30c32..be3f030 100644
--- a/wdmd/Makefile
+++ b/wdmd/Makefile
@@ -15,9 +15,9 @@ SOMINOR=0
SHLIB_TARGET = $(LIB_TARGET).so.$(SOMAJOR).$(SOMINOR)
-CMD_SOURCE = main.c
+CMD_SOURCE = main.c wdmd_sock.c
-LIB_SOURCE = client.c
+LIB_SOURCE = client.c wdmd_sock.c
TEST_SOURCE = wdmd_client.c
@@ -39,16 +39,21 @@ CFLAGS += -D_GNU_SOURCE -g \
-Wp,-D_FORTIFY_SOURCE=2 \
-fexceptions \
-fasynchronous-unwind-tables \
- -fdiagnostics-show-option
+ -fdiagnostics-show-option \
+ -fPIE -DPIE
+
+CMD_LDFLAGS += -lwdmd
+CMD_LDFLAGS += -Wl,-z,now -Wl,-z,relro -pie
+
+LIB_LDFLAGS += -Wl,-z,relro -pie
-CMD_LDFLAGS = -lwdmd
TEST_LDFLAGS = -lwdmd
all: $(SHLIB_TARGET) $(CMD_TARGET) $(TEST_TARGET)
$(SHLIB_TARGET): $(LIB_SOURCE)
- $(CC) -shared -fPIC -o $@ -Wl,-soname=$(LIB_TARGET).so.$(SOMAJOR) $^
+ $(CC) $(CFLAGS) $(LIB_LDFLAGS) -shared -fPIC -o $@
-Wl,-soname=$(LIB_TARGET).so.$(SOMAJOR) $^
ln -sf $(SHLIB_TARGET) $(LIB_TARGET).so
ln -sf $(SHLIB_TARGET) $(LIB_TARGET).so.$(SOMAJOR)
@@ -68,16 +73,17 @@ DESTDIR=
BINDIR=/usr/sbin
LIBDIR=/usr/lib64
HEADIR=/usr/include
-MANDIR=/usr/share/man/
+MANDIR=/usr/share/man
.PHONY: install
install: all
- mkdir -p $(DESTDIR)/$(BINDIR)
- mkdir -p $(DESTDIR)/$(LIBDIR)
- mkdir -p $(DESTDIR)/$(HEADIR)
+ $(INSTALL) -d $(DESTDIR)/$(BINDIR)
+ $(INSTALL) -d $(DESTDIR)/$(LIBDIR)
+ $(INSTALL) -d $(DESTDIR)/$(HEADIR)
+ $(INSTALL) -d $(DESTDIR)/$(MANDIR)
$(INSTALL) -c -m 755 $(CMD_TARGET) $(DESTDIR)/$(BINDIR)
$(INSTALL) -c -m 755 $(SHLIB_TARGET) $(DESTDIR)/$(LIBDIR)
cp -a $(LIB_TARGET).so $(DESTDIR)/$(LIBDIR)
cp -a $(LIB_TARGET).so.$(SOMAJOR) $(DESTDIR)/$(LIBDIR)
$(INSTALL) -c -m 644 $(HEADER_TARGET) $(DESTDIR)/$(HEADIR)
- install $(MAN_TARGET) ${DESTDIR}/${MANDIR}/man8
+ $(INSTALL) $(MAN_TARGET) ${DESTDIR}/${MANDIR}/man8
diff --git a/wdmd/client.c b/wdmd/client.c
index 6a459ae..95b60de 100644
--- a/wdmd/client.c
+++ b/wdmd/client.c
@@ -21,38 +21,7 @@
#include "wdmd.h"
#include "wdmd_internal.h"
-
-int get_socket_address(struct sockaddr_un *addr)
-{
- memset(addr, 0, sizeof(struct sockaddr_un));
- addr->sun_family = AF_LOCAL;
- snprintf(addr->sun_path, sizeof(addr->sun_path) - 1, "%s/%s",
- WDMD_RUN_DIR, WDMD_SOCKET_NAME);
- return 0;
-}
-
-static int connect_socket(int *sock_fd)
-{
- int rv, s;
- struct sockaddr_un addr;
-
- s = socket(AF_LOCAL, SOCK_STREAM, 0);
- if (s < 0)
- return -errno;
-
- rv = get_socket_address(&addr);
- if (rv < 0)
- return rv;
-
- rv = connect(s, (struct sockaddr *) &addr, sizeof(struct sockaddr_un));
- if (rv < 0) {
- rv = -errno;
- close(s);
- return rv;
- }
- *sock_fd = s;
- return 0;
-}
+#include "wdmd_sock.h"
int wdmd_connect(void)
{
@@ -63,7 +32,7 @@ int wdmd_connect(void)
if (s < 0)
return -errno;
- rv = get_socket_address(&addr);
+ rv = wdmd_socket_address(&addr);
if (rv < 0)
return rv;
diff --git a/wdmd/main.c b/wdmd/main.c
index 25c6781..d8994b4 100644
--- a/wdmd/main.c
+++ b/wdmd/main.c
@@ -34,6 +34,7 @@
#include "wdmd.h"
#include "wdmd_internal.h"
+#include "wdmd_sock.h"
#define DEFAULT_TEST_INTERVAL 10
#define DEFAULT_FIRE_TIMEOUT 60
@@ -284,8 +285,6 @@ static void close_clients(void)
{
}
-extern int get_socket_address(struct sockaddr_un *addr);
-
static int setup_listener_socket(int *listener_socket)
{
int rv, s;
@@ -295,7 +294,7 @@ static int setup_listener_socket(int *listener_socket)
if (s < 0)
return -errno;
- rv = get_socket_address(&addr);
+ rv = wdmd_socket_address(&addr);
if (rv < 0)
return rv;
diff --git a/wdmd/wdmd_sock.c b/wdmd/wdmd_sock.c
new file mode 100644
index 0000000..ef2923e
--- /dev/null
+++ b/wdmd/wdmd_sock.c
@@ -0,0 +1,21 @@
+#include <inttypes.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stddef.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+
+#include "wdmd.h"
+#include "wdmd_internal.h"
+#include "wdmd_sock.h"
+
+int wdmd_socket_address(struct sockaddr_un *addr)
+{
+ memset(addr, 0, sizeof(struct sockaddr_un));
+ addr->sun_family = AF_LOCAL;
+ snprintf(addr->sun_path, sizeof(addr->sun_path) - 1, "%s/%s",
+ WDMD_RUN_DIR, WDMD_SOCKET_NAME);
+ return 0;
+}
+
diff --git a/wdmd/wdmd_sock.h b/wdmd/wdmd_sock.h
new file mode 100644
index 0000000..cf2f4b1
--- /dev/null
+++ b/wdmd/wdmd_sock.h
@@ -0,0 +1,6 @@
+#ifndef __WDMD_SOCK_H__
+#define __WDMD_SOCK_H__
+
+int wdmd_socket_address(struct sockaddr_un *addr);
+
+#endif