Beispiel #1
0
void get_process_cgroup_info(ProcInfo& info) {
    if (not cgroups_enabled())
        return;

    const auto& cgroup_string = get_process_cgroup_string(info.pid);
    info.cgroup_name = cgroup_string;
}
void
get_process_cgroup_info(ProcInfo *info)
{
    gchar *path;
    gchar *cgroup_name = NULL;
    int cgroups_changed = 0;
    gchar *text;
    char **lines;
    int i;

    if (!cgroups_enabled())
        return;

    /* read out of /proc/pid/cgroup */
    path = g_strdup_printf("/proc/%d/cgroup", info->pid);
    if (!path)
        return;
    if(!g_file_get_contents(path, &text, NULL, NULL))
        goto out;
    lines = g_strsplit(text, "\n", -1);
    g_free(text);
    if (!lines)
        goto out;

    for (i = 0; lines[i] != NULL; i++) {
        if (lines[i][0] == '\0')
            continue;
        if (check_cgroup_changed(lines[i], info->cgroup_name)) {
            cgroups_changed = 1;
            break;
        }
    }

    if (cgroups_changed) {
        for (i = 0; lines[i] != NULL; i++) {
            if (lines[i][0] == '\0')
                continue;
            append_cgroup_name(lines[i], &cgroup_name);
        }
        if (info->cgroup_name)
            g_free(info->cgroup_name);
        if (!cgroup_name)
            info->cgroup_name = g_strdup("");
        else
            info->cgroup_name = cgroup_name;
    }

    g_strfreev(lines);
out:
    g_free(path);
}
static GtkWidget *
create_field_page(GtkWidget *tree, const gchar *child_schema, const gchar *text)
{
    GtkWidget *vbox;
    GtkWidget *scrolled;
    GtkWidget *label;
    GtkWidget *treeview;
    GList *it, *columns;
    GtkListStore *model;
    GtkTreeViewColumn *column;
    GtkCellRenderer *cell;

    vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);

    label = gtk_label_new_with_mnemonic (text);
    gtk_label_set_xalign (GTK_LABEL (label), 0.0);
    gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, TRUE, 0);

    scrolled = gtk_scrolled_window_new (NULL, NULL);
    gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
                                    GTK_POLICY_AUTOMATIC,
                                    GTK_POLICY_AUTOMATIC);
    gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled), GTK_SHADOW_IN);
    gtk_box_pack_start (GTK_BOX (vbox), scrolled, TRUE, TRUE, 0);

    model = gtk_list_store_new (3, G_TYPE_BOOLEAN, G_TYPE_STRING, G_TYPE_POINTER);

    treeview = gtk_tree_view_new_with_model (GTK_TREE_MODEL (model));
    gtk_container_add (GTK_CONTAINER (scrolled), treeview);
    g_object_unref (G_OBJECT (model));
    gtk_label_set_mnemonic_widget (GTK_LABEL (label), treeview);

    column = gtk_tree_view_column_new ();

    cell = gtk_cell_renderer_toggle_new ();
    gtk_tree_view_column_pack_start (column, cell, FALSE);
    gtk_tree_view_column_set_attributes (column, cell,
                                         "active", 0,
                                         NULL);
    if (g_strcmp0 (child_schema, "proctree") == 0)
        g_signal_connect (G_OBJECT (cell), "toggled", G_CALLBACK (proc_field_toggled), model);
    else if (g_strcmp0 (child_schema, "disktreenew") == 0)
        g_signal_connect (G_OBJECT (cell), "toggled", G_CALLBACK (disk_field_toggled), model);

    gtk_tree_view_column_set_clickable (column, TRUE);
    gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);

    column = gtk_tree_view_column_new ();

    cell = gtk_cell_renderer_text_new ();
    gtk_tree_view_column_pack_start (column, cell, FALSE);
    gtk_tree_view_column_set_attributes (column, cell,
                                         "text", 1,
                                         NULL);

    gtk_tree_view_column_set_title (column, "Not Shown");
    gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
    gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), FALSE);

    columns = gtk_tree_view_get_columns (GTK_TREE_VIEW (tree));

    for(it = columns; it; it = it->next)
    {
        GtkTreeViewColumn *column = static_cast<GtkTreeViewColumn*>(it->data);
        GtkTreeIter iter;
        const gchar *title;
        gboolean visible;
        gint column_id;

        title = gtk_tree_view_column_get_title (column);
        if (!title)
            title = _("Icon");

        column_id = gtk_tree_view_column_get_sort_column_id(column);
        if ((column_id == COL_CGROUP) && (!cgroups_enabled()))
            continue;

        if ((column_id == COL_UNIT ||
             column_id == COL_SESSION ||
             column_id == COL_SEAT ||
             column_id == COL_OWNER)
#ifdef HAVE_SYSTEMD
            && !LOGIND_RUNNING()
#endif
                )
            continue;

        visible = gtk_tree_view_column_get_visible (column);

        gtk_list_store_append (model, &iter);
        gtk_list_store_set (model, &iter, 0, visible, 1, title, 2, column,-1);
    }

    g_list_free(columns);

    return vbox;
}