Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpnSense
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
OpnSense
Commits
cbe5cddb
Commit
cbe5cddb
authored
Jan 20, 2016
by
Ad Schellevis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(ids) locking issue when building rule cache, closes
https://github.com/opnsense/core/issues/633
parent
7f436abb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
5 deletions
+14
-5
rulecache.py
src/opnsense/scripts/suricata/lib/rulecache.py
+14
-5
No files found.
src/opnsense/scripts/suricata/lib/rulecache.py
View file @
cbe5cddb
...
@@ -33,6 +33,7 @@ import os.path
...
@@ -33,6 +33,7 @@ import os.path
import
glob
import
glob
import
sqlite3
import
sqlite3
import
shlex
import
shlex
import
fcntl
from
lib
import
rule_source_directory
from
lib
import
rule_source_directory
...
@@ -133,17 +134,23 @@ class RuleCache(object):
...
@@ -133,17 +134,23 @@ class RuleCache(object):
""" create new cache
""" create new cache
:return: None
:return: None
"""
"""
# lock create process
lock
=
open
(
self
.
cachefile
+
'.LCK'
,
'w'
)
try
:
fcntl
.
flock
(
lock
,
fcntl
.
LOCK_EX
|
fcntl
.
LOCK_NB
)
except
IOError
:
# other process is already creating the cache, wait, let the other process do it's work and return.
fcntl
.
flock
(
lock
,
fcntl
.
LOCK_EX
)
fcntl
.
flock
(
lock
,
fcntl
.
LOCK_UN
)
return
# remove existing DB
if
os
.
path
.
exists
(
self
.
cachefile
):
if
os
.
path
.
exists
(
self
.
cachefile
):
os
.
remove
(
self
.
cachefile
)
os
.
remove
(
self
.
cachefile
)
db
=
sqlite3
.
connect
(
self
.
cachefile
)
db
=
sqlite3
.
connect
(
self
.
cachefile
)
cur
=
db
.
cursor
()
cur
=
db
.
cursor
()
# if another process created the file, exit.
cur
.
execute
(
"select count(*) from sqlite_master where name = 'stats'"
)
if
cur
.
fetchall
()[
0
][
0
]
>
0
:
return
None
cur
.
execute
(
"CREATE TABLE stats (timestamp number, files number)"
)
cur
.
execute
(
"CREATE TABLE stats (timestamp number, files number)"
)
cur
.
execute
(
"""CREATE TABLE rules (sid number, msg TEXT, classtype TEXT,
cur
.
execute
(
"""CREATE TABLE rules (sid number, msg TEXT, classtype TEXT,
rev INTEGER, gid INTEGER, reference TEXT,
rev INTEGER, gid INTEGER, reference TEXT,
...
@@ -165,6 +172,8 @@ class RuleCache(object):
...
@@ -165,6 +172,8 @@ class RuleCache(object):
'fieldvalues'
:
':'
+
(
',:'
.
join
(
self
.
_rule_fields
))},
rules
)
'fieldvalues'
:
':'
+
(
',:'
.
join
(
self
.
_rule_fields
))},
rules
)
cur
.
execute
(
'INSERT INTO stats (timestamp,files) VALUES (?,?) '
,
(
last_mtime
,
len
(
all_rule_files
)))
cur
.
execute
(
'INSERT INTO stats (timestamp,files) VALUES (?,?) '
,
(
last_mtime
,
len
(
all_rule_files
)))
db
.
commit
()
db
.
commit
()
# release lock
fcntl
.
flock
(
lock
,
fcntl
.
LOCK_UN
)
def
search
(
self
,
limit
,
offset
,
filter_txt
,
sort_by
):
def
search
(
self
,
limit
,
offset
,
filter_txt
,
sort_by
):
""" search installed rules
""" search installed rules
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment