2005-06-05 07:11:29 +04:00
/*
* udev_run_directory . c - directory multiplexer
*
* Copyright ( C ) 2005 Kay Sievers < kay @ vrfy . org >
*
* This program is free software ; you can redistribute it and / or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation version 2 of the License .
*
*/
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include <stddef.h>
# include <dirent.h>
# include <errno.h>
# include <unistd.h>
# include <fcntl.h>
# include <limits.h>
# include <sys/types.h>
# include <sys/wait.h>
# include <sys/stat.h>
2006-01-09 23:18:00 +03:00
# include "../../udev.h"
2005-07-15 02:24:59 +04:00
# include "run_directory.h"
2005-06-05 07:11:29 +04:00
2005-08-11 19:32:59 +04:00
static int exec_program ( const char * filename , const char * subsystem )
2005-06-05 07:11:29 +04:00
{
pid_t pid ;
dbg ( " running %s " , filename ) ;
pid = fork ( ) ;
switch ( pid ) {
case 0 :
/* child */
execl ( filename , filename , subsystem , NULL ) ;
dbg ( " exec of child failed " ) ;
_exit ( 1 ) ;
case - 1 :
dbg ( " fork of child failed " ) ;
break ;
return - 1 ;
default :
waitpid ( pid , NULL , 0 ) ;
}
return 0 ;
}
int run_directory ( const char * dir , const char * suffix , const char * subsystem )
{
struct name_entry * name_loop , * name_tmp ;
2005-11-09 20:53:32 +03:00
struct stat buf ;
2005-06-05 07:11:29 +04:00
LIST_HEAD ( name_list ) ;
2005-07-15 02:24:59 +04:00
dbg ( " looking at '%s' " , dir ) ;
2005-11-09 20:53:32 +03:00
if ( stat ( dir , & buf ) ! = 0 ) {
dbg ( " directory '%s' not found " , dir ) ;
return 0 ;
}
2005-07-15 02:24:59 +04:00
add_matching_files ( & name_list , dir , suffix ) ;
2005-06-05 07:11:29 +04:00
list_for_each_entry_safe ( name_loop , name_tmp , & name_list , node ) {
2005-08-11 19:32:59 +04:00
exec_program ( name_loop - > name , subsystem ) ;
2005-06-05 07:11:29 +04:00
list_del ( & name_loop - > node ) ;
}
logging_close ( ) ;
return 0 ;
}