Commit | Line | Data |
0ade1984 |
1 | #include "EXTERN.h" |
2 | #include "perl.h" |
3 | #include "XSUB.h" |
4 | |
5 | #include <sys/types.h> |
6 | #ifdef __linux__ |
7 | #include <asm/page.h> |
8 | #endif |
9 | #if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM) |
10 | #include <sys/ipc.h> |
11 | #ifdef HAS_MSG |
12 | #include <sys/msg.h> |
13 | #endif |
14 | #ifdef HAS_SEM |
15 | #include <sys/sem.h> |
16 | #endif |
17 | #ifdef HAS_SHM |
a696a92a |
18 | #if defined(PERL_SCO5) || defined(PERL_ISC) |
93502d79 |
19 | #include <sys/sysmacros.h> |
20 | #endif |
0ade1984 |
21 | #include <sys/shm.h> |
22 | # ifndef HAS_SHMAT_PROTOTYPE |
23 | extern Shmat_t shmat _((int, char *, int)); |
24 | # endif |
25 | #endif |
26 | #endif |
27 | |
1e509ade |
28 | /* Required in BSDI to get PAGE_SIZE definition for SHMLBA. |
29 | * Ugly. More beautiful solutions welcome. |
30 | * Shouting at BSDI sounds quite beautiful. */ |
31 | #ifdef __bsdi__ |
32 | # include <vm/vm_param.h> |
33 | #endif |
34 | |
85ab1d1d |
35 | #ifndef S_IRWXU |
36 | # ifdef S_IRUSR |
37 | # define S_IRWXU (S_IRUSR|S_IWUSR|S_IWUSR) |
38 | # define S_IRWXG (S_IRGRP|S_IWGRP|S_IWGRP) |
39 | # define S_IRWXO (S_IROTH|S_IWOTH|S_IWOTH) |
40 | # else |
41 | # define S_IRWXU 0700 |
42 | # define S_IRWXG 0070 |
43 | # define S_IRWXO 0007 |
44 | # endif |
45 | #endif |
46 | |
0ade1984 |
47 | MODULE=IPC::SysV PACKAGE=IPC::Msg::stat |
48 | |
49 | PROTOTYPES: ENABLE |
50 | |
51 | void |
52 | pack(obj) |
53 | SV * obj |
54 | PPCODE: |
55 | { |
6087ac44 |
56 | #ifdef HAS_MSG |
0ade1984 |
57 | SV *sv; |
58 | struct msqid_ds ds; |
59 | AV *list = (AV*)SvRV(obj); |
60 | sv = *av_fetch(list,0,TRUE); ds.msg_perm.uid = SvIV(sv); |
61 | sv = *av_fetch(list,1,TRUE); ds.msg_perm.gid = SvIV(sv); |
62 | sv = *av_fetch(list,4,TRUE); ds.msg_perm.mode = SvIV(sv); |
63 | sv = *av_fetch(list,6,TRUE); ds.msg_qbytes = SvIV(sv); |
64 | ST(0) = sv_2mortal(newSVpv((char *)&ds,sizeof(ds))); |
65 | XSRETURN(1); |
6087ac44 |
66 | #else |
67 | croak("System V msgxxx is not implemented on this machine"); |
68 | #endif |
0ade1984 |
69 | } |
70 | |
71 | void |
72 | unpack(obj,buf) |
73 | SV * obj |
74 | SV * buf |
75 | PPCODE: |
76 | { |
6087ac44 |
77 | #ifdef HAS_MSG |
0ade1984 |
78 | STRLEN len; |
79 | SV **sv_ptr; |
80 | struct msqid_ds *ds = (struct msqid_ds *)SvPV(buf,len); |
81 | AV *list = (AV*)SvRV(obj); |
82 | if (len != sizeof(*ds)) { |
83 | croak("Bad arg length for %s, length is %d, should be %d", |
84 | "IPC::Msg::stat", |
85 | len, sizeof(*ds)); |
86 | } |
87 | sv_ptr = av_fetch(list,0,TRUE); |
88 | sv_setiv(*sv_ptr, ds->msg_perm.uid); |
89 | sv_ptr = av_fetch(list,1,TRUE); |
90 | sv_setiv(*sv_ptr, ds->msg_perm.gid); |
91 | sv_ptr = av_fetch(list,2,TRUE); |
92 | sv_setiv(*sv_ptr, ds->msg_perm.cuid); |
93 | sv_ptr = av_fetch(list,3,TRUE); |
94 | sv_setiv(*sv_ptr, ds->msg_perm.cgid); |
95 | sv_ptr = av_fetch(list,4,TRUE); |
96 | sv_setiv(*sv_ptr, ds->msg_perm.mode); |
97 | sv_ptr = av_fetch(list,5,TRUE); |
98 | sv_setiv(*sv_ptr, ds->msg_qnum); |
99 | sv_ptr = av_fetch(list,6,TRUE); |
100 | sv_setiv(*sv_ptr, ds->msg_qbytes); |
101 | sv_ptr = av_fetch(list,7,TRUE); |
102 | sv_setiv(*sv_ptr, ds->msg_lspid); |
103 | sv_ptr = av_fetch(list,8,TRUE); |
104 | sv_setiv(*sv_ptr, ds->msg_lrpid); |
105 | sv_ptr = av_fetch(list,9,TRUE); |
106 | sv_setiv(*sv_ptr, ds->msg_stime); |
107 | sv_ptr = av_fetch(list,10,TRUE); |
108 | sv_setiv(*sv_ptr, ds->msg_rtime); |
109 | sv_ptr = av_fetch(list,11,TRUE); |
110 | sv_setiv(*sv_ptr, ds->msg_ctime); |
111 | XSRETURN(1); |
6087ac44 |
112 | #else |
113 | croak("System V msgxxx is not implemented on this machine"); |
114 | #endif |
0ade1984 |
115 | } |
116 | |
117 | MODULE=IPC::SysV PACKAGE=IPC::Semaphore::stat |
118 | |
119 | void |
120 | unpack(obj,ds) |
121 | SV * obj |
122 | SV * ds |
123 | PPCODE: |
124 | { |
6087ac44 |
125 | #ifdef HAS_SEM |
0ade1984 |
126 | STRLEN len; |
127 | AV *list = (AV*)SvRV(obj); |
128 | struct semid_ds *data = (struct semid_ds *)SvPV(ds,len); |
129 | if(!sv_isa(obj, "IPC::Semaphore::stat")) |
130 | croak("method %s not called a %s object", |
131 | "unpack","IPC::Semaphore::stat"); |
132 | if (len != sizeof(*data)) { |
133 | croak("Bad arg length for %s, length is %d, should be %d", |
134 | "IPC::Semaphore::stat", |
135 | len, sizeof(*data)); |
136 | } |
137 | sv_setiv(*av_fetch(list,0,TRUE), data[0].sem_perm.uid); |
138 | sv_setiv(*av_fetch(list,1,TRUE), data[0].sem_perm.gid); |
139 | sv_setiv(*av_fetch(list,2,TRUE), data[0].sem_perm.cuid); |
140 | sv_setiv(*av_fetch(list,3,TRUE), data[0].sem_perm.cgid); |
141 | sv_setiv(*av_fetch(list,4,TRUE), data[0].sem_perm.mode); |
142 | sv_setiv(*av_fetch(list,5,TRUE), data[0].sem_ctime); |
143 | sv_setiv(*av_fetch(list,6,TRUE), data[0].sem_otime); |
144 | sv_setiv(*av_fetch(list,7,TRUE), data[0].sem_nsems); |
145 | XSRETURN(1); |
6087ac44 |
146 | #else |
147 | croak("System V semxxx is not implemented on this machine"); |
148 | #endif |
0ade1984 |
149 | } |
150 | |
151 | void |
152 | pack(obj) |
153 | SV * obj |
154 | PPCODE: |
155 | { |
6087ac44 |
156 | #ifdef HAS_SEM |
0ade1984 |
157 | SV **sv_ptr; |
158 | SV *sv; |
159 | struct semid_ds ds; |
160 | AV *list = (AV*)SvRV(obj); |
161 | if(!sv_isa(obj, "IPC::Semaphore::stat")) |
162 | croak("method %s not called a %s object", |
163 | "pack","IPC::Semaphore::stat"); |
164 | if((sv_ptr = av_fetch(list,0,TRUE)) && (sv = *sv_ptr)) |
165 | ds.sem_perm.uid = SvIV(*sv_ptr); |
166 | if((sv_ptr = av_fetch(list,1,TRUE)) && (sv = *sv_ptr)) |
167 | ds.sem_perm.gid = SvIV(*sv_ptr); |
168 | if((sv_ptr = av_fetch(list,2,TRUE)) && (sv = *sv_ptr)) |
169 | ds.sem_perm.cuid = SvIV(*sv_ptr); |
170 | if((sv_ptr = av_fetch(list,3,TRUE)) && (sv = *sv_ptr)) |
171 | ds.sem_perm.cgid = SvIV(*sv_ptr); |
172 | if((sv_ptr = av_fetch(list,4,TRUE)) && (sv = *sv_ptr)) |
173 | ds.sem_perm.mode = SvIV(*sv_ptr); |
174 | if((sv_ptr = av_fetch(list,5,TRUE)) && (sv = *sv_ptr)) |
175 | ds.sem_ctime = SvIV(*sv_ptr); |
176 | if((sv_ptr = av_fetch(list,6,TRUE)) && (sv = *sv_ptr)) |
177 | ds.sem_otime = SvIV(*sv_ptr); |
178 | if((sv_ptr = av_fetch(list,7,TRUE)) && (sv = *sv_ptr)) |
179 | ds.sem_nsems = SvIV(*sv_ptr); |
180 | ST(0) = sv_2mortal(newSVpv((char *)&ds,sizeof(ds))); |
181 | XSRETURN(1); |
6087ac44 |
182 | #else |
183 | croak("System V semxxx is not implemented on this machine"); |
184 | #endif |
0ade1984 |
185 | } |
186 | |
187 | MODULE=IPC::SysV PACKAGE=IPC::SysV |
188 | |
189 | int |
190 | ftok(path, id) |
191 | char * path |
192 | int id |
193 | CODE: |
194 | #if defined(HAS_SEM) || defined(HAS_SHM) |
195 | key_t k = ftok(path, id); |
6b88bc9c |
196 | ST(0) = k == (key_t) -1 ? &PL_sv_undef : sv_2mortal(newSViv(k)); |
0ade1984 |
197 | #else |
198 | DIE(no_func, "ftok"); |
199 | #endif |
200 | |
201 | int |
202 | SHMLBA() |
203 | CODE: |
204 | #ifdef SHMLBA |
205 | ST(0) = sv_2mortal(newSViv(SHMLBA)); |
206 | #else |
207 | croak("SHMLBA is not defined on this architecture"); |
208 | #endif |
209 | |
210 | BOOT: |
211 | { |
212 | HV *stash = gv_stashpvn("IPC::SysV", 9, TRUE); |
213 | /* |
214 | * constant subs for IPC::SysV |
215 | */ |
216 | struct { char *n; I32 v; } IPC__SysV__const[] = { |
217 | #ifdef GETVAL |
218 | {"GETVAL", GETVAL}, |
219 | #endif |
220 | #ifdef GETPID |
221 | {"GETPID", GETPID}, |
222 | #endif |
223 | #ifdef GETNCNT |
224 | {"GETNCNT", GETNCNT}, |
225 | #endif |
226 | #ifdef GETZCNT |
227 | {"GETZCNT", GETZCNT}, |
228 | #endif |
229 | #ifdef GETALL |
230 | {"GETALL", GETALL}, |
231 | #endif |
232 | #ifdef IPC_ALLOC |
233 | {"IPC_ALLOC", IPC_ALLOC}, |
234 | #endif |
235 | #ifdef IPC_CREAT |
236 | {"IPC_CREAT", IPC_CREAT}, |
237 | #endif |
238 | #ifdef IPC_EXCL |
239 | {"IPC_EXCL", IPC_EXCL}, |
240 | #endif |
241 | #ifdef IPC_GETACL |
242 | {"IPC_GETACL", IPC_EXCL}, |
243 | #endif |
244 | #ifdef IPC_LOCKED |
245 | {"IPC_LOCKED", IPC_LOCKED}, |
246 | #endif |
247 | #ifdef IPC_M |
248 | {"IPC_M", IPC_M}, |
249 | #endif |
250 | #ifdef IPC_NOERROR |
251 | {"IPC_NOERROR", IPC_NOERROR}, |
252 | #endif |
253 | #ifdef IPC_NOWAIT |
254 | {"IPC_NOWAIT", IPC_NOWAIT}, |
255 | #endif |
256 | #ifdef IPC_PRIVATE |
257 | {"IPC_PRIVATE", IPC_PRIVATE}, |
258 | #endif |
259 | #ifdef IPC_R |
260 | {"IPC_R", IPC_R}, |
261 | #endif |
262 | #ifdef IPC_RMID |
263 | {"IPC_RMID", IPC_RMID}, |
264 | #endif |
265 | #ifdef IPC_SET |
266 | {"IPC_SET", IPC_SET}, |
267 | #endif |
268 | #ifdef IPC_SETACL |
269 | {"IPC_SETACL", IPC_SETACL}, |
270 | #endif |
271 | #ifdef IPC_SETLABEL |
272 | {"IPC_SETLABEL", IPC_SETLABEL}, |
273 | #endif |
274 | #ifdef IPC_STAT |
275 | {"IPC_STAT", IPC_STAT}, |
276 | #endif |
277 | #ifdef IPC_W |
278 | {"IPC_W", IPC_W}, |
279 | #endif |
280 | #ifdef IPC_WANTED |
281 | {"IPC_WANTED", IPC_WANTED}, |
282 | #endif |
283 | #ifdef MSG_NOERROR |
284 | {"MSG_NOERROR", MSG_NOERROR}, |
285 | #endif |
286 | #ifdef MSG_FWAIT |
287 | {"MSG_FWAIT", MSG_FWAIT}, |
288 | #endif |
289 | #ifdef MSG_LOCKED |
290 | {"MSG_LOCKED", MSG_LOCKED}, |
291 | #endif |
292 | #ifdef MSG_MWAIT |
293 | {"MSG_MWAIT", MSG_MWAIT}, |
294 | #endif |
295 | #ifdef MSG_WAIT |
296 | {"MSG_WAIT", MSG_WAIT}, |
297 | #endif |
298 | #ifdef MSG_R |
299 | {"MSG_R", MSG_R}, |
300 | #endif |
301 | #ifdef MSG_RWAIT |
302 | {"MSG_RWAIT", MSG_RWAIT}, |
303 | #endif |
304 | #ifdef MSG_STAT |
305 | {"MSG_STAT", MSG_STAT}, |
306 | #endif |
307 | #ifdef MSG_W |
308 | {"MSG_W", MSG_W}, |
309 | #endif |
310 | #ifdef MSG_WWAIT |
311 | {"MSG_WWAIT", MSG_WWAIT}, |
312 | #endif |
313 | #ifdef SEM_A |
314 | {"SEM_A", SEM_A}, |
315 | #endif |
316 | #ifdef SEM_ALLOC |
317 | {"SEM_ALLOC", SEM_ALLOC}, |
318 | #endif |
319 | #ifdef SEM_DEST |
320 | {"SEM_DEST", SEM_DEST}, |
321 | #endif |
322 | #ifdef SEM_ERR |
323 | {"SEM_ERR", SEM_ERR}, |
324 | #endif |
325 | #ifdef SEM_R |
326 | {"SEM_R", SEM_R}, |
327 | #endif |
328 | #ifdef SEM_ORDER |
329 | {"SEM_ORDER", SEM_ORDER}, |
330 | #endif |
331 | #ifdef SEM_UNDO |
332 | {"SEM_UNDO", SEM_UNDO}, |
333 | #endif |
334 | #ifdef SETVAL |
335 | {"SETVAL", SETVAL}, |
336 | #endif |
337 | #ifdef SETALL |
338 | {"SETALL", SETALL}, |
339 | #endif |
340 | #ifdef SHM_CLEAR |
341 | {"SHM_CLEAR", SHM_CLEAR}, |
342 | #endif |
343 | #ifdef SHM_COPY |
344 | {"SHM_COPY", SHM_COPY}, |
345 | #endif |
346 | #ifdef SHM_DCACHE |
347 | {"SHM_DCACHE", SHM_DCACHE}, |
348 | #endif |
349 | #ifdef SHM_DEST |
350 | {"SHM_DEST", SHM_DEST}, |
351 | #endif |
352 | #ifdef SHM_ECACHE |
353 | {"SHM_ECACHE", SHM_ECACHE}, |
354 | #endif |
355 | #ifdef SHM_FMAP |
356 | {"SHM_FMAP", SHM_FMAP}, |
357 | #endif |
358 | #ifdef SHM_ICACHE |
359 | {"SHM_ICACHE", SHM_ICACHE}, |
360 | #endif |
361 | #ifdef SHM_INIT |
362 | {"SHM_INIT", SHM_INIT}, |
363 | #endif |
364 | #ifdef SHM_LOCK |
365 | {"SHM_LOCK", SHM_LOCK}, |
366 | #endif |
367 | #ifdef SHM_LOCKED |
368 | {"SHM_LOCKED", SHM_LOCKED}, |
369 | #endif |
370 | #ifdef SHM_MAP |
371 | {"SHM_MAP", SHM_MAP}, |
372 | #endif |
373 | #ifdef SHM_NOSWAP |
374 | {"SHM_NOSWAP", SHM_NOSWAP}, |
375 | #endif |
376 | #ifdef SHM_RDONLY |
377 | {"SHM_RDONLY", SHM_RDONLY}, |
378 | #endif |
379 | #ifdef SHM_REMOVED |
380 | {"SHM_REMOVED", SHM_REMOVED}, |
381 | #endif |
382 | #ifdef SHM_RND |
383 | {"SHM_RND", SHM_RND}, |
384 | #endif |
385 | #ifdef SHM_SHARE_MMU |
386 | {"SHM_SHARE_MMU", SHM_SHARE_MMU}, |
387 | #endif |
388 | #ifdef SHM_SHATTR |
389 | {"SHM_SHATTR", SHM_SHATTR}, |
390 | #endif |
391 | #ifdef SHM_SIZE |
392 | {"SHM_SIZE", SHM_SIZE}, |
393 | #endif |
394 | #ifdef SHM_UNLOCK |
395 | {"SHM_UNLOCK", SHM_UNLOCK}, |
396 | #endif |
397 | #ifdef SHM_W |
398 | {"SHM_W", SHM_W}, |
399 | #endif |
400 | #ifdef S_IRUSR |
401 | {"S_IRUSR", S_IRUSR}, |
402 | #endif |
403 | #ifdef S_IWUSR |
404 | {"S_IWUSR", S_IWUSR}, |
405 | #endif |
406 | #ifdef S_IRWXU |
407 | {"S_IRWXU", S_IRWXU}, |
408 | #endif |
409 | #ifdef S_IRGRP |
410 | {"S_IRGRP", S_IRGRP}, |
411 | #endif |
412 | #ifdef S_IWGRP |
413 | {"S_IWGRP", S_IWGRP}, |
414 | #endif |
415 | #ifdef S_IRWXG |
416 | {"S_IRWXG", S_IRWXG}, |
417 | #endif |
418 | #ifdef S_IROTH |
419 | {"S_IROTH", S_IROTH}, |
420 | #endif |
421 | #ifdef S_IWOTH |
422 | {"S_IWOTH", S_IWOTH}, |
423 | #endif |
424 | #ifdef S_IRWXO |
425 | {"S_IRWXO", S_IRWXO}, |
426 | #endif |
427 | {Nullch,0}}; |
428 | char *name; |
429 | int i; |
430 | |
431 | for(i = 0 ; name = IPC__SysV__const[i].n ; i++) { |
432 | newCONSTSUB(stash,name, newSViv(IPC__SysV__const[i].v)); |
433 | } |
434 | } |
435 | |