@@ -103,10 +103,10 @@ static void delete_veritydev(struct libmnt_context *cxt,
103
103
104
104
#ifdef CRYPTSETUP_VIA_DLOPEN
105
105
static int load_libcryptsetup_symbols (struct libmnt_context * cxt ,
106
- const struct libmnt_hookset * hs ,
107
106
struct hookset_data * hsd )
108
107
{
109
108
size_t i ;
109
+ const char * errmsg = NULL ;
110
110
int flags = RTLD_LAZY | RTLD_LOCAL ;
111
111
112
112
assert (cxt );
@@ -121,18 +121,24 @@ static int load_libcryptsetup_symbols(struct libmnt_context *cxt,
121
121
#ifdef RTLD_DEEPBIND
122
122
flags |= RTLD_DEEPBIND ;
123
123
#endif
124
+ /* Don't rely on errno; the dlopen API may not use it. Also, note that
125
+ * dlerror() provides complete messages that do not need any additional
126
+ * introduction when printed to end users. */
127
+ errno = 0 ;
128
+
124
129
hsd -> dl = dlopen ("libcryptsetup.so.12" , flags );
125
130
if (!hsd -> dl ) {
126
- DBG (HOOK , ul_debugobj (hs , "cannot dlopen libcryptsetup" ));
127
- return - ENOTSUP ;
131
+ errmsg = dlerror ();
132
+ if (errmsg )
133
+ mnt_context_sprintf_mesg (cxt , "e %s" , errmsg );
134
+ goto failed ;
128
135
}
129
136
130
137
/* clear errors first, then load all the libcryptsetup symbols */
131
138
dlerror ();
132
139
133
140
/* dlsym() */
134
141
for (i = 0 ; i < ARRAY_SIZE (verity_symbols ); i ++ ) {
135
- char * errmsg ;
136
142
const struct verity_sym * def = & verity_symbols [i ];
137
143
void * * sym ;
138
144
@@ -141,11 +147,15 @@ static int load_libcryptsetup_symbols(struct libmnt_context *cxt,
141
147
142
148
errmsg = dlerror ();
143
149
if (errmsg ) {
144
- DBG ( HOOK , ul_debugobj ( hs , "dlsym failed %s: %s " , def -> name , errmsg ) );
145
- return - ENOTSUP ;
150
+ mnt_context_sprintf_mesg ( cxt , "e %s " , errmsg );
151
+ goto failed ;
146
152
}
147
153
}
148
154
return 0 ;
155
+ failed :
156
+ if (!errno )
157
+ errno = ENOTSUP ;
158
+ return - errno ;
149
159
}
150
160
#endif
151
161
@@ -190,7 +200,7 @@ static struct hookset_data *new_hookset_data(
190
200
goto failed ;
191
201
192
202
#ifdef CRYPTSETUP_VIA_DLOPEN
193
- if (load_libcryptsetup_symbols (cxt , hs , hsd ) != 0 )
203
+ if (load_libcryptsetup_symbols (cxt , hsd ) != 0 )
194
204
goto failed ;
195
205
#endif
196
206
if (mnt_context_is_verbose (cxt ))
@@ -611,7 +621,7 @@ static int hook_prepare_source(
611
621
612
622
hsd = new_hookset_data (cxt , hs );
613
623
if (!hsd )
614
- return - ENOMEM ;
624
+ return errno ? - errno : - ENOMEM ;
615
625
616
626
rc = setup_veritydev (cxt , hs , hsd , ol );
617
627
if (!rc ) {
0 commit comments