• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Aucun tag

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Opengate Source Repository


Commit MetaInfo

Révision81bf22ccced99c4ab8e2d6dd4fbbf84658826cc0 (tree)
l'heure2012-12-19 17:30:00
Auteurwatanaby <>
Commiterwatanaby <>

Message de Log

Ver1.5.26 Added sqlite3_busy_timeout to reduce lock error.

Change Summary

Modification

--- a/opengate/conf/opengatesrv.conf.sample
+++ b/opengate/conf/opengatesrv.conf.sample
@@ -42,6 +42,9 @@
4242 <Facility>local1</Facility>
4343 </Syslog>
4444
45+ <!-- SQLite busy timeout (milli-seconds) -->
46+ <SqliteBusyTimeout>100</SqliteBusyTimeout>
47+
4548 <!-- SQLite database file -->
4649 <SqliteDb>/tmp/opengate.db</SqliteDb>
4750
@@ -74,7 +77,7 @@
7477 <IpfwRule>
7578 <Min>10000</Min>
7679 <Max>40000</Max>
77- <Interval>2</Interval>
80+ <Interval>1</Interval>
7881 </IpfwRule>
7982
8083 <!-- IPFW Tag number used in rc.firewall -->
--- a/opengate/doc/Changes.html
+++ b/opengate/doc/Changes.html
@@ -737,6 +737,11 @@ Opengate History</H3>
737737 Ver.1.5.25 at 2012.12.14
738738 </DT><DD>
739739 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.
740745 </DD>
741746 </DL>
742747 <P>
--- a/opengate/opengatesrv/comm-ip6fw.c
+++ b/opengate/opengatesrv/comm-ip6fw.c
@@ -150,8 +150,10 @@ void delIp6fwRule(char *ruleNumber)
150150 ruleCount = CountRuleNumber6(ruleNumber);
151151
152152 /* 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+ }
155157 }
156158 }
157159
--- a/opengate/opengatesrv/comm-userdb.c
+++ b/opengate/opengatesrv/comm-userdb.c
@@ -6,6 +6,21 @@
66 #include "opengatesrv.h"
77 #include <sqlite3.h>
88
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+}
924
1025 /**************************************************************/
1126 /* write session info to session control database at start */
@@ -52,7 +67,8 @@ int putSessionBeginToDb(char* cookie, char* userid,
5267 sqlite3_close(db);
5368 return FALSE;
5469 }
55-
70+ sqlite3_busy_timeout(db, sqliteBusyTimeout);
71+
5672 /* create table if not exists */
5773 if(sqlite3_exec(db, createTblCmd, NULL, NULL, &pErrMsg)!=SQLITE_OK){
5874 resultFlag=FALSE;
@@ -123,6 +139,7 @@ int putSessionEndToDb(char* cookie, char* watchMode){
123139 sqlite3_close(db);
124140 return FALSE;
125141 }
142+ sqlite3_busy_timeout(db, sqliteBusyTimeout);
126143
127144 /* prepare command */
128145 updateCmd=sqlite3_mprintf(updateFormat, time(NULL), watchMode, cookie);
@@ -162,6 +179,7 @@ int fixProcessEndInDb(int pid, char* watchMode){
162179 sqlite3_close(db);
163180 return FALSE;
164181 }
182+ sqlite3_busy_timeout(db, sqliteBusyTimeout);
165183
166184 /* prepare command */
167185 updateCmd=sqlite3_mprintf(updateFormat, time(NULL), watchMode, pid);
@@ -205,6 +223,7 @@ int getSessionInfoFromDb(char* cookie, char* userid,
205223 sqlite3_close(db);
206224 return FALSE;
207225 }
226+ sqlite3_busy_timeout(db, sqliteBusyTimeout);
208227
209228 /* prepare command string */
210229 selectCmd=sqlite3_mprintf(selectFormat, cookie);
@@ -273,6 +292,7 @@ int checkNatInsertion(char* macAddr4, char* macAddr6, char* userid){
273292 sqlite3_close(db);
274293 return FALSE;
275294 }
295+ sqlite3_busy_timeout(db, sqliteBusyTimeout);
276296
277297 /* prepare command string */
278298 selectCmd=sqlite3_mprintf(selectFormat, macAddress);
@@ -377,6 +397,7 @@ int findDuplicateInDbAndClose(char* clientAddr4, int* redundantRule4,
377397 sqlite3_close(db);
378398 return FALSE;
379399 }
400+ sqlite3_busy_timeout(db, sqliteBusyTimeout);
380401
381402 /* begin transaction */
382403 sqlite3_exec(db, beginTransaction, NULL, NULL, &pErrMsg);
@@ -490,6 +511,14 @@ int findDuplicateInDbAndClose(char* clientAddr4, int* redundantRule4,
490511 /***************************************************************/
491512 /***************************************************************/
492513 /* 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+
493522 int PutSessionBeginToDb(char* cookie, char* userid,
494523 char* clientAddr4, char* clientAddr6,
495524 char* macAddr4,
--- a/opengate/opengatesrv/main.c
+++ b/opengate/opengatesrv/main.c
@@ -134,6 +134,9 @@ int main(int argc, char **argv)
134134 /* setup pointer to ExtraSet in config file */
135135 SetupConfExtra(useridshort, extraId);
136136
137+ /* setup static variable value for SqLite3_busy_timeout from conf */
138+ SetupSqliteBusyTimeoutValue();
139+
137140 /* get address of client from getenv. it might be IPv4 or IPv6. */
138141 GetClientAddr(clientAddr6);
139142
@@ -274,7 +277,6 @@ int main(int argc, char **argv)
274277 return 0;
275278 }
276279
277-
278280 /*******************************************/
279281 /* calc connection duration and put it out */
280282 /*******************************************/
--- a/opengate/opengatesrv/opengatesrv.h
+++ b/opengate/opengatesrv/opengatesrv.h
@@ -156,6 +156,7 @@ void split(char content[], char *name[], char *value[], char *next[]);
156156 int GetUserIdFromEnv(char *userid);
157157
158158 /* comm-userdb.c */
159+int SetupSqliteBusyTimeoutValue(void);
159160 int PutSessionBeginToDb(char* cookie, char* userid,
160161 char* clientAddr4, char* clientAddr6,
161162 char* macAddr4,
--- a/opengate/opengatesrv/watch-client.c
+++ b/opengate/opengatesrv/watch-client.c
@@ -422,14 +422,26 @@ void checkBasic(void)
422422 }
423423
424424 /* 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 */
425428 if(firstCheck){
426429 firstCheck=FALSE;
427430 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 */
430437 RemoveDuplicateRule(duplicateRule4, duplicateRule6);
438+ err_msg("ERR at %s#%d: duplicated ipfw rules for %s are removed",
439+ __FILE__,__LINE__, alarmArg.clientAddr4);
431440 connectMode=DUPLICATED;
432- }else{ /* the process does not exist */
441+ }
442+
443+ /* the process does not exist */
444+ else{
433445 FixProcessEndInDb(otherPid, "NONE");
434446 }
435447 }