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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
|
--- src/dc_manage.c.orig Sat Nov 24 08:43:42 2001
+++ src/dc_manage.c Sat Nov 24 13:17:32 2001
@@ -35,6 +35,11 @@
#include <fcntl.h>
#include <pthread.h>
+#if (defined(BSD) && (BSD >= 199103))
+#include <signal.h>
+#define MSG_NOSIGNAL 0
+#endif
+
#include "display.h"
#include "action.h"
#include "macro.h"
@@ -189,6 +194,9 @@
/*************************/
static int send_file_data(int sck,char *filename, int start_pos, unsigned long file_len,WAIT_ACT *act)
{
+#if (defined(BSD) && (BSD >= 199103))
+ sigset_t sigset, sigoset;
+#endif
unsigned long int i;
char buf[8192]; /* must be a multiple of 512 */
unsigned long int a=file_len-start_pos;
@@ -220,7 +228,20 @@
act->last_touch=time(NULL);
get_slices(bl_semid,sizeof(buf)/512); /* obtain upload authorization */
+#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
res=send(sck,buf,sizeof(buf),MSG_NOSIGNAL|MSG_WAITALL);
+#if (defined(BSD) && (BSD >= 199103))
+ /* restore sigmask backup */
+ (void)sigprocmask(SIG_SETMASK, &sigoset, NULL);
+#endif
act->last_touch=time(NULL);
if(res!=sizeof(buf))
@@ -240,7 +261,20 @@
act->last_touch=time(NULL);
get_slices(bl_semid,(remain+511)/512); /* obtain upload authorization */
+#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
res=send(sck,buf,remain,MSG_NOSIGNAL|MSG_WAITALL);
+#if (defined(BSD) && (BSD >= 199103))
+ /* restore sigmask backup */
+ (void)sigprocmask(SIG_SETMASK, &sigoset, NULL);
+#endif
act->last_touch=time(NULL);
if(res!=remain)
@@ -259,6 +293,9 @@
/*************************/
static int send_array_data(int sck,GByteArray *ba,WAIT_ACT *act)
{
+#if (defined(BSD) && (BSD >= 199103))
+ sigset_t sigset, sigoset;
+#endif
unsigned long int i;
unsigned long int nb;
int remain;
@@ -274,7 +311,20 @@
act->last_touch=time(NULL);
get_slices(bl_semid,BLOCK_SIZE/512); /* obtain upload authorization */
+#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
res=send(sck,ba->data+cur_pos,BLOCK_SIZE,MSG_NOSIGNAL|MSG_WAITALL);
+#if (defined(BSD) && (BSD >= 199103))
+ /* restore sigmask backup */
+ (void)sigprocmask(SIG_SETMASK, &sigoset, NULL);
+#endif
act->last_touch=time(NULL);
if(res!=BLOCK_SIZE)
@@ -292,7 +342,20 @@
act->last_touch=time(NULL);
get_slices(bl_semid,(remain+511)/512); /* obtain upload authorization */
+#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
res=send(sck,ba->data+cur_pos,remain,MSG_NOSIGNAL|MSG_WAITALL);
+#if (defined(BSD) && (BSD >= 199103))
+ /* restore sigmask backup */
+ (void)sigprocmask(SIG_SETMASK, &sigoset, NULL);
+#endif
act->last_touch=time(NULL);
if(res!=remain)
@@ -326,6 +389,9 @@
/**************************************************************************/
static int com_up_get_list_len_process(const char *cmd,WAIT_ACT *act,int sck,GString *input, char *xtra_param)
{
+#if (defined(BSD) && (BSD >= 199103))
+ sigset_t sigset, sigoset;
+#endif
GByteArray *cpy_data;
GString *out;
int res;
@@ -377,7 +443,20 @@
disp_msg(DEBUG_MSG,"reply",out->str,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
res=send(sck,out->str,out->len,MSG_NOSIGNAL);
+#if (defined(BSD) && (BSD >= 199103))
+ /* restore sigmask backup */
+ (void)sigprocmask(SIG_SETMASK, &sigoset, NULL);
+#endif
res=(res!=out->len);
g_string_free(out,TRUE);
if(res)
@@ -403,7 +482,20 @@
g_string_sprintfa(out,"%lu|",(unsigned long)100000+rand()%500000);
else
g_string_sprintfa(out,"%lu|",(unsigned long)cpy_data->len);
+#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
res=send(sck,out->str,out->len,MSG_NOSIGNAL);
+#if (defined(BSD) && (BSD >= 199103))
+ /* restore sigmask backup */
+ (void)sigprocmask(SIG_SETMASK, &sigoset, NULL);
+#endif
res=(res!=out->len);
g_string_free(out,TRUE);
if(res)
@@ -674,6 +766,9 @@
/*****************************************************************/
static int copie_fd_to_file(int remote, FILE *local, unsigned long amount,WAIT_ACT *act)
{
+#if (defined(BSD) && (BSD >= 199103))
+ sigset_t sigset, sigoset;
+#endif
while(amount!=0)
{
char buf[8192];
@@ -684,7 +779,20 @@
/* touch the action slot to avoid timeout */
act->last_touch=time(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
ret=recv(remote,buf,nb,MSG_WAITALL|MSG_NOSIGNAL);
+#if (defined(BSD) && (BSD >= 199103))
+ /* restore sigmask backup */
+ (void)sigprocmask(SIG_SETMASK, &sigoset, NULL);
+#endif
act->last_touch=time(NULL);
if((ret==-1)||(ret==0))
@@ -1019,6 +1127,9 @@
/*****************************************************************/
static int copie_fd_to_bytearray(int remote, GByteArray **ba, unsigned long amount,WAIT_ACT *act)
{
+#if (defined(BSD) && (BSD >= 199103))
+ sigset_t sigset, sigoset;
+#endif
int pos=0;
int ret;
unsigned long nb;
@@ -1032,12 +1143,25 @@
/* touch the action slot to avoid timeout */
act->last_touch=time(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
#if 0
ret=recv(remote,(*ba)->data+pos,nb,MSG_WAITALL|MSG_NOSIGNAL);
#else
ret=recv(remote,(*ba)->data+pos,nb,MSG_NOSIGNAL);
printf("%d\n",ret);
#endif
+#if (defined(BSD) && (BSD >= 199103))
+ /* restore sigmask backup */
+ (void)sigprocmask(SIG_SETMASK, &sigoset, NULL);
+#endif
act->last_touch=time(NULL);
if((ret==-1)||(ret==0))
@@ -2674,10 +2798,26 @@
/*******************************************************/
int manage_srch_port(int srch_sck, int sck)
{
+#if (defined(BSD) && (BSD >= 199103))
+ sigset_t sigset, sigoset;
+#endif
char buf[8192];
int ret;
+#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
ret=recv(srch_sck,buf,sizeof(buf),MSG_NOSIGNAL);
+#if (defined(BSD) && (BSD >= 199103))
+ /* restore sigmask backup */
+ (void)sigprocmask(SIG_SETMASK, &sigoset, NULL);
+#endif
if(ret!=-1)
{
int i;
|