Line
Link Here
|
0 |
-- orig/src/internal.h |
0 |
++ mod/src/internal.h |
Lines 5-10
Link Here
|
5 |
# define LIBRCC_DATA_DIR "/usr/lib/rcc" |
5 |
# define LIBRCC_DATA_DIR "/usr/lib/rcc" |
6 |
#endif /* LIBRCC_DATA_DIR */ |
6 |
#endif /* LIBRCC_DATA_DIR */ |
7 |
|
7 |
|
|
|
8 |
#ifndef LIBRCC_LOCK_WAIT |
9 |
# define LIBRCC_LOCK_WAIT 3000 /* ms */ |
10 |
#endif /* LIBRCC_LOCK_WAIT */ |
11 |
|
8 |
#define RCC_MAX_LANGUAGE_PARRENTS 4 |
12 |
#define RCC_MAX_LANGUAGE_PARRENTS 4 |
9 |
#define RCC_MAX_RELATIONS RCC_MAX_LANGUAGES |
13 |
#define RCC_MAX_RELATIONS RCC_MAX_LANGUAGES |
10 |
|
14 |
|
Lines 91-96
Link Here
|
91 |
}; |
95 |
}; |
92 |
typedef struct rcc_context_t rcc_context_s; |
96 |
typedef struct rcc_context_t rcc_context_s; |
93 |
|
97 |
|
|
|
98 |
int rccLock(); |
99 |
void rccUnLock(); |
100 |
|
94 |
int rccConfigure(rcc_context ctx); |
101 |
int rccConfigure(rcc_context ctx); |
95 |
char *rccCreateResult(rcc_context ctx, size_t len); |
102 |
char *rccCreateResult(rcc_context ctx, size_t len); |
96 |
|
103 |
|
97 |
-- orig/src/librcc.c |
104 |
++ mod/src/librcc.c |
Lines 1-6
Link Here
|
1 |
#include <stdio.h> |
1 |
#include <stdio.h> |
2 |
#include <string.h> |
2 |
#include <string.h> |
3 |
#include <stdlib.h> |
3 |
#include <stdlib.h> |
|
|
4 |
#include <time.h> |
5 |
#include <errno.h> |
4 |
|
6 |
|
5 |
#include "../config.h" |
7 |
#include "../config.h" |
6 |
|
8 |
|
Lines 19-24
Link Here
|
19 |
# include <pwd.h> |
21 |
# include <pwd.h> |
20 |
#endif /* HAVE_PWD_H */ |
22 |
#endif /* HAVE_PWD_H */ |
21 |
|
23 |
|
|
|
24 |
#ifdef HAVE_SYS_FILE_H |
25 |
# include <sys/file.h> |
26 |
#endif /* HAVE_SYS_FILE_H */ |
27 |
|
28 |
|
22 |
#include "internal.h" |
29 |
#include "internal.h" |
23 |
#include "rccconfig.h" |
30 |
#include "rccconfig.h" |
24 |
#include "rccenca.h" |
31 |
#include "rccenca.h" |
Lines 135-140
Link Here
|
135 |
initialized = 0; |
142 |
initialized = 0; |
136 |
} |
143 |
} |
137 |
|
144 |
|
|
|
145 |
static int lockfd = -1; |
146 |
|
147 |
int rccLock() { |
148 |
# ifdef HAVE_SYS_FILE_H |
149 |
int err, i; |
150 |
int size; |
151 |
char *stmp; |
152 |
struct timespec wait = { 0, 10000000 }; |
153 |
|
154 |
if (lockfd>=0) return -1; |
155 |
|
156 |
size = strlen(rcc_home_dir) + 32; |
157 |
stmp = (char*)malloc(size*sizeof(char)); |
158 |
if (!stmp) return -1; |
159 |
|
160 |
sprintf(stmp,"%s/.rcc/", rcc_home_dir); |
161 |
mkdir(stmp, 00755); |
162 |
|
163 |
sprintf(stmp,"%s/.rcc/locks/", rcc_home_dir); |
164 |
mkdir(stmp, 00700); |
165 |
|
166 |
sprintf(stmp,"%s/.rcc/locks/rcc.lock", rcc_home_dir); |
167 |
|
168 |
lockfd = open(stmp, O_RDWR|O_CREAT, 0644); |
169 |
if (lockfd >= 0) { |
170 |
for (err = -1, i = 0; i < (LIBRCC_LOCK_WAIT/10); i++) { |
171 |
err = flock(lockfd, LOCK_EX|LOCK_NB); |
172 |
if ((err)&&(errno == EWOULDBLOCK)) nanosleep(&wait, NULL); |
173 |
else break; |
174 |
} |
175 |
|
176 |
if (err) { |
177 |
close(lockfd); |
178 |
|
179 |
// Removing invalid lock |
180 |
if (i == (LIBRCC_LOCK_WAIT/10)) { |
181 |
remove(stmp); |
182 |
|
183 |
lockfd = open(stmp, O_RDWR|O_CREAT, 0644); |
184 |
if (lockfd >= 0) { |
185 |
for (err = -1, i = 0; i < (LIBRCC_LOCK_WAIT/10); i++) { |
186 |
err = flock(lockfd, LOCK_EX|LOCK_NB); |
187 |
if ((err)&&(errno == EWOULDBLOCK)) nanosleep(&wait, NULL); |
188 |
else break; |
189 |
} |
190 |
|
191 |
if (err) close(lockfd); |
192 |
else return 0; |
193 |
} |
194 |
} |
195 |
|
196 |
lockfd = -1; |
197 |
return -1; |
198 |
} |
199 |
|
200 |
return 0; |
201 |
} |
202 |
|
203 |
return -1; |
204 |
# else /* HAVE_SYS_FILE_H */ |
205 |
return 0; |
206 |
# endif /* HAVE_SYS_FILE_H */ |
207 |
} |
208 |
|
209 |
void rccUnLock() { |
210 |
#ifdef HAVE_SYS_FILE_H |
211 |
int size; |
212 |
char *stmp; |
213 |
|
214 |
if (lockfd<0) return; |
215 |
|
216 |
size = strlen(rcc_home_dir) + 32; |
217 |
stmp = (char*)malloc(size*sizeof(char)); |
218 |
if (!stmp) return; |
219 |
|
220 |
sprintf(stmp,"%s/.rcc/locks/rcc.lock", rcc_home_dir); |
221 |
|
222 |
flock(lockfd, LOCK_UN); |
223 |
close(lockfd); |
224 |
lockfd = -1; |
225 |
#endif /* HAVE_SYS_FILE_H */ |
226 |
} |
227 |
|
138 |
rcc_context rccCreateContext(const char *locale_variable, unsigned int max_languages, unsigned int max_classes, rcc_class_ptr defclasses, rcc_init_flags flags) { |
228 |
rcc_context rccCreateContext(const char *locale_variable, unsigned int max_languages, unsigned int max_classes, rcc_class_ptr defclasses, rcc_init_flags flags) { |
139 |
unsigned int i; |
229 |
unsigned int i; |
140 |
|
230 |
|
141 |
-- orig/src/rccdb4.c |
231 |
++ mod/src/rccdb4.c |
Lines 15-25
Link Here
|
15 |
#ifdef HAVE_DB_H |
15 |
#ifdef HAVE_DB_H |
16 |
DB_ENV *dbe; |
16 |
DB_ENV *dbe; |
17 |
DB *db; |
17 |
DB *db; |
|
|
18 |
|
19 |
char stmp[160]; |
18 |
|
20 |
|
19 |
err = db_env_create(&dbe, 0); |
21 |
err = db_env_create(&dbe, 0); |
20 |
if (err) return NULL; |
22 |
if (err) return NULL; |
|
|
23 |
|
24 |
err = dbe->open(dbe, dbpath, DB_CREATE|DB_INIT_CDB|DB_INIT_MPOOL, 00644); |
25 |
if (err == DB_VERSION_MISMATCH) { |
26 |
|
27 |
if (!rccLock()) { |
28 |
err = dbe->open(dbe, dbpath, DB_CREATE|DB_INIT_LOCK|DB_INIT_LOG|DB_INIT_MPOOL|DB_INIT_TXN|DB_USE_ENVIRON|DB_PRIVATE|DB_RECOVER, 0); |
29 |
rccUnLock(); |
30 |
} else err = -1; |
31 |
|
32 |
dbe->close(dbe, 0); |
33 |
if (err) return NULL; |
34 |
|
35 |
if (strlen(dbpath)<128) { |
36 |
sprintf(stmp, "%s/log.0000000001", dbpath); |
37 |
remove(stmp); |
38 |
} |
39 |
|
40 |
err = db_env_create(&dbe, 0); |
41 |
if (err) return NULL; |
42 |
|
43 |
err = dbe->open(dbe, dbpath, DB_CREATE|DB_INIT_CDB|DB_INIT_MPOOL, 00644); |
44 |
|
45 |
} |
21 |
|
46 |
|
22 |
err = dbe->open(dbe, dbpath, DB_CREATE|DB_INIT_CDB|DB_INIT_MPOOL, 00755); |
|
|
23 |
if (err) { |
47 |
if (err) { |
24 |
dbe->close(dbe, 0); |
48 |
dbe->close(dbe, 0); |
25 |
return NULL; |
49 |
return NULL; |