Browse Source

Fix build problem with MSG_NOSIGNAL on OpenBSD.

git-svn-id: https://klish.googlecode.com/svn/trunk@278 0eaa4687-2ee9-07dd-09d9-bcdd2d2dd5fb
Serj Kalichev 13 years ago
parent
commit
ea400c7333
4 changed files with 49 additions and 4 deletions
  1. 13 0
      bin/clish.cpp
  2. 13 0
      bin/konf.c
  3. 15 3
      bin/konfd.c
  4. 8 1
      konf/net/net.c

+ 13 - 0
bin/clish.cpp

@@ -15,6 +15,7 @@
 #ifdef HAVE_GETOPT_H
 #include <getopt.h>
 #endif
+#include <signal.h>
 
 #include "clish/shell.h"
 #include "clish/internal.h"
@@ -54,6 +55,10 @@ int main(int argc, char **argv)
 	const char *view = getenv("CLISH_VIEW");
 	const char *viewid = getenv("CLISH_VIEWID");
 
+	/* Signal vars */
+	struct sigaction sigpipe_act;
+	sigset_t sigpipe_set;
+
 	static const char *shortopts = "hvs:ledx:w:i:";
 #ifdef HAVE_GETOPT_H
 	static const struct option longopts[] = {
@@ -70,6 +75,14 @@ int main(int argc, char **argv)
 	};
 #endif
 
+	/* Ignore SIGPIPE */
+	sigemptyset(&sigpipe_set);
+	sigaddset(&sigpipe_set, SIGPIPE);
+	sigpipe_act.sa_flags = 0;
+	sigpipe_act.sa_mask = sigpipe_set;
+	sigpipe_act.sa_handler = SIG_IGN;
+	sigaction(SIGPIPE, &sigpipe_act, NULL);
+
 	/* Parse command line options */
 	optind = 0;
 	while(1) {

+ 13 - 0
bin/konf.c

@@ -15,6 +15,7 @@
 #ifdef HAVE_GETOPT_H
 #include <getopt.h>
 #endif
+#include <signal.h>
 
 #include "konf/net.h"
 #include "konf/query.h"
@@ -47,6 +48,10 @@ int main(int argc, char **argv)
 	const char *socket_path = KONFD_SOCKET_PATH;
 	unsigned i = 0;
 
+	/* Signal vars */
+	struct sigaction sigpipe_act;
+	sigset_t sigpipe_set;
+
 	static const char *shortopts = "hvs:";
 #ifdef HAVE_GETOPT_H
 	static const struct option longopts[] = {
@@ -57,6 +62,14 @@ int main(int argc, char **argv)
 	};
 #endif
 
+	/* Ignore SIGPIPE */
+	sigemptyset(&sigpipe_set);
+	sigaddset(&sigpipe_set, SIGPIPE);
+	sigpipe_act.sa_flags = 0;
+	sigpipe_act.sa_mask = sigpipe_set;
+	sigpipe_act.sa_handler = SIG_IGN;
+	sigaction(SIGPIPE, &sigpipe_act, NULL);
+
 	/* Parse command line options */
 	optind = 0;
 	while(1) {

+ 15 - 3
bin/konfd.c

@@ -45,6 +45,11 @@
 #define UNIX_PATH_MAX 108
 #endif
 
+/* OpenBSD has no MSG_NOSIGNAL flag */
+#ifndef MSG_NOSIGNAL
+#define MSG_NOSIGNAL 0
+#endif
+
 #define MAXMSG 1024
 
 /* Global signal vars */
@@ -74,9 +79,8 @@ int main(int argc, char **argv)
 	const char *socket_path = KONFD_SOCKET_PATH;
 
 	/* Signal vars */
-	struct sigaction sig_act;
-	sigset_t sig_set;
-
+	struct sigaction sig_act, sigpipe_act;
+	sigset_t sig_set, sigpipe_set;
 	/* Command line options */
 	static const char *shortopts = "hvs:";
 #ifdef HAVE_GETOPT_H
@@ -131,6 +135,14 @@ int main(int argc, char **argv)
 	sigaction(SIGINT, &sig_act, NULL);
 	sigaction(SIGQUIT, &sig_act, NULL);
 
+	/* Ignore SIGPIPE */
+	sigemptyset(&sigpipe_set);
+	sigaddset(&sigpipe_set, SIGPIPE);
+	sigpipe_act.sa_flags = 0;
+	sigpipe_act.sa_mask = sigpipe_set;
+	sigpipe_act.sa_handler = SIG_IGN;
+	sigaction(SIGPIPE, &sigpipe_act, NULL);
+
 	/* Create listen socket */
 	if ((sock = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
 		fprintf(stderr, "Cannot create socket: %s\n", strerror(errno));

+ 8 - 1
konf/net/net.c

@@ -14,11 +14,18 @@
 #include "lub/string.h"
 #include "private.h"
 
-/* Socket name in filesystem */
+/* UNIX socket name in filesystem */
 #ifndef UNIX_PATH_MAX
 #define UNIX_PATH_MAX 108
 #endif
 
+/* OpenBSD has no MSG_NOSIGNAL flag.
+ * The SIGPIPE must be ignored in application.
+ */
+#ifndef MSG_NOSIGNAL
+#define MSG_NOSIGNAL 0
+#endif
+
 /*--------------------------------------------------------- */
 konf_client_t *konf_client_new(const char *path)
 {