Created
April 27, 2017 09:50
-
-
Save benruijl/6e68d7e905c8f2a17e8462f74efc9b2a to your computer and use it in GitHub Desktop.
Minimal example of crash of nautilus extension and seafile_get_repo_list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// gcc -c -g test.c -o libnautilus-seafile.o -fPIC `pkg-config --cflags glib-2.0`; | |
// gcc -shared libnautilus-seafile.o -o libnautilus-seafile.so `pkg-config --libs libccnet libseafile` | |
#include <stdio.h> | |
#include <glib.h> | |
#include <searpc-client.h> | |
#include <ccnet.h> | |
#include <searpc.h> | |
#include <seafile/seafile.h> | |
#include <seafile/seafile-object.h> | |
static GType type_list[1]; | |
static CcnetClient *sync_client_ = NULL; | |
static SearpcClient *rpc_client_ = NULL; | |
static const char *kSeafileRpcService = "seafile-rpcserver"; | |
static const char *get_ccnet_conf_dir () | |
{ | |
static const char *ccnet_dir = NULL; | |
if (!ccnet_dir) | |
{ | |
ccnet_dir = g_getenv ("CCNET_CONF_DIR"); | |
if (!ccnet_dir) | |
{ | |
ccnet_dir = g_build_path ("/", g_get_home_dir (), | |
".ccnet", NULL); | |
} | |
} | |
return ccnet_dir; | |
} | |
SearpcClient* seafile_rpc_get_instance () | |
{ | |
const char *ccnet_dir = get_ccnet_conf_dir (); | |
sync_client_ = ccnet_client_new (); | |
if (ccnet_client_load_confdir (sync_client_, NULL, ccnet_dir) < 0) | |
{ | |
g_warning("Loading configuration directory failed"); | |
g_object_unref (sync_client_); | |
return NULL; | |
} | |
if (ccnet_client_connect_daemon (sync_client_, CCNET_CLIENT_SYNC) < 0) | |
{ | |
g_warning("Connecting to client daemon failed"); | |
g_object_unref (sync_client_); | |
return NULL; | |
} | |
return ccnet_create_rpc_client (sync_client_, NULL, kSeafileRpcService); | |
} | |
typedef struct _SeafileExtension SeafileExtension; | |
typedef struct _SeafileExtensionClass SeafileExtensionClass; | |
static void seafile_extension_instance_init (SeafileExtension *seafile) {} | |
static void seafile_extension_class_init (SeafileExtensionClass *class) {} | |
static GType seafile_type = 0; | |
GType | |
seafile_extension_get_type (void) | |
{ | |
return seafile_type; | |
} | |
struct _SeafileExtension { | |
GObject parent_slot; | |
}; | |
struct _SeafileExtensionClass { | |
GObjectClass parent_slot; | |
}; | |
void | |
seafile_extension_register_type (GTypeModule *module) | |
{ | |
static const GTypeInfo info = { | |
sizeof (SeafileExtensionClass), | |
(GBaseInitFunc) NULL, | |
(GBaseFinalizeFunc) NULL, | |
(GClassInitFunc) seafile_extension_class_init, | |
NULL, | |
NULL, | |
sizeof (SeafileExtension), | |
0, | |
(GInstanceInitFunc) seafile_extension_instance_init, | |
NULL | |
}; | |
seafile_type = g_type_module_register_type (module, G_TYPE_OBJECT, "seafileExtension", &info, 0); | |
} | |
void nautilus_module_initialize(GTypeModule *module) | |
{ | |
GError *error = NULL; | |
g_message ("Initializing nautilus-seafile extension\n"); | |
seafile_extension_register_type (module); | |
type_list[0] = seafile_extension_get_type (); | |
SearpcClient *client = seafile_rpc_get_instance (); | |
g_message ("Obtained client: %p\n", client); | |
seafile_get_repo_list (client, 0, 0, &error); // crash occurs here | |
g_free(client); | |
} | |
void nautilus_module_shutdown(void) | |
{ | |
g_message ("Unloading nautilus-seafile extension\n"); | |
} | |
void nautilus_module_list_types(const GType **types, int *num_types) { | |
*types = type_list; | |
*num_types = G_N_ELEMENTS(type_list); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment