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() {
69
69
DIR * d ;
70
70
struct dirent * de ;
71
71
handler * h ,* tmp ;
72
- char * path ;
72
+ char * path , * cwd ;
73
73
void * handle ;
74
74
size_t len ;
75
75
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
+
76
95
d = opendir (HANDLERS_DIR );
77
96
78
97
if (!d ) {
79
98
print ( ERROR , "opendir: %s" , strerror (errno ) );
99
+ free (cwd );
80
100
return -1 ;
81
101
}
82
102
@@ -90,7 +110,7 @@ int load_handlers() {
90
110
if (strncmp (de -> d_name + (len - 3 ), ".so" , 3 ))
91
111
continue ;
92
112
93
- if (asprintf (& path , HANDLERS_DIR "/%s" , de -> d_name ) == -1 ) {
113
+ if (asprintf (& path , "%s/" HANDLERS_DIR "/%s" , cwd , de -> d_name ) == -1 ) {
94
114
print ( ERROR , "asprintf: %s" , strerror (errno ) );
95
115
continue ;
96
116
}
@@ -127,6 +147,8 @@ int load_handlers() {
127
147
128
148
closedir (d );
129
149
150
+ free (cwd );
151
+
130
152
if (!handlers .head ) {
131
153
print ( ERROR , "no handlers found" );
132
154
return -1 ;
You can’t perform that action at this time.
0 commit comments