Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
criu
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zhul
criu
Commits
b48e4cbf
Commit
b48e4cbf
authored
May 08, 2014
by
Pavel Emelyanov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
proc: Introduce helper for parsing /proc/$pid/cgroup file
Signed-off-by:
Pavel Emelyanov
<
xemul@parallels.com
>
parent
e5eb73ea
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
78 additions
and
0 deletions
+78
-0
proc_parse.h
include/proc_parse.h
+19
-0
proc_parse.c
proc_parse.c
+59
-0
No files found.
include/proc_parse.h
View file @
b48e4cbf
...
...
@@ -178,4 +178,23 @@ extern int parse_threads(int pid, struct pid **_t, int *_n);
extern
int
check_mnt_id
(
void
);
/*
* This struct describes a group controlled by one controller.
* The @name is the controller name or 'name=...' for named cgroups.
* The @path is the path from the hierarchy root.
*/
struct
cg_ctl
{
struct
list_head
l
;
char
*
name
;
char
*
path
;
};
/*
* Returns the list of cg_ctl-s sorted by name
*/
extern
int
parse_task_cgroup
(
int
pid
,
struct
list_head
*
l
,
unsigned
int
*
n
);
extern
void
put_ctls
(
struct
list_head
*
);
#endif
/* __CR_PROC_PARSE_H__ */
proc_parse.c
View file @
b48e4cbf
...
...
@@ -1497,3 +1497,62 @@ int parse_threads(int pid, struct pid **_t, int *_n)
return
0
;
}
int
parse_task_cgroup
(
int
pid
,
struct
list_head
*
retl
,
unsigned
int
*
n
)
{
int
ret
=
0
;
FILE
*
f
;
f
=
fopen_proc
(
pid
,
"cgroup"
);
while
(
fgets
(
buf
,
BUF_SIZE
,
f
))
{
struct
cg_ctl
*
ncc
,
*
cc
;
char
*
name
,
*
path
,
*
e
;
ret
=
-
1
;
ncc
=
xmalloc
(
sizeof
(
*
cc
));
if
(
!
ncc
)
goto
err
;
name
=
strchr
(
buf
,
':'
)
+
1
;
path
=
strchr
(
name
,
':'
);
e
=
strchr
(
name
,
'\n'
);
*
path
++
=
'\0'
;
if
(
e
)
*
e
=
'\0'
;
ncc
->
name
=
xstrdup
(
name
);
ncc
->
path
=
xstrdup
(
path
);
if
(
!
ncc
->
name
||
!
ncc
->
name
)
{
xfree
(
ncc
->
name
);
xfree
(
ncc
->
path
);
xfree
(
ncc
);
goto
err
;
}
list_for_each_entry
(
cc
,
retl
,
l
)
if
(
strcmp
(
cc
->
name
,
name
)
>=
0
)
break
;
list_add_tail
(
&
ncc
->
l
,
&
cc
->
l
);
(
*
n
)
++
;
}
fclose
(
f
);
return
0
;
err:
put_ctls
(
retl
);
fclose
(
f
);
return
ret
;
}
void
put_ctls
(
struct
list_head
*
l
)
{
struct
cg_ctl
*
c
,
*
n
;
list_for_each_entry_safe
(
c
,
n
,
l
,
l
)
{
xfree
(
c
->
name
);
xfree
(
c
->
path
);
xfree
(
c
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment