Differences From Artifact [a1d37f278e]:
- File
src/OFProcess.m
— part of check-in
[02ab9aa8a9]
at
2011-10-05 23:26:08
on branch trunk
— Add OFProcess.
Win32 implementation following later. (user: js, size: 2901) [annotate] [blame] [check-ins using]
To Artifact [12b36ce01a]:
- File src/OFProcess.m — part of check-in [20ba008347] at 2011-10-06 00:10:17 on branch trunk — OFProcess: Make sure that we don't leave zombies behind. (user: js, size: 2915) [annotate] [blame] [check-ins using]
1 2 3 4 5 6 7 8 9 10 11 12 | #include "config.h" #include <alloca.h> #include <unistd.h> #import "OFProcess.h" #import "OFString.h" #import "OFArray.h" #import "OFInitializationFailedException.h" #import "OFReadFailedException.h" #import "OFWriteFailedException.h" | > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | #include "config.h" #include <alloca.h> #include <unistd.h> #include <sys/wait.h> #import "OFProcess.h" #import "OFString.h" #import "OFArray.h" #import "OFInitializationFailedException.h" #import "OFReadFailedException.h" #import "OFWriteFailedException.h" |
︙ | ︙ | |||
28 29 30 31 32 33 34 | self = [super init]; @try { if (pipe(readPipe) != 0 || pipe(writePipe) != 0) @throw [OFInitializationFailedException exceptionWithClass: isa]; | | | 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | self = [super init]; @try { if (pipe(readPipe) != 0 || pipe(writePipe) != 0) @throw [OFInitializationFailedException exceptionWithClass: isa]; switch ((pid = fork())) { case 0:; OFString **cArray = [arguments cArray]; size_t i, count = [arguments count]; char **argv = alloca((count + 2) * sizeof(char*)); argv[0] = (char*)[programName cStringWithEncoding: OF_STRING_ENCODING_NATIVE]; |
︙ | ︙ | |||
106 107 108 109 110 111 112 | @throw [OFWriteFailedException exceptionWithClass: isa stream: self requestedLength: length]; } - (void)dealloc { | < | < < > > > > | 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | @throw [OFWriteFailedException exceptionWithClass: isa stream: self requestedLength: length]; } - (void)dealloc { [self close]; [super dealloc]; } /* * FIXME: Add -[fileDescriptor]. The problem is that we have two FDs, which is * not yet supported by OFStreamObserver. This has to be split into one * FD for reading and one for writing. */ - (void)close { if (readPipe[0] != -1) close(readPipe[0]); if (writePipe[1] != -1) close(writePipe[1]); if (pid != -1) waitpid(pid, &status, WNOHANG); pid = -1; readPipe[0] = -1; writePipe[1] = -1; } @end |