osmo_io: Make name optional, add _set_name() API

This allows renaming the iofd at any later point in time. This is useful
for instance if the parent object holding the iofd changes its name.

Change-Id: If2772a3ccaa98616e0189862a49ab0243435e343
diff --git a/src/core/osmo_io.c b/src/core/osmo_io.c
index b0287ec..c9b0b29 100644
--- a/src/core/osmo_io.c
+++ b/src/core/osmo_io.c
@@ -128,7 +128,8 @@
 
 	OSMO_ASSERT(iofd->msgb_alloc.size < 0xffff - headroom);
 	return msgb_alloc_headroom_c(iofd->msgb_alloc.ctx,
-				     iofd->msgb_alloc.size + headroom, headroom, iofd->name);
+				     iofd->msgb_alloc.size + headroom, headroom,
+				     iofd->name ? : "iofd_msgb");
 }
 
 /*! return the pending msgb in iofd or NULL if there is none*/
@@ -388,7 +389,8 @@
 	iofd->fd = fd;
 	iofd->mode = mode;
 
-	iofd->name = talloc_strdup(iofd, name);
+	if (name)
+		iofd->name = talloc_strdup(iofd, name);
 
 	if (ioops)
 		iofd->io_ops = *ioops;
@@ -578,6 +580,14 @@
 	return iofd->name;
 }
 
+/*! Set the name of the file descriptor
+ *  \param[in] iofd the file descriptor
+ *  \param[in] name the name to set on the file descriptor */
+void osmo_iofd_set_name(struct osmo_io_fd *iofd, const char *name)
+{
+	osmo_talloc_replace_string(iofd, &iofd->name, name);
+}
+
 /*! Set the osmo_io_ops for an iofd
  *  \param[in] iofd Target iofd file descriptor
  *  \param[in] ioops osmo_io_ops structure to be set */