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