Working bot.
[xavierbot.git] / ocamlbotwrapper.c
index d7ad40d..d5f7127 100644 (file)
@@ -1,5 +1,5 @@
 /* -*- C -*-
- * $Id: ocamlbotwrapper.c,v 1.1 2007/06/28 19:47:26 rjones Exp $
+ * $Id: ocamlbotwrapper.c,v 1.2 2007/06/28 20:49:10 rjones Exp $
  * SUID wrapper around ocaml program.
  */
 
@@ -16,8 +16,32 @@ const char *new_environ[] = {
 int
 main ()
 {
+  /* Don't worry about races here because we're just checking that
+   * the installation looks reasonable.
+   *
+   * Die if the init script does not exist. */
+  if (access ("init", R_OK) == -1) {
+    perror ("init");
+    exit (1);
+  }
+
+  /* Die if the ocaml program does not exist. */
+  if (access ("/usr/bin/ocaml", R_OK|X_OK) == -1) {
+    perror ("/usr/bin/ocaml");
+    exit (1);
+  }
+
+  /* Die if the chroot directory does not exist. */
+  if (access ("/var/local/xavierbot/chroot", R_OK|X_OK) == -1) {
+    perror ("/var/local/xavierbot/chroot");
+    exit (1);
+  }
+
   /* Run the ocaml program with the correct args. */
-  execle ("/usr/bin/ocaml", "@OCAML@", "-init", "xavierbot/share/xavierbot/init", NULL, new_environ);
+  execle ("/usr/bin/ocaml", "@OCAML@",
+         "-init", "init",
+         "-noprompt",
+         NULL, new_environ);
 
   /* If it failed, die with an error message. */
   perror ("/usr/bin/ocaml");