socsvn commit: r289927 - soc2015/roam/ayiya_listen
roam at FreeBSD.org
roam at FreeBSD.org
Wed Aug 19 15:56:24 UTC 2015
Author: roam
Date: Wed Aug 19 15:56:23 2015
New Revision: 289927
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=289927
Log:
ayiya_listen: autodetect the path to ayiya_resp
Modified:
soc2015/roam/ayiya_listen/main.c
Modified: soc2015/roam/ayiya_listen/main.c
==============================================================================
--- soc2015/roam/ayiya_listen/main.c Wed Aug 19 15:56:16 2015 (r289926)
+++ soc2015/roam/ayiya_listen/main.c Wed Aug 19 15:56:23 2015 (r289927)
@@ -28,6 +28,7 @@
#include <sys/types.h>
#include <sys/socket.h>
+#include <sys/stat.h>
#include <sys/wait.h>
#include <netinet/in.h>
@@ -162,9 +163,6 @@
} else if (tunnelsfile == NULL) {
warnx("No tunnels file (-t) specified");
usage(1);
- } else if (resppath == NULL) {
- warnx("No ayiya_resp path (-r) specified");
- usage(1);
}
argc -= optind;
@@ -174,6 +172,68 @@
usage(1);
}
+ if (resppath == NULL) {
+ debug("Trying to autodetect the ayiya_resp location\n");
+ int makev[2];
+ if (pipe(makev) == -1)
+ err(1, "pipe() failed");
+ const pid_t makepid = fork();
+ if (makepid == -1) {
+ err(1, "fork() for make -V .OBJDIR failed");
+ } else if (makepid == 0) {
+ if (chdir("ayiya_resp") == -1) {
+ if (errno != ENOENT)
+ err(1, "chdir('ayiya_resp') failed");
+ if (chdir("../ayiya_resp") == -1)
+ err(1, "chdir('../ayiya_resp') failed");
+ }
+
+ close(makev[0]);
+ if (makev[1] != 1) {
+ close(1);
+ if (dup2(makev[1], 1) == -1)
+ err(1, "dup2() failed");
+ }
+ execlp("make", "make", "-V", ".OBJDIR", NULL);
+ err(1, "exec('make') failed");
+ }
+ debug("makepid is %jd\n", (intmax_t)makepid);
+ close(makev[1]);
+ FILE * const fp = fdopen(makev[0], "r");
+ if (fp == NULL)
+ err(1, "fdopen(%d) for make -V .OBJDIR failed",
+ makev[0]);
+ char *line = NULL;
+ size_t sz = 0;
+ ssize_t len = getline(&line, &sz, fp);
+ if (len < 1) {
+ if (feof(fp))
+ errx(1, "make -V .OBJDIR produced no output");
+ else
+ err(1, "getline() for make -V .OBJDIR failed");
+ }
+ fclose(fp);
+ int stat;
+ const pid_t wpid = waitpid(makepid, &stat, 0);
+ check_wait_result(wpid, stat, makepid, "make -V .OBJDIR");
+
+ while (len > 0 && (line[len - 1] == '\r' || line[len - 1] == '\n'))
+ line[--len] = '\0';
+ debug("make -V .OBJDIR for ayiya_resp returned '%s'\n", line);
+ char *path;
+ asprintf(&path, "%s/%s", line, "ayiya_resp");
+ if (path == NULL)
+ err(1, "Could not build the ayiya_resp path");
+ resppath = path;
+ debug("Autodetected ayiya_resp path '%s'\n", resppath);
+ }
+ debug("Checking the ayiya_resp path '%s' for validity\n", resppath);
+ struct stat st;
+ if (stat(resppath, &st) == -1)
+ err(1, "Invalid ayiya_resp path '%s'", resppath);
+ else if (!S_ISREG(st.st_mode) || ((st.st_mode & 0111) == 0))
+ errx(1, "Non-executable file '%s'", resppath);
+
parse_tunnels(tunnelsfile);
signal(SIGPIPE, SIG_IGN);
More information about the svn-soc-all
mailing list