" -c, --credential Credential for Basic Authentication (format: username:password)\n"
" -u, --uid User id to run with\n"
" -g, --gid Group id to run with\n"
- " -s, --signal Signal to send to the command when exit it (default: SIGHUP)\n"
+ " -s, --signal Signal to send to the command when exit it (default: 9, SIGHUP)\n"
" -r, --reconnect Time to reconnect for the client in seconds (default: 10)\n"
" -R, --readonly Do not allow clients to write to the TTY\n"
" -t, --client-option Send option to client (format: key=value), repeat to add more options\n"
ts->client_count = 0;
ts->reconnect = 10;
ts->sig_code = SIGHUP;
- ts->sig_name = strdup("SIGHUP");
+ get_sig_name(ts->sig_code, ts->sig_name, sizeof(ts->sig_name));
if (start == argc)
return ts;
free(ts->argv[i++]);
} while (ts->argv[i] != NULL);
free(ts->argv);
- free(ts->sig_name);
- if (ts->socket_path != NULL) {
+ if (strlen(ts->socket_path) > 0) {
struct stat st;
if (!stat(ts->socket_path, &st)) {
unlink(ts->socket_path);
}
- free(ts->socket_path);
}
free(ts);
}
exit(EXIT_FAILURE);
char sig_name[20];
- get_sig_name(sig, sig_name);
+ get_sig_name(sig, sig_name, sizeof(sig_name));
lwsl_notice("received signal: %s (%d), exiting...\n", sig_name, sig);
force_exit = true;
lws_cancel_service(context);
case 's': {
int sig = get_sig(optarg);
if (sig > 0) {
- server->sig_code = get_sig(optarg);
- server->sig_name = uppercase(strdup(optarg));
+ server->sig_code = sig;
+ get_sig_name(sig, server->sig_name, sizeof(server->sig_code));
} else {
fprintf(stderr, "ttyd: invalid signal: %s\n", optarg);
return -1;
if (strlen(iface) > 0) {
info.iface = iface;
if (endswith(info.iface, ".sock") || endswith(info.iface, ".socket")) {
-#ifdef LWS_USE_UNIX_SOCK
+#if defined(LWS_USE_UNIX_SOCK) || defined(LWS_WITH_UNIX_SOCK)
info.options |= LWS_SERVER_OPTION_UNIX_SOCK;
- server->socket_path = strdup(info.iface);
+ strncpy(server->socket_path, info.iface, sizeof(server->socket_path));
#else
fprintf(stderr, "libwebsockets is not compiled with UNIX domain socket support");
return -1;
char *command; // full command line
char **argv; // command with arguments
int sig_code; // close signal
- char *sig_name; // human readable signal string
+ char sig_name[20]; // human readable signal string
bool readonly; // whether not allow clients to write to the TTY
bool check_origin; // whether allow websocket connection from different origin
int max_clients; // maximum clients to support
bool once; // whether accept only one client and exit on disconnection
- char *socket_path; // UNIX domain socket path
+ char socket_path[255]; // UNIX domain socket path
pthread_mutex_t lock;
};
}
int
-get_sig_name(int sig, char *buf) {
- int n = sprintf(buf, "SIG%s", sig < NSIG ? sys_signame[sig] : "unknown");
+get_sig_name(int sig, char *buf, size_t len) {
+ int n = snprintf(buf, len, "SIG%s", sig < NSIG ? sys_signame[sig] : "unknown");
uppercase(buf);
return n;
}
int
get_sig(const char *sig_name) {
- if (strlen(sig_name) <= 3 || strcasestr(sig_name, "sig") == NULL) {
- return -1;
- }
for (int sig = 1; sig < NSIG; sig++) {
const char *name = sys_signame[sig];
- if (name != NULL && strcasecmp(name, sig_name + 3) == 0)
+ if (name != NULL && (strcasecmp(name, sig_name) == 0 || strcasecmp(name, sig_name + 3) == 0))
return sig;
}
- return -1;
+ return atoi(sig_name);
}
int