/mandos/release

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/release

« back to all changes in this revision

Viewing changes to mandos

  • Committer: Teddy Hogeborn
  • Date: 2012-06-17 22:26:40 UTC
  • mfrom: (301.1.1 release)
  • Revision ID: teddy@recompile.se-20120617222640-49scfn0husnrr5bi
Tags: version-1.6.0-1
* Makefile (version): Changed to "1.6.0".
* NEWS (Version 1.6.0): New entry.
* debian/changelog (1.6.0-1): - '' -

Show diffs side-by-side

added added

removed removed

Lines of Context:
88
88
    except ImportError:
89
89
        SO_BINDTODEVICE = None
90
90
 
91
 
version = "1.5.5"
 
91
version = "1.6.0"
92
92
stored_state_file = "clients.pickle"
93
93
 
94
94
logger = logging.getLogger()
1948
1948
                try:
1949
1949
                    self.socket.setsockopt(socket.SOL_SOCKET,
1950
1950
                                           SO_BINDTODEVICE,
1951
 
                                           str(self.interface
1952
 
                                               + '\0'))
 
1951
                                           str(self.interface + '\0'))
1953
1952
                except socket.error as error:
1954
1953
                    if error.errno == errno.EPERM:
1955
 
                        logger.error("No permission to"
1956
 
                                     " bind to interface %s",
1957
 
                                     self.interface)
 
1954
                        logger.error("No permission to bind to"
 
1955
                                     " interface %s", self.interface)
1958
1956
                    elif error.errno == errno.ENOPROTOOPT:
1959
1957
                        logger.error("SO_BINDTODEVICE not available;"
1960
1958
                                     " cannot bind to interface %s",
1961
1959
                                     self.interface)
1962
1960
                    elif error.errno == errno.ENODEV:
1963
 
                        logger.error("Interface %s does not"
1964
 
                                     " exist, cannot bind",
1965
 
                                     self.interface)
 
1961
                        logger.error("Interface %s does not exist,"
 
1962
                                     " cannot bind", self.interface)
1966
1963
                    else:
1967
1964
                        raise
1968
1965
        # Only bind(2) the socket if we really need to.
2201
2198
                        " socket to use instead of creating one")
2202
2199
    parser.add_argument("--statedir", metavar="DIR",
2203
2200
                        help="Directory to save/restore state in")
 
2201
    parser.add_argument("--foreground", action="store_true",
 
2202
                        help="Run in foreground")
2204
2203
    
2205
2204
    options = parser.parse_args()
2206
2205
    
2222
2221
                        "debuglevel": "",
2223
2222
                        "restore": "True",
2224
2223
                        "socket": "",
2225
 
                        "statedir": "/var/lib/mandos"
 
2224
                        "statedir": "/var/lib/mandos",
 
2225
                        "foreground": "False",
2226
2226
                        }
2227
2227
    
2228
2228
    # Parse config file for server-global settings
2233
2233
    # Convert the SafeConfigParser object to a dict
2234
2234
    server_settings = server_config.defaults()
2235
2235
    # Use the appropriate methods on the non-string config options
2236
 
    for option in ("debug", "use_dbus", "use_ipv6"):
 
2236
    for option in ("debug", "use_dbus", "use_ipv6", "foreground"):
2237
2237
        server_settings[option] = server_config.getboolean("DEFAULT",
2238
2238
                                                           option)
2239
2239
    if server_settings["port"]:
2255
2255
    for option in ("interface", "address", "port", "debug",
2256
2256
                   "priority", "servicename", "configdir",
2257
2257
                   "use_dbus", "use_ipv6", "debuglevel", "restore",
2258
 
                   "statedir", "socket"):
 
2258
                   "statedir", "socket", "foreground"):
2259
2259
        value = getattr(options, option)
2260
2260
        if value is not None:
2261
2261
            server_settings[option] = value
2264
2264
    for option in server_settings.keys():
2265
2265
        if type(server_settings[option]) is str:
2266
2266
            server_settings[option] = unicode(server_settings[option])
 
2267
    # Debug implies foreground
 
2268
    if server_settings["debug"]:
 
2269
        server_settings["foreground"] = True
2267
2270
    # Now we have our good server settings in "server_settings"
2268
2271
    
2269
2272
    ##################################################################
2275
2278
    use_ipv6 = server_settings["use_ipv6"]
2276
2279
    stored_state_path = os.path.join(server_settings["statedir"],
2277
2280
                                     stored_state_file)
 
2281
    foreground = server_settings["foreground"]
2278
2282
    
2279
2283
    if debug:
2280
2284
        initlogger(debug, logging.DEBUG)
2312
2316
                              use_dbus=use_dbus,
2313
2317
                              socketfd=(server_settings["socket"]
2314
2318
                                        or None))
2315
 
    if not debug:
 
2319
    if not foreground:
2316
2320
        pidfilename = "/var/run/mandos.pid"
 
2321
        pidfile = None
2317
2322
        try:
2318
2323
            pidfile = open(pidfilename, "w")
2319
2324
        except IOError as e:
2358
2363
            os.close(null)
2359
2364
    
2360
2365
    # Need to fork before connecting to D-Bus
2361
 
    if not debug:
 
2366
    if not foreground:
2362
2367
        # Close all input and output, do double fork, etc.
2363
2368
        daemon()
2364
2369
    
2497
2502
    if not tcp_server.clients:
2498
2503
        logger.warning("No clients defined")
2499
2504
    
2500
 
    if not debug:
2501
 
        try:
2502
 
            with pidfile:
2503
 
                pid = os.getpid()
2504
 
                pidfile.write(str(pid) + "\n".encode("utf-8"))
2505
 
            del pidfile
2506
 
        except IOError:
2507
 
            logger.error("Could not write to file %r with PID %d",
2508
 
                         pidfilename, pid)
2509
 
        except NameError:
2510
 
            # "pidfile" was never created
2511
 
            pass
 
2505
    if not foreground:
 
2506
        if pidfile is not None:
 
2507
            try:
 
2508
                with pidfile:
 
2509
                    pid = os.getpid()
 
2510
                    pidfile.write(str(pid) + "\n".encode("utf-8"))
 
2511
            except IOError:
 
2512
                logger.error("Could not write to file %r with PID %d",
 
2513
                             pidfilename, pid)
 
2514
        del pidfile
2512
2515
        del pidfilename
2513
2516
    
2514
2517
    signal.signal(signal.SIGHUP, lambda signum, frame: sys.exit())