diff options
author | Marius Halden <marius.h@lden.org> | 2016-11-04 14:02:37 +0100 |
---|---|---|
committer | Marius Halden <marius.h@lden.org> | 2016-11-04 14:02:37 +0100 |
commit | 40cf0121601f69a4f5c491ab1e2fd54bd7fe4b75 (patch) | |
tree | 0119b3b7b5c55aa81dbbed459ebc317a4d3c41cc | |
parent | d7b994eccb760a68315fc48b1600f9164282a127 (diff) | |
download | runq-40cf0121601f69a4f5c491ab1e2fd54bd7fe4b75.tar.gz runq-40cf0121601f69a4f5c491ab1e2fd54bd7fe4b75.tar.bz2 runq-40cf0121601f69a4f5c491ab1e2fd54bd7fe4b75.tar.xz |
Initial for executing filedescriptor
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile | 21 | ||||
-rw-r--r-- | batchd.c | 2 | ||||
-rw-r--r-- | newbatch.c | 13 | ||||
-rw-r--r-- | runfd.c | 15 |
5 files changed, 50 insertions, 2 deletions
@@ -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 @@ -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()"); @@ -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); } @@ -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()"); +} |