Changeset 2811


Ignore:
Timestamp:
08/23/07 15:14:51 (6 years ago)
Author:
mickey
Message:

openmoko-dialer1: don't segfault if dbus is not running. thanks Elrond. closes #631

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/target/OM-2007/applications/openmoko-dialer/src/dialer-main.c

    r2342 r2811  
    4242} 
    4343 
     44 
     45static DBusGConnection * 
     46dbus_setup(gboolean *p_already_running) 
     47{ 
     48  DBusGConnection *connection; 
     49  DBusGProxy *proxy; 
     50  GError *error = NULL; 
     51  guint32 ret; 
     52 
     53  if (p_already_running) 
     54    *p_already_running = FALSE; 
     55 
     56  connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error); 
     57  if (connection == NULL) 
     58  { 
     59    g_warning ("Failed to make a connection to the session bus: %s",  
     60               error->message); 
     61    g_error_free (error); 
     62    return NULL; 
     63  } 
     64 
     65  proxy = dbus_g_proxy_new_for_name (connection,  
     66                                     DBUS_SERVICE_DBUS, 
     67                                     DBUS_PATH_DBUS,  
     68                                     DBUS_INTERFACE_DBUS); 
     69  if (proxy == NULL) 
     70  { 
     71    g_warning ("Error getting a DBus Proxy\n"); 
     72    dbus_g_connection_unref (connection); 
     73    return NULL; 
     74  } 
     75 
     76  if (!org_freedesktop_DBus_request_name (proxy, 
     77                                          DIALER_NAMESPACE, 
     78                                          0, &ret, &error)) 
     79  { 
     80    /* Error requesting the name */ 
     81    g_warning ("There was an error requesting the name: %s\n",error->message); 
     82    g_error_free (error); 
     83 
     84    dbus_g_connection_unref (connection); 
     85     
     86    return NULL; 
     87  } 
     88  if (ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) 
     89  { 
     90    if (p_already_running) 
     91      *p_already_running = TRUE; 
     92  } 
     93 
     94  return connection; 
     95} 
     96 
     97 
    4498static void 
    4599_show_dialer (DBusGConnection *conn) 
     
    100154  MokoDialer *dialer; 
    101155  DBusGConnection *connection; 
    102   DBusGProxy *proxy; 
    103   GError *error = NULL; 
    104   guint32 ret; 
     156  gboolean already_running; 
    105157 
    106158  if (argc != 1) 
     
    122174 
    123175  /* Try and setup our DBus service */ 
    124   connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error); 
     176  connection = dbus_setup(&already_running); 
    125177  if (connection == NULL) 
    126178  { 
    127     g_warning ("Failed to make a connection to the session bus: %s",  
    128                error->message); 
    129     g_error_free (error); 
    130   } 
    131   proxy = dbus_g_proxy_new_for_name (connection,  
    132                                      DBUS_SERVICE_DBUS, 
    133                                      DBUS_PATH_DBUS,  
    134                                      DBUS_INTERFACE_DBUS); 
    135   if (!org_freedesktop_DBus_request_name (proxy, 
    136                                           DIALER_NAMESPACE, 
    137                                           0, &ret, &error)) 
    138   { 
    139     /* Error requesting the name */ 
    140     g_warning ("There was an error requesting the name: %s\n",error->message); 
    141     g_error_free (error); 
    142      
    143     gdk_init(&argc, &argv); 
    144     gdk_notify_startup_complete (); 
    145  
    146     return 1; 
    147   } 
    148   if (ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) 
     179    /* 
     180     * If no dbus, we can't get a remote signal to show 
     181     * the dialer, so just show it immediately 
     182     */ 
     183    show_dialer = TRUE; 
     184  } 
     185 
     186  if (already_running) 
    149187  { 
    150188    /* Someone else hase registere dthe object */ 
Note: See TracChangeset for help on using the changeset viewer.