~ubuntu-branches/ubuntu/utopic/ubuntu-app-launch/utopic

« back to all changes in this revision

Viewing changes to libubuntu-app-launch/ubuntu-app-launch.c

  • Committer: Package Import Robot
  • Author(s): Łukasz 'sil2100' Zemczak
  • Date: 2014-08-19 09:52:33 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20140819095233-5mvkp2nderj92rww
Tags: 0.4+14.10.20140808.3.is.0.4+14.10.20140605.3-0ubuntu1
Temporarily revert the cgroup support introduced in the last
version, as it was causing regressions in our test infrastructure

Show diffs side-by-side

added added

removed removed

Lines of Context:
1045
1045
        return pid;
1046
1046
}
1047
1047
 
1048
 
/* Get the PIDs for an AppID. If it's click or legacy single instance that's
1049
 
   a simple call to the helper. But if it's not, we have to make a call for
1050
 
   each instance of the app that we have running. */
1051
 
static GList *
1052
 
pids_for_appid (const gchar * appid)
1053
 
{
1054
 
        GDBusConnection * cgmanager = cgroup_manager_connection();
1055
 
        g_return_val_if_fail(cgmanager != NULL, NULL);
1056
 
 
1057
 
        if (is_click(appid)) {
1058
 
                GList * pids = pids_from_cgroup(cgmanager, "application-click", appid);
1059
 
                g_clear_object(&cgmanager);
1060
 
                return pids;
1061
 
        } else if (legacy_single_instance(appid)) {
1062
 
                gchar * jobname = g_strdup_printf("%s-", appid);
1063
 
                GList * pids = pids_from_cgroup(cgmanager, "application-legacy", jobname);
1064
 
                g_free(jobname);
1065
 
                g_clear_object(&cgmanager);
1066
 
                return pids;
1067
 
        }
1068
 
 
1069
 
        /* If we're not single instance, we need to find all the pids for all
1070
 
           the instances of the app */
1071
 
        unsigned int i;
1072
 
        GDBusConnection * con = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL);
1073
 
        g_return_val_if_fail(con != NULL, NULL);
1074
 
 
1075
 
        GList * pids = NULL;
1076
 
 
1077
 
        GArray * apps = g_array_new(TRUE, TRUE, sizeof(gchar *));
1078
 
        g_array_set_clear_func(apps, free_helper);
1079
 
 
1080
 
        apps_for_job(con, "application-legacy", apps, FALSE);
1081
 
        gchar * appiddash = g_strdup_printf("%s-", appid); /* Probably could go RegEx here, but let's start with just a prefix lookup */
1082
 
        for (i = 0; i < apps->len; i++) {
1083
 
                const gchar * array_id = g_array_index(apps, const gchar *, i);
1084
 
                if (g_str_has_prefix(array_id, appiddash)) {
1085
 
                        GList * morepids = pids_from_cgroup(cgmanager, "application-legacy", array_id);
1086
 
                        pids = g_list_concat(pids, morepids);
1087
 
                }
1088
 
        }
1089
 
        g_free(appiddash);
1090
 
 
1091
 
        g_array_free(apps, TRUE);
1092
 
        g_object_unref(con);
1093
 
 
1094
 
        g_clear_object(&cgmanager);
1095
 
 
1096
 
        return pids;
1097
 
}
1098
 
 
1099
1048
gboolean
1100
1049
ubuntu_app_launch_pid_in_app_id (GPid pid, const gchar * appid)
1101
1050
{
1105
1054
                return FALSE;
1106
1055
        }
1107
1056
 
1108
 
        GList * pidlist = pids_for_appid(appid);
1109
 
        GList * head;
1110
 
 
1111
 
        for (head = pidlist; head != NULL; head = g_list_next(head)) {
1112
 
                GPid checkpid = GPOINTER_TO_INT(head->data);
1113
 
                if (checkpid == pid) {
1114
 
                        g_list_free(pidlist);
1115
 
                        return TRUE;
1116
 
                }
1117
 
        }
1118
 
 
1119
 
        g_list_free(pidlist);
1120
 
        return FALSE;
 
1057
        GPid primary = ubuntu_app_launch_get_primary_pid(appid);
 
1058
 
 
1059
        return primary == pid;
1121
1060
}
1122
1061
 
1123
1062
gboolean