summaryrefslogtreecommitdiff
path: root/src/safeguard.c
diff options
context:
space:
mode:
authorcsilvers <csilvers@01de4be4-8c4a-0410-9132-4925637da917>2008-04-11 22:36:40 +0000
committercsilvers <csilvers@01de4be4-8c4a-0410-9132-4925637da917>2008-04-11 22:36:40 +0000
commit6b117b70f948dc72b107dab6d3e9ac99be297b6d (patch)
tree1726969de95d86fc5647af1eeb99ea0489ba91c4 /src/safeguard.c
parent204634dc3c7d4662fab0132140f1ac59e8c9312b (diff)
downloaddistcc-6b117b70f948dc72b107dab6d3e9ac99be297b6d.tar.gz
The first step of moving everything in the distcc directory to the top
level. I'm doing this in two stages, because I don't understand svn enough to be confident to do it in one. This first stage just copies all the files from distcc/FOO to FOO. Now there are two copies of each file under distcc; the Makefile/etc uses the one in distcc and ignores the one at the top level. The next commit will delete everything under distcc, and rewrite the Makefile/etc to use the top-level versions instead. git-svn-id: http://distcc.googlecode.com/svn/trunk@22 01de4be4-8c4a-0410-9132-4925637da917
Diffstat (limited to 'src/safeguard.c')
-rw-r--r--src/safeguard.c81
1 files changed, 81 insertions, 0 deletions
diff --git a/src/safeguard.c b/src/safeguard.c
new file mode 100644
index 0000000..204484e
--- /dev/null
+++ b/src/safeguard.c
@@ -0,0 +1,81 @@
+/* -*- c-file-style: "java"; indent-tabs-mode: nil; fill-column: 78 -*-
+ *
+ * distcc -- A simple distributed compiler system
+ *
+ * Copyright (C) 2002, 2003 by Martin Pool <mbp@samba.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+#include "config.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+
+#include "distcc.h"
+#include "trace.h"
+#include "util.h"
+#include "exitcode.h"
+
+
+/**
+ * @file
+ * @brief Protect against unbounded recursion.
+ *
+ * It would be fairly easy for somebody to get confused in masquerade mode and
+ * try to get distcc to invoke itself in a loop. We can't always work out the
+ * right thing to do but we can at least flag an error.
+ *
+ * This environment variable is set to guard against distcc accidentally
+ * recursively invoking itself, thinking it's the real compiler.
+ **/
+
+static const char dcc_safeguard_name[] = "_DISTCC_SAFEGUARD";
+static char dcc_safeguard_set[] = "_DISTCC_SAFEGUARD=1";
+static int dcc_safeguard_level;
+
+int dcc_recursion_safeguard(void)
+{
+ char *env = getenv(dcc_safeguard_name);
+
+ if (env) {
+ rs_trace("safeguard: %s", env);
+ if (!(dcc_safeguard_level = atoi(env)))
+ dcc_safeguard_level = 1;
+ }
+ else
+ dcc_safeguard_level = 0;
+ rs_trace("safeguard level=%d", dcc_safeguard_level);
+
+ return dcc_safeguard_level;
+}
+
+
+int dcc_increment_safeguard(void)
+{
+ if (dcc_safeguard_level > 0)
+ dcc_safeguard_set[sizeof dcc_safeguard_set-2] = dcc_safeguard_level+'1';
+ rs_trace("setting safeguard: %s", dcc_safeguard_set);
+ if ((putenv(strdup(dcc_safeguard_set)) == -1)) {
+ rs_log_error("putenv failed");
+ /* and continue */
+ }
+
+ return 0;
+}