Ignore tarballs.
[xavierbot.git] / ocamlbotwrapper.c.in
1 /* -*- C -*-
2  * $Id: ocamlbotwrapper.c.in,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 ("@INITSCRIPT@", R_OK) == -1) {
24     perror ("@INITSCRIPT@");
25     exit (1);
26   }
27
28   /* Die if the ocaml program does not exist. */
29   if (access ("@OCAML@", R_OK|X_OK) == -1) {
30     perror ("@OCAML@");
31     exit (1);
32   }
33
34   /* Die if the chroot directory does not exist. */
35   if (access ("@CHROOTDIR@", R_OK|X_OK) == -1) {
36     perror ("@CHROOTDIR@");
37     exit (1);
38   }
39
40   /* Run the ocaml program with the correct args. */
41   execle ("@OCAML@", "@OCAML@",
42           "-init", "@INITSCRIPT@",
43           "-noprompt",
44           NULL, new_environ);
45
46   /* If it failed, die with an error message. */
47   perror ("@OCAML@");
48   exit (1);
49 }