File tree Expand file tree Collapse file tree 1 file changed +24
-2
lines changed
Expand file tree Collapse file tree 1 file changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -69,14 +69,34 @@ int load_handlers() {
6969 DIR * d ;
7070 struct dirent * de ;
7171 handler * h ,* tmp ;
72- char * path ;
72+ char * path , * cwd ;
7373 void * handle ;
7474 size_t len ;
7575
76+ len = 50 ;
77+ cwd = malloc (len );
78+
79+ while (cwd && len < PATH_MAX ) {
80+ if (getcwd (cwd , len )) break ;
81+ if (errno != ERANGE ) {
82+ print ( ERROR , "getcwd: %s" , strerror (errno ));
83+ free (cwd );
84+ return -1 ;
85+ }
86+ len += 50 ;
87+ cwd = realloc (cwd , len );
88+ }
89+
90+ if (!cwd ) {
91+ print ( ERROR , "malloc(%d): %s" , len , strerror (errno ));
92+ return -1 ;
93+ }
94+
7695 d = opendir (HANDLERS_DIR );
7796
7897 if (!d ) {
7998 print ( ERROR , "opendir: %s" , strerror (errno ) );
99+ free (cwd );
80100 return -1 ;
81101 }
82102
@@ -90,7 +110,7 @@ int load_handlers() {
90110 if (strncmp (de -> d_name + (len - 3 ), ".so" , 3 ))
91111 continue ;
92112
93- if (asprintf (& path , HANDLERS_DIR "/%s" , de -> d_name ) == -1 ) {
113+ if (asprintf (& path , "%s/" HANDLERS_DIR "/%s" , cwd , de -> d_name ) == -1 ) {
94114 print ( ERROR , "asprintf: %s" , strerror (errno ) );
95115 continue ;
96116 }
@@ -127,6 +147,8 @@ int load_handlers() {
127147
128148 closedir (d );
129149
150+ free (cwd );
151+
130152 if (!handlers .head ) {
131153 print ( ERROR , "no handlers found" );
132154 return -1 ;
You can’t perform that action at this time.
0 commit comments