summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorRichard Boulton <richard@tartarus.org>2001-01-07 04:51:31 +0000
committerRichard Boulton <richard@tartarus.org>2001-01-07 04:51:31 +0000
commit62c3227e2fe4d225ab1ee48e96ea11b6db705e5e (patch)
tree7feed87aac105f60750981bde6b813cd6606d40a /tools
parent4bdaed3966dfc3d959b8e444c5dca541b786d079 (diff)
Almost completely rewritten gstreamer-register.
Original commit message from CVS: Almost completely rewritten gstreamer-register. Now checks most errors that can happen, and displays a useful message.
Diffstat (limited to 'tools')
-rw-r--r--tools/gstreamer-register.c124
1 files changed, 115 insertions, 9 deletions
diff --git a/tools/gstreamer-register.c b/tools/gstreamer-register.c
index e008e4f04d..e3097f59fa 100644
--- a/tools/gstreamer-register.c
+++ b/tools/gstreamer-register.c
@@ -1,21 +1,127 @@
+/* GStreamer
+ * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
+ * 2000 Wim Taymans <wtay@chello.be>
+ *
+ * gstreamer-register.c: Plugin subsystem for loading elements, types, and libs
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
#include <stdlib.h>
#include <gst/gst.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include <string.h>
+#include <errno.h>
+
+#define GST_CONFIG_DIR "/etc/gstreamer"
+#define GLOBAL_REGISTRY_FILE GST_CONFIG_DIR"/reg.xml"
+#define GLOBAL_REGISTRY_FILE_TMP GST_CONFIG_DIR"/.reg.xml.tmp"
+
extern gboolean _gst_plugin_spew;
+static void error_perm() {
+ g_print("\n(%s)\n"
+ "Do you have the appropriate permissions?\n"
+ "You may need to be root to run this command.\n\n",
+ strerror(errno));
+ exit(1);
+}
+
+static void usage(const char *progname) {
+ g_print("usage: %s\n", progname);
+ g_print("Builds the plugin registry for gstreamer.\n");
+ g_print("This command will usually require superuser privileges.\n\n");
+ exit(0);
+}
+
+static int is_file(const char * filename) {
+ struct stat statbuf;
+ if(stat(filename, &statbuf)) return 0;
+ return S_ISREG(statbuf.st_mode);
+}
+
+static int is_dir(const char * filename) {
+ struct stat statbuf;
+ if(stat(filename, &statbuf)) return 0;
+ return S_ISDIR(statbuf.st_mode);
+}
+
+static void move_file(const char * nameold, const char * namenew) {
+ if (!is_file(nameold)) {
+ g_print("Temporary `%s' is not a file", nameold);
+ error_perm();
+ }
+ if (is_dir(namenew)) {
+ g_print("Destination path `%s' is a directory\n", namenew);
+ g_print("Please remove, or reconfigure GStreamer\n\n");
+ exit(1);
+ }
+ if (rename(nameold, namenew)) {
+ g_print("Cannot move `%s' to `%s'", nameold, namenew);
+ error_perm();
+ }
+}
+
+static int make_dir(const char * dirname) {
+ mode_t mode = 0766;
+ return !mkdir(dirname, mode);
+}
+
+void check_dir(const char * dirname) {
+ if (!is_dir(dirname)) {
+ if (!make_dir(dirname)) {
+ g_print("Cannot create GStreamer registry directory `%s'",
+ dirname);
+ error_perm();
+ }
+ }
+}
+
int main(int argc,char *argv[])
{
- xmlDocPtr doc;
+ xmlDocPtr doc;
+
+ if (argc != 1) usage(argv[0]);
+
+ // Check that directory for config exists
+ check_dir(GST_CONFIG_DIR);
+
+ // Read the plugins
+ _gst_plugin_spew = TRUE;
+ gst_init(&argc,&argv);
+ doc = xmlNewDoc("1.0");
+ doc->root = xmlNewDocNode(doc, NULL, "GST-PluginRegistry", NULL);
+ gst_plugin_save_thyself(doc->root);
- unlink("/etc/gstreamer/reg.xml");
+ // Save the registry to a tmp file.
+ // FIXME; check for failure.
+ if (xmlSaveFile(GLOBAL_REGISTRY_FILE_TMP, doc)) {
+ g_print("Cannot save new registry `%s'",
+ GLOBAL_REGISTRY_FILE_TMP);
+ error_perm();
+ }
- _gst_plugin_spew = TRUE;
- gst_init(&argc,&argv);
+ // Make the tmp file live.
+ move_file(GLOBAL_REGISTRY_FILE_TMP, GLOBAL_REGISTRY_FILE);
- doc = xmlNewDoc("1.0");
- doc->root = xmlNewDocNode(doc, NULL, "GST-PluginRegistry", NULL);
- gst_plugin_save_thyself(doc->root);
- xmlSaveFile("/etc/gstreamer/reg.xml", doc);
- exit(0);
+ return(0);
}