From: Mark Wooding Date: Wed, 3 Jun 2020 20:47:41 +0000 (+0100) Subject: disobedience/rtp.c: Allow setting a `disorder-playrtp' instance name. X-Git-Url: https://git.distorted.org.uk/~mdw/disorder/commitdiff_plain/53a4a6fdcc52280765216ff019cf77b85ec48c18 disobedience/rtp.c: Allow setting a `disorder-playrtp' instance name. This way, multiple processes can be running at the same time without interfering or getting too badly confused. --- diff --git a/disobedience/rtp.c b/disobedience/rtp.c index bb71022..40e1ea2 100644 --- a/disobedience/rtp.c +++ b/disobedience/rtp.c @@ -34,21 +34,45 @@ static char *rtp_socket; /** @brief Path to RTP player's logfile */ static char *rtp_log; +static char *substitute_instance_name(void) { + const char *p = config->rtp_instance_name; + struct utsname uts; + size_t n; + int ok; + struct dynstr z; + + ok = (uname(&uts) >= 0); + if(!p) p = "%h-rtp"; + dynstr_init(&z); + for(;;) { + n = strcspn(p, "%"); + if(n) { dynstr_append_bytes(&z, p, n); p += n; } + if(!*p) break; + p++; + switch(*p) { + case '%': dynstr_append_bytes(&z, "%", 1); p++; break; + case 'h': + if(ok) { dynstr_append_string(&z, uts.nodename); p++; } + else { p++; if(*p) p++; } + case 0: break; + default: dynstr_append_bytes(&z, p - 1, 2); p++; break; + } + } + dynstr_terminate(&z); + return z.vec; +} + /** @brief Initialize @ref rtp_socket and @ref rtp_log if necessary */ static void rtp_init(void) { if(!rtp_socket) { const char *home = getenv("HOME"); - char *dir, *base; - struct utsname uts; + char *dir, *instance; byte_xasprintf(&dir, "%s/.disorder/", home); mkdir(dir, 02700); - if(uname(&uts) < 0) - byte_xasprintf(&base, "%s/", dir); - else - byte_xasprintf(&base, "%s/%s-", dir, uts.nodename); - byte_xasprintf(&rtp_socket, "%srtp", base); - byte_xasprintf(&rtp_log, "%srtp.log", base); + instance = substitute_instance_name(); + byte_xasprintf(&rtp_socket, "%s%s", dir, instance); + byte_xasprintf(&rtp_log, "%s%s.log", dir, instance); } } diff --git a/lib/configuration.c b/lib/configuration.c index bb75173..bd9c65d 100644 --- a/lib/configuration.c +++ b/lib/configuration.c @@ -1111,6 +1111,7 @@ static const struct conf conf[] = { { C(replay_min), &type_integer, validate_non_negative }, { C(rtp_always_request), &type_boolean, validate_any }, { C(rtp_delay_threshold), &type_integer, validate_positive }, + { C(rtp_instance_name), &type_string, validate_any }, { C(rtp_max_payload), &type_integer, validate_positive }, { C(rtp_maxbuffer), &type_integer, validate_non_negative }, { C(rtp_minbuffer), &type_integer, validate_non_negative }, diff --git a/lib/configuration.h b/lib/configuration.h index 3811b34..284ae7a 100644 --- a/lib/configuration.h +++ b/lib/configuration.h @@ -244,12 +244,15 @@ struct config { /** @brief RTP buffer maximum size */ long rtp_maxbuffer; - /* @brief RTP receive buffer size */ + /** @brief RTP receive buffer size */ long rtp_rcvbuf; /** @brief Fixed RTP listening address */ struct netaddress rtp_request_address; + /** @brief @c disorder-playrtp instance name (for naming sockets etc.) */ + char *rtp_instance_name; + /** @brief Verbose RTP transmission logging */ int rtp_verbose;