-
Notifications
You must be signed in to change notification settings - Fork 0
/
revision-2925.patch
233 lines (217 loc) · 4.88 KB
/
revision-2925.patch
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
Index: lib/coroipcc.c
===================================================================
--- lib/coroipcc.c (revision 2924)
+++ lib/coroipcc.c (revision 2925)
@@ -469,34 +469,48 @@
return (CS_OK);
}
-static cs_error_t
-reply_receive (
+inline static cs_error_t
+ipc_sem_wait (
struct ipc_instance *ipc_instance,
- void *res_msg,
- size_t res_len)
+ int sem_num)
{
#if _POSIX_THREAD_PROCESS_SHARED < 1
struct sembuf sop;
#else
struct timespec timeout;
struct pollfd pfd;
+ sem_t *sem;
#endif
- coroipc_response_header_t *response_header;
int res;
#if _POSIX_THREAD_PROCESS_SHARED > 0
+ switch (sem_num) {
+ case 0:
+ sem = &ipc_instance->control_buffer->sem0;
+ break;
+ case 1:
+ sem = &ipc_instance->control_buffer->sem1;
+ break;
+ case 2:
+ sem = &ipc_instance->control_buffer->sem2;
+ break;
+ }
+
retry_semwait:
timeout.tv_sec = time(NULL) + IPC_SEMWAIT_TIMEOUT;
timeout.tv_nsec = 0;
- res = sem_timedwait (&ipc_instance->control_buffer->sem1, &timeout);
+ res = sem_timedwait (sem, &timeout);
if (res == -1 && errno == ETIMEDOUT) {
pfd.fd = ipc_instance->fd;
pfd.events = 0;
res = poll (&pfd, 1, 0);
- if (res == -1 && errno != EINTR) {
+ if (res == -1 && errno == EINTR) {
+ return (CS_ERR_TRY_AGAIN);
+ } else
+ if (res == -1) {
return (CS_ERR_LIBRARY);
}
@@ -507,17 +521,19 @@
}
goto retry_semwait;
- }
-
+ } else
if (res == -1 && errno == EINTR) {
- goto retry_semwait;
+ return (CS_ERR_TRY_AGAIN);
+ } else
+ if (res == -1) {
+ return (CS_ERR_LIBRARY);
}
#else
/*
- * Wait for semaphore #1 indicating a new message from server
- * to client in the response queue
+ * Wait for semaphore indicating a new message from server
+ * to client in queue
*/
- sop.sem_num = 1;
+ sop.sem_num = sem_num;
sop.sem_op = -1;
sop.sem_flg = 0;
@@ -534,7 +550,22 @@
return (CS_ERR_LIBRARY);
}
#endif
+ return (CS_OK);
+}
+static cs_error_t
+reply_receive (
+ struct ipc_instance *ipc_instance,
+ void *res_msg,
+ size_t res_len)
+{
+ coroipc_response_header_t *response_header;
+ cs_error_t err;
+
+ if ((err = ipc_sem_wait (ipc_instance, 1)) != CS_OK) {
+ return (err);
+ }
+
response_header = (coroipc_response_header_t *)ipc_instance->response_buffer;
if (response_header->error == CS_ERR_TRY_AGAIN) {
return (CS_ERR_TRY_AGAIN);
@@ -549,62 +580,12 @@
struct ipc_instance *ipc_instance,
void **res_msg)
{
-#if _POSIX_THREAD_PROCESS_SHARED < 1
- struct sembuf sop;
-#else
- struct timespec timeout;
- struct pollfd pfd;
-#endif
- int res;
+ cs_error_t err;
-#if _POSIX_THREAD_PROCESS_SHARED > 0
-retry_semwait:
- timeout.tv_sec = time(NULL) + IPC_SEMWAIT_TIMEOUT;
- timeout.tv_nsec = 0;
-
- res = sem_timedwait (&ipc_instance->control_buffer->sem1, &timeout);
- if (res == -1 && errno == ETIMEDOUT) {
- pfd.fd = ipc_instance->fd;
- pfd.events = 0;
-
- res = poll (&pfd, 1, 0);
-
- if (res == -1 && errno != EINTR) {
- return (CS_ERR_LIBRARY);
- }
- if (pfd.revents == POLLERR || pfd.revents == POLLHUP) {
- return (CS_ERR_LIBRARY);
- }
-
- goto retry_semwait;
+ if ((err = ipc_sem_wait (ipc_instance, 1)) != CS_OK) {
+ return (err);
}
- if (res == -1 && errno == EINTR) {
- goto retry_semwait;
- }
-#else
- /*
- * Wait for semaphore #1 indicating a new message from server
- * to client in the response queue
- */
- sop.sem_num = 1;
- sop.sem_op = -1;
- sop.sem_flg = 0;
-
-retry_semop:
- res = semop (ipc_instance->semid, &sop, 1);
- if (res == -1 && errno == EINTR) {
- return (CS_ERR_TRY_AGAIN);
- } else
- if (res == -1 && errno == EACCES) {
- priv_change_send (ipc_instance);
- goto retry_semop;
- } else
- if (res == -1) {
- return (CS_ERR_LIBRARY);
- }
-#endif
-
*res_msg = (char *)ipc_instance->response_buffer;
return (CS_OK);
}
@@ -987,12 +968,9 @@
cs_error_t
coroipcc_dispatch_put (hdb_handle_t handle)
{
-#if _POSIX_THREAD_PROCESS_SHARED < 1
- struct sembuf sop;
-#endif
coroipc_response_header_t *header;
struct ipc_instance *ipc_instance;
- int res;
+ cs_error_t res;
char *addr;
unsigned int read_idx;
@@ -1000,31 +978,10 @@
if (res != CS_OK) {
return (res);
}
-#if _POSIX_THREAD_PROCESS_SHARED > 0
-retry_semwait:
- res = sem_wait (&ipc_instance->control_buffer->sem2);
- if (res == -1 && errno == EINTR) {
- goto retry_semwait;
- }
-#else
- sop.sem_num = 2;
- sop.sem_op = -1;
- sop.sem_flg = 0;
-retry_semop:
- res = semop (ipc_instance->semid, &sop, 1);
- if (res == -1 && errno == EINTR) {
- res = CS_ERR_TRY_AGAIN;
+
+ if ((res = ipc_sem_wait (ipc_instance, 2)) != CS_OK) {
goto error_exit;
- } else
- if (res == -1 && errno == EACCES) {
- priv_change_send (ipc_instance);
- goto retry_semop;
- } else
- if (res == -1) {
- res = CS_ERR_LIBRARY;
- goto error_exit;
}
-#endif
addr = ipc_instance->dispatch_buffer;
@@ -1037,9 +994,7 @@
*/
res = CS_OK;
-#if _POSIX_THREAD_PROCESS_SHARED < 1
error_exit:
-#endif
hdb_handle_put (&ipc_hdb, handle);
hdb_handle_put (&ipc_hdb, handle);