Print this page
3900 illumos will not build against gcc compiled perl
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/perl/contrib/Sun/Solaris/Project/Project.xs
+++ new/usr/src/cmd/perl/contrib/Sun/Solaris/Project/Project.xs
1 1 /*
2 2 * Copyright (c) 1999, 2007, Oracle and/or its affiliates. All rights reserved.
3 + * Copyright (c) 2014 Racktop Systems.
3 4 */
4 5 /*
5 6 * Project.xs contains XS wrappers for the project database maniplulation
6 7 * functions as provided by libproject and described in getprojent(3EXACCT).
7 8 */
8 9
9 10 /* Solaris includes. */
10 11 #include <zone.h>
11 12 #include <project.h>
12 13 #include <pool.h>
13 14 #include <sys/pool_impl.h>
14 15 #include <rctl.h>
15 16 #include <stdio.h>
16 17
17 18 /* Perl includes. */
18 19 #include "EXTERN.h"
19 20 #include "perl.h"
20 21 #include "XSUB.h"
21 22
22 23 /*
23 24 * Convert and save a struct project on the perl XS return stack.
24 25 * In a void context it returns nothing, in a scalar context it returns just
25 26 * the name of the project and in a list context it returns a 6-element list
26 27 * consisting of (name, projid, comment, users, groups, attr), where users and
27 28 * groups are references to arrays containing the appropriate lists.
28 29 */
29 30 static int
30 31 pushret_project(const struct project *proj)
31 32 {
32 33 char **cp;
33 34 AV *ary;
34 35
35 36 dSP;
36 37 if (GIMME_V == G_SCALAR) {
37 38 EXTEND(SP, 1);
38 39 PUSHs(sv_2mortal(newSVpv(proj->pj_name, 0)));
39 40 PUTBACK;
40 41 return (1);
41 42 } else if (GIMME_V == G_ARRAY) {
42 43 EXTEND(SP, 6);
43 44 PUSHs(sv_2mortal(newSVpv(proj->pj_name, 0)));
44 45 PUSHs(sv_2mortal(newSViv(proj->pj_projid)));
45 46 PUSHs(sv_2mortal(newSVpv(proj->pj_comment, 0)));
46 47 ary = newAV();
47 48 for (cp = proj->pj_users; *cp != NULL; cp++) {
48 49 av_push(ary, newSVpv(*cp, 0));
49 50 }
50 51 PUSHs(sv_2mortal(newRV_noinc((SV *)ary)));
51 52 ary = newAV();
52 53 for (cp = proj->pj_groups; *cp != NULL; cp++) {
53 54 av_push(ary, newSVpv(*cp, 0));
54 55 }
55 56 PUSHs(sv_2mortal(newRV_noinc((SV *)ary)));
56 57 PUSHs(sv_2mortal(newSVpv(proj->pj_attr, 0)));
57 58 PUTBACK;
58 59 return (6);
59 60 } else {
60 61 return (0);
61 62 }
62 63 }
63 64
64 65 static int
65 66 pwalk_cb(const projid_t project, void *walk_data)
66 67 {
67 68 int *nitemsp;
68 69
69 70 dSP;
70 71 nitemsp = (int *) walk_data;
71 72 EXTEND(SP, 1);
72 73 PUSHs(sv_2mortal(newSViv(project)));
73 74 (*nitemsp)++;
74 75 PUTBACK;
75 76 return (0);
76 77 }
77 78
78 79 /*
79 80 * The XS code exported to perl is below here. Note that the XS preprocessor
80 81 * has its own commenting syntax, so all comments from this point on are in
81 82 * that form. Note also that the PUTBACK; lines are necessary to synchronise
82 83 * the local and global views of the perl stack before calling pushret_project,
83 84 * as the code generated by the perl XS compiler twiddles with the stack on
84 85 * entry to an XSUB.
85 86 */
86 87
87 88 MODULE = Sun::Solaris::Project PACKAGE = Sun::Solaris::Project
88 89 PROTOTYPES: ENABLE
89 90
90 91 #
91 92 # Define any constants that need to be exported. By doing it this way we can
92 93 # avoid the overhead of using the DynaLoader package, and in addition constants
93 94 # defined using this mechanism are eligible for inlining by the perl
94 95 # interpreter at compile time.
95 96 #
96 97 BOOT:
97 98 {
98 99 HV *stash;
99 100 char buf[128];
100 101 stash = gv_stashpv("Sun::Solaris::Project", TRUE);
101 102 newCONSTSUB(stash, "MAXPROJID", newSViv(MAXPROJID));
102 103 newCONSTSUB(stash, "PROJNAME_MAX", newSViv(PROJNAME_MAX));
103 104 newCONSTSUB(stash, "PROJF_PATH",
104 105 newSVpv(PROJF_PATH, sizeof (PROJF_PATH) - 1));
105 106 newCONSTSUB(stash, "PROJECT_BUFSZ", newSViv(PROJECT_BUFSZ));
106 107 newCONSTSUB(stash, "SETPROJ_ERR_TASK", newSViv(SETPROJ_ERR_TASK));
107 108 newCONSTSUB(stash, "SETPROJ_ERR_POOL", newSViv(SETPROJ_ERR_POOL));
108 109 newCONSTSUB(stash, "RCTL_GLOBAL_NOBASIC",
109 110 newSViv(RCTL_GLOBAL_NOBASIC));
110 111 newCONSTSUB(stash, "RCTL_GLOBAL_LOWERABLE",
111 112 newSViv(RCTL_GLOBAL_LOWERABLE));
112 113 newCONSTSUB(stash, "RCTL_GLOBAL_DENY_ALWAYS",
113 114 newSViv(RCTL_GLOBAL_DENY_ALWAYS));
114 115 newCONSTSUB(stash, "RCTL_GLOBAL_DENY_NEVER",
115 116 newSViv(RCTL_GLOBAL_DENY_NEVER));
116 117 newCONSTSUB(stash, "RCTL_GLOBAL_FILE_SIZE",
117 118 newSViv(RCTL_GLOBAL_FILE_SIZE));
118 119 newCONSTSUB(stash, "RCTL_GLOBAL_CPU_TIME",
119 120 newSViv(RCTL_GLOBAL_CPU_TIME));
120 121 newCONSTSUB(stash, "RCTL_GLOBAL_SIGNAL_NEVER",
121 122 newSViv(RCTL_GLOBAL_SIGNAL_NEVER));
122 123 newCONSTSUB(stash, "RCTL_GLOBAL_INFINITE",
123 124 newSViv(RCTL_GLOBAL_INFINITE));
124 125 newCONSTSUB(stash, "RCTL_GLOBAL_UNOBSERVABLE",
125 126 newSViv(RCTL_GLOBAL_UNOBSERVABLE));
126 127 newCONSTSUB(stash, "RCTL_GLOBAL_BYTES",
127 128 newSViv(RCTL_GLOBAL_BYTES));
128 129 newCONSTSUB(stash, "RCTL_GLOBAL_SECONDS",
129 130 newSViv(RCTL_GLOBAL_SECONDS));
130 131 newCONSTSUB(stash, "RCTL_GLOBAL_COUNT",
131 132 newSViv(RCTL_GLOBAL_COUNT));
132 133 sprintf(buf, "%llu", UINT64_MAX);
133 134 newCONSTSUB(stash, "RCTL_MAX_VALUE",
134 135 newSVpv(buf, strlen(buf)));
135 136 }
136 137
137 138 projid_t
138 139 getprojid()
139 140
140 141 int
141 142 setproject(name, user_name, flags)
142 143 const char *name;
143 144 const char *user_name
144 145 uint_t flags
145 146
146 147 void
147 148 activeprojects()
148 149 PREINIT:
149 150 int nitems;
150 151 PPCODE:
151 152 PUTBACK;
152 153 nitems = 0;
↓ open down ↓ |
140 lines elided |
↑ open up ↑ |
153 154 project_walk(&pwalk_cb, (void*)&nitems);
154 155 XSRETURN(nitems);
155 156
156 157 void
157 158 getprojent()
158 159 PREINIT:
159 160 struct project proj, *projp;
160 161 char buf[PROJECT_BUFSZ];
161 162 PPCODE:
162 163 PUTBACK;
163 - if (projp = getprojent(&proj, buf, sizeof (buf))) {
164 + if ((projp = getprojent(&proj, buf, sizeof (buf)))) {
164 165 XSRETURN(pushret_project(projp));
165 166 } else {
166 167 XSRETURN_EMPTY;
167 168 }
168 169
169 170 void
170 171 setprojent()
171 172
172 173 void
173 174 endprojent()
174 175
175 176 void
176 177 getprojbyname(name)
177 178 char *name
178 179 PREINIT:
179 180 struct project proj, *projp;
180 181 char buf[PROJECT_BUFSZ];
181 182 PPCODE:
182 183 PUTBACK;
183 - if (projp = getprojbyname(name, &proj, buf, sizeof (buf))) {
184 + if ((projp = getprojbyname(name, &proj, buf, sizeof (buf)))) {
184 185 XSRETURN(pushret_project(projp));
185 186 } else {
186 187 XSRETURN_EMPTY;
187 188 }
188 189
189 190 void
190 191 getprojbyid(id)
191 192 projid_t id
192 193 PREINIT:
193 194 struct project proj, *projp;
194 195 char buf[PROJECT_BUFSZ];
195 196 PPCODE:
196 197 PUTBACK;
197 - if (projp = getprojbyid(id, &proj, buf, sizeof (buf))) {
198 + if ((projp = getprojbyid(id, &proj, buf, sizeof (buf)))) {
198 199 XSRETURN(pushret_project(projp));
199 200 } else {
200 201 XSRETURN_EMPTY;
201 202 }
202 203
203 204 void
204 205 getdefaultproj(user)
205 206 char *user
206 207 PREINIT:
207 208 struct project proj, *projp;
208 209 char buf[PROJECT_BUFSZ];
209 210 PPCODE:
210 211 PUTBACK;
211 - if (projp = getdefaultproj(user, &proj, buf, sizeof (buf))) {
212 + if ((projp = getdefaultproj(user, &proj, buf, sizeof (buf)))) {
212 213 XSRETURN(pushret_project(projp));
213 214 } else {
214 215 XSRETURN_EMPTY;
215 216 }
216 217
217 218 void
218 219 fgetprojent(fh)
219 220 FILE *fh
220 221 PREINIT:
221 222 struct project proj, *projp;
222 223 char buf[PROJECT_BUFSZ];
223 224 PPCODE:
224 225 PUTBACK;
225 - if (projp = fgetprojent(fh, &proj, buf, sizeof (buf))) {
226 + if ((projp = fgetprojent(fh, &proj, buf, sizeof (buf)))) {
226 227 XSRETURN(pushret_project(projp));
227 228 } else {
228 229 XSRETURN_EMPTY;
229 230 }
230 231
231 232 bool
232 233 inproj(user, proj)
233 234 char *user
234 235 char *proj
235 236 PREINIT:
236 237 char buf[PROJECT_BUFSZ];
237 238 CODE:
238 239 RETVAL = inproj(user, proj, buf, sizeof (buf));
240 +OUTPUT:
241 + RETVAL
239 242
240 243
241 244 int
242 245 getprojidbyname(proj)
243 246 char *proj
244 247 PREINIT:
245 248 int id;
246 249 PPCODE:
247 250 if ((id = getprojidbyname(proj)) == -1) {
248 251 XSRETURN_UNDEF;
249 252 } else {
250 253 XSRETURN_IV(id);
251 254 }
252 255
253 256
254 257 # rctl_get_info(name)
255 258 #
256 259 # For the given rctl name, returns the list
257 260 # ($max, $flags), where $max is the integer value
258 261 # of the system rctl, and $flags are the rctl's
259 262 # global flags, as returned by rctlblk_get_global_flags
260 263 #
↓ open down ↓ |
12 lines elided |
↑ open up ↑ |
261 264 # This function is private to Project.pm
262 265 void
263 266 rctl_get_info(name)
264 267 char *name
265 268 PREINIT:
266 269 rctlblk_t *blk1 = NULL;
267 270 rctlblk_t *blk2 = NULL;
268 271 rctlblk_t *tmp = NULL;
269 272 rctl_priv_t priv;
270 273 rctl_qty_t value;
271 - int flags;
274 + int flags = 0;
272 275 int ret;
273 276 int err = 0;
274 277 char string[24]; /* 24 will always hold a uint64_t */
275 278 PPCODE:
276 279 Newc(0, blk1, rctlblk_size(), char, rctlblk_t);
277 280 if (blk1 == NULL) {
278 281 err = 1;
279 282 goto out;
280 283 }
281 284 Newc(1, blk2, rctlblk_size(), char, rctlblk_t);
282 285 if (blk2 == NULL) {
283 286 err = 1;
284 287 goto out;
285 288 }
286 289 ret = getrctl(name, NULL, blk1, RCTL_FIRST);
287 290 if (ret != 0) {
288 291 err = 1;
289 292 goto out;
290 293 }
291 294 priv = rctlblk_get_privilege(blk1);
292 295 while (priv != RCPRIV_SYSTEM) {
293 296 tmp = blk2;
294 297 blk2 = blk1;
295 298 blk1 = tmp;
296 299 ret = getrctl(name, blk2, blk1, RCTL_NEXT);
297 300 if (ret != 0) {
298 301 err = 1;
299 302 goto out;
300 303 }
301 304 priv = rctlblk_get_privilege(blk1);
302 305 }
303 306 value = rctlblk_get_value(blk1);
304 307 flags = rctlblk_get_global_flags(blk1);
305 308 ret = sprintf(string, "%llu", value);
306 309 if (ret <= 0) {
307 310 err = 1;
308 311 }
309 312 out:
310 313 if (blk1)
311 314 Safefree(blk1);
312 315 if (blk2)
313 316 Safefree(blk2);
314 317 if (err)
315 318 XSRETURN(0);
316 319
317 320 XPUSHs(sv_2mortal(newSVpv(string, 0)));
318 321 XPUSHs(sv_2mortal(newSViv(flags)));
319 322 XSRETURN(2);
320 323
321 324 #
322 325 # pool_exists(name)
323 326 #
324 327 # Returns 0 a pool with the given name exists on the current system.
325 328 # Returns 1 if pools are disabled or the pool does not exist
326 329 #
327 330 # Used internally by project.pm to validate the project.pool attribute
328 331 #
329 332 # This function is private to Project.pm
330 333 void
331 334 pool_exists(name)
332 335 char *name
333 336 PREINIT:
334 337 pool_conf_t *conf;
335 338 pool_t *pool;
336 339 pool_status_t status;
337 340 int fd;
338 341 PPCODE:
339 342
340 343 /*
341 344 * Determine if pools are enabled using /dev/pool directly, as
342 345 * libpool may not be present.
343 346 */
344 347 if (getzoneid() != GLOBAL_ZONEID) {
345 348 XSRETURN_IV(1);
346 349 }
347 350 if ((fd = open("/dev/pool", O_RDONLY)) < 0) {
348 351 XSRETURN_IV(1);
349 352 }
350 353 if (ioctl(fd, POOL_STATUSQ, &status) < 0) {
351 354 (void) close(fd);
352 355 XSRETURN_IV(1);
353 356 }
354 357 close(fd);
355 358 if (status.ps_io_state != 1) {
356 359 XSRETURN_IV(1);
357 360 }
358 361
359 362 /*
360 363 * If pools are enabled, assume libpool is present.
361 364 */
362 365 conf = pool_conf_alloc();
363 366 if (conf == NULL) {
364 367 XSRETURN_IV(1);
365 368 }
366 369 if (pool_conf_open(conf, pool_dynamic_location(), PO_RDONLY)) {
367 370 pool_conf_free(conf);
368 371 XSRETURN_IV(1);
369 372 }
370 373 pool = pool_get_pool(conf, name);
371 374 if (pool == NULL) {
372 375 pool_conf_close(conf);
373 376 pool_conf_free(conf);
374 377 XSRETURN_IV(1);
375 378 }
376 379 pool_conf_close(conf);
377 380 pool_conf_free(conf);
378 381 XSRETURN_IV(0);
379 382
↓ open down ↓ |
98 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX