summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarius Halden <marius.h@lden.org>2016-11-04 14:02:37 +0100
committerMarius Halden <marius.h@lden.org>2016-11-04 14:02:37 +0100
commit40cf0121601f69a4f5c491ab1e2fd54bd7fe4b75 (patch)
tree0119b3b7b5c55aa81dbbed459ebc317a4d3c41cc
parentd7b994eccb760a68315fc48b1600f9164282a127 (diff)
downloadrunq-40cf0121601f69a4f5c491ab1e2fd54bd7fe4b75.tar.gz
runq-40cf0121601f69a4f5c491ab1e2fd54bd7fe4b75.tar.bz2
runq-40cf0121601f69a4f5c491ab1e2fd54bd7fe4b75.tar.xz
Initial for executing filedescriptor
-rw-r--r--.gitignore1
-rw-r--r--Makefile21
-rw-r--r--batchd.c2
-rw-r--r--newbatch.c13
-rw-r--r--runfd.c15
5 files changed, 50 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore
index 113002d..d48beeb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,3 +7,4 @@ done
new
tmp
failed
+runfd
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..ffb3f6b
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,21 @@
+CC = cc
+CFLAGS = -O2 -Wall -Wextra -Werror -pedantic -std=c99
+
+all: newbatch createspool batchd
+
+newbatch: newbatch.c
+ $(CC) -o newbatch $(CFLAGS) newbatch.c
+
+createspool: createspool.c
+ $(CC) -o createspool $(CFLAGS) createspool.c
+
+batchd: batchd.c
+ $(CC) -o batchd $(CFLAGS) batchd.c
+
+runfd: runfd.c
+ $(CC) -o runfd $(CFLAGS) runfd.c
+
+.PHONY: clean
+
+clean:
+ rm -f newbatch createspool batchd
diff --git a/batchd.c b/batchd.c
index c2cadc8..75930b7 100644
--- a/batchd.c
+++ b/batchd.c
@@ -33,7 +33,7 @@ run_job(char *queuedir, int fd)
return -1;
case 0:
asprintf(&run, "%s/run", queuedir);
- dup2(fd, STDIN_FILENO);
+ dup2(fd, 3);
close(fd);
execl(run, "run", (char*)NULL);
perror("execle()");
diff --git a/newbatch.c b/newbatch.c
index 6b27234..0bac7ee 100644
--- a/newbatch.c
+++ b/newbatch.c
@@ -18,6 +18,7 @@ main(int argc, char **argv)
char *timestr = NULL, *queuedir = NULL, *tmpfile = NULL, *newfile = NULL;
char buf[1024], *tmp;
int fd, l, m;
+ int perm = 0640;
mypid = getpid();
gettimeofday(&tv, NULL);
@@ -35,12 +36,19 @@ main(int argc, char **argv)
free(timestr);
free(queuedir);
- fd = open(tmpfile, O_WRONLY | O_CREAT | O_EXCL, 0660);
+ if (getenv("NEWBATCH_EXEC") != NULL) {
+ perm = 0750;
+ }
+
+ fd = open(tmpfile, O_WRONLY | O_CREAT | O_EXCL, perm);
if (fd == -1)
err(1, "open()");
while ((l = read(STDIN_FILENO, buf, sizeof(buf))) != 0) {
if (l == -1) {
+ if (errno == EINTR)
+ continue;
+
unlink(tmpfile);
err(1, NULL);
}
@@ -49,6 +57,9 @@ main(int argc, char **argv)
while (l > 0) {
m = write(fd, tmp, l);
if (m == -1) {
+ if (errno == EINTR)
+ continue;
+
unlink(tmpfile);
err(1, NULL);
}
diff --git a/runfd.c b/runfd.c
new file mode 100644
index 0000000..6a92bb6
--- /dev/null
+++ b/runfd.c
@@ -0,0 +1,15 @@
+#include <stdio.h>
+#include <err.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+char *args[] = { "batchrun", NULL };
+
+int
+main()
+{
+ //fcntl(3, F_SETFD, FD_CLOEXEC);
+
+ fexecve(3, args, NULL);
+ err(1, "fexecve()");
+}