~ubuntu-branches/ubuntu/lucid/menu-cache/lucid

« back to all changes in this revision

Viewing changes to libmenu-cache/menu-cache.c

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Lee (李健秋)
  • Date: 2009-11-09 18:38:57 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20091109183857-8xp9qyveufi7dhu5
Tags: 0.2.6-1
* New upstream release
  - Fixed invalid pointers
  - Fixed memory leaks
* Marked urgency=high
* Fix debian/watch file
* Bumped Standard-Version to 3.8.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
86
86
 
87
87
static int server_fd = -1;
88
88
static GIOChannel* server_ch = NULL;
 
89
static guint server_watch = 0;
89
90
static GHashTable* hash = NULL;
90
91
 
91
92
 
350
351
    if( g_atomic_int_dec_and_test( &cache->n_ref ) )
351
352
    {
352
353
        unregister_menu_from_server( cache );
 
354
        /* g_debug("unregister to server"); */
353
355
        g_hash_table_remove( hash, cache->menu_name );
354
356
        if( g_hash_table_size(hash) == 0 )
355
357
        {
 
358
            /* g_debug("destroy hash"); */
356
359
            g_hash_table_destroy(hash);
 
360
 
 
361
            /* g_debug("disconnect from server"); */
 
362
            g_source_remove(server_watch);
 
363
            g_io_channel_unref(server_ch);
 
364
            server_fd = -1;
 
365
            server_ch = NULL;
357
366
            hash = NULL;
358
367
        }
359
368
 
663
672
 
664
673
static void get_socket_name( char* buf, int len )
665
674
{
666
 
    char* dpy = g_getenv("DISPLAY");
667
 
    g_snprintf( buf, len, "/tmp/.menu-cached-%s-%s", dpy, g_get_user_name() );
 
675
    char* dpy = g_strdup(g_getenv("DISPLAY"));
 
676
    if(dpy && *dpy)
 
677
    {
 
678
        char* p = strchr(dpy, ':');
 
679
        for(++p; *p && *p != '.';)
 
680
            ++p;
 
681
        if(*p)
 
682
            *p = '\0';
 
683
    }
 
684
    g_snprintf( buf, len, "/tmp/.menu-cached-%s-%s", dpy ? dpy : ":0", g_get_user_name() );
 
685
    g_free(dpy);
668
686
}
669
687
 
670
688
#define MAX_RETRIES 25
707
725
    if( cond & (G_IO_ERR|G_IO_HUP) )
708
726
    {
709
727
reconnect:
710
 
        g_debug("IO error, try to re-connect.");
 
728
        g_debug("IO error %d, try to re-connect.", cond);
711
729
        g_io_channel_unref(ch);
712
730
        server_fd = -1;
713
731
        if( ! connect_server() )
721
739
            MenuCache* cache;
722
740
            g_debug("successfully restart server.\nre-register menus.");
723
741
            /* re-register all menu caches */
724
 
            g_hash_table_iter_init(&it, hash);
725
 
            while(g_hash_table_iter_next(&it, (gpointer*)&menu_name, (gpointer*)&cache))
726
 
                register_menu_to_server( menu_name, TRUE );
 
742
            if(hash)
 
743
            {
 
744
                g_hash_table_iter_init(&it, hash);
 
745
                while(g_hash_table_iter_next(&it, (gpointer*)&menu_name, (gpointer*)&cache))
 
746
                    register_menu_to_server( menu_name, TRUE );
 
747
            }
727
748
        }
728
749
        return FALSE;
729
750
    }
811
832
    server_fd = fd;
812
833
    server_ch = g_io_channel_unix_new(fd);
813
834
    g_io_channel_set_close_on_unref(server_ch, TRUE);
814
 
    g_io_add_watch(server_ch, G_IO_IN|G_IO_PRI|G_IO_ERR|G_IO_HUP, on_server_io, NULL);
 
835
    server_watch = g_io_add_watch(server_ch, G_IO_IN|G_IO_PRI|G_IO_ERR|G_IO_HUP, on_server_io, NULL);
815
836
    return TRUE;
816
837
}
817
838