-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic.c
More file actions
executable file
·82 lines (60 loc) · 1.47 KB
/
Copy pathbasic.c
File metadata and controls
executable file
·82 lines (60 loc) · 1.47 KB
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
/* basic.c - test that basic persistency works */
#include "rvm.h"
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
#define TEST_STRING "hello, world"
#define OFFSET2 1000
/* proc1 writes some data, commits it, then exits */
void proc1()
{
rvm_t rvm;
trans_t trans;
char* segs[1];
rvm = rvm_init("rvm_segments");
rvm_destroy(rvm, "testseg");
segs[0] = (char *) rvm_map(rvm, "testseg", 10000);
trans = rvm_begin_trans(rvm, 1, (void **) segs);
rvm_about_to_modify(trans, segs[0], 0, 100);
sprintf(segs[0], TEST_STRING);
rvm_about_to_modify(trans, segs[0], OFFSET2, 100);
sprintf(segs[0]+OFFSET2, TEST_STRING);
rvm_commit_trans(trans);
abort();
}
/* proc2 opens the segments and reads from them */
void proc2()
{
char* segs[1];
rvm_t rvm;
rvm = rvm_init("rvm_segments");
segs[0] = (char *) rvm_map(rvm, "testseg", 10000);
if(strcmp(segs[0], TEST_STRING)) {
printf("ERROR: first hello not present\n");
exit(2);
}
if(strcmp(segs[0]+OFFSET2, TEST_STRING)) {
printf("ERROR: second hello not present\n");
exit(2);
}
printf("OK\n");
exit(0);
}
int main(int argc, char **argv)
{
int pid;
pid = fork();
if(pid < 0) {
perror("fork");
exit(2);
}
if(pid == 0) {
proc1();
exit(0);
}
waitpid(pid, NULL, 0);
proc2();
return 0;
}