]> git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/lxc.h
change C/R api
[mirror_lxc.git] / src / lxc / lxc.h
1 /*
2 * lxc: linux Container library
3 *
4 * (C) Copyright IBM Corp. 2007, 2008
5 *
6 * Authors:
7 * Daniel Lezcano <dlezcano at fr.ibm.com>
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23 #ifndef __lxc_h
24 #define __lxc_h
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30 #include <stddef.h>
31 #include <lxc/state.h>
32
33 struct lxc_msg;
34
35 /**
36 Following code is for liblxc.
37
38 lxc/lxc.h will contain exports of liblxc
39 **/
40
41 /*
42 * Start the specified command inside a container
43 * @name : the name of the container
44 * @argv : an array of char * corresponding to the commande line
45 * Returns 0 on sucess, < 0 otherwise
46 */
47 extern int lxc_start(const char *name, char *const argv[], const char *rcfile);
48
49 /*
50 * Stop the container previously started with lxc_start, all
51 * the processes running inside this container will be killed.
52 * @name : the name of the container
53 * Returns 0 on success, < 0 otherwise
54 */
55 extern int lxc_stop(const char *name);
56
57 /*
58 * Open the monitoring mechanism for a specific container
59 * The function will return an fd corresponding to the events
60 * Returns a file descriptor on success, < 0 otherwise
61 */
62 extern int lxc_monitor_open(void);
63
64 /*
65 * Read the state of the container if this one has changed
66 * The function will block until there is an event available
67 * @fd : the file descriptor provided by lxc_monitor_open
68 * @state : the variable which will be filled with the state
69 * Returns 0 if the monitored container has exited, > 0 if
70 * data was readen, < 0 otherwise
71 */
72 extern int lxc_monitor_read(int fd, struct lxc_msg *msg);
73
74 /*
75 * Close the fd associated with the monitoring
76 * @fd : the file descriptor provided by lxc_monitor_open
77 * Returns 0 on success, < 0 otherwise
78 */
79 extern int lxc_monitor_close(int fd);
80
81 /*
82 * Show the console of the container.
83 * @name : the name of container
84 * @tty : the tty number
85 * @fd : a pointer to a tty file descriptor
86 * Returns 0 on sucess, < 0 otherwise
87 */
88 extern int lxc_console(const char *name, int ttynum, int *fd);
89
90 /*
91 * Freeze all the tasks running inside the container <name>
92 * @name : the container name
93 * Returns 0 on success, < 0 otherwise
94 */
95 extern int lxc_freeze(const char *name);
96
97 /*
98 * Unfreeze all previously frozen tasks.
99 * @name : the name of the container
100 * Return 0 on sucess, < 0 otherwise
101 */
102 extern int lxc_unfreeze(const char *name);
103
104 /*
105 * Retrieve the container state
106 * @name : the name of the container
107 * Returns the state of the container on success, < 0 otherwise
108 */
109 extern lxc_state_t lxc_state(const char *name);
110
111 /*
112 * Set a specified value for a specified subsystem. The specified
113 * subsystem must be fully specified, eg. "cpu.shares"
114 * @name : the name of the container
115 * @subsystem : the subsystem
116 * @value : the value to be set
117 * Returns 0 on success, < 0 otherwise
118 */
119 extern int lxc_cgroup_set(const char *name, const char *subsystem, const char *value);
120
121 /*
122 * Get a specified value for a specified subsystem. The specified
123 * subsystem must be fully specified, eg. "cpu.shares"
124 * @name : the name of the container
125 * @subsystem : the subsystem
126 * @value : the value to be set
127 * @len : the len of the value variable
128 * Returns the number of bytes read, < 0 on error
129 */
130 extern int lxc_cgroup_get(const char *name, const char *subsystem,
131 char *value, size_t len);
132
133 /*
134 * Retrieve the error string associated with the error returned by
135 * the function.
136 * @error : the value of the error
137 * Returns a string on success or NULL otherwise.
138 */
139 extern const char *lxc_strerror(int error);
140
141 /*
142 * Checkpoint a container
143 * @name : the name of the container being checkpointed
144 * @statefile: string object on which the container is checkpointed
145 * @flags : checkpoint flags (an ORed value)
146 * Returns 0 on success, < 0 otherwise
147 */
148 extern int lxc_checkpoint(const char *name, const char *statefile, int flags);
149 #define LXC_FLAG_PAUSE 1
150 #define LXC_FLAG_HALT 2
151
152 /*
153 * Restart a container
154 * @name : the name of the container being restarted
155 * @statefile: string object from which the container is restarted
156 * @rcfile: container configuration file.
157 * @flags : restart flags (an ORed value)
158 * Returns 0 on success, < 0 otherwise
159 */
160 extern int lxc_restart(const char *, const char *, const char *, int);
161
162 /*
163 * Returns the version number of the library
164 */
165 extern const char const *lxc_version(void);
166
167 #ifdef __cplusplus
168 }
169 #endif
170
171 #endif