1 /* SPDX-License-Identifier: LGPL-2.1+ */
5 #include <microhttpd.h>
13 #include "sd-daemon.h"
14 #include "sd-journal.h"
16 #include "alloc-util.h"
18 #include "errno-util.h"
21 #include "hostname-util.h"
23 #include "logs-show.h"
24 #include "main-func.h"
25 #include "microhttpd-util.h"
27 #include "parse-util.h"
28 #include "pretty-print.h"
30 #include "tmpfile-util.h"
33 #define JOURNAL_WAIT_TIMEOUT (10*USEC_PER_SEC)
35 static char *arg_key_pem
= NULL
;
36 static char *arg_cert_pem
= NULL
;
37 static char *arg_trust_pem
= NULL
;
38 static const char *arg_directory
= NULL
;
40 STATIC_DESTRUCTOR_REGISTER(arg_key_pem
, freep
);
41 STATIC_DESTRUCTOR_REGISTER(arg_cert_pem
, freep
);
42 STATIC_DESTRUCTOR_REGISTER(arg_trust_pem
, freep
);
44 typedef struct RequestMeta
{
57 int argument_parse_error
;
66 static const char* const mime_types
[_OUTPUT_MODE_MAX
] = {
67 [OUTPUT_SHORT
] = "text/plain",
68 [OUTPUT_JSON
] = "application/json",
69 [OUTPUT_JSON_SSE
] = "text/event-stream",
70 [OUTPUT_JSON_SEQ
] = "application/json-seq",
71 [OUTPUT_EXPORT
] = "application/vnd.fdo.journal",
74 static RequestMeta
*request_meta(void **connection_cls
) {
77 assert(connection_cls
);
79 return *connection_cls
;
81 m
= new0(RequestMeta
, 1);
89 static void request_meta_free(
91 struct MHD_Connection
*connection
,
92 void **connection_cls
,
93 enum MHD_RequestTerminationCode toe
) {
95 RequestMeta
*m
= *connection_cls
;
100 sd_journal_close(m
->journal
);
108 static int open_journal(RequestMeta
*m
) {
115 return sd_journal_open_directory(&m
->journal
, arg_directory
, 0);
117 return sd_journal_open(&m
->journal
, SD_JOURNAL_LOCAL_ONLY
|SD_JOURNAL_SYSTEM
);
120 static int request_meta_ensure_tmp(RequestMeta
*m
) {
128 fd
= open_tmpfile_unlinkable("/tmp", O_RDWR
|O_CLOEXEC
);
132 m
->tmp
= fdopen(fd
, "w+");
142 static ssize_t
request_reader_entries(
148 RequestMeta
*m
= cls
;
155 assert(pos
>= m
->delta
);
159 while (pos
>= m
->size
) {
162 /* End of this entry, so let's serialize the next
165 if (m
->n_entries_set
&&
167 return MHD_CONTENT_READER_END_OF_STREAM
;
170 r
= sd_journal_previous_skip(m
->journal
, (uint64_t) -m
->n_skip
+ 1);
171 else if (m
->n_skip
> 0)
172 r
= sd_journal_next_skip(m
->journal
, (uint64_t) m
->n_skip
+ 1);
174 r
= sd_journal_next(m
->journal
);
177 log_error_errno(r
, "Failed to advance journal pointer: %m");
178 return MHD_CONTENT_READER_END_WITH_ERROR
;
182 r
= sd_journal_wait(m
->journal
, (uint64_t) JOURNAL_WAIT_TIMEOUT
);
184 log_error_errno(r
, "Couldn't wait for journal event: %m");
185 return MHD_CONTENT_READER_END_WITH_ERROR
;
187 if (r
== SD_JOURNAL_NOP
)
193 return MHD_CONTENT_READER_END_OF_STREAM
;
199 r
= sd_journal_test_cursor(m
->journal
, m
->cursor
);
201 log_error_errno(r
, "Failed to test cursor: %m");
202 return MHD_CONTENT_READER_END_WITH_ERROR
;
206 return MHD_CONTENT_READER_END_OF_STREAM
;
212 if (m
->n_entries_set
)
217 r
= request_meta_ensure_tmp(m
);
219 log_error_errno(r
, "Failed to create temporary file: %m");
220 return MHD_CONTENT_READER_END_WITH_ERROR
;
223 r
= show_journal_entry(m
->tmp
, m
->journal
, m
->mode
, 0, OUTPUT_FULL_WIDTH
,
226 log_error_errno(r
, "Failed to serialize item: %m");
227 return MHD_CONTENT_READER_END_WITH_ERROR
;
231 if (sz
== (off_t
) -1) {
232 log_error_errno(errno
, "Failed to retrieve file position: %m");
233 return MHD_CONTENT_READER_END_WITH_ERROR
;
236 m
->size
= (uint64_t) sz
;
239 if (m
->tmp
== NULL
&& m
->follow
)
242 if (fseeko(m
->tmp
, pos
, SEEK_SET
) < 0) {
243 log_error_errno(errno
, "Failed to seek to position: %m");
244 return MHD_CONTENT_READER_END_WITH_ERROR
;
254 k
= fread(buf
, 1, n
, m
->tmp
);
256 log_error("Failed to read from file: %s", errno
!= 0 ? strerror_safe(errno
) : "Premature EOF");
257 return MHD_CONTENT_READER_END_WITH_ERROR
;
263 static int request_parse_accept(
265 struct MHD_Connection
*connection
) {
272 header
= MHD_lookup_connection_value(connection
, MHD_HEADER_KIND
, "Accept");
276 if (streq(header
, mime_types
[OUTPUT_JSON
]))
277 m
->mode
= OUTPUT_JSON
;
278 else if (streq(header
, mime_types
[OUTPUT_JSON_SSE
]))
279 m
->mode
= OUTPUT_JSON_SSE
;
280 else if (streq(header
, mime_types
[OUTPUT_JSON_SEQ
]))
281 m
->mode
= OUTPUT_JSON_SEQ
;
282 else if (streq(header
, mime_types
[OUTPUT_EXPORT
]))
283 m
->mode
= OUTPUT_EXPORT
;
285 m
->mode
= OUTPUT_SHORT
;
290 static int request_parse_range(
292 struct MHD_Connection
*connection
) {
294 const char *range
, *colon
, *colon2
;
300 range
= MHD_lookup_connection_value(connection
, MHD_HEADER_KIND
, "Range");
304 if (!startswith(range
, "entries="))
308 range
+= strspn(range
, WHITESPACE
);
310 colon
= strchr(range
, ':');
312 m
->cursor
= strdup(range
);
316 colon2
= strchr(colon
+ 1, ':');
318 _cleanup_free_
char *t
;
320 t
= strndup(colon
+ 1, colon2
- colon
- 1);
324 r
= safe_atoi64(t
, &m
->n_skip
);
329 p
= (colon2
? colon2
: colon
) + 1;
331 r
= safe_atou64(p
, &m
->n_entries
);
335 if (m
->n_entries
<= 0)
338 m
->n_entries_set
= true;
341 m
->cursor
= strndup(range
, colon
- range
);
347 m
->cursor
[strcspn(m
->cursor
, WHITESPACE
)] = 0;
348 if (isempty(m
->cursor
))
349 m
->cursor
= mfree(m
->cursor
);
354 static int request_parse_arguments_iterator(
356 enum MHD_ValueKind kind
,
360 RequestMeta
*m
= cls
;
361 _cleanup_free_
char *p
= NULL
;
367 m
->argument_parse_error
= -EINVAL
;
371 if (streq(key
, "follow")) {
372 if (isempty(value
)) {
377 r
= parse_boolean(value
);
379 m
->argument_parse_error
= r
;
387 if (streq(key
, "discrete")) {
388 if (isempty(value
)) {
393 r
= parse_boolean(value
);
395 m
->argument_parse_error
= r
;
403 if (streq(key
, "boot")) {
407 r
= parse_boolean(value
);
409 m
->argument_parse_error
= r
;
415 char match
[9 + 32 + 1] = "_BOOT_ID=";
418 r
= sd_id128_get_boot(&bid
);
420 log_error_errno(r
, "Failed to get boot ID: %m");
424 sd_id128_to_string(bid
, match
+ 9);
425 r
= sd_journal_add_match(m
->journal
, match
, sizeof(match
)-1);
427 m
->argument_parse_error
= r
;
435 p
= strjoin(key
, "=", strempty(value
));
437 m
->argument_parse_error
= log_oom();
441 r
= sd_journal_add_match(m
->journal
, p
, 0);
443 m
->argument_parse_error
= r
;
450 static int request_parse_arguments(
452 struct MHD_Connection
*connection
) {
457 m
->argument_parse_error
= 0;
458 MHD_get_connection_values(connection
, MHD_GET_ARGUMENT_KIND
, request_parse_arguments_iterator
, m
);
460 return m
->argument_parse_error
;
463 static int request_handler_entries(
464 struct MHD_Connection
*connection
,
465 void *connection_cls
) {
467 _cleanup_(MHD_destroy_responsep
) struct MHD_Response
*response
= NULL
;
468 RequestMeta
*m
= connection_cls
;
476 return mhd_respondf(connection
, r
, MHD_HTTP_INTERNAL_SERVER_ERROR
, "Failed to open journal: %m");
478 if (request_parse_accept(m
, connection
) < 0)
479 return mhd_respond(connection
, MHD_HTTP_BAD_REQUEST
, "Failed to parse Accept header.");
481 if (request_parse_range(m
, connection
) < 0)
482 return mhd_respond(connection
, MHD_HTTP_BAD_REQUEST
, "Failed to parse Range header.");
484 if (request_parse_arguments(m
, connection
) < 0)
485 return mhd_respond(connection
, MHD_HTTP_BAD_REQUEST
, "Failed to parse URL arguments.");
489 return mhd_respond(connection
, MHD_HTTP_BAD_REQUEST
, "Discrete seeks require a cursor specification.");
492 m
->n_entries_set
= true;
496 r
= sd_journal_seek_cursor(m
->journal
, m
->cursor
);
497 else if (m
->n_skip
>= 0)
498 r
= sd_journal_seek_head(m
->journal
);
499 else if (m
->n_skip
< 0)
500 r
= sd_journal_seek_tail(m
->journal
);
502 return mhd_respond(connection
, MHD_HTTP_BAD_REQUEST
, "Failed to seek in journal.");
504 response
= MHD_create_response_from_callback(MHD_SIZE_UNKNOWN
, 4*1024, request_reader_entries
, m
, NULL
);
506 return respond_oom(connection
);
508 MHD_add_response_header(response
, "Content-Type", mime_types
[m
->mode
]);
509 return MHD_queue_response(connection
, MHD_HTTP_OK
, response
);
512 static int output_field(FILE *f
, OutputMode m
, const char *d
, size_t l
) {
516 eq
= memchr(d
, '=', l
);
520 j
= l
- (eq
- d
+ 1);
522 if (m
== OUTPUT_JSON
) {
523 fprintf(f
, "{ \"%.*s\" : ", (int) (eq
- d
), d
);
524 json_escape(f
, eq
+1, j
, OUTPUT_FULL_WIDTH
);
527 fwrite(eq
+1, 1, j
, f
);
534 static ssize_t
request_reader_fields(
540 RequestMeta
*m
= cls
;
547 assert(pos
>= m
->delta
);
551 while (pos
>= m
->size
) {
556 /* End of this field, so let's serialize the next
559 if (m
->n_fields_set
&&
561 return MHD_CONTENT_READER_END_OF_STREAM
;
563 r
= sd_journal_enumerate_unique(m
->journal
, &d
, &l
);
565 log_error_errno(r
, "Failed to advance field index: %m");
566 return MHD_CONTENT_READER_END_WITH_ERROR
;
568 return MHD_CONTENT_READER_END_OF_STREAM
;
576 r
= request_meta_ensure_tmp(m
);
578 log_error_errno(r
, "Failed to create temporary file: %m");
579 return MHD_CONTENT_READER_END_WITH_ERROR
;
582 r
= output_field(m
->tmp
, m
->mode
, d
, l
);
584 log_error_errno(r
, "Failed to serialize item: %m");
585 return MHD_CONTENT_READER_END_WITH_ERROR
;
589 if (sz
== (off_t
) -1) {
590 log_error_errno(errno
, "Failed to retrieve file position: %m");
591 return MHD_CONTENT_READER_END_WITH_ERROR
;
594 m
->size
= (uint64_t) sz
;
597 if (fseeko(m
->tmp
, pos
, SEEK_SET
) < 0) {
598 log_error_errno(errno
, "Failed to seek to position: %m");
599 return MHD_CONTENT_READER_END_WITH_ERROR
;
607 k
= fread(buf
, 1, n
, m
->tmp
);
609 log_error("Failed to read from file: %s", errno
!= 0 ? strerror_safe(errno
) : "Premature EOF");
610 return MHD_CONTENT_READER_END_WITH_ERROR
;
616 static int request_handler_fields(
617 struct MHD_Connection
*connection
,
619 void *connection_cls
) {
621 _cleanup_(MHD_destroy_responsep
) struct MHD_Response
*response
= NULL
;
622 RequestMeta
*m
= connection_cls
;
630 return mhd_respondf(connection
, r
, MHD_HTTP_INTERNAL_SERVER_ERROR
, "Failed to open journal: %m");
632 if (request_parse_accept(m
, connection
) < 0)
633 return mhd_respond(connection
, MHD_HTTP_BAD_REQUEST
, "Failed to parse Accept header.");
635 r
= sd_journal_query_unique(m
->journal
, field
);
637 return mhd_respond(connection
, MHD_HTTP_BAD_REQUEST
, "Failed to query unique fields.");
639 response
= MHD_create_response_from_callback(MHD_SIZE_UNKNOWN
, 4*1024, request_reader_fields
, m
, NULL
);
641 return respond_oom(connection
);
643 MHD_add_response_header(response
, "Content-Type", mime_types
[m
->mode
== OUTPUT_JSON
? OUTPUT_JSON
: OUTPUT_SHORT
]);
644 return MHD_queue_response(connection
, MHD_HTTP_OK
, response
);
647 static int request_handler_redirect(
648 struct MHD_Connection
*connection
,
649 const char *target
) {
652 _cleanup_(MHD_destroy_responsep
) struct MHD_Response
*response
= NULL
;
657 if (asprintf(&page
, "<html><body>Please continue to the <a href=\"%s\">journal browser</a>.</body></html>", target
) < 0)
658 return respond_oom(connection
);
660 response
= MHD_create_response_from_buffer(strlen(page
), page
, MHD_RESPMEM_MUST_FREE
);
663 return respond_oom(connection
);
666 MHD_add_response_header(response
, "Content-Type", "text/html");
667 MHD_add_response_header(response
, "Location", target
);
668 return MHD_queue_response(connection
, MHD_HTTP_MOVED_PERMANENTLY
, response
);
671 static int request_handler_file(
672 struct MHD_Connection
*connection
,
674 const char *mime_type
) {
676 _cleanup_(MHD_destroy_responsep
) struct MHD_Response
*response
= NULL
;
677 _cleanup_close_
int fd
= -1;
684 fd
= open(path
, O_RDONLY
|O_CLOEXEC
);
686 return mhd_respondf(connection
, errno
, MHD_HTTP_NOT_FOUND
, "Failed to open file %s: %m", path
);
688 if (fstat(fd
, &st
) < 0)
689 return mhd_respondf(connection
, errno
, MHD_HTTP_INTERNAL_SERVER_ERROR
, "Failed to stat file: %m");
691 response
= MHD_create_response_from_fd_at_offset64(st
.st_size
, fd
, 0);
693 return respond_oom(connection
);
696 MHD_add_response_header(response
, "Content-Type", mime_type
);
697 return MHD_queue_response(connection
, MHD_HTTP_OK
, response
);
700 static int get_virtualization(char **v
) {
701 _cleanup_(sd_bus_unrefp
) sd_bus
*bus
= NULL
;
705 r
= sd_bus_default_system(&bus
);
709 r
= sd_bus_get_property_string(
711 "org.freedesktop.systemd1",
712 "/org/freedesktop/systemd1",
713 "org.freedesktop.systemd1.Manager",
730 static int request_handler_machine(
731 struct MHD_Connection
*connection
,
732 void *connection_cls
) {
734 _cleanup_(MHD_destroy_responsep
) struct MHD_Response
*response
= NULL
;
735 RequestMeta
*m
= connection_cls
;
737 _cleanup_free_
char* hostname
= NULL
, *os_name
= NULL
;
738 uint64_t cutoff_from
= 0, cutoff_to
= 0, usage
= 0;
740 _cleanup_free_
char *v
= NULL
, *json
= NULL
;
747 return mhd_respondf(connection
, r
, MHD_HTTP_INTERNAL_SERVER_ERROR
, "Failed to open journal: %m");
749 r
= sd_id128_get_machine(&mid
);
751 return mhd_respondf(connection
, r
, MHD_HTTP_INTERNAL_SERVER_ERROR
, "Failed to determine machine ID: %m");
753 r
= sd_id128_get_boot(&bid
);
755 return mhd_respondf(connection
, r
, MHD_HTTP_INTERNAL_SERVER_ERROR
, "Failed to determine boot ID: %m");
757 hostname
= gethostname_malloc();
759 return respond_oom(connection
);
761 r
= sd_journal_get_usage(m
->journal
, &usage
);
763 return mhd_respondf(connection
, r
, MHD_HTTP_INTERNAL_SERVER_ERROR
, "Failed to determine disk usage: %m");
765 r
= sd_journal_get_cutoff_realtime_usec(m
->journal
, &cutoff_from
, &cutoff_to
);
767 return mhd_respondf(connection
, r
, MHD_HTTP_INTERNAL_SERVER_ERROR
, "Failed to determine disk usage: %m");
769 (void) parse_os_release(NULL
, "PRETTY_NAME", &os_name
, NULL
);
770 (void) get_virtualization(&v
);
773 "{ \"machine_id\" : \"" SD_ID128_FORMAT_STR
"\","
774 "\"boot_id\" : \"" SD_ID128_FORMAT_STR
"\","
775 "\"hostname\" : \"%s\","
776 "\"os_pretty_name\" : \"%s\","
777 "\"virtualization\" : \"%s\","
778 "\"usage\" : \"%"PRIu64
"\","
779 "\"cutoff_from_realtime\" : \"%"PRIu64
"\","
780 "\"cutoff_to_realtime\" : \"%"PRIu64
"\" }\n",
781 SD_ID128_FORMAT_VAL(mid
),
782 SD_ID128_FORMAT_VAL(bid
),
783 hostname_cleanup(hostname
),
784 os_name
? os_name
: "Linux",
790 return respond_oom(connection
);
792 response
= MHD_create_response_from_buffer(strlen(json
), json
, MHD_RESPMEM_MUST_FREE
);
794 return respond_oom(connection
);
797 MHD_add_response_header(response
, "Content-Type", "application/json");
798 return MHD_queue_response(connection
, MHD_HTTP_OK
, response
);
801 static int request_handler(
803 struct MHD_Connection
*connection
,
807 const char *upload_data
,
808 size_t *upload_data_size
,
809 void **connection_cls
) {
813 assert(connection_cls
);
817 if (!streq(method
, "GET"))
818 return mhd_respond(connection
, MHD_HTTP_NOT_ACCEPTABLE
, "Unsupported method.");
820 if (!*connection_cls
) {
821 if (!request_meta(connection_cls
))
822 return respond_oom(connection
);
827 r
= check_permissions(connection
, &code
, NULL
);
833 return request_handler_redirect(connection
, "/browse");
835 if (streq(url
, "/entries"))
836 return request_handler_entries(connection
, *connection_cls
);
838 if (startswith(url
, "/fields/"))
839 return request_handler_fields(connection
, url
+ 8, *connection_cls
);
841 if (streq(url
, "/browse"))
842 return request_handler_file(connection
, DOCUMENT_ROOT
"/browse.html", "text/html");
844 if (streq(url
, "/machine"))
845 return request_handler_machine(connection
, *connection_cls
);
847 return mhd_respond(connection
, MHD_HTTP_NOT_FOUND
, "Not found.");
850 static int help(void) {
851 _cleanup_free_
char *link
= NULL
;
854 r
= terminal_urlify_man("systemd-journal-gatewayd.service", "8", &link
);
858 printf("%s [OPTIONS...] ...\n\n"
859 "HTTP server for journal events.\n\n"
860 " -h --help Show this help\n"
861 " --version Show package version\n"
862 " --cert=CERT.PEM Server certificate in PEM format\n"
863 " --key=KEY.PEM Server key in PEM format\n"
864 " --trust=CERT.PEM Certificate authority certificate in PEM format\n"
865 " -D --directory=PATH Serve journal files in directory\n"
866 "\nSee the %s for details.\n"
867 , program_invocation_short_name
874 static int parse_argv(int argc
, char *argv
[]) {
884 static const struct option options
[] = {
885 { "help", no_argument
, NULL
, 'h' },
886 { "version", no_argument
, NULL
, ARG_VERSION
},
887 { "key", required_argument
, NULL
, ARG_KEY
},
888 { "cert", required_argument
, NULL
, ARG_CERT
},
889 { "trust", required_argument
, NULL
, ARG_TRUST
},
890 { "directory", required_argument
, NULL
, 'D' },
897 while ((c
= getopt_long(argc
, argv
, "hD:", options
, NULL
)) >= 0)
909 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
910 "Key file specified twice");
911 r
= read_full_file(optarg
, &arg_key_pem
, NULL
);
913 return log_error_errno(r
, "Failed to read key file: %m");
919 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
920 "Certificate file specified twice");
921 r
= read_full_file(optarg
, &arg_cert_pem
, NULL
);
923 return log_error_errno(r
, "Failed to read certificate file: %m");
924 assert(arg_cert_pem
);
930 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
931 "CA certificate file specified twice");
932 r
= read_full_file(optarg
, &arg_trust_pem
, NULL
);
934 return log_error_errno(r
, "Failed to read CA certificate file: %m");
935 assert(arg_trust_pem
);
938 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
939 "Option --trust is not available.");
942 arg_directory
= optarg
;
949 assert_not_reached("Unhandled option");
953 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
954 "This program does not take arguments.");
956 if (!!arg_key_pem
!= !!arg_cert_pem
)
957 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
958 "Certificate and key files must be specified together");
960 if (arg_trust_pem
&& !arg_key_pem
)
961 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
962 "CA certificate can only be used with certificate file");
967 static int run(int argc
, char *argv
[]) {
968 _cleanup_(MHD_stop_daemonp
) struct MHD_Daemon
*d
= NULL
;
969 struct MHD_OptionItem opts
[] = {
970 { MHD_OPTION_NOTIFY_COMPLETED
,
971 (intptr_t) request_meta_free
, NULL
},
972 { MHD_OPTION_EXTERNAL_LOGGER
,
973 (intptr_t) microhttpd_logger
, NULL
},
974 { MHD_OPTION_END
, 0, NULL
},
975 { MHD_OPTION_END
, 0, NULL
},
976 { MHD_OPTION_END
, 0, NULL
},
977 { MHD_OPTION_END
, 0, NULL
},
978 { MHD_OPTION_END
, 0, NULL
},
982 /* We force MHD_USE_ITC here, in order to make sure
983 * libmicrohttpd doesn't use shutdown() on our listening
984 * socket, which would break socket re-activation. See
986 * https://lists.gnu.org/archive/html/libmicrohttpd/2015-09/msg00014.html
987 * https://github.com/systemd/systemd/pull/1286
994 MHD_USE_POLL_INTERNAL_THREAD
|
995 MHD_USE_THREAD_PER_CONNECTION
;
1000 r
= parse_argv(argc
, argv
);
1006 r
= setup_gnutls_logger(NULL
);
1010 n
= sd_listen_fds(1);
1012 return log_error_errno(n
, "Failed to determine passed sockets: %m");
1014 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Can't listen on more than one socket.");
1017 opts
[opts_pos
++] = (struct MHD_OptionItem
)
1018 { MHD_OPTION_LISTEN_SOCKET
, SD_LISTEN_FDS_START
};
1021 assert(arg_cert_pem
);
1022 opts
[opts_pos
++] = (struct MHD_OptionItem
)
1023 { MHD_OPTION_HTTPS_MEM_KEY
, 0, arg_key_pem
};
1024 opts
[opts_pos
++] = (struct MHD_OptionItem
)
1025 { MHD_OPTION_HTTPS_MEM_CERT
, 0, arg_cert_pem
};
1026 flags
|= MHD_USE_TLS
;
1029 if (arg_trust_pem
) {
1030 assert(flags
& MHD_USE_TLS
);
1031 opts
[opts_pos
++] = (struct MHD_OptionItem
)
1032 { MHD_OPTION_HTTPS_MEM_TRUST
, 0, arg_trust_pem
};
1035 d
= MHD_start_daemon(flags
, 19531,
1037 request_handler
, NULL
,
1038 MHD_OPTION_ARRAY
, opts
,
1041 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Failed to start daemon!");
1048 DEFINE_MAIN_FUNCTION(run
);