Print this page
3900 illumos will not build against gcc compiled perl
4723 Remove unused perl extensions
Reviewed by: Keith Wesolowski <keith.wesolowski@joyent.com>
Reviewed by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
Approved by: Dan McDonald <danmcd@omniti.com>
| 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));
239 240 OUTPUT:
240 241 RETVAL
241 242
242 243
243 244 int
244 245 getprojidbyname(proj)
245 246 char *proj
246 247 PREINIT:
247 248 int id;
248 249 PPCODE:
249 250 if ((id = getprojidbyname(proj)) == -1) {
250 251 XSRETURN_UNDEF;
251 252 } else {
252 253 XSRETURN_IV(id);
253 254 }
254 255
255 256
256 257 # rctl_get_info(name)
257 258 #
258 259 # For the given rctl name, returns the list
259 260 # ($max, $flags), where $max is the integer value
260 261 # of the system rctl, and $flags are the rctl's
261 262 # global flags, as returned by rctlblk_get_global_flags
262 263 #
|
↓ open down ↓ |
27 lines elided |
↑ open up ↑ |
263 264 # This function is private to Project.pm
264 265 void
265 266 rctl_get_info(name)
266 267 char *name
267 268 PREINIT:
268 269 rctlblk_t *blk1 = NULL;
269 270 rctlblk_t *blk2 = NULL;
270 271 rctlblk_t *tmp = NULL;
271 272 rctl_priv_t priv;
272 273 rctl_qty_t value;
273 - int flags;
274 + int flags = 0;
274 275 int ret;
275 276 int err = 0;
276 277 char string[24]; /* 24 will always hold a uint64_t */
277 278 PPCODE:
278 279 Newc(0, blk1, rctlblk_size(), char, rctlblk_t);
279 280 if (blk1 == NULL) {
280 281 err = 1;
281 282 goto out;
282 283 }
283 284 Newc(1, blk2, rctlblk_size(), char, rctlblk_t);
284 285 if (blk2 == NULL) {
285 286 err = 1;
286 287 goto out;
287 288 }
288 289 ret = getrctl(name, NULL, blk1, RCTL_FIRST);
289 290 if (ret != 0) {
290 291 err = 1;
291 292 goto out;
292 293 }
293 294 priv = rctlblk_get_privilege(blk1);
294 295 while (priv != RCPRIV_SYSTEM) {
295 296 tmp = blk2;
296 297 blk2 = blk1;
297 298 blk1 = tmp;
298 299 ret = getrctl(name, blk2, blk1, RCTL_NEXT);
299 300 if (ret != 0) {
300 301 err = 1;
301 302 goto out;
302 303 }
303 304 priv = rctlblk_get_privilege(blk1);
304 305 }
305 306 value = rctlblk_get_value(blk1);
306 307 flags = rctlblk_get_global_flags(blk1);
307 308 ret = sprintf(string, "%llu", value);
308 309 if (ret <= 0) {
309 310 err = 1;
310 311 }
311 312 out:
312 313 if (blk1)
313 314 Safefree(blk1);
314 315 if (blk2)
315 316 Safefree(blk2);
316 317 if (err)
317 318 XSRETURN(0);
318 319
319 320 XPUSHs(sv_2mortal(newSVpv(string, 0)));
320 321 XPUSHs(sv_2mortal(newSViv(flags)));
321 322 XSRETURN(2);
322 323
323 324 #
324 325 # pool_exists(name)
325 326 #
326 327 # Returns 0 a pool with the given name exists on the current system.
327 328 # Returns 1 if pools are disabled or the pool does not exist
328 329 #
329 330 # Used internally by project.pm to validate the project.pool attribute
330 331 #
331 332 # This function is private to Project.pm
332 333 void
333 334 pool_exists(name)
334 335 char *name
335 336 PREINIT:
336 337 pool_conf_t *conf;
337 338 pool_t *pool;
338 339 pool_status_t status;
339 340 int fd;
340 341 PPCODE:
341 342
342 343 /*
343 344 * Determine if pools are enabled using /dev/pool directly, as
344 345 * libpool may not be present.
345 346 */
346 347 if (getzoneid() != GLOBAL_ZONEID) {
347 348 XSRETURN_IV(1);
348 349 }
349 350 if ((fd = open("/dev/pool", O_RDONLY)) < 0) {
350 351 XSRETURN_IV(1);
351 352 }
352 353 if (ioctl(fd, POOL_STATUSQ, &status) < 0) {
353 354 (void) close(fd);
354 355 XSRETURN_IV(1);
355 356 }
356 357 close(fd);
357 358 if (status.ps_io_state != 1) {
358 359 XSRETURN_IV(1);
359 360 }
360 361
361 362 /*
362 363 * If pools are enabled, assume libpool is present.
363 364 */
364 365 conf = pool_conf_alloc();
365 366 if (conf == NULL) {
366 367 XSRETURN_IV(1);
367 368 }
368 369 if (pool_conf_open(conf, pool_dynamic_location(), PO_RDONLY)) {
369 370 pool_conf_free(conf);
370 371 XSRETURN_IV(1);
371 372 }
372 373 pool = pool_get_pool(conf, name);
373 374 if (pool == NULL) {
374 375 pool_conf_close(conf);
375 376 pool_conf_free(conf);
376 377 XSRETURN_IV(1);
377 378 }
378 379 pool_conf_close(conf);
379 380 pool_conf_free(conf);
380 381 XSRETURN_IV(0);
381 382
|
↓ open down ↓ |
98 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX