MCPcopy Create free account
hub / github.com/F-Stack/f-stack / setclassresources

Function setclassresources

tools/libutil/login_class.c:74–117  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

72
73
74void
75setclassresources(login_cap_t *lc)
76{
77 struct login_res *lr;
78
79 if (lc == NULL)
80 return;
81
82 for (lr = resources; lr->what != NULL; ++lr) {
83 struct rlimit rlim;
84
85 /*
86 * The login.conf file can have <limit>, <limit>-max, and
87 * <limit>-cur entries.
88 * What we do is get the current current- and maximum- limits.
89 * Then, we try to get an entry for <limit> from the capability,
90 * using the current and max limits we just got as the
91 * default/error values.
92 * *Then*, we try looking for <limit>-cur and <limit>-max,
93 * again using the appropriate values as the default/error
94 * conditions.
95 */
96
97 if (getrlimit(lr->why, &rlim) != 0)
98 syslog(LOG_ERR, "getting %s resource limit: %m", lr->what);
99 else {
100 char name_cur[40];
101 char name_max[40];
102 rlim_t rcur = rlim.rlim_cur;
103 rlim_t rmax = rlim.rlim_max;
104
105 sprintf(name_cur, "%s-cur", lr->what);
106 sprintf(name_max, "%s-max", lr->what);
107
108 rcur = (*lr->who)(lc, lr->what, rcur, rcur);
109 rmax = (*lr->who)(lc, lr->what, rmax, rmax);
110 rlim.rlim_cur = (*lr->who)(lc, name_cur, rcur, rcur);
111 rlim.rlim_max = (*lr->who)(lc, name_max, rmax, rmax);
112
113 if (setrlimit(lr->why, &rlim) == -1)
114 syslog(LOG_WARNING, "set class '%s' resource limit %s: %m", lc->lc_class, lr->what);
115 }
116 }
117}
118
119
120

Callers 1

setlogincontextFunction · 0.85

Calls 1

sprintfFunction · 0.85

Tested by

no test coverage detected