aboutsummaryrefslogtreecommitdiffstats
path: root/net/dctc/files/patch-src:db.c
blob: 74abd7eca69b5f2a4280841f7df4ff2dae947a95 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
--- src/db.c.orig   Thu Nov 22 00:08:34 2001
+++ src/db.c    Thu Nov 22 00:11:49 2001
@@ -30,6 +30,15 @@
 #include <netinet/in.h>
 #include <glib.h>
 
+#if (defined(__unix__) || defined(unix)) && !defined(USG)
+#include <sys/param.h>
+#endif
+
+#if (defined(BSD) && (BSD >= 199103))
+#include <signal.h>
+#define MSG_NOSIGNAL 0
+#endif
+
 #include "db.h"
 #include "display.h"
 #include "var.h"
@@ -711,6 +720,9 @@
 /******************************************************************************************/
 static void send_a_db_result(int output_sck, char *dest_nick, DB_ENTRY *de, struct sockaddr_in *dest_addr, char *md5sum)
 {
+#if (defined(BSD) && (BSD >= 199103))
+   sigset_t sigset, sigoset;
+#endif
    GString *str;
    GString *adapted;
 
@@ -752,10 +764,38 @@
    printf("dest_addr: %s, str: %s\n",dest_addr,str->str);
 #endif
 
-   if(dest_addr==NULL)
+   if(dest_addr==NULL) {
+#if (defined(BSD) && (BSD >= 199103))
+   /* possible race condition since backup and restore
+   are not guaranteed to occur as a single operation */
+
+   /* backup sigmask and block SIGPIPE */
+   sigemptyset(&sigset);
+   sigaddset(&sigset,SIGPIPE);
+   (void) sigprocmask(SIG_BLOCK, &sigset, &sigoset);
+#endif
        send(output_sck,str->str,str->len,MSG_NOSIGNAL);
-   else
+#if (defined(BSD) && (BSD >= 199103))
+       /* restore sigmask backup */
+       (void)sigprocmask(SIG_SETMASK, &sigoset, NULL);
+#endif
+   } else {
+#if (defined(BSD) && (BSD >= 199103))
+   /* possible race condition since backup and restore
+   are not guaranteed to occur as a single operation */
+
+   /* backup sigmask and block SIGPIPE */
+   sigemptyset(&sigset);
+   sigaddset(&sigset,SIGPIPE);
+   (void) sigprocmask(SIG_BLOCK, &sigset, &sigoset);
+#endif
        sendto(output_sck,str->str,str->len,MSG_NOSIGNAL,(void*)dest_addr, sizeof(struct sockaddr_in));
+
+#if (defined(BSD) && (BSD >= 199103))
+       /* restore sigmask backup */
+       (void)sigprocmask(SIG_SETMASK, &sigoset, NULL);
+#endif
+   }
 
    disp_msg(INFO_MSG,"send_search_result_line",str->str,NULL);