|
@@ -52,22 +52,16 @@ static inline int create_process_handle (PAL_HANDLE * parent,
|
|
|
PAL_HANDLE * child)
|
|
|
{
|
|
|
PAL_HANDLE phdl = NULL, chdl = NULL;
|
|
|
- int fds[6] = { -1, -1, -1, -1, -1, -1 };
|
|
|
+ int fds[4] = { -1, -1, -1, -1 };
|
|
|
int socktype = SOCK_STREAM | SOCK_CLOEXEC;
|
|
|
int ret;
|
|
|
|
|
|
if (IS_ERR((ret = INLINE_SYSCALL(socketpair, 4, AF_UNIX, socktype, 0, &fds[0]))) ||
|
|
|
- IS_ERR((ret = INLINE_SYSCALL(socketpair, 4, AF_UNIX, socktype, 0, &fds[2]))) ||
|
|
|
- IS_ERR((ret = INLINE_SYSCALL(socketpair, 4, AF_UNIX, socktype, 0, &fds[4])))) {
|
|
|
+ IS_ERR((ret = INLINE_SYSCALL(socketpair, 4, AF_UNIX, socktype, 0, &fds[2])))) {
|
|
|
ret = -PAL_ERROR_DENIED;
|
|
|
goto out;
|
|
|
}
|
|
|
|
|
|
- int proc_fds[2][3] = {
|
|
|
- { fds[0], fds[3], fds[4] },
|
|
|
- { fds[2], fds[1], fds[5] },
|
|
|
- };
|
|
|
-
|
|
|
phdl = malloc(HANDLE_SIZE(process));
|
|
|
if (!phdl) {
|
|
|
ret = -PAL_ERROR_NOMEM;
|
|
@@ -75,10 +69,9 @@ static inline int create_process_handle (PAL_HANDLE * parent,
|
|
|
}
|
|
|
|
|
|
SET_HANDLE_TYPE(phdl, process);
|
|
|
- phdl->hdr.flags |= RFD(0)|WFD(1)|RFD(2)|WFD(2)|WRITABLE(1)|WRITABLE(2);
|
|
|
- phdl->process.stream_in = proc_fds[0][0];
|
|
|
- phdl->process.stream_out = proc_fds[0][1];
|
|
|
- phdl->process.cargo = proc_fds[0][2];
|
|
|
+ phdl->hdr.flags |= RFD(0)|WFD(0)|RFD(1)|WFD(1)|WRITABLE(0)|WRITABLE(1);
|
|
|
+ phdl->process.stream = fds[0];
|
|
|
+ phdl->process.cargo = fds[2];
|
|
|
phdl->process.pid = bsd_state.pid;
|
|
|
phdl->process.nonblocking = PAL_FALSE;
|
|
|
|
|
@@ -89,10 +82,9 @@ static inline int create_process_handle (PAL_HANDLE * parent,
|
|
|
}
|
|
|
|
|
|
SET_HANDLE_TYPE(chdl, process);
|
|
|
- chdl->hdr.flags |= RFD(0)|WFD(1)|RFD(2)|WFD(2)|WRITABLE(1)|WRITABLE(2);
|
|
|
- chdl->process.stream_in = proc_fds[1][0];
|
|
|
- chdl->process.stream_out = proc_fds[1][1];
|
|
|
- chdl->process.cargo = proc_fds[1][2];
|
|
|
+ chdl->hdr.flags |= RFD(0)|WFD(0)|RFD(1)|WFD(1)|WRITABLE(0)|WRITABLE(1);
|
|
|
+ chdl->process.stream = fds[1];
|
|
|
+ chdl->process.cargo = fds[3];
|
|
|
chdl->process.pid = 0; /* unknown yet */
|
|
|
chdl->process.nonblocking = PAL_FALSE;
|
|
|
|
|
@@ -105,7 +97,7 @@ out:
|
|
|
_DkObjectClose(phdl);
|
|
|
if (chdl)
|
|
|
_DkObjectClose(chdl);
|
|
|
- for (int i = 0 ; i < 6 ; i++)
|
|
|
+ for (int i = 0; i < 4; i++)
|
|
|
if (fds[i] != -1)
|
|
|
INLINE_SYSCALL(close, 1, fds[i]);
|
|
|
}
|
|
@@ -133,8 +125,7 @@ static int child_process (void * param)
|
|
|
struct proc_param * proc_param = param;
|
|
|
int ret;
|
|
|
|
|
|
- ret = INLINE_SYSCALL(dup2, 2, proc_param->parent->process.stream_in,
|
|
|
- PROC_INIT_FD);
|
|
|
+ ret = INLINE_SYSCALL(dup2, 2, proc_param->parent->process.stream, PROC_INIT_FD);
|
|
|
if (IS_ERR(ret))
|
|
|
goto failed;
|
|
|
|
|
@@ -272,7 +263,7 @@ int _DkProcessCreate (PAL_HANDLE * handle, const char * uri, const char ** args)
|
|
|
/* step 4: send parameters over the process handle */
|
|
|
|
|
|
ret = INLINE_SYSCALL(write, 3,
|
|
|
- child_handle->process.stream_out,
|
|
|
+ child_handle->process.stream,
|
|
|
proc_args,
|
|
|
sizeof(struct proc_args) + datasz);
|
|
|
|
|
@@ -388,8 +379,7 @@ noreturn void _DkProcessExit (int exitcode)
|
|
|
static int proc_read (PAL_HANDLE handle, int offset, int count,
|
|
|
void * buffer)
|
|
|
{
|
|
|
- int bytes = INLINE_SYSCALL(read, 3, handle->process.stream_in, buffer,
|
|
|
- count);
|
|
|
+ int bytes = INLINE_SYSCALL(read, 3, handle->process.stream, buffer, count);
|
|
|
|
|
|
if (IS_ERR(bytes))
|
|
|
switch(ERRNO(bytes)) {
|
|
@@ -407,13 +397,12 @@ static int proc_read (PAL_HANDLE handle, int offset, int count,
|
|
|
static int proc_write (PAL_HANDLE handle, int offset, int count,
|
|
|
const void * buffer)
|
|
|
{
|
|
|
- int bytes = INLINE_SYSCALL(write, 3, handle->process.stream_out, buffer,
|
|
|
- count);
|
|
|
+ int bytes = INLINE_SYSCALL(write, 3, handle->process.stream, buffer, count);
|
|
|
|
|
|
if (IS_ERR(bytes))
|
|
|
switch(ERRNO(bytes)) {
|
|
|
case EWOULDBLOCK:
|
|
|
- handle->hdr.flags &= ~WRITABLE(1);
|
|
|
+ handle->hdr.flags &= ~WRITABLE(0);
|
|
|
return-PAL_ERROR_TRYAGAIN;
|
|
|
case EINTR:
|
|
|
return -PAL_ERROR_INTERRUPTED;
|
|
@@ -422,23 +411,18 @@ static int proc_write (PAL_HANDLE handle, int offset, int count,
|
|
|
}
|
|
|
|
|
|
if (bytes == count)
|
|
|
- handle->hdr.flags |= WRITABLE(1);
|
|
|
+ handle->hdr.flags |= WRITABLE(0);
|
|
|
else
|
|
|
- handle->hdr.flags &= ~WRITABLE(1);
|
|
|
+ handle->hdr.flags &= ~WRITABLE(0);
|
|
|
|
|
|
return bytes;
|
|
|
}
|
|
|
|
|
|
static int proc_close (PAL_HANDLE handle)
|
|
|
{
|
|
|
- if (handle->process.stream_in != PAL_IDX_POISON) {
|
|
|
- INLINE_SYSCALL(close, 1, handle->process.stream_in);
|
|
|
- handle->process.stream_in = PAL_IDX_POISON;
|
|
|
- }
|
|
|
-
|
|
|
- if (handle->process.stream_out != PAL_IDX_POISON) {
|
|
|
- INLINE_SYSCALL(close, 1, handle->process.stream_out);
|
|
|
- handle->process.stream_out = PAL_IDX_POISON;
|
|
|
+ if (handle->process.stream != PAL_IDX_POISON) {
|
|
|
+ INLINE_SYSCALL(close, 1, handle->process.stream);
|
|
|
+ handle->process.stream = PAL_IDX_POISON;
|
|
|
}
|
|
|
|
|
|
if (handle->process.cargo != PAL_IDX_POISON) {
|
|
@@ -466,17 +450,8 @@ static int proc_delete (PAL_HANDLE handle, int access)
|
|
|
return -PAL_ERROR_INVAL;
|
|
|
}
|
|
|
|
|
|
- if (access != PAL_DELETE_WR &&
|
|
|
- handle->process.stream_in != PAL_IDX_POISON) {
|
|
|
- INLINE_SYSCALL(close, 1, handle->process.stream_in);
|
|
|
- handle->process.stream_in = PAL_IDX_POISON;
|
|
|
- }
|
|
|
-
|
|
|
- if (access != PAL_DELETE_RD &&
|
|
|
- handle->process.stream_out != PAL_IDX_POISON) {
|
|
|
- INLINE_SYSCALL(close, 1, handle->process.stream_out);
|
|
|
- handle->process.stream_out = PAL_IDX_POISON;
|
|
|
- }
|
|
|
+ if (handle->process.stream != PAL_IDX_POISON)
|
|
|
+ INLINE_SYSCALL(shutdown, 2, handle->process.stream, shutdown);
|
|
|
|
|
|
if (handle->process.cargo != PAL_IDX_POISON)
|
|
|
INLINE_SYSCALL(shutdown, 2, handle->process.cargo, shutdown);
|
|
@@ -488,18 +463,18 @@ static int proc_attrquerybyhdl (PAL_HANDLE handle, PAL_STREAM_ATTR * attr)
|
|
|
{
|
|
|
int ret, val;
|
|
|
|
|
|
- if (handle->process.stream_in == PAL_IDX_POISON)
|
|
|
+ if (handle->process.stream == PAL_IDX_POISON)
|
|
|
return -PAL_ERROR_BADHANDLE;
|
|
|
|
|
|
- ret = INLINE_SYSCALL(ioctl, 3, handle->process.stream_in, FIONREAD, &val);
|
|
|
+ ret = INLINE_SYSCALL(ioctl, 3, handle->process.stream, FIONREAD, &val);
|
|
|
if (IS_ERR(ret))
|
|
|
return unix_to_pal_error(ERRNO(ret));
|
|
|
|
|
|
attr->handle_type = pal_type_process;
|
|
|
attr->nonblocking = handle->process.nonblocking;
|
|
|
- attr->disconnected = handle->hdr.flags & (ERROR(0)|ERROR(1));
|
|
|
+ attr->disconnected = handle->hdr.flags & ERROR(0);
|
|
|
attr->readable = !!val;
|
|
|
- attr->writable = handle->hdr.flags & WRITABLE(1);
|
|
|
+ attr->writable = handle->hdr.flags & WRITABLE(0);
|
|
|
attr->runnable = PAL_FALSE;
|
|
|
attr->pending_size = val;
|
|
|
|
|
@@ -508,12 +483,12 @@ static int proc_attrquerybyhdl (PAL_HANDLE handle, PAL_STREAM_ATTR * attr)
|
|
|
|
|
|
static int proc_attrsetbyhdl (PAL_HANDLE handle, PAL_STREAM_ATTR * attr)
|
|
|
{
|
|
|
- if (handle->process.stream_in == PAL_IDX_POISON)
|
|
|
+ if (handle->process.stream == PAL_IDX_POISON)
|
|
|
return -PAL_ERROR_BADHANDLE;
|
|
|
|
|
|
int ret;
|
|
|
if (attr->nonblocking != handle->process.nonblocking) {
|
|
|
- ret = INLINE_SYSCALL(fcntl, 3, handle->process.stream_in, F_SETFL,
|
|
|
+ ret = INLINE_SYSCALL(fcntl, 3, handle->process.stream, F_SETFL,
|
|
|
handle->process.nonblocking ? O_NONBLOCK : 0);
|
|
|
|
|
|
if (IS_ERR(ret))
|