mirror of
https://github.com/yrutschle/sslh.git
synced 2025-04-14 08:07:14 +03:00
Merge pull request #240 from niobos/feature/descriptive-ps-name
Change process name to indicate task of process
This commit is contained in:
commit
544c2b6d2f
6
Makefile
6
Makefile
@ -7,6 +7,7 @@ USELIBPCRE=1 # Use libpcre? (needed for regex on musl)
|
||||
USELIBWRAP?= # Use libwrap?
|
||||
USELIBCAP= # Use libcap?
|
||||
USESYSTEMD= # Make use of systemd socket activation
|
||||
USELIBBSD?= # Use libbsd (needed to update process name in `ps`)
|
||||
COV_TEST= # Perform test coverage?
|
||||
PREFIX?=/usr
|
||||
BINDIR?=$(PREFIX)/sbin
|
||||
@ -59,6 +60,11 @@ ifneq ($(strip $(USESYSTEMD)),)
|
||||
CONDITIONAL_TARGETS+=systemd-sslh-generator
|
||||
endif
|
||||
|
||||
ifneq ($(strip $(USELIBBSD)),)
|
||||
LIBS:=$(LIBS) -lbsd
|
||||
CPPFLAGS+=-DLIBBSD
|
||||
endif
|
||||
|
||||
|
||||
all: sslh $(MAN) echosrv $(CONDITIONAL_TARGETS)
|
||||
|
||||
|
22
common.c
22
common.c
@ -30,6 +30,10 @@
|
||||
#include <systemd/sd-daemon.h>
|
||||
#endif
|
||||
|
||||
#ifdef LIBBSD
|
||||
#include <bsd/unistd.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Settings that depend on the command line or the config file
|
||||
*/
|
||||
@ -621,6 +625,24 @@ void log_connection(struct connection_desc* desc, const struct connection *cnx)
|
||||
desc->target);
|
||||
}
|
||||
|
||||
void set_proctitle_shovel(struct connection_desc* desc, const struct connection *cnx)
|
||||
{
|
||||
#ifdef LIBBSD
|
||||
struct connection_desc d;
|
||||
|
||||
if (!desc) {
|
||||
desc = &d;
|
||||
get_connection_desc(desc, cnx);
|
||||
}
|
||||
setproctitle("shovel %s %s->%s => %s->%s",
|
||||
cnx->proto->name,
|
||||
desc->peer,
|
||||
desc->service,
|
||||
desc->local,
|
||||
desc->target);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/* libwrap (tcpd): check the connection is legal. This is necessary because
|
||||
* the actual server will only see a connection coming from localhost and can't
|
||||
|
1
common.h
1
common.h
@ -123,6 +123,7 @@ char* sprintaddr(char* buf, size_t size, struct addrinfo *a);
|
||||
void resolve_name(struct addrinfo **out, char* fullname);
|
||||
int get_connection_desc(struct connection_desc* desc, const struct connection *cnx);
|
||||
void log_connection(struct connection_desc* desc, const struct connection *cnx);
|
||||
void set_proctitle_shovel(struct connection_desc* desc, const struct connection *cnx);
|
||||
int check_access_rights(int in_socket, const char* service);
|
||||
void setup_signals(void);
|
||||
void setup_syslog(const char* bin_name);
|
||||
|
@ -27,6 +27,9 @@ distclean` for example), you will also need to add
|
||||
[conf2struct](https://www.rutschle.net/tech/conf2struct/README.html)
|
||||
(v1.0) to your path.
|
||||
|
||||
There is optional support to change the process name (as shown in `ps`),
|
||||
which requires `libbsd` at runtime, and `libbsd-dev` at compile-time.
|
||||
|
||||
Compilation
|
||||
-----------
|
||||
|
||||
@ -48,6 +51,9 @@ of the Makefile:
|
||||
* `USESYSTEMD` compiles support for using systemd socket activation.
|
||||
You will need `systemd` headers to compile (`systemd-devel` in Fedora).
|
||||
|
||||
* `USELIBBSD` compiles support for updating the process name (as shown
|
||||
by `ps`).
|
||||
|
||||
Binaries
|
||||
--------
|
||||
|
||||
|
24
sslh-fork.c
24
sslh-fork.c
@ -23,6 +23,10 @@
|
||||
#include "common.h"
|
||||
#include "probe.h"
|
||||
|
||||
#ifdef LIBBSD
|
||||
#include <bsd/unistd.h>
|
||||
#endif
|
||||
|
||||
const char* server_type = "sslh-fork";
|
||||
|
||||
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
|
||||
@ -114,6 +118,7 @@ void start_shoveler(int in_socket)
|
||||
|
||||
get_connection_desc(&desc, &cnx);
|
||||
log_connection(&desc, &cnx);
|
||||
set_proctitle_shovel(&desc, &cnx);
|
||||
|
||||
flush_deferred(&cnx.q[1]);
|
||||
|
||||
@ -140,6 +145,24 @@ void stop_listeners(int sig)
|
||||
}
|
||||
}
|
||||
|
||||
void set_listen_procname(int listen_socket)
|
||||
{
|
||||
#ifdef LIBBSD
|
||||
int res;
|
||||
struct addrinfo addr;
|
||||
struct sockaddr_storage ss;
|
||||
char listen_addr[NI_MAXHOST+1+NI_MAXSERV+1];
|
||||
|
||||
addr.ai_addr = (struct sockaddr*)&ss;
|
||||
addr.ai_addrlen = sizeof(ss);
|
||||
res = getsockname(listen_socket, addr.ai_addr, &addr.ai_addrlen);
|
||||
if (res != -1) {
|
||||
sprintaddr(listen_addr, sizeof(listen_addr), &addr);
|
||||
setproctitle("listener %s", listen_addr);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void main_loop(int listen_sockets[], int num_addr_listen)
|
||||
{
|
||||
int in_socket, i, res;
|
||||
@ -160,6 +183,7 @@ void main_loop(int listen_sockets[], int num_addr_listen)
|
||||
case 0:
|
||||
/* Listening process just accepts a connection, forks, and goes
|
||||
* back to listening */
|
||||
set_listen_procname(listen_sockets[i]);
|
||||
while (1)
|
||||
{
|
||||
in_socket = accept(listen_sockets[i], 0, 0);
|
||||
|
@ -33,6 +33,10 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef LIBBSD
|
||||
#include <bsd/unistd.h>
|
||||
#endif
|
||||
|
||||
#include "common.h"
|
||||
#include "probe.h"
|
||||
|
||||
@ -247,7 +251,7 @@ void config_sanity_check(struct sslhcfg_item* cfg) {
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[], char* envp[])
|
||||
{
|
||||
|
||||
extern char *optarg;
|
||||
@ -255,6 +259,9 @@ int main(int argc, char *argv[])
|
||||
int res, num_addr_listen;
|
||||
int *listen_sockets;
|
||||
|
||||
#ifdef LIBBSD
|
||||
setproctitle_init(argc, argv, envp);
|
||||
#endif
|
||||
|
||||
memset(&cfg, 0, sizeof(cfg));
|
||||
sslhcfg_cl_parse(argc, argv, &cfg);
|
||||
|
Loading…
x
Reference in New Issue
Block a user