~ubuntu-branches/ubuntu/maverick/landscape-client/maverick

« back to all changes in this revision

Viewing changes to landscape/watchdog.py

  • Committer: Bazaar Package Importer
  • Author(s): Christopher Armstrong
  • Date: 2009-04-09 17:09:50 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20090409170950-mc5mqadawk0ls2vc
Tags: 1.0.29-0ubuntu0.9.04.0
* New upstream bugfix release (LP: #358744)
  - Add a timeout to HTTP operations to avoid hanging (LP: #349737)
  - Clean up environment variables on startup to avoid propagating
    variables that will corrupt package installation (LP: #348681)
  - Clean up FDs on startup for the same reason (LP: #352458)
  - Catch and handle certain errors from smart (such as invalid package
    data) to avoid "stuck" Landscape activities (LP: #268745)
  - Don't print warnings meant for developers to the console (LP: #336669)

Show diffs side-by-side

added added

removed removed

Lines of Context:
412
412
 
413
413
 
414
414
def daemonize():
415
 
    # See http://web.archive.org/web/20070410070022/www.erlenstar.demon.co.uk/unix/faq_2.html#SEC13
 
415
    # See http://www.steve.org.uk/Reference/Unix/faq_2.html#SEC16
416
416
    if os.fork():   # launch child and...
417
417
        os._exit(0) # kill off parent
418
418
    os.setsid()
507
507
    ])
508
508
 
509
509
 
 
510
def clean_environment():
 
511
    """Unset any environment variables that begin with DEBIAN_ or DEBCONF_.
 
512
 
 
513
    We do this to avoid any problems when landscape-client is invoked from its
 
514
    postinst script.  Some environment variables may be set which would affect
 
515
    *other* maintainer scripts which landscape-client invokes (via smart).
 
516
    """
 
517
    for key in os.environ.keys():
 
518
        if (key.startswith("DEBIAN_")
 
519
            or key.startswith("DEBCONF_")
 
520
            or key == "LANDSCAPE_ATTACHMENTS"):
 
521
            del os.environ[key]
 
522
 
 
523
 
510
524
def run(args=sys.argv, reactor=None):
 
525
    """Start the watchdog.
 
526
 
 
527
    This is the topmost function that kicks off the Landscape client.  It cleans
 
528
    up the environment, loads the configuration, and starts the reactor.
 
529
 
 
530
    @param args: Command line arguments, including the program name as the
 
531
        first element.
 
532
    @param reactor: The reactor to use.  If none is specified, the global
 
533
        reactor is used.
 
534
    @raise SystemExit: if command line arguments are bad, or when landscape-
 
535
        client is running as non-root and the configuration indicates use of
 
536
        the system bus.
 
537
    """
 
538
    clean_environment()
 
539
 
511
540
    config = WatchDogConfiguration()
512
541
    config.load(args)
513
542