Subject: keep forked children when father dies
To: None <tech-pkg@netbsd.org>
From: Joel CARNAT <joel@carnat.net>
List: tech-pkg
Date: 03/24/2004 19:42:25
Hi,

I'm doing portage for suxpanel (this is ~ a launching bar).
It compiles and run OK but...

When it launches an apps (say XTerm), it forks.
But If I Ctrl-C suxpanel, then all the forked apps die too...

The code is :
static void spawn_app(GtkWidget *widget, gpointer data)
{
        gchar *app, *path;
        pid_t child;

        path = (gchar*) g_object_get_data(G_OBJECT(widget), "path");

        app = g_strdup_printf("%s/%s/AppRun", path ? path : app_path,
(gchar*)data);

        child = fork();
        if (child == -1) {
                GtkWidget *dialog;

                dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL,
                        GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
                        "Cannot fork. Yay.");
                gtk_dialog_run(GTK_DIALOG(dialog));
                gtk_widget_destroy(dialog);
        } else if (child == 0) {
                char *argv[2];

                argv[0] = app;
                argv[1] = 0;

                execv(app, argv);
                _exit(127);
        }

        g_free(app);
}

I thought I could use another exec* function or send a SIG* to the
child, but can't find a clue in the man...
Can anyone enlighten me ?

ThX,
	Jo