commit
[crak.git] / tests / ck.c
blobd9643e2cff77fdefdafab4c6e49b3193b3dd2576
1 /*!
2 * \file ck.c
3 * - Author: Alejandro Cabrera
4 * - Date: August 2008
5 * - Brief: Library interface to CRAK module. Wraps IOCTL
6 * functionality in convenient uspace functions.
7 * - Modifications:
8 * - Added doxygen-style documentation.
9 */
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <sys/ioctl.h>
13 #include <fcntl.h>
14 #include "../src/ckpt.h"
16 #define CKPT_TEST "testfile"
18 /*!
19 * \brief IOCTL wrapper to run kernel-level checkpoint.
20 * @param[in] fd
21 * @param[in] pid
22 * @param[in] flags
23 * @return < 0 - error, 0 - success
25 int checkpoint(int fd, int pid, int flags)
27 struct ckpt_param param;
28 int ret, dev_fd;
30 dev_fd = open(CKPT_DEV_FILE, O_RDONLY);
31 if (dev_fd<0) {
32 perror(CKPT_DEV_FILE);
33 return dev_fd;
36 param.fd = fd;
37 param.pid = pid;
38 param.flags = flags;
40 printf("Sending...\n");
41 ret = ioctl(dev_fd, CKPT_IOCTL_CHECKPOINT, (int)&param);
42 printf("Done...\n");
43 close(dev_fd);
44 return ret;
47 int main()
49 int fd, pid;
51 fd = open(CKPT_TEST, O_RDWR);
52 if(!fd){
53 perror(CKPT_TEST);
54 return -1;
57 printf("Before ckpt.\n");
59 checkpoint(fd, getpid(), CKPT_KILL);
61 printf("After ckpt.\n");
63 close(fd);
65 exit(0);