Deleted Added
full compact
login_class.c (169189) login_class.c (180815)
1/*-
2 * Copyright (c) 1996 by
3 * Sean Eric Fagan <sef@kithrup.com>
4 * David Nugent <davidn@blaze.net.au>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, is permitted provided that the following conditions

--- 9 unchanged lines hidden (view full) ---

18 * 4. Absolutely no warranty of function or purpose is made by the authors.
19 * 5. Modifications may be freely made to this file providing the above
20 * conditions are met.
21 *
22 * High-level routines relating to use of the user capabilities database
23 */
24
25#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1996 by
3 * Sean Eric Fagan <sef@kithrup.com>
4 * David Nugent <davidn@blaze.net.au>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, is permitted provided that the following conditions

--- 9 unchanged lines hidden (view full) ---

18 * 4. Absolutely no warranty of function or purpose is made by the authors.
19 * 5. Modifications may be freely made to this file providing the above
20 * conditions are met.
21 *
22 * High-level routines relating to use of the user capabilities database
23 */
24
25#include <sys/cdefs.h>
26__FBSDID("$FreeBSD: head/lib/libutil/login_class.c 169189 2007-05-01 18:50:33Z yar $");
26__FBSDID("$FreeBSD: head/lib/libutil/login_class.c 180815 2008-07-25 19:58:14Z brooks $");
27
28#include <sys/types.h>
27
28#include <sys/types.h>
29#include <sys/param.h>
29#include <sys/stat.h>
30#include <sys/time.h>
31#include <sys/resource.h>
30#include <sys/stat.h>
31#include <sys/time.h>
32#include <sys/resource.h>
33#include <sys/cpuset.h>
32#include <sys/mac.h>
33#include <sys/rtprio.h>
34#include <errno.h>
35#include <fcntl.h>
36#include <login_cap.h>
37#include <paths.h>
38#include <pwd.h>
39#include <stdio.h>

--- 194 unchanged lines hidden (view full) ---

234 }
235 ++set_env;
236 }
237 }
238 }
239}
240
241
34#include <sys/mac.h>
35#include <sys/rtprio.h>
36#include <errno.h>
37#include <fcntl.h>
38#include <login_cap.h>
39#include <paths.h>
40#include <pwd.h>
41#include <stdio.h>

--- 194 unchanged lines hidden (view full) ---

236 }
237 ++set_env;
238 }
239 }
240 }
241}
242
243
244static int
245list2cpuset(const char *list, cpuset_t *mask)
246{
247 enum { NONE, NUM, DASH } state;
248 int lastnum;
249 int curnum;
250 const char *l;
251
252 state = NONE;
253 curnum = lastnum = 0;
254 for (l = list; *l != '\0';) {
255 if (isdigit(*l)) {
256 curnum = atoi(l);
257 if (curnum > CPU_SETSIZE)
258 errx(EXIT_FAILURE,
259 "Only %d cpus supported", CPU_SETSIZE);
260 while (isdigit(*l))
261 l++;
262 switch (state) {
263 case NONE:
264 lastnum = curnum;
265 state = NUM;
266 break;
267 case DASH:
268 for (; lastnum <= curnum; lastnum++)
269 CPU_SET(lastnum, mask);
270 state = NONE;
271 break;
272 case NUM:
273 default:
274 return (0);
275 }
276 continue;
277 }
278 switch (*l) {
279 case ',':
280 switch (state) {
281 case NONE:
282 break;
283 case NUM:
284 CPU_SET(curnum, mask);
285 state = NONE;
286 break;
287 case DASH:
288 return (0);
289 break;
290 }
291 break;
292 case '-':
293 if (state != NUM)
294 return (0);
295 state = DASH;
296 break;
297 default:
298 return (0);
299 }
300 l++;
301 }
302 switch (state) {
303 case NONE:
304 break;
305 case NUM:
306 CPU_SET(curnum, mask);
307 break;
308 case DASH:
309 return (0);
310 }
311 return 1;
312}
313
314
315void
316setclasscpumask(login_cap_t *lc)
317{
318 const char *maskstr;
319 cpuset_t maskset;
320 cpusetid_t setid;
321
322 maskstr = login_getcapstr(lc, "cpumask", NULL, NULL);
323 CPU_ZERO(&maskset);
324 if (maskstr == NULL)
325 return;
326 if (strcasecmp("default", maskstr) == 0)
327 return;
328 if (!list2cpuset(maskstr, &maskset)) {
329 syslog(LOG_WARNING,
330 "list2cpuset(%s) invalid mask specification", maskstr);
331 return;
332 }
333
334 if (cpuset(&setid) != 0) {
335 syslog(LOG_ERR, "cpuset(): %s", strerror(errno));
336 return;
337 }
338
339 if (cpuset_setaffinity(CPU_LEVEL_CPUSET, CPU_WHICH_PID, -1,
340 sizeof(maskset), &maskset) != 0)
341 syslog(LOG_ERR, "cpuset_setaffinity(%s): %s", maskstr,
342 strerror(errno));
343}
344
345
242/*
243 * setclasscontext()
244 *
245 * For the login class <class>, set various class context values
246 * (limits, mainly) to the values for that class. Which values are
247 * set are controlled by <flags> -- see <login_class.h> for the
248 * possible values.
249 *

--- 34 unchanged lines hidden (view full) ---

284 if (flags & LOGIN_SETUMASK)
285 mymask = (mode_t)login_getcapnum(lc, "umask", mymask, mymask);
286 /* Set paths */
287 if (flags & LOGIN_SETPATH)
288 setclassenvironment(lc, pwd, 1);
289 /* Set environment */
290 if (flags & LOGIN_SETENV)
291 setclassenvironment(lc, pwd, 0);
346/*
347 * setclasscontext()
348 *
349 * For the login class <class>, set various class context values
350 * (limits, mainly) to the values for that class. Which values are
351 * set are controlled by <flags> -- see <login_class.h> for the
352 * possible values.
353 *

--- 34 unchanged lines hidden (view full) ---

388 if (flags & LOGIN_SETUMASK)
389 mymask = (mode_t)login_getcapnum(lc, "umask", mymask, mymask);
390 /* Set paths */
391 if (flags & LOGIN_SETPATH)
392 setclassenvironment(lc, pwd, 1);
393 /* Set environment */
394 if (flags & LOGIN_SETENV)
395 setclassenvironment(lc, pwd, 0);
396 /* Set cpu affinity */
397 if (flags & LOGIN_SETCPUMASK)
398 setclasscpumask(lc);
292 }
293 return mymask;
294}
295
296
297
298/*
299 * setusercontext()

--- 130 unchanged lines hidden ---
399 }
400 return mymask;
401}
402
403
404
405/*
406 * setusercontext()

--- 130 unchanged lines hidden ---