OPTIONS:
--port, -p Port to listen (default: 7681, use `0` for random port)
- --interface, -i Network interface to bind
+ --interface, -i Network interface to bind (eg: eth0), or UNIX domain socket path (eg: /var/run/ttyd.sock)
--credential, -c Credential for Basic Authentication (format: username:password)
--uid, -u User id to run with
--gid, -g Group id to run with
" %s\n\n"
"OPTIONS:\n"
" --port, -p Port to listen (default: 7681, use `0` for random port)\n"
- " --interface, -i Network interface to bind\n"
+ " --interface, -i Network interface to bind (eg: eth0), or UNIX domain socket path (eg: /var/run/ttyd.sock)\n"
" --credential, -c Credential for Basic Authentication (format: username:password)\n"
" --uid, -u User id to run with\n"
" --gid, -g Group id to run with\n"
} while (ts->argv[i] != NULL);
free(ts->argv);
free(ts->sig_name);
+ if (ts->socket_path != NULL) {
+ struct stat st;
+ if (!stat(ts->socket_path, &st)) {
+ unlink(ts->socket_path);
+ }
+ free(ts->socket_path);
+ }
free(ts);
}
lws_set_log_level(debug_level, NULL);
-#if LWS_LIBRARY_VERSION_MAJOR == 2
+#if LWS_LIBRARY_VERSION_MAJOR >= 2
char server_hdr[128] = "";
sprintf(server_hdr, "ttyd/%s (libwebsockets/%s)", TTYD_VERSION, LWS_LIBRARY_VERSION);
info.server_string = server_hdr;
#endif
- if (strlen(iface) > 0)
+ if (strlen(iface) > 0) {
info.iface = iface;
+ if (endswith(info.iface, ".sock") || endswith(info.iface, ".socket")) {
+#ifdef LWS_USE_UNIX_SOCK
+ info.options |= LWS_SERVER_OPTION_UNIX_SOCK;
+ server->socket_path = strdup(info.iface);
+#else
+ fprintf(stderr, "libwebsockets is not compiled with UNIX domain socket support");
+ return -1;
+#endif
+ }
+ }
if (ssl) {
info.ssl_cert_filepath = cert_path;
info.ssl_private_key_filepath = key_path;
"!AES256-SHA256";
if (strlen(info.ssl_ca_filepath) > 0)
info.options |= LWS_SERVER_OPTION_REQUIRE_VALID_OPENSSL_CLIENT_CERT;
-#if LWS_LIBRARY_VERSION_MAJOR == 2
+#if LWS_LIBRARY_VERSION_MAJOR >= 2
info.options |= LWS_SERVER_OPTION_REDIRECT_HTTP_TO_HTTPS;
#endif
}
#include <stdio.h>
#include <stdlib.h>
+#include <stdbool.h>
#include <ctype.h>
#include <string.h>
#include <signal.h>
return str;
}
+bool
+endswith(const char * str, const char * suffix) {
+ size_t str_len = strlen(str);
+ size_t suffix_len = strlen(suffix);
+ return str_len > suffix_len && !strcmp(str + (str_len - suffix_len), suffix);
+}
+
int
get_sig_name(int sig, char *buf) {
int n = sprintf(buf, "SIG%s", sig < NSIG ? strsignal(sig) : "unknown");