Opengate Source Repository
Révision | 81bf22ccced99c4ab8e2d6dd4fbbf84658826cc0 (tree) |
---|---|
l'heure | 2012-12-19 17:30:00 |
Auteur | watanaby <> |
Commiter | watanaby <> |
Ver1.5.26 Added sqlite3_busy_timeout to reduce lock error.
@@ -42,6 +42,9 @@ | ||
42 | 42 | <Facility>local1</Facility> |
43 | 43 | </Syslog> |
44 | 44 | |
45 | + <!-- SQLite busy timeout (milli-seconds) --> | |
46 | + <SqliteBusyTimeout>100</SqliteBusyTimeout> | |
47 | + | |
45 | 48 | <!-- SQLite database file --> |
46 | 49 | <SqliteDb>/tmp/opengate.db</SqliteDb> |
47 | 50 |
@@ -74,7 +77,7 @@ | ||
74 | 77 | <IpfwRule> |
75 | 78 | <Min>10000</Min> |
76 | 79 | <Max>40000</Max> |
77 | - <Interval>2</Interval> | |
80 | + <Interval>1</Interval> | |
78 | 81 | </IpfwRule> |
79 | 82 | |
80 | 83 | <!-- IPFW Tag number used in rc.firewall --> |
@@ -737,6 +737,11 @@ Opengate History</H3> | ||
737 | 737 | Ver.1.5.25 at 2012.12.14 |
738 | 738 | </DT><DD> |
739 | 739 | Fixed small bugs in http header and parameter[contributed by M.Tagawa]. |
740 | + </DD><DT> | |
741 | + Ver.1.5.26 at 2012.12.19 | |
742 | + </DT><DD> | |
743 | + Added sqlite3_busy_timeout to reduce db-lock error. Added | |
744 | + error checks. | |
740 | 745 | </DD> |
741 | 746 | </DL> |
742 | 747 | <P> |
@@ -150,8 +150,10 @@ void delIp6fwRule(char *ruleNumber) | ||
150 | 150 | ruleCount = CountRuleNumber6(ruleNumber); |
151 | 151 | |
152 | 152 | /* delete rule */ |
153 | - if(Systeml(1, GetConfValue("IpfwPath"),"delete",ruleNumber,(char *)0) != 0){ | |
154 | - err_msg("ERR at %s#%d: exec ipfw del error",__FILE__,__LINE__); | |
153 | + if(ruleCount>0){ | |
154 | + if(Systeml(1, GetConfValue("IpfwPath"),"delete",ruleNumber,(char *)0) != 0){ | |
155 | + err_msg("ERR at %s#%d: exec ipfw del error",__FILE__,__LINE__); | |
156 | + } | |
155 | 157 | } |
156 | 158 | } |
157 | 159 |
@@ -6,6 +6,21 @@ | ||
6 | 6 | #include "opengatesrv.h" |
7 | 7 | #include <sqlite3.h> |
8 | 8 | |
9 | +static int sqliteBusyTimeout=100; /* value used in sqite3_busy_timeout() */ | |
10 | + | |
11 | +/******************************************************************* | |
12 | + read sqlite busy timeout value from conf and set to static variable | |
13 | +*******************************************************************/ | |
14 | +int setupSqliteBusyTimeoutValue(void){ | |
15 | + | |
16 | + char *str; | |
17 | + | |
18 | + /* if set in conf, use the value. if not, use the above default. */ | |
19 | + str=GetConfValue("SqliteBusyTimeout"); | |
20 | + if(str!=NULL) sqliteBusyTimeout=atoi(str); | |
21 | + | |
22 | + return sqliteBusyTimeout; | |
23 | +} | |
9 | 24 | |
10 | 25 | /**************************************************************/ |
11 | 26 | /* write session info to session control database at start */ |
@@ -52,7 +67,8 @@ int putSessionBeginToDb(char* cookie, char* userid, | ||
52 | 67 | sqlite3_close(db); |
53 | 68 | return FALSE; |
54 | 69 | } |
55 | - | |
70 | + sqlite3_busy_timeout(db, sqliteBusyTimeout); | |
71 | + | |
56 | 72 | /* create table if not exists */ |
57 | 73 | if(sqlite3_exec(db, createTblCmd, NULL, NULL, &pErrMsg)!=SQLITE_OK){ |
58 | 74 | resultFlag=FALSE; |
@@ -123,6 +139,7 @@ int putSessionEndToDb(char* cookie, char* watchMode){ | ||
123 | 139 | sqlite3_close(db); |
124 | 140 | return FALSE; |
125 | 141 | } |
142 | + sqlite3_busy_timeout(db, sqliteBusyTimeout); | |
126 | 143 | |
127 | 144 | /* prepare command */ |
128 | 145 | updateCmd=sqlite3_mprintf(updateFormat, time(NULL), watchMode, cookie); |
@@ -162,6 +179,7 @@ int fixProcessEndInDb(int pid, char* watchMode){ | ||
162 | 179 | sqlite3_close(db); |
163 | 180 | return FALSE; |
164 | 181 | } |
182 | + sqlite3_busy_timeout(db, sqliteBusyTimeout); | |
165 | 183 | |
166 | 184 | /* prepare command */ |
167 | 185 | updateCmd=sqlite3_mprintf(updateFormat, time(NULL), watchMode, pid); |
@@ -205,6 +223,7 @@ int getSessionInfoFromDb(char* cookie, char* userid, | ||
205 | 223 | sqlite3_close(db); |
206 | 224 | return FALSE; |
207 | 225 | } |
226 | + sqlite3_busy_timeout(db, sqliteBusyTimeout); | |
208 | 227 | |
209 | 228 | /* prepare command string */ |
210 | 229 | selectCmd=sqlite3_mprintf(selectFormat, cookie); |
@@ -273,6 +292,7 @@ int checkNatInsertion(char* macAddr4, char* macAddr6, char* userid){ | ||
273 | 292 | sqlite3_close(db); |
274 | 293 | return FALSE; |
275 | 294 | } |
295 | + sqlite3_busy_timeout(db, sqliteBusyTimeout); | |
276 | 296 | |
277 | 297 | /* prepare command string */ |
278 | 298 | selectCmd=sqlite3_mprintf(selectFormat, macAddress); |
@@ -377,6 +397,7 @@ int findDuplicateInDbAndClose(char* clientAddr4, int* redundantRule4, | ||
377 | 397 | sqlite3_close(db); |
378 | 398 | return FALSE; |
379 | 399 | } |
400 | + sqlite3_busy_timeout(db, sqliteBusyTimeout); | |
380 | 401 | |
381 | 402 | /* begin transaction */ |
382 | 403 | sqlite3_exec(db, beginTransaction, NULL, NULL, &pErrMsg); |
@@ -490,6 +511,14 @@ int findDuplicateInDbAndClose(char* clientAddr4, int* redundantRule4, | ||
490 | 511 | /***************************************************************/ |
491 | 512 | /***************************************************************/ |
492 | 513 | /* debug write routine */ |
514 | +int SetupSqliteBusyTimeoutValue(void){ | |
515 | + int ret; | |
516 | + if(debug>1) err_msg("DEBUG:=>setupSqliteBusyTimeoutValue()"); | |
517 | + ret=setupSqliteBusyTimeoutValue(); | |
518 | + if(debug>1) err_msg("DEBUG:(%d)<=setupSqliteBusyTimeoutValue()",ret); | |
519 | + return ret; | |
520 | +} | |
521 | + | |
493 | 522 | int PutSessionBeginToDb(char* cookie, char* userid, |
494 | 523 | char* clientAddr4, char* clientAddr6, |
495 | 524 | char* macAddr4, |
@@ -134,6 +134,9 @@ int main(int argc, char **argv) | ||
134 | 134 | /* setup pointer to ExtraSet in config file */ |
135 | 135 | SetupConfExtra(useridshort, extraId); |
136 | 136 | |
137 | + /* setup static variable value for SqLite3_busy_timeout from conf */ | |
138 | + SetupSqliteBusyTimeoutValue(); | |
139 | + | |
137 | 140 | /* get address of client from getenv. it might be IPv4 or IPv6. */ |
138 | 141 | GetClientAddr(clientAddr6); |
139 | 142 |
@@ -274,7 +277,6 @@ int main(int argc, char **argv) | ||
274 | 277 | return 0; |
275 | 278 | } |
276 | 279 | |
277 | - | |
278 | 280 | /*******************************************/ |
279 | 281 | /* calc connection duration and put it out */ |
280 | 282 | /*******************************************/ |
@@ -156,6 +156,7 @@ void split(char content[], char *name[], char *value[], char *next[]); | ||
156 | 156 | int GetUserIdFromEnv(char *userid); |
157 | 157 | |
158 | 158 | /* comm-userdb.c */ |
159 | +int SetupSqliteBusyTimeoutValue(void); | |
159 | 160 | int PutSessionBeginToDb(char* cookie, char* userid, |
160 | 161 | char* clientAddr4, char* clientAddr6, |
161 | 162 | char* macAddr4, |
@@ -422,14 +422,26 @@ void checkBasic(void) | ||
422 | 422 | } |
423 | 423 | |
424 | 424 | /* duplicated session check */ |
425 | + /* this is added for ios behavior */ | |
426 | + /* (duplication of ios web-auth and user web-auth) */ | |
427 | + /* if dup, the process in basic mode is ended */ | |
425 | 428 | if(firstCheck){ |
426 | 429 | firstCheck=FALSE; |
427 | 430 | if( FindDuplicateInDbAndClose(alarmArg.clientAddr4, |
428 | - &duplicateRule4, &duplicateRule6, &otherPid) ){ | |
429 | - if(kill(otherPid, 0)==0){ /* the process exists */ | |
431 | + &duplicateRule4, &duplicateRule6, &otherPid) ){ | |
432 | + | |
433 | + /* the process exists (ret==0 means the existence) */ | |
434 | + if(kill(otherPid, 0)==0){ | |
435 | + | |
436 | + /* remove my rules and return as duplicated */ | |
430 | 437 | RemoveDuplicateRule(duplicateRule4, duplicateRule6); |
438 | + err_msg("ERR at %s#%d: duplicated ipfw rules for %s are removed", | |
439 | + __FILE__,__LINE__, alarmArg.clientAddr4); | |
431 | 440 | connectMode=DUPLICATED; |
432 | - }else{ /* the process does not exist */ | |
441 | + } | |
442 | + | |
443 | + /* the process does not exist */ | |
444 | + else{ | |
433 | 445 | FixProcessEndInDb(otherPid, "NONE"); |
434 | 446 | } |
435 | 447 | } |