diff options
author | StalkR <stalkr@stalkr.net> | 2016-07-15 10:48:35 +0200 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2016-07-15 16:19:04 -0400 |
commit | dee9b5042951795cd7abc415f1c4f4becc6363d3 (patch) | |
tree | 4f754137f87d9f22e86c2c8c97b6f5b86b5607c7 | |
parent | f891e8d7aafa336b89d0252e31bf52e1510de6b8 (diff) | |
download | moreutils-dee9b5042951795cd7abc415f1c4f4becc6363d3.tar.gz |
cygwin support
-rw-r--r-- | Makefile | 7 | ||||
-rw-r--r-- | parallel.c | 82 |
2 files changed, 88 insertions, 1 deletions
@@ -4,7 +4,12 @@ MANS=sponge.1 vidir.1 vipe.1 isutf8.1 ts.1 combine.1 ifdata.1 ifne.1 pee.1 zrun. CFLAGS?=-O2 -g -Wall INSTALL_BIN?=install -s PREFIX?=/usr -DOCBOOKXSL?=/usr/share/xml/docbook/stylesheet/docbook-xsl + +ifeq ($(shell uname -o),Cygwin) + DOCBOOKXSL?=/usr/share/sgml/docbook/xsl-stylesheets +else + DOCBOOKXSL?=/usr/share/xml/docbook/stylesheet/docbook-xsl +endif DOCBOOK2XMAN=xsltproc --param man.authors.section.enabled 0 $(DOCBOOKXSL)/manpages/docbook.xsl @@ -27,6 +27,7 @@ #include <time.h> #include <stdlib.h> #include <errno.h> +#include <fcntl.h> #include <sys/select.h> #include <sys/types.h> #include <sys/wait.h> @@ -113,6 +114,60 @@ void exec_child(char **command, char **arguments, int replace_cb, int nargs, return; } +#if defined(__CYGWIN__) +typedef enum { + P_ALL, + P_PID, + P_PGID +} idtype_t; +int waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options) { + pid_t pid; + switch (idtype) { + case P_PID: + pid = id; + break; + case P_PGID: + pid = -id; + break; + case P_ALL: + pid = -1; + break; + default: + errno = EINVAL; + return -1; + } + int status; + pid = waitpid(pid, &status, WEXITED | options); + if (pid == -1) { + return -1; + } + infop->si_pid = pid; + infop->si_signo = SIGCHLD; + if (WIFEXITED(status)) { + infop->si_code = CLD_EXITED; + infop->si_status = WEXITSTATUS(status); + } + else if (WIFSIGNALED(status)) { + infop->si_code = CLD_KILLED; + infop->si_status = WTERMSIG(status); +#ifdef WCOREDUMP + if (WCOREDUMP(status)) { + infop->si_code = CLD_DUMPED; + } +#endif + } + else if (WIFSTOPPED(status)) { + infop->si_code = CLD_STOPPED; + infop->si_status = WSTOPSIG(status); + } + else if (WIFCONTINUED(status)) { + infop->si_code = CLD_CONTINUED; + infop->si_status = SIGCONT; + } + return 0; +} +#endif + int wait_for_child(int options) { id_t id_ignored = 0; siginfo_t infop; @@ -186,6 +241,33 @@ pid_t create_pipe_child(int *fd, int orig_fd) return pipe_child(fds[0], orig_fd); } +#if defined(__CYGWIN__) +int getloadavg(double loadavg[], int nelem) { + int fd, n, elem; + char buf[128]; + char const* p = buf; + fd = open("/proc/loadavg", O_RDONLY); + if (fd == -1) { + return -1; + } + n = read(fd, buf, sizeof(buf)-1); + if (close(fd) == -1 || n == -1) { + return -1; + } + buf[n] = '\0'; + for (elem = 0; elem < nelem; elem++) { + char* end; + double d = strtod(p, &end); + if (p == end) { + break; + } + loadavg[elem] = d; + p = end; + } + return elem == 0 ? -1 : elem; +} +#endif + int main(int argc, char **argv) { int maxjobs = -1; int curjobs = 0; |