neels has submitted this change. ( https://gerrit.osmocom.org/c/libosmo-netif/+/39310?usp=email )
Change subject: add osmo_stream_*_set_name_f() ...................................................................... add osmo_stream_*_set_name_f() Change-Id: Ide87f872246549d5963c3fac1627af397ef2e0c1 --- M include/osmocom/netif/stream.h M src/stream_cli.c M src/stream_srv.c 3 files changed, 50 insertions(+), 4 deletions(-) Approvals: Jenkins Builder: Verified neels: Looks good to me, approved diff --git a/include/osmocom/netif/stream.h b/include/osmocom/netif/stream.h index 91a9b5e..075e5e9 100644 --- a/include/osmocom/netif/stream.h +++ b/include/osmocom/netif/stream.h @@ -126,6 +126,7 @@ void *data); struct osmo_stream_srv *osmo_stream_srv_create2(void *ctx, struct osmo_stream_srv_link *link, int fd, void *data); void osmo_stream_srv_set_name(struct osmo_stream_srv *conn, const char *name); +void osmo_stream_srv_set_name_f(struct osmo_stream_srv *conn, const char *fmt, ...); const char *osmo_stream_srv_get_name(const struct osmo_stream_srv *conn); void osmo_stream_srv_set_read_cb(struct osmo_stream_srv *conn, osmo_stream_srv_read_cb2_t read_cb); void osmo_stream_srv_set_closed_cb(struct osmo_stream_srv *conn, osmo_stream_srv_closed_cb_t close_cb); @@ -203,6 +204,7 @@ typedef int (*osmo_stream_cli_segmentation_cb2_t)(struct osmo_stream_cli *cli, 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 0028dcc..028ab07 100644 --- a/src/stream_cli.c +++ b/src/stream_cli.c @@ -667,9 +667,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((void *)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()). diff --git a/src/stream_srv.c b/src/stream_srv.c index 50efbb8..be950ce 100644 --- a/src/stream_srv.c +++ b/src/stream_srv.c @@ -1011,9 +1011,31 @@ */ void osmo_stream_srv_set_name(struct osmo_stream_srv *conn, const char *name) { - osmo_talloc_replace_string(conn, &conn->name, name); + osmo_stream_srv_set_name_f(conn, "%s", name); +} + +/*! Set a name on the srv object using arguments like printf() (used during logging). + * \param[in] srv stream_srv whose name is to be set + * \param[in] name the name to be set on srv + */ +void osmo_stream_srv_set_name_f(struct osmo_stream_srv *conn, const char *fmt, ...) +{ + char *name = NULL; + + if (fmt) { + va_list ap; + + va_start(ap, fmt); + name = talloc_vasprintf(conn, fmt, ap); + va_end(ap); + } + + if (conn->name) + talloc_free((void *)conn->name); + conn->name = name; + if (conn->mode == OSMO_STREAM_MODE_OSMO_IO && conn->iofd) - osmo_iofd_set_name(conn->iofd, name); + osmo_iofd_set_name(conn->iofd, conn->name); } /*! Retrieve name previously set on the srv object (see osmo_stream_srv_set_name()). -- To view, visit https://gerrit.osmocom.org/c/libosmo-netif/+/39310?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: merged Gerrit-Project: libosmo-netif Gerrit-Branch: master Gerrit-Change-Id: Ide87f872246549d5963c3fac1627af397ef2e0c1 Gerrit-Change-Number: 39310 Gerrit-PatchSet: 3 Gerrit-Owner: neels <nhofm...@sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria <vyanits...@sysmocom.de> Gerrit-Reviewer: neels <nhofm...@sysmocom.de> Gerrit-Reviewer: pespin <pes...@sysmocom.de>