Revision 3e87c1bf

b/lib/daemon.py
491 491
def _VerifyDaemonUser(daemon_name):
492 492
  """Verifies the process uid matches the configured uid.
493 493

  
494
  This method verifies that a daemon is started as the user it is intended to be
495
  run
494
  This method verifies that a daemon is started as the user it is
495
  intended to be run
496 496

  
497 497
  @param daemon_name: The name of daemon to be started
498 498
  @return: A tuple with the first item indicating success or not,
......
512 512
          daemon_uids[daemon_name])
513 513

  
514 514

  
515
def _BeautifyError(err):
516
  """Try to format an error better.
517

  
518
  Since we're dealing with daemon startup errors, in many cases this
519
  will be due to socket error and such, so we try to format these cases better.
520

  
521
  @param err: an exception object
522
  @rtype: string
523
  @return: the formatted error description
524

  
525
  """
526
  try:
527
    if isinstance(err, socket.error):
528
      return "Socket-related error: %s (errno=%s)" % (err.args[1], err.args[0])
529
    elif isinstance(err, EnvironmentError):
530
      if err.filename is None:
531
        return "%s (errno=%s)" % (err.strerror, err.errno)
532
      else:
533
        return "%s (file %s) (errno=%s)" % (err.strerror, err.filename,
534
                                            err.errno)
535
    else:
536
      return str(err)
537
  except Exception: # pylint: disable-msg=W0703
538
    logging.exception("Error while handling existing error %s", err)
539
    return "%s" % str(err)
540

  
541

  
515 542
def GenericMain(daemon_name, optionparser,
516 543
                check_fn, prepare_fn, exec_fn,
517 544
                multithreaded=False, console_logging=False,
......
645 672
      logging.info("%s daemon startup", daemon_name)
646 673
    except Exception, err:
647 674
      if wpipe is not None:
648
        os.write(wpipe, str(err))
675
        os.write(wpipe, _BeautifyError(err))
649 676
      raise
650 677

  
651 678
    if wpipe is not None:

Also available in: Unified diff