public
Description: Phusion Passenger (mod_rails)
Homepage: http://www.modrails.com/
Clone URL: git://github.com/FooBarWidget/passenger.git
Search Repo:
Click here to lend your support to: passenger and make a donation at www.pledgie.com !
Attempt to fix file descriptor passing in OS X (again).
Hongli Lai (Phusion) (author)
Tue May 06 11:52:33 -0700 2008
commit  8ec6efa06d48810822b3dedf6a26cca3576f5363
tree    323f6d1cfa149a8b566b0b5a1e2a363db2d65dd9
parent  a5abd879c20bfef2ae97c15ca349fec23ec2d857
...
186
187
188
189
 
 
190
191
192
 
 
193
194
195
196
197
198
199
 
 
200
201
202
...
186
187
188
 
189
190
191
192
 
193
194
195
196
197
198
199
200
 
201
202
203
204
205
0
@@ -186,17 +186,20 @@
0
     'MessageChannelTest.o' => %w(MessageChannelTest.cpp ../ext/apache2/MessageChannel.h),
0
     'SpawnManagerTest.o' => %w(SpawnManagerTest.cpp
0
       ../ext/apache2/SpawnManager.h
0
- ../ext/apache2/Application.h),
0
+ ../ext/apache2/Application.h
0
+ ../ext/apache2/MessageChannel.h),
0
     'ApplicationPoolServerTest.o' => %w(ApplicationPoolServerTest.cpp
0
       ../ext/apache2/StandardApplicationPool.h
0
- ../ext/apache2/ApplicationPoolClientServer.h),
0
+ ../ext/apache2/ApplicationPoolClientServer.h
0
+ ../ext/apache2/MessageChannel.h),
0
     'ApplicationPoolServer_ApplicationPoolTest.o' => %w(ApplicationPoolServer_ApplicationPoolTest.cpp
0
       ApplicationPoolTest.cpp
0
       ../ext/apache2/ApplicationPoolClientServer.h
0
       ../ext/apache2/ApplicationPool.h
0
       ../ext/apache2/StandardApplicationPool.h
0
       ../ext/apache2/SpawnManager.h
0
- ../ext/apache2/Application.h),
0
+ ../ext/apache2/Application.h
0
+ ../ext/apache2/MessageChannel.h),
0
     'StandardApplicationPoolTest.o' => %w(StandardApplicationPoolTest.cpp
0
       ApplicationPoolTest.cpp
0
       ../ext/apache2/ApplicationPool.h
...
259
260
261
262
 
 
 
 
 
 
 
 
263
264
265
266
267
268
...
272
273
274
275
 
276
277
278
279
280
 
 
281
282
283
 
 
 
 
 
 
 
284
285
286
287
288
289
...
425
426
427
428
 
 
 
 
 
 
 
 
429
430
431
...
437
438
439
440
 
441
442
443
444
...
446
447
448
449
450
 
451
452
453
454
455
 
 
 
 
 
456
457
458
...
259
260
261
 
262
263
264
265
266
267
268
269
270
271
272
273
274
275
...
279
280
281
 
282
283
284
 
 
 
285
286
287
288
 
289
290
291
292
293
294
295
296
 
 
297
298
299
...
435
436
437
 
438
439
440
441
442
443
444
445
446
447
448
...
454
455
456
 
457
458
459
460
461
...
463
464
465
 
 
466
467
468
469
470
 
471
472
473
474
475
476
477
478
0
@@ -259,7 +259,14 @@
0
     struct msghdr msg;
0
     struct iovec vec;
0
     char dummy[1];
0
- char control_data[CMSG_SPACE(sizeof(int))];
0
+ #ifdef __APPLE__
0
+ struct {
0
+ struct cmsghdr header;
0
+ int fd;
0
+ } control_data;
0
+ #else
0
+ char control_data[CMSG_SPACE(sizeof(int))];
0
+ #endif
0
     struct cmsghdr *control_header;
0
   
0
     msg.msg_name = NULL;
0
0
0
0
@@ -272,18 +279,21 @@
0
     msg.msg_iov = &vec;
0
     msg.msg_iovlen = 1;
0
   
0
- msg.msg_control = (caddr_t) control_data;
0
+ msg.msg_control = (caddr_t) &control_data;
0
     msg.msg_controllen = sizeof(control_data);
0
     msg.msg_flags = 0;
0
-
0
- control_header = CMSG_FIRSTHDR(&msg);
0
- control_header->cmsg_len = CMSG_LEN(sizeof(int));
0
+
0
+ control_header = CMSG_FIRSTHDR(&msg);
0
     control_header->cmsg_level = SOL_SOCKET;
0
     control_header->cmsg_type = SCM_RIGHTS;
0
- memcpy(CMSG_DATA(control_header), &fileDescriptor, sizeof(int));
0
+ #ifdef __APPLE__
0
+ control_header->cmsg_len = sizeof(control_data);
0
+ control_data.fd = fileDescriptor;
0
+ #else
0
+ control_header->cmsg_len = CMSG_LEN(sizeof(int));
0
+ memcpy(CMSG_DATA(control_header), &fileDescriptor, sizeof(int));
0
+ #endif
0
     
0
- msg.msg_controllen = control_header->cmsg_len;
0
-
0
     if (sendmsg(fd, &msg, 0) == -1) {
0
       throw SystemException("Cannot send file descriptor with sendmsg()", errno);
0
     }
0
@@ -425,7 +435,14 @@
0
     struct msghdr msg;
0
     struct iovec vec;
0
     char dummy[1];
0
- char control_data[CMSG_SPACE(sizeof(int))];
0
+ #ifdef __APPLE__
0
+ struct {
0
+ struct cmsghdr header;
0
+ int fd;
0
+ } control_data;
0
+ #else
0
+ char control_data[CMSG_SPACE(sizeof(int))];
0
+ #endif
0
     struct cmsghdr *control_header;
0
 
0
     msg.msg_name = NULL;
0
@@ -437,7 +454,7 @@
0
     msg.msg_iov = &vec;
0
     msg.msg_iovlen = 1;
0
 
0
- msg.msg_control = (caddr_t) control_data;
0
+ msg.msg_control = (caddr_t) &control_data;
0
     msg.msg_controllen = sizeof(control_data);
0
     msg.msg_flags = 0;
0
     
0
0
@@ -446,13 +463,16 @@
0
     }
