@@ -156,34 +156,46 @@ target_destroy(struct target *target)
156156}
157157
158158int
159- target_discover_running (const char * base_path , enum target_type type_mask , zhashx_t * targets )
159+ target_discover_running (const char * base_path , zhashx_t * targets )
160160{
161161 const char * path [] = { base_path , NULL };
162162 FTS * file_system = NULL ;
163163 FTSENT * node = NULL ;
164- enum target_type type ;
164+ enum target_type type = TARGET_TYPE_UNKNOWN ;
165165 struct target * target = NULL ;
166166
167- file_system = fts_open ((char * const * )path , FTS_LOGICAL | FTS_NOCHDIR , NULL );
167+ file_system = fts_open ((char * const * ) path , FTS_PHYSICAL | FTS_NOCHDIR | FTS_NOSTAT , NULL );
168168 if (!file_system )
169169 return -1 ;
170170
171171 for (node = fts_read (file_system ); node ; node = fts_read (file_system )) {
172172 /*
173- * Filtering the directories having 2 hard links leading to them to only get leaves directories.
174- * The cgroup subsystems does not support hard links, so this will always work.
173+ * Mark a directory's parent when a child directory is seen in pre-order.
174+ * Then, when the directory is seen in post-order, it is a leaf if no
175+ * child directory marked it.
175176 */
176- if (node -> fts_info == FTS_D && node -> fts_statp -> st_nlink == 2 ) {
177- type = target_detect_type (node -> fts_path );
178- if ((type & type_mask ) && target_validate_type (type , node -> fts_path )) {
179- target = target_create (type , base_path , node -> fts_path );
180- if (target )
181- zhashx_insert (targets , node -> fts_path , target );
182- }
177+ if (node -> fts_info == FTS_D ) {
178+ if (node -> fts_parent )
179+ node -> fts_parent -> fts_number = 1 ;
180+
181+ continue ;
183182 }
183+
184+ if (node -> fts_info != FTS_DP )
185+ continue ;
186+
187+ /* Do not report the traversal root itself as a target */
188+ if (node -> fts_level == FTS_ROOTLEVEL )
189+ continue ;
190+
191+ /* A child directory was seen, so this directory is not a leaf */
192+ if (node -> fts_number != 0 )
193+ continue ;
194+
195+ target = target_create (type , base_path , node -> fts_path );
196+ zhashx_insert (targets , node -> fts_path , target );
184197 }
185198
186199 fts_close (file_system );
187200 return 0 ;
188201}
189-
0 commit comments