]> git.proxmox.com Git - mirror_lxc.git/blame - src/lxc/checkpoint.c
lxc: use new logging system
[mirror_lxc.git] / src / lxc / checkpoint.c
CommitLineData
925aaa31 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#define _GNU_SOURCE
24#include <stdio.h>
25#undef _GNU_SOURCE
26#include <fcntl.h>
27#include <signal.h>
28#include <stdlib.h>
29#include <string.h>
30#include <unistd.h>
31#include <errno.h>
32#include <sys/types.h>
33#include <sys/stat.h>
34#include <sys/param.h>
35#include <sys/file.h>
36#include <netinet/in.h>
37#include <net/if.h>
38
1f3da8f8 39#include "error.h"
f66af38b 40#include "lxc_plugin.h"
925aaa31 41#include <lxc.h>
42
36eb9bde
CLG
43#include <lxc/log.h>
44
45lxc_log_define(lxc_checkpoint, lxc);
46
2aa79ee7 47#define MAXPIDLEN 20
925aaa31 48
f66af38b 49int lxc_checkpoint(const char *name, const char *statefile,
50 unsigned long flags)
925aaa31 51{
52 char init[MAXPATHLEN];
53 char val[MAXPIDLEN];
54 int fd, lock, ret = -1;
55 size_t pid;
56
57 lock = lxc_get_lock(name);
1f3da8f8 58 if (lock >= 0) {
925aaa31 59 lxc_put_lock(lock);
b0a33c1e 60 return -LXC_ERROR_ESRCH;
925aaa31 61 }
62
b0a33c1e 63 if (lock < 0 && lock != -LXC_ERROR_EBUSY)
64 return lock;
925aaa31 65
66 snprintf(init, MAXPATHLEN, LXCPATH "/%s/init", name);
67 fd = open(init, O_RDONLY);
68 if (fd < 0) {
36eb9bde 69 SYSERROR("failed to open init file for %s", name);
b0a33c1e 70 goto out_close;
925aaa31 71 }
72
73 if (read(fd, val, sizeof(val)) < 0) {
36eb9bde 74 SYSERROR("failed to read %s", init);
925aaa31 75 goto out_close;
76 }
77
78 pid = atoi(val);
79
f66af38b 80 if (lxc_plugin_checkpoint(pid, statefile, flags) < 0) {
36eb9bde 81 SYSERROR("failed to checkpoint %zd", pid);
925aaa31 82 goto out_close;
83 }
84
85 ret = 0;
86
87out_close:
88 close(fd);
925aaa31 89 return ret;
90}