0
     
0
     control_header = CMSG_FIRSTHDR(&msg);
0
- if (msg.msg_controllen != sizeof(control_data)
0
- || control_header->cmsg_len != CMSG_LEN(sizeof(int))
0
+ if (control_header->cmsg_len != CMSG_LEN(sizeof(int))
0
      || control_header->cmsg_level != SOL_SOCKET
0
      || control_header->cmsg_type != SCM_RIGHTS) {
0
       throw IOException("No valid file descriptor received.");
0
     }
0
- return *((int *) CMSG_DATA(control_header));
0
+ #ifdef __APPLE__
0
+ return control_data.fd;
0
+ #else
0
+ return *((int *) CMSG_DATA(control_header));
0
+ #endif
0
   }
0
 };
0
 
...
57
58
59
60
 
61
62
63
64
65
 
66
67
68
69
 
 
 
 
 
 
 
70
71
72
73
74
75
...
93
94
95
96
 
 
 
 
 
 
 
 
97
98
99
...
105
106
107
108
 
109
110
111
112
...
115
116
117
118
119
 
120
121
122
123
124
125
 
 
 
 
 
126
127
128
...
57
58
59
 
60
61
62
63
 
 
64
65
66
67
 
68
69
70
71
72
73
74
75
 
 
76
77
78
...
96
97
98
 
99
100
101
102
103
104
105
106
107
108
109
...
115
116
117
 
118
119
120
121
122
...
125
126
127
 
 
128
129
130
131
132
133
 
134
135
136
137
138
139
140
141
0
@@ -57,19 +57,22 @@
0
   msg.msg_iov = &vec;
0
   msg.msg_iovlen = 1;
0
   
0
- msg.msg_control = (caddr_t) control_data;
0
+ msg.msg_control = (caddr_t) &control_data;
0
   msg.msg_controllen = sizeof(control_data);
0
   msg.msg_flags = 0;
0
   
0
- control_header = CMSG_FIRSTHDR(&msg);
0
- control_header->cmsg_len = CMSG_LEN(sizeof(int));
0
+ control_header = CMSG_FIRSTHDR(&msg);
0
   control_header->cmsg_level = SOL_SOCKET;
0
   control_header->cmsg_type = SCM_RIGHTS;
0
   control_payload = NUM2INT(fd_to_send);
0
- memcpy(CMSG_DATA(control_header), &control_payload, sizeof(int));
0
+ #ifdef __APPLE__
0
+ control_header->cmsg_len = sizeof(control_data);
0
+ control_data.fd = control_payload;
0
+ #else
0
+ control_header->cmsg_len = CMSG_LEN(sizeof(int));
0
+ memcpy(CMSG_DATA(control_header), &control_payload, sizeof(int));
0
+ #endif
0
   
0
- msg.msg_controllen = control_header->cmsg_len;
0
-
0
   if (sendmsg(NUM2INT(socket_fd), &msg, 0) == -1) {
0
     rb_sys_fail("sendmsg(2)");
0
     return Qnil;
0
@@ -93,7 +96,14 @@
0
   struct msghdr msg;
0
   struct iovec vec;
0
   char dummy[1];
0
- char control_data[CMSG_SPACE(sizeof(int))];
0
+ #ifdef __APPLE__
0
+ struct {
0
+ struct cmsghdr header;
0
+ int fd;
0
+ } control_data;
0
+ #else
0
+ char control_data[CMSG_SPACE(sizeof(int))];
0
+ #endif
0
   struct cmsghdr *control_header;
0
 
0
   msg.msg_name = NULL;
0
@@ -105,7 +115,7 @@
0
   msg.msg_iov = &vec;
0
   msg.msg_iovlen = 1;
0
 
0
- msg.msg_control = (caddr_t) control_data;
0
+ msg.msg_control = (caddr_t) &control_data;
0
   msg.msg_controllen = sizeof(control_data);
0
   msg.msg_flags = 0;
0
   
0
0
@@ -115,14 +125,17 @@
0
   }
0
   
0
   control_header = CMSG_FIRSTHDR(&msg);
0
- if (msg.msg_controllen != sizeof(control_data)
0
- || control_header->cmsg_len != CMSG_LEN(sizeof(int))
0
+ if (control_header->cmsg_len != CMSG_LEN(sizeof(int))
0
    || control_header->cmsg_level != SOL_SOCKET
0
    || control_header->cmsg_type != SCM_RIGHTS) {
0
     rb_sys_fail("No valid file descriptor received.");
0
     return Qnil;
0
   }
0
- return INT2NUM(*((int *) CMSG_DATA(control_header)));
0
+ #ifdef __APPLE__
0
+ return INT2NUM(control_data.fd);
0
+ #else
0
+ return INT2NUM(*((int *) CMSG_DATA(control_header)));
0
+ #endif
0
 }
0
 
0
 /*

Comments

    No one has commented yet.