Skip to content

Commit

Permalink
Improve messages when some of options are not available
Browse files Browse the repository at this point in the history
Also fail when encryption is requested but libencrypt.so is not
preloaded.
  • Loading branch information
mkozlowski committed Sep 29, 2024
1 parent 27c3fd8 commit 37486b6
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions memcr.c
Original file line number Diff line number Diff line change
Expand Up @@ -2869,7 +2869,7 @@ static void usage(const char *name, int status)
exit(status);
}

static void die(const char *fmt, ...)
static void __attribute__((noreturn)) die(const char *fmt, ...)
{
va_list ap;

Expand Down Expand Up @@ -2944,13 +2944,13 @@ int main(int argc, char *argv[])
break;
case 'z':
#ifndef COMPRESS_LZ4
die("not enabled, recompile with COMPRESS_LZ4=1\n");
die("compression not available, recompile with COMPRESS_LZ4=1\n");
#endif
compress = 1;
break;
case 'c':
#ifndef CHECKSUM_MD5
die("not enabled, recompile with CHECKSUM_MD5=1\n");
die("checksumming not available, recompile with CHECKSUM_MD5=1\n");
#endif
checksum = 1;
break;
Expand Down Expand Up @@ -2988,19 +2988,20 @@ int main(int argc, char *argv[])
if (ret)
die("/proc/kpageflags not present (depends on CONFIG_PROC_PAGE_MONITOR)\n");

kpageflags_fd = open("/proc/kpageflags", O_RDONLY);
if (kpageflags_fd == -1)
die("/proc/kpageflags: %m\n");

register_signal_handlers();

setvbuf(stdout, NULL, _IOLBF, 0);

if (lib__init) {
ret = lib__init(encrypt, encrypt_arg);
if (ret)
goto err;
}
exit(1);
} else if (encrypt)
die("encryption not available, preload libencrypt.so\n");

kpageflags_fd = open("/proc/kpageflags", O_RDONLY);
if (kpageflags_fd == -1)
die("/proc/kpageflags: %m\n");

if (listen_location)
ret = service_mode(listen_location);
Expand All @@ -3010,7 +3011,6 @@ int main(int argc, char *argv[])
if (lib__fini)
lib__fini();

err:
close(kpageflags_fd);

return ret;
Expand Down

0 comments on commit 37486b6

Please sign in to comment.