~ubuntu-branches/ubuntu/quantal/lxc/quantal-201208301614

« back to all changes in this revision

Viewing changes to src/lxc/lxccontainer.c

  • Committer: Package Import Robot
  • Author(s): Stéphane Graber, Serge Hallyn, Stéphane Graber
  • Date: 2012-08-25 12:44:17 UTC
  • Revision ID: package-import@ubuntu.com-20120825124417-yn1xu1x10fi7o972
Tags: 0.8.0~rc1-4ubuntu29
[ Serge Hallyn ]
* fix lxcapi_start to not return true when it container failed to start.
* 0201-fix-mkdir-race: don't raise error if mkdir fails with EEXIST.
* 0202-make-api-start-reliable: have daemonized start through the api
  wait until the container is RUNNING before returning true.  If a 5
  second timeout is hit before the container is RUNNING, return false.

[ Stéphane Graber ]
* python-lxc: in get_ips() if timeout is 1 don't wait one second before
  returning.
* python-lxc: Add import time warning that the API isn't yet stable and
  so may change at any point in the future.

Show diffs side-by-side

added added

removed removed

Lines of Context:
244
244
        c->daemonize = 1;
245
245
}
246
246
 
 
247
static bool lxcapi_wait(struct lxc_container *c, char *state, int timeout)
 
248
{
 
249
        int ret;
 
250
 
 
251
        if (!c)
 
252
                return false;
 
253
 
 
254
        ret = lxc_wait(c->name, state, timeout);
 
255
        return ret == 0;
 
256
}
 
257
 
 
258
 
 
259
static bool wait_on_daemonized_start(struct lxc_container *c)
 
260
{
 
261
        /* we'll probably want to make this timeout configurable? */
 
262
        int timeout = 5;
 
263
 
 
264
        return lxcapi_wait(c, "RUNNING", timeout);
 
265
}
 
266
 
247
267
/*
248
268
 * I can't decide if it'd be more convenient for callers if we accept '...',
249
269
 * or a null-terminated array (i.e. execl vs execv)
257
277
                "/sbin/init",
258
278
                '\0',
259
279
        };
260
 
        bool needreboot;
261
280
 
262
281
        /* container exists */
263
282
        if (!c)
299
318
                        return false;
300
319
                }
301
320
                if (pid != 0)
302
 
                        return true;
 
321
                        return wait_on_daemonized_start(c);
303
322
                /* like daemon(), chdir to / and redirect 0,1,2 to /dev/null */
304
323
                chdir("/");
305
324
                close(0);
322
341
        }
323
342
 
324
343
reboot:
 
344
        conf->reboot = 0;
325
345
        ret = lxc_start(c->name, argv, conf);
326
346
 
327
 
        needreboot = false;
328
 
        if (lxclock(c->privlock, 0))
329
 
                return true;
330
 
        conf = c->lxc_conf;
331
 
        if (conf && conf->reboot) {
 
347
        if (conf->reboot) {
332
348
                INFO("container requested reboot");
333
349
                conf->reboot = 0;
334
350
                if (conf->maincmd_fd)
335
351
                        close(conf->maincmd_fd);
336
352
                conf->maincmd_fd = 0;
337
 
                needreboot = true;
338
 
        }
339
 
        lxcunlock(c->privlock);
340
 
        if (needreboot)
341
353
                goto reboot;
 
354
        }
342
355
 
343
356
        if (daemonize) {
344
357
                lxc_container_put(c);
415
428
        return ret == 0;
416
429
}
417
430
 
418
 
static bool lxcapi_wait(struct lxc_container *c, char *state, int timeout)
419
 
{
420
 
        int ret;
421
 
 
422
 
        if (!c)
423
 
                return false;
424
 
 
425
 
        ret = lxc_wait(c->name, state, timeout);
426
 
        return ret == 0;
427
 
}
428
 
 
429
431
static bool valid_template(char *t)
430
432
{
431
433
        struct stat statbuf;