-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtwo_directories.c
92 lines (69 loc) · 1.91 KB
/
two_directories.c
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
/* 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 FIRST_STRING "FIRST DIRECTORY"
#define SECOND_STRING "SECOND DIRECTORY"
/* proc1 writes some data, commits it, then exits */
void proc1()
{
rvm_t rvm;
trans_t trans;
char* segs[0];
fprintf(stderr, "\nCreating FIRST directory");
rvm = rvm_init("rvm_segments1");
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], FIRST_STRING);
rvm_commit_trans(trans);
fprintf(stderr, "\nCreating SECOND directory");
rvm = rvm_init("rvm_segments2");
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], SECOND_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_segments1");
segs[0] = (char *) rvm_map(rvm, "testseg", 10000);
if(strcmp(segs[0], FIRST_STRING)) {
printf("ERROR: first directory string not present\n");
exit(2);
}
rvm = rvm_init("rvm_segments2");
segs[0] = (char *) rvm_map(rvm, "testseg", 10000);
if(strcmp(segs[0], SECOND_STRING)) {
printf("ERROR: second directory 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;
}