/usr/src/blcr-0.8.5/tests/replace_cb.c is in blcr-dkms 0.8.5-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 | /*
* Berkeley Lab Checkpoint/Restart (BLCR) for Linux is Copyright (c)
* 2008, The Regents of the University of California, through Lawrence
* Berkeley National Laboratory (subject to receipt of any required
* approvals from the U.S. Dept. of Energy). All rights reserved.
*
* Portions may be copyrighted by others, as may be noted in specific
* copyright notices within specific files.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* $Id: replace_cb.c,v 1.9 2008/07/26 06:38:15 phargrov Exp $
*/
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "crut_util.h"
static int cb0(void* arg);
static int cb1(void* arg);
static int cb2(void* arg);
static int cb3(void* arg);
static int cb4(void* arg);
static int cb5(void* arg);
int count = 0;
static void out(const char* s)
{
write(1, s, strlen(s));
}
static int cb0(void* arg)
{
int ret;
out(arg); out(" (in cb0)\n");
ret = cr_replace_self(cb2, "003 self/THREAD from CHECKPOINT section", CR_THREAD_CONTEXT);
if (ret) {
printf("XXX cr_replace_self() in cb0 returned %d w/ errno=%d(%s)\n", ret, errno, cr_strerror(errno));
}
ret = cr_replace_self(cb2, "XXX wrong flags from cb0", CR_SIGNAL_CONTEXT);
if (!ret) {
printf("XXX cr_replace_self() in cb0 suceeded unexpectedly\n");
} else if (errno != EINVAL) {
printf("XXX cr_replace_self() in cb0 returned %d w/ errno=%d(%s)\n", ret, errno, cr_strerror(errno));
}
return 0;
}
static int cb1(void* arg)
{
int ret;
out(arg); out(" (in cb1)\n");
ret = cr_replace_self(cb3, "004 self/SIGNAL from CHECKPOINT section", CR_SIGNAL_CONTEXT);
if (ret) {
printf("XXX cr_replace_self() in cb1 returned %d w/ errno=%d(%s)\n", ret, errno, cr_strerror(errno));
}
ret = cr_replace_self(cb3, "XXX wrong flags from cb2", CR_THREAD_CONTEXT);
if (!ret) {
printf("XXX cr_replace_self() in cb1 suceeded unexpectedly\n");
} else if (errno != EINVAL) {
printf("XXX cr_replace_self() in cb1 returned %d w/ errno=%d(%s)\n", ret, errno, cr_strerror(errno));
}
return 0;
}
static int cb2(void* arg)
{
int ret;
out(arg); out(" (in cb2)\n");
ret = cr_replace_self(cb4, "XXX self/THREAD not overwritten by CONTINUE", CR_THREAD_CONTEXT);
if (ret) {
printf("XXX cr_replace_self() cb2/pre returned %d w/ errno=%d(%s)\n", ret, errno, cr_strerror(errno));
}
ret = cr_checkpoint(0);
if (ret) {
printf("XXX cr_checkpoint() unexpectedy returned %d in cb2\n", ret);
}
ret = cr_replace_self(cb4, "005 self/THREAD from CONTINUE section", CR_THREAD_CONTEXT);
if (ret) {
printf("XXX cr_replace_self() cb2/post returned %d w/ errno=%d(%s)\n", ret, errno, cr_strerror(errno));
}
return 0;
}
static int cb3(void* arg)
{
int ret;
out(arg); out(" (in cb3)\n");
ret = cr_replace_self(cb5, "XXX self/SIGNAL not overwritten by CONTINUE", CR_SIGNAL_CONTEXT);
if (ret) {
printf("XXX cr_replace_self() cb3/pre returned %d w/ errno=%d(%s)\n", ret, errno, cr_strerror(errno));
}
cr_checkpoint(0);
if (ret) {
printf("XXX cr_checkpoint() unexpectedy returned %d in cb3\n", ret);
}
ret = cr_replace_self(cb5, "006 self/SIGNAL from CONTINUE section", CR_SIGNAL_CONTEXT);
if (ret) {
printf("XXX cr_replace_self() cb3/post returned %d w/ errno=%d(%s)\n", ret, errno, cr_strerror(errno));
}
return 0;
}
static int cb4(void* arg)
{
out(arg); out(" (in cb4)\n");
return 0;
}
static int cb5(void* arg)
{
out(arg); out(" (in cb5)\n");
return 0;
}
int main(void)
{
pid_t my_pid;
cr_callback_id_t id0;
cr_callback_id_t id1;
cr_client_id_t my_id;
char *filename;
int ret;
setlinebuf(stdout);
my_pid = getpid();
filename = crut_aprintf("context.%d", my_pid);
printf("000 Process started with pid %d\n", my_pid);
printf("#ST_ALARM:120\n");
fflush(stdout);
my_id = cr_init();
id0 = cr_register_callback(cb0, "001 register THREAD from main", CR_THREAD_CONTEXT);
id1 = cr_register_callback(cb1, "002 register SIGNAL from main", CR_SIGNAL_CONTEXT);
ret = crut_checkpoint_block(filename);
if (ret < 0) {
printf("XXX crut_checkpoint_block() #1 returned %d w/ errno=%d(%s)\n", ret, errno, cr_strerror(errno));
}
ret = crut_checkpoint_block(filename);
if (ret < 0) {
printf("XXX crut_checkpoint_block() #2 returned %d w/ errno=%d(%s)\n", ret, errno, cr_strerror(errno));
}
ret = crut_checkpoint_block(filename);
if (ret < 0) {
printf("XXX crut_checkpoint_block() #3 returned %d w/ errno=%d(%s)\n", ret, errno, cr_strerror(errno));
}
cr_enter_cs(my_id);
// These two should succeed
ret = cr_replace_callback(id0, cb4, "007 replace THREAD from main", CR_THREAD_CONTEXT);
if (ret) {
printf("XXX cr_replace_callback() #2 returned %d w/ errno=%d(%s)\n", ret, errno, cr_strerror(errno));
}
ret = cr_replace_callback(id1, cb5, "008 replace SIGNAL from main", CR_SIGNAL_CONTEXT);
if (ret) {
printf("XXX cr_replace_callback() #1 returned %d w/ errno=%d(%s)\n", ret, errno, cr_strerror(errno));
}
// Next two should fail due to wrong context in flags
ret = cr_replace_callback(id0, cb4, "XXX THREAD->SIGNAL from main", CR_SIGNAL_CONTEXT);
if (!ret) {
printf("XXX cr_replace_callback() #3 suceeded unexpectedly\n");
} else if (errno != EINVAL) {
printf("XXX cr_replace_callback() #3 returned %d w/ errno=%d(%s)\n", ret, errno, cr_strerror(errno));
}
ret = cr_replace_callback(id1, cb5, "XXX SIGNAL->THREAD from main", CR_THREAD_CONTEXT);
if (!ret) {
printf("XXX cr_replace_callback() #4 suceeded unexpectedly\n");
} else if (errno != EINVAL) {
printf("XXX cr_replace_callback() #4 returned %d w/ errno=%d(%s)\n", ret, errno, cr_strerror(errno));
}
// Next two should fail due to invalid id
// -1 can't be valid since that is the error return from register
ret = cr_replace_callback(-1, cb4, NULL, CR_SIGNAL_CONTEXT);
if (!ret) {
printf("XXX cr_replace_callback() #5 suceeded unexpectedly\n");
} else if (errno != EINVAL) {
printf("XXX cr_replace_callback() #5 returned %d w/ errno=%d(%s)\n", ret, errno, cr_strerror(errno));
}
ret = cr_replace_callback(-1, cb5, NULL, CR_THREAD_CONTEXT);
if (!ret) {
printf("XXX cr_replace_callback() #6 suceeded unexpectedly\n");
} else if (errno != EINVAL) {
printf("XXX cr_replace_callback() #6 returned %d w/ errno=%d(%s)\n", ret, errno, cr_strerror(errno));
}
//
cr_leave_cs(my_id);
ret = crut_checkpoint_block(filename);
if (ret < 0) {
printf("XXX crut_checkpoint_block() #4 returned %d w/ errno=%d(%s)\n", ret, errno, cr_strerror(errno));
}
(void)unlink(filename); // may fail silently
out("009 DONE\n");
return 0;
}
|