Added README file.
[xavierbot.git] / ocamlbotwrapper.c
1 /* -*- C -*-
2  * $Id: ocamlbotwrapper.c,v 1.2 2007/06/28 20:49:10 rjones Exp $
3  * SUID wrapper around ocaml program.
4  */
5
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <unistd.h>
9 #include <errno.h>
10
11 const char *new_environ[] = {
12   "PATH=/usr/bin",
13   NULL
14 };
15
16 int
17 main ()
18 {
19   /* Don't worry about races here because we're just checking that
20    * the installation looks reasonable.
21    *
22    * Die if the init script does not exist. */
23   if (access ("init", R_OK) == -1) {
24     perror ("init");
25     exit (1);
26   }
27
28   /* Die if the ocaml program does not exist. */
29   if (access ("/usr/bin/ocaml", R_OK|X_OK) == -1) {
30     perror ("/usr/bin/ocaml");
31     exit (1);
32   }
33
34   /* Die if the chroot directory does not exist. */
35   if (access ("/var/local/xavierbot/chroot", R_OK|X_OK) == -1) {
36     perror ("/var/local/xavierbot/chroot");
37     exit (1);
38   }
39
40   /* Run the ocaml program with the correct args. */
41   execle ("/usr/bin/ocaml", "@OCAML@",
42           "-init", "init",
43           "-noprompt",
44           NULL, new_environ);
45
46   /* If it failed, die with an error message. */
47   perror ("/usr/bin/ocaml");
48   exit (1);
49 }