~ubuntu-branches/debian/jessie/systemd/jessie

« back to all changes in this revision

Viewing changes to src/cgroup.c

  • Committer: Package Import Robot
  • Author(s): Tollef Fog Heen, Tollef Fog Heen, Michael Biebl
  • Date: 2012-04-03 19:59:17 UTC
  • mfrom: (1.1.10) (6.1.3 experimental)
  • Revision ID: package-import@ubuntu.com-20120403195917-l532urrbg4pkreas
Tags: 44-1
[ Tollef Fog Heen ]
* New upstream version.
  - Backport 3492207: journal: PAGE_SIZE is not known on ppc and other
    archs
  - Backport 5a2a2a1: journal: react with immediate rotation to a couple
    of more errors
  - Backport 693ce21: util: never follow symlinks in rm_rf_children()
    Fixes CVE-2012-1174, closes: #664364
* Drop output message from init-functions hook, it's pointless.
* Only rmdir /lib/init/rw if it exists.
* Explicitly order debian-fixup before sysinit.target to prevent a
  possible race condition with the creation of sockets.  Thanks to
  Michael Biebl for debugging this.
* Always restart the initctl socket on upgrades, to mask sysvinit
  removing it.

[ Michael Biebl ]
* Remove workaround for non-interactive sessions from pam config again.
* Create compat /dev/initctl symlink in case we are upgrading from a system
  running a newer version of sysvinit (using /run/initctl) and sysvinit is
  replaced with systemd-sysv during the upgrade. Closes: #663219
* Install new man pages.
* Build-Depend on valac (>= 0.12) instead of valac-0.12. Closes: #663323

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
        assert(b->path);
39
39
        assert(b->controller);
40
40
 
41
 
        if (b->realized)
42
 
                return 0;
43
 
 
44
41
        r = cg_create(b->controller, b->path);
45
42
        if (r < 0) {
46
43
                log_warning("Failed to create cgroup %s:%s: %s", b->controller, b->path, strerror(-r));
63
60
        return 0;
64
61
}
65
62
 
66
 
