neels has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmo-netif/+/39310?usp=email )
Change subject: add osmo_stream_cli_set_name_f() ......................................................................
add osmo_stream_cli_set_name_f()
Change-Id: Ide87f872246549d5963c3fac1627af397ef2e0c1 --- M include/osmocom/netif/stream.h M src/stream_cli.c 2 files changed, 25 insertions(+), 2 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmo-netif refs/changes/10/39310/1
diff --git a/include/osmocom/netif/stream.h b/include/osmocom/netif/stream.h index f63560a..4f3db25 100644 --- a/include/osmocom/netif/stream.h +++ b/include/osmocom/netif/stream.h @@ -199,6 +199,7 @@ typedef int (*osmo_stream_cli_segmentation_cb_t)(struct msgb *msg);
void osmo_stream_cli_set_name(struct osmo_stream_cli *cli, const char *name); +void osmo_stream_cli_set_name_f(struct osmo_stream_cli *cli, const char *fmt, ...); const char *osmo_stream_cli_get_name(const struct osmo_stream_cli *cli); void osmo_stream_cli_set_nodelay(struct osmo_stream_cli *cli, bool nodelay); int osmo_stream_cli_set_priority(struct osmo_stream_cli *cli, int sk_prio); diff --git a/src/stream_cli.c b/src/stream_cli.c index 48a8858..ec5325a 100644 --- a/src/stream_cli.c +++ b/src/stream_cli.c @@ -671,9 +671,31 @@ */ void osmo_stream_cli_set_name(struct osmo_stream_cli *cli, const char *name) { - osmo_talloc_replace_string(cli, &cli->name, name); + osmo_stream_cli_set_name_f(cli, "%s", name); +} + +/*! Set a name on the cli object using arguments like printf() (used during logging). + * \param[in] cli stream_cli whose name is to be set + * \param[in] name the name to be set on cli + */ +void osmo_stream_cli_set_name_f(struct osmo_stream_cli *cli, const char *fmt, ...); +{ + char *name = NULL; + + if (fmt) { + va_list ap; + + va_start(ap, fmt); + name = talloc_vasprintf(cli, fmt, ap); + va_end(ap); + } + + if (cli->name) + talloc_free((char*)cli->name); + cli->name = name; + if (cli->mode == OSMO_STREAM_MODE_OSMO_IO && cli->iofd) - osmo_iofd_set_name(cli->iofd, name); + osmo_iofd_set_name(cli->iofd, cli->name); }
/*! Retrieve name previously set on the cli object (see osmo_stream_cli_set_name()).