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