Skip to content

Commit e4f6d45

Browse files
committed
libmount: (verity) use messages API for dlopen errors
Signed-off-by: Karel Zak <kzak@redhat.com>
1 parent f2e7214 commit e4f6d45

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

libmount/src/hook_veritydev.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ static void delete_veritydev(struct libmnt_context *cxt,
103103

104104
#ifdef CRYPTSETUP_VIA_DLOPEN
105105
static int load_libcryptsetup_symbols(struct libmnt_context *cxt,
106-
const struct libmnt_hookset *hs,
107106
struct hookset_data *hsd)
108107
{
109108
size_t i;
109+
const char *errmsg = NULL;
110110
int flags = RTLD_LAZY | RTLD_LOCAL;
111111

112112
assert(cxt);
@@ -121,18 +121,24 @@ static int load_libcryptsetup_symbols(struct libmnt_context *cxt,
121121
#ifdef RTLD_DEEPBIND
122122
flags |= RTLD_DEEPBIND;
123123
#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+
124129
hsd->dl = dlopen("libcryptsetup.so.12", flags);
125130
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;
128135
}
129136

130137
/* clear errors first, then load all the libcryptsetup symbols */
131138
dlerror();
132139

133140
/* dlsym() */
134141
for (i = 0; i < ARRAY_SIZE(verity_symbols); i++) {
135-
char *errmsg;
136142
const struct verity_sym *def = &verity_symbols[i];
137143
void **sym;
138144

@@ -141,11 +147,15 @@ static int load_libcryptsetup_symbols(struct libmnt_context *cxt,
141147

142148
errmsg = dlerror();
143149
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;
146152
}
147153
}
148154
return 0;
155+
failed:
156+
if (!errno)
157+
errno = ENOTSUP;
158+
return -errno;
149159
}
150160
#endif
151161

@@ -190,7 +200,7 @@ static struct hookset_data *new_hookset_data(
190200
goto failed;
191201

192202
#ifdef CRYPTSETUP_VIA_DLOPEN
193-
if (load_libcryptsetup_symbols(cxt, hs, hsd) != 0)
203+
if (load_libcryptsetup_symbols(cxt, hsd) != 0)
194204
goto failed;
195205
#endif
196206
if (mnt_context_is_verbose(cxt))
@@ -611,7 +621,7 @@ static int hook_prepare_source(
611621

612622
hsd = new_hookset_data(cxt, hs);
613623
if (!hsd)
614-
return -ENOMEM;
624+
return errno ? -errno : -ENOMEM;
615625

616626
rc = setup_veritydev(cxt, hs, hsd, ol);
617627
if (!rc) {

0 commit comments

Comments
 (0)