This file is indexed.

/usr/src/blcr-0.8.2/tests/cr_signal.c is in blcr-dkms 0.8.2-15ubuntu2.

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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
/*
 * Berkeley Lab Checkpoint/Restart (BLCR) for Linux is Copyright (c)
 * 2007, 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: cr_signal.c,v 1.6 2008/08/29 21:36:53 phargrov Exp $
 *
 * Check for interference w/ out signal handler
 */

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <signal.h>
#include <fcntl.h>
#include <string.h>

#include "crut.h"

// This test is disabled.
// We don't currently do the right thing.
#define TEST_SIGNAL_BLOCKED 0

#define MSG "Hello world!\n"

struct testdata_t {
	char *msg;
	void *handler;
};

static int
common_setup(void **testdata, void *handler)
{
    struct testdata_t *data;
    struct sigaction sa;

    data = malloc(sizeof(*data));
    if (!data) { return -1; }
    data->msg = strdup(MSG);
    if (!data->msg) { return -1; }

    data->handler = handler;
    sa.sa_handler = handler;
    sa.sa_flags = 0;
    (void)sigaction(CR_SIGNUM, &sa, NULL); /* Ignore any failure */

    *testdata = data;
    return 0;
}

volatile int flag = -1;
static void catcher(int signo) {
    if (flag != 0) {
	CRUT_FAIL("Catcher ran unexpectedly");
	exit(-1);
    }
    flag = 1;
    return;
}

static void empty_handler(int signo) {
    CRUT_DEBUG("Running empty handler");
}

static int
test1_setup(void **testdata) {
    /* Test1: catch the signal */
    return common_setup(testdata, &catcher);
}

static int
test2_setup(void **testdata) {
    /* Test2: ignore the signal */
    return common_setup(testdata, SIG_IGN);
}

static int
test3_setup(void **testdata) {
    /* Test3: reset to default */
    return common_setup(testdata, SIG_DFL);
}

#if TEST_SIGNAL_BLOCKED
static int
test4_setup(void **testdata) {
    /* Test4: block it */
    sigset_t mask;
    sigemptyset(&mask);
    sigaddset(&mask, CR_SIGNUM);
    sigprocmask(SIG_BLOCK, &mask, NULL);
    return common_setup(testdata, empty_handler);
}
#endif

static int
test5_setup(void **testdata) {
    /* Test5: corrupt the sa_restorer!! */
    struct testdata_t *data;
    struct sigaction sa;

    data = malloc(sizeof(*data));
    if (!data) { return -1; }
    data->msg = strdup(MSG);
    if (!data->msg) { return -1; }

    (void)sigaction(CR_SIGNUM, NULL, &sa); /* Ignore any failure */
    data->handler = sa.sa_sigaction;
    if (sa.sa_restorer) {
	sa.sa_restorer = (void *)&abort;
	(void)sigaction(CR_SIGNUM, &sa, NULL); /* Ignore any failure */
    } else {
	/* Don't mess w/ NULL */
    }

    *testdata = data;
    return 0;
}

