summaryrefslogtreecommitdiff
path: root/clients
diff options
context:
space:
mode:
Diffstat (limited to 'clients')
-rw-r--r--clients/bokfweb.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/clients/bokfweb.c b/clients/bokfweb.c
index d04e2d6..cc19826 100644
--- a/clients/bokfweb.c
+++ b/clients/bokfweb.c
@@ -15,6 +15,7 @@
directly: only Caddy and the wrapper in the same container talk to it. */
#include <arpa/inet.h>
#include <errno.h>
+#include <locale.h>
#include <netinet/in.h>
#include <signal.h>
#include <stdio.h>
@@ -23,6 +24,7 @@
#include <sys/socket.h>
#include <sys/time.h>
#include <unistd.h>
+#include <wchar.h>
#include "client.h"
#include "log.h"
@@ -446,8 +448,30 @@ static void serve(int cfd, struct gate *g)
memset(buf, 0, n); /* the body may hold a password */
}
-int main(void)
+/* `bokfweb --check-locale`, run while the web image is built: bokftui in
+ the same image needs a UTF-8 locale for åäö, and a statically linked
+ glibc finds none unless its locale data is installed. Exits 1 without. */
+static int check_locale(void)
{
+ const char *l = setlocale(LC_ALL, "");
+ wchar_t w = 0;
+ mbstate_t st;
+ memset(&st, 0, sizeof st);
+ size_t n = mbrtowc(&w, "\xc3\xa5", 2, &st); /* å */
+ if (!l || n != 2 || w != 0xE5) {
+ fprintf(stderr, "bokfweb: no UTF-8 locale (setlocale: %s); bokftui "
+ "would show no åäö\n",
+ l ? l : "failed");
+ return 1;
+ }
+ printf("locale ok: %s\n", l);
+ return 0;
+}
+
+int main(int argc, char **argv)
+{
+ if (argc > 1 && strcmp(argv[1], "--check-locale") == 0)
+ return check_locale();
signal(SIGPIPE, SIG_IGN);
const char *lvl = getenv("BOKFWEB_LOG_LEVEL");
log_set_level(lvl ? log_level_from_name(lvl) : LOG_INFO);