=== modified file 'TODO'
--- TODO 2012-06-16 23:25:46 +0000
+++ TODO 2012-06-17 14:55:31 +0000
@@ -31,7 +31,7 @@
* plugin-runner
** TODO handle printing for errors for plugins
-*** Hook up stderr of plugins, buffer them, and prepend mandos pluig [plugin name]
+*** Hook up stderr of plugins, buffer them, and prepend "Mandos Plugin [plugin name]"
** TODO [#B] use scandir(3) instead of readdir(3)
** TODO [#C] use same file name rules as run-parts(8)
** kernel command line option for debug info
@@ -44,8 +44,6 @@
** TODO [#C] config for TXT record
** TODO Log level dbus option
SetLogLevel D-Bus call
-** TODO Implement --foreground :BUGS:
- [[info:standards:Option%20Table][Table of Long Options]]
** TODO [#C] DBusServiceObjectUsingSuper
** TODO [#B] Global enable/disable flag
** TODO [#B] By-client countdown on number of secrets given
=== modified file 'mandos'
--- mandos 2012-06-01 18:39:03 +0000
+++ mandos 2012-06-17 14:55:31 +0000
@@ -1948,21 +1948,18 @@
try:
self.socket.setsockopt(socket.SOL_SOCKET,
SO_BINDTODEVICE,
- str(self.interface
- + '\0'))
+ str(self.interface + '\0'))
except socket.error as error:
if error.errno == errno.EPERM:
- logger.error("No permission to"
- " bind to interface %s",
- self.interface)
+ logger.error("No permission to bind to"
+ " interface %s", self.interface)
elif error.errno == errno.ENOPROTOOPT:
logger.error("SO_BINDTODEVICE not available;"
" cannot bind to interface %s",
self.interface)
elif error.errno == errno.ENODEV:
- logger.error("Interface %s does not"
- " exist, cannot bind",
- self.interface)
+ logger.error("Interface %s does not exist,"
+ " cannot bind", self.interface)
else:
raise
# Only bind(2) the socket if we really need to.
@@ -2201,6 +2198,8 @@
" socket to use instead of creating one")
parser.add_argument("--statedir", metavar="DIR",
help="Directory to save/restore state in")
+ parser.add_argument("--foreground", action="store_true",
+ help="Run in foreground")
options = parser.parse_args()
@@ -2222,7 +2221,8 @@
"debuglevel": "",
"restore": "True",
"socket": "",
- "statedir": "/var/lib/mandos"
+ "statedir": "/var/lib/mandos",
+ "foreground": "False",
}
# Parse config file for server-global settings
@@ -2233,7 +2233,7 @@
# Convert the SafeConfigParser object to a dict
server_settings = server_config.defaults()
# Use the appropriate methods on the non-string config options
- for option in ("debug", "use_dbus", "use_ipv6"):
+ for option in ("debug", "use_dbus", "use_ipv6", "foreground"):
server_settings[option] = server_config.getboolean("DEFAULT",
option)
if server_settings["port"]:
@@ -2255,7 +2255,7 @@
for option in ("interface", "address", "port", "debug",
"priority", "servicename", "configdir",
"use_dbus", "use_ipv6", "debuglevel", "restore",
- "statedir", "socket"):
+ "statedir", "socket", "foreground"):
value = getattr(options, option)
if value is not None:
server_settings[option] = value
@@ -2264,6 +2264,9 @@
for option in server_settings.keys():
if type(server_settings[option]) is str:
server_settings[option] = unicode(server_settings[option])
+ # Debug implies foreground
+ if server_settings["debug"]:
+ server_settings["foreground"] = True
# Now we have our good server settings in "server_settings"
##################################################################
@@ -2275,6 +2278,7 @@
use_ipv6 = server_settings["use_ipv6"]
stored_state_path = os.path.join(server_settings["statedir"],
stored_state_file)
+ foreground = server_settings["foreground"]
if debug:
initlogger(debug, logging.DEBUG)
@@ -2312,8 +2316,9 @@
use_dbus=use_dbus,
socketfd=(server_settings["socket"]
or None))
- if not debug:
+ if not foreground:
pidfilename = "/var/run/mandos.pid"
+ pidfile = None
try:
pidfile = open(pidfilename, "w")
except IOError as e:
@@ -2358,7 +2363,7 @@
os.close(null)
# Need to fork before connecting to D-Bus
- if not debug:
+ if not foreground:
# Close all input and output, do double fork, etc.
daemon()
@@ -2497,18 +2502,16 @@
if not tcp_server.clients:
logger.warning("No clients defined")
- if not debug:
- try:
- with pidfile:
- pid = os.getpid()
- pidfile.write(str(pid) + "\n".encode("utf-8"))
- del pidfile
- except IOError:
- logger.error("Could not write to file %r with PID %d",
- pidfilename, pid)
- except NameError:
- # "pidfile" was never created
- pass
+ if not foreground:
+ if pidfile is not None:
+ try:
+ with pidfile:
+ pid = os.getpid()
+ pidfile.write(str(pid) + "\n".encode("utf-8"))
+ except IOError:
+ logger.error("Could not write to file %r with PID %d",
+ pidfilename, pid)
+ del pidfile
del pidfilename
signal.signal(signal.SIGHUP, lambda signum, frame: sys.exit())
=== modified file 'mandos-options.xml'
--- mandos-options.xml 2012-05-26 22:21:17 +0000
+++ mandos-options.xml 2012-06-17 14:55:31 +0000
@@ -103,4 +103,11 @@
default, the server will create a new network socket.
+
+ This option will make the server run in the foreground and not
+ write a PID file. The default is to not run
+ in the foreground, except in mode, which
+ implies this option.
+
+
=== modified file 'mandos.conf'
--- mandos.conf 2011-11-26 22:22:20 +0000
+++ mandos.conf 2012-06-17 14:55:31 +0000
@@ -42,3 +42,6 @@
# The directory where state is saved
;statedir = /var/lib/mandos
+
+# Whether to run in the foreground
+;foreground = False
=== modified file 'mandos.xml'
--- mandos.xml 2012-05-26 22:21:17 +0000
+++ mandos.xml 2012-06-17 14:55:31 +0000
@@ -2,7 +2,7 @@
-
+
%common;
]>
@@ -103,6 +103,8 @@
+
+ &COMMANDNAME;
@@ -311,6 +313,14 @@
+
+
+
+
+
+
+
@@ -561,9 +571,6 @@
There is no fine-grained control over logging and debug output.
- Debug mode is conflated with running in the foreground.
-
-
This server does not check the expire time of clients’ OpenPGP
keys.