~serge-hallyn/ubuntu/lucid/lxc/fix-separate-var

« back to all changes in this revision

Viewing changes to src/lxc/cr_plugin_columbia.c

  • Committer: Bazaar Package Importer
  • Author(s): Guido Trotter
  • Date: 2009-04-29 17:49:13 UTC
  • Revision ID: james.westby@ubuntu.com-20090429174913-jvahs1ykizqtodje
Tags: upstream-0.6.2
ImportĀ upstreamĀ versionĀ 0.6.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
37
#include "error.h"
 
38
#include <lxc.h>
 
39
#include <lxc/log.h>
 
40
 
 
41
lxc_log_define(lxc_columbia, lxc);
 
42
 
 
43
 
 
44
 
 
45
#if __i386__
 
46
#    define __NR_checkpoint 333
 
47
#    define __NR_restart 334
 
48
static inline long sys_checkpoint(pid_t pid, int fd, unsigned long flags)
 
49
{
 
50
        return syscall(__NR_checkpoint, pid, fd, flags);
 
51
}
 
52
static inline long sys_restart(pid_t pid, int fd, unsigned long flags)
 
53
{
 
54
        return syscall(__NR_restart, pid, fd, flags);
 
55
}
 
56
#elif __x86_64__
 
57
#    define __NR_checkpoint 295
 
58
#    define __NR_restart 296
 
59
static inline long sys_checkpoint(pid_t pid, int fd, unsigned long flags)
 
60
{
 
61
        return syscall(__NR_checkpoint, pid, fd, flags);
 
62
}
 
63
static inline long sys_restart(pid_t pid, int fd, unsigned long flags)
 
64
{
 
65
        return syscall(__NR_restart, pid, fd, flags);
 
66
}
 
67
#else
 
68
#    warning "Architecture not supported for checkpoint"
 
69
static inline long sys_checkpoint(pid_t pid, int fd, unsigned long flags)
 
70
{
 
71
        errno = ENOSYS;
 
72
        return -1;
 
73
}
 
74
static inline long sys_restart(pid_t pid, int fd, unsigned long flags)
 
75
{
 
76
        errno = ENOSYS;
 
77
        return -1;
 
78
}
 
79
#    warning "Architecture not supported for restart syscall"
 
80
 
 
81
#endif
 
82
 
 
83
 
 
84
int lxc_plugin_checkpoint(pid_t pid, const char *statefile, unsigned long flags)
 
85
{
 
86
        int fd, ret;
 
87
 
 
88
        fd = open(statefile, O_RDWR);
 
89
        if (fd < 0) {
 
90
                SYSERROR("failed to open init file for %s", statefile);
 
91
                return -1;
 
92
        }
 
93
        
 
94
        ret = sys_checkpoint(pid, fd, flags);
 
95
        if (ret < 0) {
 
96
                SYSERROR("failed to checkpoint %d", pid);
 
97
                goto out_close;
 
98
        }
 
99
 
 
100
        ret = 0;
 
101
 
 
102
out_close:
 
103
        close(fd);
 
104
        return ret;
 
105
}
 
106
 
 
107
int lxc_plugin_restart(pid_t pid, const char *statefile, unsigned long flags)
 
108
{
 
109
        int fd;
 
110
 
 
111
        fd = open(statefile, O_RDONLY);
 
112
        if (fd < 0) {
 
113
                SYSERROR("failed to open init file for %s", statefile);
 
114
                return -1;
 
115
        }
 
116
        
 
117
        sys_restart(pid, fd, flags);
 
118
        SYSERROR("failed to restart %d", pid);
 
119
        close(fd);
 
120
        return -1;
 
121
}