@@ -210,35 +210,13 @@ libcrun_get_cgroup_mode (libcrun_error_t *err)
210210 return cgroup_mode ;
211211}
212212
213- int
214- libcrun_get_cgroup_process ( pid_t pid , char * * path , bool absolute , libcrun_error_t * err )
213+ static int
214+ get_cgroup_process_from_content ( char * content , int cgroup_mode , char * * path , bool absolute , libcrun_error_t * err )
215215{
216- cleanup_free char * content = NULL ;
217- char proc_cgroup_file [64 ];
218216 char * cg_path = NULL ;
219- size_t content_size ;
220217 char * controller ;
221218 char * saveptr ;
222- int cgroup_mode ;
223219 bool has_data ;
224- int ret ;
225-
226- cgroup_mode = libcrun_get_cgroup_mode (err );
227- if (UNLIKELY (cgroup_mode < 0 ))
228- return cgroup_mode ;
229-
230- if (pid == 0 )
231- strcpy (proc_cgroup_file , PROC_SELF_CGROUP );
232- else
233- {
234- int len = snprintf (proc_cgroup_file , sizeof (proc_cgroup_file ), "/proc/%d/cgroup" , pid );
235- if (UNLIKELY (len >= (int ) sizeof (proc_cgroup_file )))
236- return crun_make_error (err , 0 , "internal error: static buffer too small" );
237- }
238-
239- ret = read_all_file (proc_cgroup_file , & content , & content_size , err );
240- if (UNLIKELY (ret < 0 ))
241- return ret ;
242220
243221 for (has_data = read_proc_cgroup (content , & saveptr , NULL , & controller , & cg_path );
244222 has_data ;
@@ -266,6 +244,54 @@ libcrun_get_cgroup_process (pid_t pid, char **path, bool absolute, libcrun_error
266244 return 0 ;
267245}
268246
247+ int
248+ libcrun_get_cgroup_process_at (int dirfd , char * * path , bool absolute , libcrun_error_t * err )
249+ {
250+ cleanup_free char * content = NULL ;
251+ size_t content_size ;
252+ int cgroup_mode ;
253+ int ret ;
254+
255+ cgroup_mode = libcrun_get_cgroup_mode (err );
256+ if (UNLIKELY (cgroup_mode < 0 ))
257+ return cgroup_mode ;
258+
259+ ret = read_all_file_at (dirfd , SELF_CGROUP , & content , & content_size , err );
260+ if (UNLIKELY (ret < 0 ))
261+ return ret ;
262+
263+ return get_cgroup_process_from_content (content , cgroup_mode , path , absolute , err );
264+ }
265+
266+ int
267+ libcrun_get_cgroup_process (pid_t pid , char * * path , bool absolute , libcrun_error_t * err )
268+ {
269+ cleanup_free char * content = NULL ;
270+ char proc_cgroup_file [64 ];
271+ size_t content_size ;
272+ int cgroup_mode ;
273+ int ret ;
274+
275+ cgroup_mode = libcrun_get_cgroup_mode (err );
276+ if (UNLIKELY (cgroup_mode < 0 ))
277+ return cgroup_mode ;
278+
279+ if (pid == 0 )
280+ strcpy (proc_cgroup_file , PROC_SELF_CGROUP );
281+ else
282+ {
283+ int len = snprintf (proc_cgroup_file , sizeof (proc_cgroup_file ), "/proc/%d/cgroup" , pid );
284+ if (UNLIKELY (len >= (int ) sizeof (proc_cgroup_file )))
285+ return crun_make_error (err , 0 , "internal error: static buffer too small" );
286+ }
287+
288+ ret = read_all_file (proc_cgroup_file , & content , & content_size , err );
289+ if (UNLIKELY (ret < 0 ))
290+ return ret ;
291+
292+ return get_cgroup_process_from_content (content , cgroup_mode , path , absolute , err );
293+ }
294+
269295static int
270296read_pids_cgroup (int dfd , bool recurse , pid_t * * pids , size_t * n_pids , size_t * allocated , libcrun_error_t * err )
271297{
0 commit comments