Ticket #1447: sugar-toolkit-1447.patch

File sugar-toolkit-1447.patch, 2.9 KB (added by alsroot, 14 years ago)
  • src/sugar/activity/activityfactory.py

    From eccb44134b943da61f0537cb7dc68aa4a1d2d112 Mon Sep 17 00:00:00 2001
    From: Aleksey Lim <alsroot@member.fsf.org>
    Date: Wed, 10 Mar 2010 09:05:27 +0000
    Subject: Notify shell when activity process terminates #1447
    
    
    diff --git a/src/sugar/activity/activityfactory.py b/src/sugar/activity/activityfactory.py
    index c12630e..6b4ba32 100644
    a b class ActivityCreationHandler(gobject.GObject): 
    274274
    275275        gobject.child_watch_add(child.pid,
    276276                                _child_watch_cb,
    277                                 (environment_dir, log_file))
     277                                (environment_dir, log_file,
     278                                    self._handle.activity_id))
    278279
    279280    def _no_reply_handler(self, *args):
    280281        pass
    def create_with_object_id(bundle, object_id): 
    337338def _child_watch_cb(pid, condition, user_data):
    338339    # FIXME we use standalone method here instead of ActivityCreationHandler's
    339340    # member to have workaround code, see #1123
    340     environment_dir, log_file = user_data
     341    environment_dir, log_file, activity_id = user_data
    341342    if environment_dir is not None:
    342343        subprocess.call(['/bin/rm', '-rf', environment_dir])
     344
     345    if os.WIFEXITED(condition):
     346        status = os.WEXITSTATUS(condition)
     347        signum = None
     348        message = 'Exited with status %s' % status
     349    elif os.WIFSIGNALED(condition):
     350        status = None
     351        signum = os.WTERMSIG(condition)
     352        message = 'Terminated by signal %s' % signum
     353    else:
     354        status = None
     355        signum = os.WTERMSIG(condition)
     356        message = 'Undefined status with signal %s' % signum
     357
    343358    try:
    344         log_file.write('Activity died: pid %s condition %s data %s\n' %
    345             (pid, condition, user_data))
     359        log_file.write('%s, pid %s data %s\n' % (message, pid, user_data))
    346360    finally:
    347361        log_file.close()
    348362
    def _child_watch_cb(pid, condition, user_data): 
    352366    except OSError:
    353367        # SIGCHLD = SIG_IGN, no zombies
    354368        pass
     369
     370    if status or signum:
     371        # XXX have to recreate dbus object since we can't reuse
     372        # ActivityCreationHandler's one, see
     373        # https://bugs.freedesktop.org/show_bug.cgi?id=23507
     374        bus = dbus.SessionBus()
     375        bus_object = bus.get_object(_SHELL_SERVICE, _SHELL_PATH)
     376        shell = dbus.Interface(bus_object, _SHELL_IFACE)
     377
     378        def reply_handler_cb(*args):
     379            pass
     380
     381        def error_handler_cb(error):
     382            logging.error('Cannot send NotifyLaunchFailure to the shell')
     383
     384        # TODO send launching failure but activity could already show
     385        # main window, see http://bugs.sugarlabs.org/ticket/1447#comment:19
     386        shell.NotifyLaunchFailure(activity_id,
     387                reply_handler=reply_handler_cb,
     388                error_handler=error_handler_cb)