g_spawn_async from a reloadable module



Does g_spawn_async do something to make it incompatible with being
called from a module that is unloaded and reloaded? I am calling this
function from a Mozilla plug-in (the module is loaded an unloaded on a
per-page basis). The function is called once each time the module is
loaded. The first time always succeeds. Subsequent attempts tend to fail
with this error:

        Failed to execute child process "/home/braden/src/openvrml/openvrml-0.15/BUILD/mozilla-plugin/src/openvrml-player/.libs/openvrml-player" (Bad address)

It doesn't fail 100% of the time. Sometimes it works. If I wait a little
while between unloading and reloading, the odds of it working seem to
improve a bit.

The code around the call to g_spawn_async looks like this:

        using std::vector;
        using std::string;
        using boost::lexical_cast;
        
        this->window = reinterpret_cast<GdkNativeWindow>(window.window);
        
        const char * exec_path = g_getenv("OPENVRML_PLAYER");
        if (!exec_path) {
             exec_path = OPENVRML_LIBEXECDIR_ "/openvrml-player";
        }
        vector<char> exec_path_vec(exec_path,
                                   exec_path + strlen(exec_path) + 1);
        
        string socket_id_arg =
            "--gtk-socket-id=" + lexical_cast<string>(this->window);
        const char * socket_id_arg_c_str = socket_id_arg.c_str();
        vector<char> socket_id_arg_vec(
            socket_id_arg_c_str,
            socket_id_arg_c_str + socket_id_arg.length() + 1);
        
        const char * uri_arg_c_str = this->initialURL.c_str();
        vector<char> uri_arg_vec(
            uri_arg_c_str,
            uri_arg_c_str + this->initialURL.length() + 1);
        
        char * argv[] = {
            &exec_path_vec.front(),
            &socket_id_arg_vec.front(),
            &uri_arg_vec.front()
        };
        
        const gchar * working_directory = 0;
        char ** envp = 0;
        GSpawnFlags flags = G_SPAWN_DO_NOT_REAP_CHILD;
        GSpawnChildSetupFunc child_setup = 0;
        gpointer user_data = 0;
        GError * error = 0;
        bool succeeded = g_spawn_async(working_directory,
                                       argv,
                                       envp,
                                       flags,
                                       child_setup,
                                       user_data,
                                       &this->player_pid,
                                       &error);
        if (!succeeded) {
            if (error) {
                g_printerr(error->message);
                g_error_free(error);
            }
        }

-- 
Braden McDaniel                           e-mail: <braden endoframe com>
<http://endoframe.com>                    Jabber: <braden jabber org>





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]