]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
Add a new test command "proctest".
authorKen'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp>
Fri, 26 Jun 2009 06:11:16 +0000 (15:11 +0900)
committerDhaval Giani <dhaval@linux.vnet.ibm.com>
Mon, 29 Jun 2009 11:23:21 +0000 (16:53 +0530)
Hi,

Changelog of v6:
================
 * New patch.

This patch adds a new test command "proctest" for testing both
cgroup_get_uid_gid_from_procfs() and cgroup_get_procname_from_procfs().

 # sleep 100 &
 [1] 28558
 # ./tests/proctest $$ 28558
   Pid  |        Process name              |  Uid  |  Gid
 -------+----------------------------------+-------+-------
  27219 |                        /bin/bash |     0 |     0
  28558 |                       /bin/sleep |     0 |     0
 #

The functions get a process information from /proc fs, and they are
fragile because the content of /proc fs is not stable. If changing
/proc fs in future, this test command will be useful for catching
the change.

Thanks
Ken'ichi Ohmichi

Signed-off-by: Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp>
Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
tests/Makefile.am
tests/proctest.c [new file with mode: 0644]

index b10f3562fe1289c6b9c5dae40c2d08c499da2675..14bcdf3dfa21f00714494faefe47481d1983fcdb 100644 (file)
@@ -2,7 +2,7 @@ INCLUDES = -I$(top_srcdir)/include
 LDADD = $(top_srcdir)/src/.libs/libcgroup.la
 
 # compile the tests, but do not install them
-noinst_PROGRAMS = libcgrouptest01 libcg_ba setuid pathtest walk_test read_stats walk_task get_controller get_mount_point
+noinst_PROGRAMS = libcgrouptest01 libcg_ba setuid pathtest walk_test read_stats walk_task get_controller get_mount_point proctest
 
 libcgrouptest01_SOURCES=libcgrouptest01.c test_functions.c libcgrouptest.h
 libcg_ba_SOURCES=libcg_ba.cpp
@@ -13,6 +13,7 @@ read_stats_SOURCES=read_stats.c
 walk_task_SOURCES=walk_task.c
 get_controller_SOURCES=get_controller.c
 get_mount_point_SOURCES=get_mount_point.c
+proctest_SOURCES=proctest.c
 
 EXTRA_DIST = pathtest.sh runlibcgrouptest.sh
 
diff --git a/tests/proctest.c b/tests/proctest.c
new file mode 100644 (file)
index 0000000..8e840c1
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Copyright NEC Soft Ltd. 2009
+ *
+ * Author:     Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2.1 of the GNU Lesser General Public License
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "../src/libcgroup-internal.h"
+
+int main(int argc, char *argv[])
+{
+       int i;
+       int ret;
+       pid_t pid;
+       uid_t uid;
+       gid_t gid;
+       char *procname;
+
+       if (argc < 2) {
+               printf("Specify process-id.\n");
+               return 1;
+       }
+       printf("  Pid  |        Process name              |  Uid  |  Gid  \n");
+       printf("-------+----------------------------------+-------+-------\n");
+
+       for (i = 1; i < argc; i++) {
+               pid = atoi(argv[i]);
+
+               ret = cgroup_get_uid_gid_from_procfs(pid, &uid, &gid);
+               if (ret) {
+                       printf("%6d | ret = %d\n", pid, ret);
+                       continue;
+               }
+               ret = cgroup_get_procname_from_procfs(pid, &procname);
+               if (ret) {
+                       printf("%6d | ret = %d\n", pid, ret);
+                       continue;
+               }
+               printf("%6d | %32s | %5d | %5d\n", pid, procname, uid, gid);
+               free(procname);
+       }
+       return 0;
+}