78
snprintf(freezer, MAXPATHLEN, "%s/freezer.state", nsgroup);
81
err = snprintf(freezer, MAXPATHLEN, "%s/freezer.state", nsgroup);
82
if (err < 0 || err >= MAXPATHLEN)
80
85
file = fopen(freezer, "r");
92
97
return lxc_str2state(status);
95
static lxc_state_t __lxc_getstate(const char *name)
100
static lxc_state_t __lxc_getstate(const char *name, const char *lxcpath)
97
102
struct lxc_command command = {
98
103
.request = { .type = LXC_COMMAND_STATE },
125
130
return command.answer.ret;
128
lxc_state_t lxc_getstate(const char *name)
133
lxc_state_t lxc_getstate(const char *name, const char *lxcpath)
130
135
int state = freezer_state(name);
131
136
if (state != FROZEN && state != FREEZING)
132
state = __lxc_getstate(name);
137
state = __lxc_getstate(name, lxcpath);
168
static int fillwaitedstates(const char *strstates, int *states)
170
char *token, *saveptr = NULL;
171
char *strstates_dup = strdup(strstates);
177
token = strtok_r(strstates_dup, "|", &saveptr);
180
state = lxc_str2state(token);
188
token = strtok_r(NULL, "|", &saveptr);
194
extern int lxc_wait(const char *lxcname, const char *states, int timeout)
198
int s[MAX_STATE] = { }, fd;
199
/* TODO: add cmdline arg to specify lxcpath */
200
char *lxcpath = NULL;
202
if (fillwaitedstates(states, s))
205
fd = lxc_monitor_open();
210
* if container present,
211
* then check if already in requested state
214
state = lxc_getstate(lxcname, lxcpath);
217
} else if ((state >= 0) && (s[state])) {
223
int elapsed_time, curtime = 0;
229
retval = gettimeofday(&tv, NULL);
234
if (lxc_monitor_read_timeout(fd, &msg, timeout) < 0)
238
retval = gettimeofday(&tv, NULL);
241
elapsed_time = tv.tv_sec - curtime;
242
if (timeout - elapsed_time <= 0)
244
timeout -= elapsed_time;
247
if (strcmp(lxcname, msg.name)) {
257
if (msg.value < 0 || msg.value >= MAX_STATE) {
258
ERROR("Receive an invalid state number '%d'",
273
/* just ignore garbage */
279
lxc_monitor_close(fd);