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
135a8615
Commit
135a8615
authored
Apr 01, 2016
by
Ad Schellevis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(configd) small style fixes
parent
abcb4cce
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
14 deletions
+21
-14
configd.py
src/opnsense/service/configd.py
+21
-14
No files found.
src/opnsense/service/configd.py
View file @
135a8615
...
...
@@ -32,8 +32,6 @@
function: delivers a process coordinator to handle frontend functions
"""
__author__
=
'Ad Schellevis'
import
os
import
sys
import
logging
...
...
@@ -44,10 +42,10 @@ import subprocess
import
modules.processhandler
import
modules.csconfigparser
from
modules.daemonize
import
Daemonize
import
cProfile
,
pstats
import
cProfile
# find program path
if
len
(
__file__
.
split
(
'/'
)[:
-
1
])
>
0
:
if
len
(
__file__
.
split
(
'/'
)[:
-
1
])
>
0
:
program_path
=
'/'
.
join
(
__file__
.
split
(
'/'
)[:
-
1
])
else
:
program_path
=
os
.
getcwd
()
...
...
@@ -56,6 +54,7 @@ else:
sys
.
path
.
append
(
program_path
)
os
.
chdir
(
program_path
)
def
get_config
():
""" open configuration
"""
...
...
@@ -63,43 +62,51 @@ def get_config():
cnf
.
read
(
'conf/configd.conf'
)
return
cnf
def
validate_config
(
cnf
):
""" validate configuration, exit on missing item
:param cnf: config handle
"""
for
config_item
in
[
'socket_filename'
,
'pid_filename'
]:
if
cnf
.
has_section
(
'main'
)
==
False
or
cnf
.
has_option
(
'main'
,
config_item
)
==
False
:
print
(
'configuration item main/
%
s not found in
%
s/conf/configd.conf'
%
(
config_item
,
program_path
))
for
config_item
in
[
'socket_filename'
,
'pid_filename'
]:
if
cnf
.
has_section
(
'main'
)
==
False
or
cnf
.
has_option
(
'main'
,
config_item
)
==
False
:
print
(
'configuration item main/
%
s not found in
%
s/conf/configd.conf'
%
(
config_item
,
program_path
))
sys
.
exit
(
0
)
def
main
(
cnf
,
simulate
=
False
,
single_threaded
=
False
):
""" configd startup
:param cnf: config handle
:param simulate: simulate only
:param single_threaded: start single threaded
"""
# setup configd environment to use for all configured actions
if
not
cnf
.
has_section
(
'environment'
):
config_environment
=
os
.
environ
.
copy
()
else
:
config_environment
=
{}
config_environment
=
dict
()
for
envKey
in
cnf
.
items
(
'environment'
):
config_environment
[
envKey
[
0
]]
=
envKey
[
1
]
# run process coordinator ( on console or as daemon )
# if command-line arguments contain "emulate", start in emulation mode
if
simulate
:
proc_handler
=
modules
.
processhandler
.
Handler
(
socket_filename
=
cnf
.
get
(
'main'
,
'socket_filename'
),
config_path
=
'
%
s/conf'
%
program_path
,
proc_handler
=
modules
.
processhandler
.
Handler
(
socket_filename
=
cnf
.
get
(
'main'
,
'socket_filename'
),
config_path
=
'
%
s/conf'
%
program_path
,
config_environment
=
config_environment
,
simulation_mode
=
True
)
else
:
proc_handler
=
modules
.
processhandler
.
Handler
(
socket_filename
=
cnf
.
get
(
'main'
,
'socket_filename'
),
config_path
=
'
%
s/conf'
%
program_path
,
proc_handler
=
modules
.
processhandler
.
Handler
(
socket_filename
=
cnf
.
get
(
'main'
,
'socket_filename'
),
config_path
=
'
%
s/conf'
%
program_path
,
config_environment
=
config_environment
)
proc_handler
.
single_threaded
=
single_threaded
proc_handler
.
run
()
def
run_watch
():
""" start configd process and restart if it dies unexpected
"""
current_child_pid
=
None
def
signal_handler
(
sig
,
frame
):
print
current_child_pid
if
current_child_pid
is
not
None
:
...
...
@@ -118,7 +125,7 @@ def run_watch():
this_config
=
get_config
()
validate_config
(
this_config
)
if
len
(
sys
.
argv
)
>
1
and
'console'
in
sys
.
argv
[
1
:]:
print
(
'run
%
s in console mode'
%
sys
.
argv
[
0
])
print
(
'run
%
s in console mode'
%
sys
.
argv
[
0
])
if
'profile'
in
sys
.
argv
[
1
:]:
# profile configd
# for graphical output use gprof2dot:
...
...
@@ -160,7 +167,7 @@ else:
loghandle
=
None
# daemonize process
daemon
=
Daemonize
(
app
=
__file__
.
split
(
'/'
)[
-
1
]
.
split
(
'.py'
)[
0
],
pid
=
this_config
.
get
(
'main'
,
'pid_filename'
),
pid
=
this_config
.
get
(
'main'
,
'pid_filename'
),
action
=
run_watch
,
logger
=
loghandle
)
...
...
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