forked from lxc/cgmanager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cgm-release-agent.c
92 lines (81 loc) · 2.38 KB
/
cgm-release-agent.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/* cgmanager
*
* Copyright © 2014 Canonical
* Author: Serge Hallyn <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2, as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <stdio.h>
#include <sys/types.h>
#include "cgmanager.h"
#include "cgmanager-client.h"
#include <nih-dbus/dbus_connection.h>
#include "cgmanager-client.h"
#include <nih/alloc.h>
#include <nih/error.h>
#include <nih/logging.h>
#include <nih/string.h>
#define CG_REMOVE_RECURSIVE 1
int do_remove_cgroup(const char *controller, const char *cgroup)
{
DBusError dbus_error;
DBusConnection *connection;
dbus_error_init(&dbus_error);
NihDBusProxy *cgroup_manager = NULL;
connection = dbus_connection_open_private(CGMANAGER_DBUS_PATH, &dbus_error);
if (!connection) {
nih_error("Failed opening dbus connection: %s: %s",
dbus_error.name, dbus_error.message);
dbus_error_free(&dbus_error);
return -1;
}
if (nih_dbus_setup(connection, NULL) < 0) {
NihError *nerr;
nerr = nih_error_get();
nih_free(nerr);
dbus_error_free(&dbus_error);
dbus_connection_unref(connection);
return -1;
}
dbus_error_free(&dbus_error);
cgroup_manager = nih_dbus_proxy_new(NULL, connection,
NULL /* p2p */,
"/org/linuxcontainers/cgmanager", NULL, NULL);
dbus_connection_unref(connection);
if (!cgroup_manager) {
NihError *nerr;
nerr = nih_error_get();
nih_free(nerr);
return -1;
}
int existed;
if ( cgmanager_remove_sync(NULL, cgroup_manager, controller,
cgroup, CG_REMOVE_RECURSIVE, &existed) != 0) {
NihError *nerr;
nerr = nih_error_get();
nih_free(nerr);
}
nih_free(cgroup_manager);
return 0;
}
int main(int argc, char *argv[])
{
char *p;
nih_assert (argv[1] != NULL);
p = strstr(argv[0], ".");
if (!p)
return -1;
/* controller is now in *(p+1), cgroup is in argv[1] */
return do_remove_cgroup(p+1, argv[1]);
}