[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r22408 - gnunet/src/pt
From: |
gnunet |
Subject: |
[GNUnet-SVN] r22408 - gnunet/src/pt |
Date: |
Sat, 30 Jun 2012 01:15:36 +0200 |
Author: schanzen
Date: 2012-06-30 01:15:36 +0200 (Sat, 30 Jun 2012)
New Revision: 22408
Modified:
gnunet/src/pt/test_gns_vpn.c
Log:
-check for ipt
Modified: gnunet/src/pt/test_gns_vpn.c
===================================================================
--- gnunet/src/pt/test_gns_vpn.c 2012-06-29 22:13:18 UTC (rev 22407)
+++ gnunet/src/pt/test_gns_vpn.c 2012-06-29 23:15:36 UTC (rev 22408)
@@ -437,9 +437,88 @@
}
+/**
+ * Run the given command and wait for it to complete.
+ *
+ * @param file name of the binary to run
+ * @param cmd command line arguments (as given to 'execv')
+ * @return 0 on success, 1 on any error
+ */
+static int
+fork_and_exec (const char *file,
+ char *const cmd[])
+{
+ int status;
+ pid_t pid;
+ pid_t ret;
+
+ pid = fork ();
+ if (-1 == pid)
+ {
+ fprintf (stderr,
+ "fork failed: %s\n",
+ strerror (errno));
+ return 1;
+ }
+ if (0 == pid)
+ {
+ /* we are the child process */
+ /* close stdin/stdout to not cause interference
+ with the helper's main protocol! */
+ (void) close (0);
+ (void) close (1);
+ (void) execv (file, cmd);
+ /* can only get here on error */
+ fprintf (stderr,
+ "exec `%s' failed: %s\n",
+ file,
+ strerror (errno));
+ _exit (1);
+ }
+ /* keep running waitpid as long as the only error we get is 'EINTR' */
+ while ( (-1 == (ret = waitpid (pid, &status, 0))) &&
+ (errno == EINTR) );
+ if (-1 == ret)
+ {
+ fprintf (stderr,
+ "waitpid failed: %s\n",
+ strerror (errno));
+ return 1;
+ }
+ if (! (WIFEXITED (status) && (0 == WEXITSTATUS (status))))
+ return 1;
+ /* child process completed and returned success, we're happy */
+ return 0;
+}
+
int
main (int argc, char *const *argv)
{
+ char *sbin_iptables;
+ char *const iptables_args[] =
+ {
+ "iptables", "-t", "mangle", "-L", "-v", NULL
+ };
+
+ if (0 == access ("/sbin/iptables", X_OK))
+ sbin_iptables = "/sbin/iptables";
+ else if (0 == access ("/usr/sbin/iptables", X_OK))
+ sbin_iptables = "/usr/sbin/iptables";
+ else
+ {
+ fprintf (stderr,
+ "Executable iptables not found in approved directories: %s,
skipping\n",
+ strerror (errno));
+ return 0;
+ }
+
+ if (0 != fork_and_exec (sbin_iptables, iptables_args))
+ {
+ fprintf (stderr,
+ "IPtables not available, Skipping.\n");
+ return 0;
+ }
+
if (0 != ACCESS ("/dev/net/tun", R_OK))
{
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
@@ -449,6 +528,7 @@
"WARNING: System unable to run test, skipping.\n");
return 0;
}
+
if ( (GNUNET_YES !=
GNUNET_OS_check_helper_binary ("gnunet-helper-vpn")) ||
(GNUNET_YES !=
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r22408 - gnunet/src/pt,
gnunet <=