~ubuntu-branches/ubuntu/utopic/ubuntu-app-launch/utopic

« back to all changes in this revision

Viewing changes to cgroup-reap-all.c

  • Committer: Package Import Robot
  • Author(s): Łukasz 'sil2100' Zemczak
  • Date: 2014-08-19 09:52:33 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20140819095233-5mvkp2nderj92rww
Tags: 0.4+14.10.20140808.3.is.0.4+14.10.20140605.3-0ubuntu1
Temporarily revert the cgroup support introduced in the last
version, as it was causing regressions in our test infrastructure

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright © 2014 Canonical Ltd.
3
 
 *
4
 
 * This program is free software: you can redistribute it and/or modify it
5
 
 * under the terms of the GNU General Public License version 3, as published
6
 
 * by the Free Software Foundation.
7
 
 *
8
 
 * This program is distributed in the hope that it will be useful, but
9
 
 * WITHOUT ANY WARRANTY; without even the implied warranties of
10
 
 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11
 
 * PURPOSE.  See the GNU General Public License for more details.
12
 
 *
13
 
 * You should have received a copy of the GNU General Public License along
14
 
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
15
 
 *
16
 
 * Authors:
17
 
 *     Ted Gould <ted.gould@canonical.com>
18
 
 */
19
 
 
20
 
#include "helpers.h"
21
 
 
22
 
int kill (pid_t pid, int signal);
23
 
pid_t getpgid (pid_t);
24
 
 
25
 
int
26
 
main (int argc, char * argv[])
27
 
{
28
 
        /* Break off a new process group */
29
 
        setpgid(0, 0);
30
 
 
31
 
        GDBusConnection * cgmanager = cgroup_manager_connection();
32
 
        g_return_val_if_fail(cgmanager != NULL, -1);
33
 
 
34
 
        /* We're gonna try to kill things forever, literally. It's important
35
 
           enough that we can't consider failure an option. */
36
 
        gboolean killed = TRUE;
37
 
        while (killed) {
38
 
                GList * pidlist = pids_from_cgroup(cgmanager, NULL, NULL);
39
 
                GList * head;
40
 
 
41
 
                killed = FALSE;
42
 
 
43
 
                for (head = pidlist; head != NULL; head = g_list_next(head)) {
44
 
                        GPid pid = GPOINTER_TO_INT(head->data);
45
 
 
46
 
                        /* We don't want to kill ourselves, or if we're being executed by
47
 
                           a script, that script, either. We also don't want things in our
48
 
                           process group which we forked at the opening */
49
 
                        if (pid != getpid() && pid != getppid() && getpgid(pid) != getpid()) {
50
 
                                g_debug("Killing pid: %d", pid);
51
 
                                kill(pid, SIGKILL);
52
 
                                killed = TRUE;
53
 
                        }
54
 
                }
55
 
 
56
 
                g_list_free(pidlist);
57
 
        }
58
 
 
59
 
        g_clear_object(&cgmanager);
60
 
 
61
 
        return 0;
62
 
}