GConf-dbus Error! Is a BUG? Can you help me !
Is this a bug of gconf-dbus?
/**
* In Debian system, If I mark the function test1() in programm, then the gconf is normal. If I invoke test1(), gconf will cause error.
*/
/*
* The following program will cause failure to invoke gconf client API, You can run the following programm.
* The error is " DBUS erro".
* GConf Error: Configuration server couldn't be contacted: D-BUS error: Message has the same reply serial
* as a currently-outstanding existing method call
* GConf Error: Configuration server couldn't be contacted: D-BUS error: No reply within specified time
*
*
*/
#include "gconf/gconf-client.h"
#include "glib.h"
#include "sys/types.h"
#include "sys/time.h"
#include "unistd.h"
#include "stdio.h"
#include "string.h"
#include "stdlib.h"
#include "sys/wait.h"
pid_t pid, pid2;
void test1()
{
GConfClient* client_read;
char temp_key[100];
char *text;
int i;
client_read = gconf_client_get_default();
for(i = 0; i <= 10; i++)
{
sprintf(temp_key, "/test/test%04d/key%04d", 3, i);
text = gconf_client_get_string(client_read, temp_key, NULL);
if(text)g_free(text);
}
g_object_unref (G_OBJECT (client_read));
}
void test_subproc1(void)
{
pid = fork();
if(pid == 0)
{
GConfClient* client_set;
char temp_key[100];
int i;
gboolean ret;
client_set = gconf_client_get_default();
for(i = 0; i <= 1000; i++)
{
sprintf(temp_key, "/test/test%04d/key%04d", 4, i);
ret = gconf_client_set_string(client_set, temp_key, "test ok", NULL);
}
g_object_unref (G_OBJECT (client_set));
exit(0);
}
}
void test_subproc2(void)
{
pid = fork();
if(pid == 0)
{
GConfClient* client_set;
char temp_key[100];
gboolean ret;
int i;
client_set = gconf_client_get_default();
for(i = 0; i <= 1000; i++)
{
sprintf(temp_key, "/test/test%04d/key%04d", 5, i);
ret = gconf_client_set_string(client_set, temp_key, "test ok", NULL);
}
g_object_unref (G_OBJECT (client_set));
exit(0);
}
}
int main()
{
int status;
g_type_init();
test_subproc1();
test_subproc2();
waitpid(pid, &status, 0);
waitpid(pid2, &status, 0);
test1(); // Invoking test1() will affect the gconf usage
test_subproc1();
test_subproc2();
waitpid(pid, &status, 0);
waitpid(pid2, &status, 0);
}

(At first I thought dbus
(At first I thought dbus wasn't properly setup, but I just noticed that I misread the error message, so editing the comment). I'm not sure what happens but I think it is because you are forking and therefore reusing the dbus connection in the other children. Please try forking before using gconf first or make sure to close all open file descriptors in the forked children.
Thanks ! when I run the
Thanks !
when I run the programm above, it returned errors as following:
" GConf Error: Configuration server couldn't be contacted: D-BUS error: Message has the same reply serial"
"GConf Error: Configuration server couldn't be contacted: D-BUS error: No reply within specified time"
But if I removed the code
"test1(); // Invoking test1() will affect the gconf usage" in file,
and then I compiled and run the file above, no error was returned. So I thought that dbus(session dbus) was ok. And I wander that the gconf-dbus is not stable especially when using forking.
would you give me some help?
I'd just say that you simply
I'd just say that you simply can't do fork() and use gconf in both the parent and children like that.