void cgroup_bonding_free(CGroupBonding *b, bool remove_or_trim) {
 
63
void cgroup_bonding_free(CGroupBonding *b, bool trim) {
67
64
        assert(b);
68
65
 
69
66
        if (b->unit) {
70
67
                CGroupBonding *f;
71
68
 
72
 
                LIST_REMOVE(CGroupBonding, by_unit, b->unit->meta.cgroup_bondings, b);
 
69
                LIST_REMOVE(CGroupBonding, by_unit, b->unit->cgroup_bondings, b);
73
70
 
74
71
                if (streq(b->controller, SYSTEMD_CGROUP_CONTROLLER)) {
75
 
                        assert_se(f = hashmap_get(b->unit->meta.manager->cgroup_bondings, b->path));
 
72
                        assert_se(f = hashmap_get(b->unit->manager->cgroup_bondings, b->path));
76
73
                        LIST_REMOVE(CGroupBonding, by_path, f, b);
77
74
 
78
75
                        if (f)
79
 
                                hashmap_replace(b->unit->meta.manager->cgroup_bondings, b->path, f);
 
76
                                hashmap_replace(b->unit->manager->cgroup_bondings, b->path, f);
80
77
                        else
81
 
                                hashmap_remove(b->unit->meta.manager->cgroup_bondings, b->path);
 
78
                                hashmap_remove(b->unit->manager->cgroup_bondings, b->path);
82
79
                }
83
80
        }
84
81
 
85
 
        if (b->realized && b->ours && remove_or_trim) {
86
 
 
87
 
                if (cgroup_bonding_is_empty(b) > 0)
88
 
                        cg_delete(b->controller, b->path);
89
 
                else
90
 
                        cg_trim(b->controller, b->path, false);
91
 
        }
 
82
        if (b->realized && b->ours && trim)
 
83
                cg_trim(b->controller, b->path, false);
92
84
 
93
85
        free(b->controller);
94
86
        free(b->path);
162
154
        return 0;
163
155
}
164
156
 
165
 
int cgroup_bonding_set_task_access(CGroupBonding *b, mode_t mode, uid_t uid, gid_t gid) {
 
157
int cgroup_bonding_set_task_access(CGroupBonding *b, mode_t mode, uid_t uid, gid_t gid, int sticky) {
166
158
        assert(b);
167
159
 
168
160
        if (!b->realized)
169
161
                return -EINVAL;
170
162
 
171
 
        return cg_set_task_access(b->controller, b->path, mode, uid, gid);
 
163
        return cg_set_task_access(b->controller, b->path, mode, uid, gid, sticky);
172
164
}
173
165
 
174
 
int cgroup_bonding_set_task_access_list(CGroupBonding *first, mode_t mode, uid_t uid, gid_t gid) {
 
166
int cgroup_bonding_set_task_access_list(CGroupBonding *first, mode_t mode, uid_t uid, gid_t gid, int sticky) {
175
167
        CGroupBonding *b;
176
168
        int r;
177
169
 
178
170
        LIST_FOREACH(by_unit, b, first) {
179
 
                r = cgroup_bonding_set_task_access(b, mode, uid, gid);
 
171
                r = cgroup_bonding_set_task_access(b, mode, uid, gid, sticky);
180
172
                if (r < 0)
181
173
                        return r;
182
174
        }
200
192
        Set *allocated_set = NULL;
201
193
        int ret = -EAGAIN, r;
202
194
 
 
195
        if (!first)
 
196
                return 0;
 
197
 
203
198
        if (!s)
204
199
                if (!(s = allocated_set = set_new(trivial_hash_func, trivial_compare_func)))
205
200
                        return -ENOMEM;
360
355
        m->cgroup_hierarchy = NULL;
361
356
}
362
357
 
 
358
int cgroup_bonding_get(Manager *m, const char *cgroup, CGroupBonding **bonding) {
 
359
        CGroupBonding *b;
 
360
        char *p;
 
361
 
 
362
        assert(m);
 
363
        assert(cgroup);
 
364
        assert(bonding);
 
365
 
 
366
        b = hashmap_get(m->cgroup_bondings, cgroup);
 
367
        if (b) {
 
368
                *bonding = b;
 
369
                return 1;
 
370
        }
 
371
 
 
372
        p = strdup(cgroup);
 
373
        if (!p)
 
374
                return -ENOMEM;
 
375
 
 
376
        for (;;) {
 
377
                char *e;
 
378
 
 
379
                e = strrchr(p, '/');
 
380
                if (!e || e == p) {
 
381
                        free(p);
 
382
                        *bonding = NULL;
 
383
                        return 0;
 
384
                }
 
385
 
 
386
                *e = 0;
 
387
 
 
388
                b = hashmap_get(m->cgroup_bondings, p);
 
389
                if (b) {
 
390
                        free(p);
 
391
                        *bonding = b;
 
392
                        return 1;
 
393
                }
 
394
        }
 
395
}
 
396
 
363
397
int cgroup_notify_empty(Manager *m, const char *group) {
364
398
        CGroupBonding *l, *b;
 
399
        int r;
365
400
 
366
401
        assert(m);
367
402
        assert(group);
368
403
 
369
 
        if (!(l = hashmap_get(m->cgroup_bondings, group)))
370
 
                return 0;
 
404
        r = cgroup_bonding_get(m, group, &l);
 
405
        if (r <= 0)
 
406
                return r;
371
407
 
372
408
        LIST_FOREACH(by_path, b, l) {
373
409
                int t;
375
411
                if (!b->unit)
376
412
                        continue;
377
413
 
378
 
                if ((t = cgroup_bonding_is_empty_list(b)) < 0) {
 
414
                t = cgroup_bonding_is_empty_list(b);
 
415
                if (t < 0) {
379
416
 
380
417
                        /* If we don't know, we don't know */
381
418
                        if (t != -EAGAIN)
384
421
                        continue;
385
422
                }
386
423
 
387
 
                if (t > 0)
 
424
                if (t > 0) {
 
425
                        /* If it is empty, let's delete it */
 
426
                        cgroup_bonding_trim_list(b->unit->cgroup_bondings, true);
 
427
 
388
428
                        if (UNIT_VTABLE(b->unit)->cgroup_notify_empty)
389
429
                                UNIT_VTABLE(b->unit)->cgroup_notify_empty(b->unit);
 
430
                }
390
431
        }
391
432
 
392
433
        return 0;