libweston: weston_output_init(..., +name)

Add 'name' argument to weston_output_init(). This is much more obvious
than the assert inside weston_output_init() to ensure the caller has set
a field in weston_output first.

Now weston_output_init() will strdup() the name itself, which means we
can drop a whole bunch of strdup()s in the backends. This matches
weston_output_destroy() which was already calling free() on the name.

All backends are slightly reordered to call weston_output_init() before
accessing any fields of weston_output, except the Wayland backend which
would make it a little awkward to do it in this patch. Mind, that
weston_output_init() still does not reset the struct to zero - it is
presumed the caller has done it, since weston_output is embedded in the
backend output structs.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Reviewed-by: Ian Ray <ian.ray@ge.com>
Reviewed-by: David Fort <contact@hardening-consulting.com>
[Daniel: document name copying]
Acked-by Daniel Stone <daniels@collabora.com>
diff --git a/libweston/compositor.c b/libweston/compositor.c
index bed3cd8..165ff01 100644
--- a/libweston/compositor.c
+++ b/libweston/compositor.c
@@ -4679,23 +4679,25 @@
  *
  * \param output     The weston_output object to initialize
  * \param compositor The compositor instance.
+ * \param name       Name for the output (the string is copied).
  *
  * Sets initial values for fields that are expected to be
  * configured either by compositors or backends.
  *
+ * The name is used in logs, and can be used by compositors as a configuration
+ * identifier.
+ *
  * \memberof weston_output
  * \internal
  */
 WL_EXPORT void
 weston_output_init(struct weston_output *output,
-		   struct weston_compositor *compositor)
+		   struct weston_compositor *compositor,
+		   const char *name)
 {
 	output->compositor = compositor;
 	output->destroying = 0;
-
-	/* Backends must set output->name */
-	assert(output->name);
-
+	output->name = strdup(name);
 	wl_list_init(&output->link);
 	output->enabled = false;