Example #1
0
/*
** Timeout event: An instance didn't spawn in time.
**  - If there is no more service file, destroy the watch
**  - Else, make it spawn again
*/
static gboolean on_instance_timeout(gpointer user_data)
{
    struct watch_instance *watch = user_data;
    gchar *service_path = NULL;
    gboolean service_exists = FALSE;

    service_path = get_service_file_path(watch->name);
    service_exists = g_file_test(service_path, G_FILE_TEST_EXISTS);
    g_free(service_path);

    if (service_exists == FALSE)
    {
        g_print("No more service file: %s\n", watch->name);

        watch_instance_free(watch);

        return FALSE;
    }

    g_print("Still no answer from: %s\n", watch->name);

    autolaunch_process_by_busname(watch->name);

    return TRUE;
}
Example #2
0
/*
** DBus event: An instance bus vanished
**  - Create a timeout watch
**  - Unwatch the instance bus
*/
static void on_instance_name_vanished(GDBusConnection *conn,
                                      const gchar *name,
                                      gpointer user_data)
{
    struct watch_instance *watch = user_data;
    gchar *service_path = NULL;
    gboolean service_exists = FALSE;

    g_print("Instance vanished: %s\n", watch->name);
    g_dbus_object_manager_server_unexport(manager, watch->path);

    service_path = get_service_file_path(watch->name);
    service_exists = g_file_test(service_path, G_FILE_TEST_EXISTS);
    g_free(service_path);

    if (service_exists == FALSE)
    {
        g_print("No more service file: %s\n", watch->name);

        watch_instance_free(watch);
    }
    else
    {
        g_print("Trying to restart: %s\n", name);

        watch->timeout_id = g_timeout_add_seconds(
            300,
            on_instance_timeout,
            watch);

        autolaunch_process_by_busname(watch->name);
    }
}
Example #3
0
/*
** Remove the service file for a specific Bus name
*/
static void delete_service_file(const gchar *BusName)
{
    gchar *service_file_path = NULL;

    service_file_path = get_service_file_path(BusName);
    remove(service_file_path);
    g_free(service_file_path);
}
Example #4
0
/*
** Craft a service file for a specific Bus name
*/
static void create_service_file(const gchar *RootPath,
                                const gchar *BusName,
                                const gchar *DBusID,
                                const gchar *Server,
                                const gchar *Options)
{
    FILE *service_file = NULL;
    gchar *service_file_path = NULL;

    service_file_path = get_service_file_path(BusName);
    service_file = fopen(service_file_path, "w");
    g_free(service_file_path);

    if (service_file != NULL)
    {
        gchar *exe_path = NULL;

        if (DBusID != NULL && Server != NULL)
        {
            exe_path = g_build_filename(
                RootPath ? RootPath : prog_path,
                "wbd_launcher",
                NULL);

            fprintf(
                service_file,
                "[D-BUS Service]\n"
                "Name=%s\n"
                "Exec=%s %s %s %s\n",
                BusName,
                exe_path,
                DBusID,
                Server,
                Options ? Options : "");
        }
        else
        {
            exe_path = g_build_filename(
               RootPath ? RootPath : prog_path,
               "wbm",
               NULL);

            fprintf(
                service_file,
                "[D-BUS Service]\n"
                "Name=%s\n"
                "Exec=%s %s\n",
                BusName,
                exe_path,
                Options ? Options : "");
        }

        fclose(service_file);

        g_free(exe_path);
    }
}
Example #5
0
/*
** Craft a service file for a specific Bus name
*/
static void create_service_file(const gchar *BusName,
                                const gchar *Nickname,
                                const gchar *Server)
{
    FILE *service_file = NULL;
    gchar *service_file_path = NULL;

    service_file_path = get_service_file_path(BusName);
    service_file = fopen(service_file_path, "w");
    g_free(service_file_path);

    if (service_file != NULL)
    {
        gchar *exe_path = NULL;

        if (Nickname != NULL && Server != NULL)
        {
            exe_path = g_build_filename(prog_path, "wbd_launcher", NULL);

            fprintf(
                service_file,
                "[D-BUS Service]\n"
                "Name=%s\n"
                "Exec=%s %s %s\n",
                BusName,
                exe_path,
                Nickname,
                Server);
        }
        else
        {
            exe_path = g_build_filename(prog_path, "wbm", NULL);

            fprintf(
                service_file,
                "[D-BUS Service]\n"
                "Name=%s\n"
                "Exec=%s\n",
                BusName,
                exe_path);
        }

        fclose(service_file);

        g_free(exe_path);
    }
}