Revision 810a20fa nfdhcpd

b/nfdhcpd
33 33
import pyinotify
34 34

  
35 35
import IPy
36
import socket
36 37
from select import select
37 38
from socket import AF_INET, AF_INET6
38 39

  
......
255 256

  
256 257
        try:
257 258
            f = open(file, 'r')
258
            ifindex = int(f.readline().strip())
259
            f.close()
260
        except IOError:
261
            logging.debug("%s is down, removing" % iface)
259
        except EnvironmentError:
260
            logging.debug("%s is probably down, removing" % iface)
262 261
            self.remove_iface(iface)
263 262

  
263
            return ifindex
264

  
265
        try:
266
            ifindex = f.readline().strip()
267
            try:
268
                ifindex = int(ifindex)
269
            except ValueError, e:
270
                logging.warn("Failed to get ifindex for %s, cannot parse sysfs"
271
                             " output '%s'" % (iface, ifindex))
272
        except EnvironmentError, e:
273
            logging.warn("Error reading %s's ifindex from sysfs: %s" %
274
                         (iface, str(e)))
275
            self.remove_iface(iface)
276
        finally:
277
            f.close()
278

  
264 279
        return ifindex
265 280

  
266 281

  
......
275 290
        addr = None
276 291
        try:
277 292
            f = open(file, 'r')
293
        except EnvironmentError:
294
            logging.debug("%s is probably down, removing" % iface)
295
            self.remove_iface(iface)
296
            return addr
297

  
298
        try:
278 299
            addr = f.readline().strip()
300
        except EnvironmentError, e:
301
            logging.warn("Failed to read hw address for %s from sysfs: %s" %
302
                         (iface, str(e)))
303
        finally:
279 304
            f.close()
280
        except IOError:
281
            logging.debug("%s is down, removing" % iface)
282
            self.remove_iface(iface)
283 305

  
284 306
        return addr
285 307

  
......
304 326

  
305 327
        for route in routes:
306 328
            # Find the least-specific connected route
329
            m = re.match("^([^\\s]+) dev %s" % def_dev, route)
330
            if not m:
331
                continue
332
            def_net = m.groups(1)
333

  
307 334
            try:
308
                def_net = re.match("^([^\\s]+) dev %s" %
309
                                   def_dev, route).groups()[0]
310 335
                def_net = IPy.IP(def_net)
311
            except:
312
                pass
336
            except ValueError, e:
337
                logging.warn("Unable to parse default route entry %s: %s" %
338
                             (def_net, str(e)))
313 339

  
314 340
        return Subnet(net=def_net, gw=def_gw, dev=def_dev)
315 341

  
......
319 345
        """
320 346
        try:
321 347
            iffile = open(path, 'r')
322
        except:
348
        except EnvironmentError, e:
349
            logging.warn("Unable to open binding file %s: %s" % (path, str(e)))
323 350
            return (None, None, None, None)
351

  
324 352
        mac = None
325 353
        ips = None
326 354
        link = None
......
565 593
                                         lifetime=self.ra_period * 3)
566 594
            try:
567 595
                sendp(resp, iface=iface, verbose=False)
568
            except:
569
                logging.debug("Periodic RA on %s failed" % iface)
596
            except socket.error, e:
597
                logging.warn("Periodic RA on %s failed: %s" % (iface, str(e)))
598
            except Exception, e:
599
                logging.warn("Unkown error during periodic RA on %s: %s" %
600
                             (iface, str(e)))
570 601
            i += 1
571 602
        logging.debug("Sent %d RAs in %.2f seconds" % (i, time.time() - start))
572 603

  
......
602 633
                for fd in rlist:
603 634
                    try:
604 635
                        self.nfq[fd].process_pending()
605
                    except e, msg:
606
                        logging.warn("Error processing fd %d: %s" % (fd, e))
636
                    except Exception, e:
637
                        logging.warn("Error processing fd %d: %s" %
638
                                     (fd, str(e)))
607 639

  
608 640
            if self.ipv6_enabled:
609 641
                # Calculate the new timeout
......
620 652
    from cStringIO import StringIO
621 653
    from capng import *
622 654
    from pwd import getpwnam, getpwuid
623
    from configobj import ConfigObj, flatten_errors
655
    from configobj import ConfigObj, ConfigObjError, flatten_errors
624 656

  
625 657
    import validate
626 658

  
......
669 701

  
670 702
    try:
671 703
        config = ConfigObj(opts.config_file, configspec=config_spec)
672
    except:
673
        sys.stderr.write("Failed to parse config file %s" % opts.config_file)
704
    except ConfigObjError, e:
705
        sys.stderr.write("Failed to parse config file %s: %s" %
706
                         (opts.config_file, str(e)))
674 707
        sys.exit(1)
675 708

  
676 709
    results = config.validate(validator)

Also available in: Unified diff