registrybinary: registry file mode via GST_REGISTRY_MODE
authorRobert Rosengren <robertr@axis.com>
Mon, 10 May 2021 10:50:18 +0000 (12:50 +0200)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Tue, 5 Oct 2021 10:49:27 +0000 (10:49 +0000)
In an embedded system where all services run as seperate users it is
useful to have the gstreamer registry readable by all so it can be
re-used, in similar manner as a host system where one user have seperate
applications running but all share same registry.

To make this possible introducing GST_REGISTRY_MODE for adjusting the
changing mode of the registry binary when finishing up with the
temporary file (which has restricted access).

Fixes: #692
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/825>

subprojects/gstreamer/gst/gstregistrybinary.c

index db2846f..1e86464 100644 (file)
@@ -252,6 +252,7 @@ static gboolean
 gst_registry_binary_cache_finish (BinaryRegistryCache * cache, gboolean success)
 {
   gint fclose_ret;
+  const gchar *registry_mode;
 
   if (success) {
     /* flush the file and make sure the OS's buffer has been written to disk */
@@ -292,6 +293,22 @@ gst_registry_binary_cache_finish (BinaryRegistryCache * cache, gboolean success)
   if (g_rename (cache->tmp_location, cache->location) < 0)
     goto rename_failed;
 
+  /* Change mode of registry if set in environment */
+  registry_mode = g_getenv ("GST_REGISTRY_MODE");
+  if (registry_mode) {
+    gchar *endptr;
+    gint64 mode;
+
+    /* Expect numeric mode as one to four octal digits */
+    mode = g_ascii_strtoll (registry_mode, &endptr, 8);
+    if (mode > G_MAXINT || *endptr != '\0')
+      GST_ERROR ("GST_REGISTRY_MODE not an integer value");
+    else if (g_chmod (cache->location, mode) < 0)
+      GST_ERROR ("g_chmod failed: %s", g_strerror (errno));
+    else
+      GST_INFO ("Changed mode of registry cache to %s", registry_mode);
+  }
+
   g_free (cache->tmp_location);
   g_slice_free (BinaryRegistryCache, cache);
   GST_INFO ("Wrote binary registry cache");