static int
check_it(struct testdata_t *data)
{
    sigset_t mask, old_mask;
    /* The sigismember() checks that follow avoid false-alarms when glibc thinks
     * that CR_SIGNUM is out of bounds, by thinking -1 is OK.
     */
    if (data->handler == &catcher) { /* TEST1 */
	flag = 0;
	CRUT_DEBUG("Raise signal to test");
	raise(CR_SIGNUM);
	if (flag != 1) {
	    CRUT_FAIL("Signal handler failed to run");
	    return -1;
	}
    } else if (data->handler == SIG_IGN) { /* TEST2 */
	/* Check that signal actually *is* ignored (as opposed to blocked) */
	CRUT_DEBUG("Raise signal to test");
	raise(CR_SIGNUM);
	sigemptyset(&mask);
	sigpending(&mask);
	if (sigismember(&mask,CR_SIGNUM) == 1) {
	    CRUT_FAIL("Failed to ignore the signal");
	    return -1;
	}
    } else if (data->handler == SIG_DFL) { /* TEST3 */
	/* Not safe to raise */
    } else if (data->handler == empty_handler) { /* TEST4 */
	/* Check that signal actually *is* blocked (as opposed to ignored) */
	CRUT_DEBUG("Checking signal mask");
	sigemptyset(&mask);
	sigprocmask(SIG_BLOCK, &mask, &old_mask);
	if (sigismember(&old_mask,CR_SIGNUM) == 0) {
	    CRUT_FAIL("Failed to mask the signal");
	    return -1;
	}
	CRUT_DEBUG("Raise signal to test");
	raise(CR_SIGNUM);
	sigemptyset(&mask);
	sigpending(&mask);
	if (sigismember(&mask,CR_SIGNUM) == 0) {
	    CRUT_FAIL("Failed to block the signal");
	    return -1;
	}
	/* Absorb the pending signal */
	sigemptyset(&mask);
	sigaddset(&mask, CR_SIGNUM);
	sigprocmask(SIG_UNBLOCK, &mask, NULL);
	sigprocmask(SIG_BLOCK, &mask, NULL);
    } else { /* TEST5 */
	/* Do nothing here */
    }
    return strncmp(data->msg, MSG, sizeof(MSG)) ? -1 : 0;
}

static int
common_precheckpoint(void *p)
{
    CRUT_DEBUG("Testing sanity before we checkpoint");
    return check_it(p);
}

static int
common_continue(void *p)
{
    CRUT_DEBUG("Continuing after checkpoint.");
    return check_it(p);
}

static int
common_restart(void *p)
{
    CRUT_DEBUG("Restarting from checkpoint.");
    return check_it(p);
}

static int
common_teardown(void *p)
{
    struct testdata_t *data = (struct testdata_t *)p;
    free(data->msg);

    return 0;
}

int
main(int argc, char *argv[])
{
    int ret;
    struct crut_operations test1_ops = {
	test_scope:CR_SCOPE_PROC,
	test_name:"cr_signal_catch",
        test_description:"Signal catch test.",
	test_setup:test1_setup,
	test_precheckpoint:common_precheckpoint,
	test_continue:common_continue,
	test_restart:common_restart,
	test_teardown:common_teardown,
    };

    struct crut_operations test2_ops = {
	test_scope:CR_SCOPE_PROC,
	test_name:"cr_signal_ignore",
        test_description:"SIG_IGN test.",
	test_setup:test2_setup,
	test_precheckpoint:common_precheckpoint,
	test_continue:common_continue,
	test_restart:common_restart,
	test_teardown:common_teardown,
    };

    struct crut_operations test3_ops = {
	test_scope:CR_SCOPE_PROC,
	test_name:"cr_signal_default",
        test_description:"SIG_DFL test.",
	test_setup:test3_setup,
	test_precheckpoint:common_precheckpoint,
	test_continue:common_continue,
	test_restart:common_restart,
	test_teardown:common_teardown,
    };

#if TEST_SIGNAL_BLOCKED
    struct crut_operations test4_ops = {
	test_scope:CR_SCOPE_PROC,
	test_name:"cr_signal_block",
        test_description:"Signal blocking test.",
	test_setup:test4_setup,
	test_precheckpoint:common_precheckpoint,
	test_continue:common_continue,
	test_restart:common_restart,
	test_teardown:common_teardown,
    };
#endif

    struct crut_operations test5_ops = {
	test_scope:CR_SCOPE_PROC,
	test_name:"cr_signal_restorer",
        test_description:"Signal restorer test.",
	test_setup:test5_setup,
	test_precheckpoint:common_precheckpoint,
	test_continue:common_continue,
	test_restart:common_restart,
	test_teardown:common_teardown,
    };


    /* add the tests */
    crut_add_test(&test1_ops);
    crut_add_test(&test2_ops);
    crut_add_test(&test3_ops);
#if TEST_SIGNAL_BLOCKED
    crut_add_test(&test4_ops);
#endif
    crut_add_test(&test5_ops);

    ret = crut_main(argc, argv);

    return ret;
}