#include <stdio.h>
#include <errno.h>
#include <string.h>
+#include "pipe.h"
static int _handle_msg(struct cxmsg *msg)
{
break;
case CXIO_PIPE:
+ sys_pipe(msg->cm_src, (struct cxio_pipe*)msg->cm_data);
memset(str, 0, sizeof(str));
len = snprintf(str, sizeof(str), "CXIO_PIPE from %u\n", msg->cm_src);
debug(str, len);
#include <stdlib.h>
#include <string.h>
#include <errno.h>
+#include <stdio.h>
+#include <crxstd.h>
#include "file.h"
#include "proc.h"
#include "filedesc.h"
static ssize_t _pipe_read(struct file *file, void *dst, const size_t dst_size)
{
+ char buf[128];
+ int len;
+
+ len = snprintf(buf, sizeof(buf), "%s(%p, %p, %lu)\n", __func__, file, dst, dst_size);
+ debug(buf, len);
+
return(-ENOSYS);
}
static ssize_t _pipe_write(struct file *file, const void *src, const size_t src_size)
{
+ char buf[128];
+ int len;
+
+ len = snprintf(buf, sizeof(buf), "%s(%p, %p, %lu)\n", __func__, file, src, src_size);
+ debug(buf, len);
+
return(-ENOSYS);
}
return(ret_val);
}
-void cxio_pipe(pid_t pid, struct cxio_pipe *req)
+void sys_pipe(pid_t pid, struct cxio_pipe *req)
{
struct proc *proc;
struct file *file;
int err;
int i;
+ char buf[128];
+ int len;
+
file = NULL;
memset(&fd, 0, sizeof(fd));
memset(&fildes, 0, sizeof(fildes));
+ len = snprintf(buf, sizeof(buf), "%s(%d, %p)\n", __func__, pid, req);
+ debug(buf, len);
+
err = proc_lookup(pid, &proc);
if(err < 0) {
fd_set_file(fildes[i], file);
fd[i] = proc_add_fd(proc, fildes[i]);
+
+ len = snprintf(buf, sizeof(buf), "%s: pipe[%d]=%d fd=%p file=%p\n", __func__, i, fd[i], fildes[i], file);
+ debug(buf, len);
}
cleanup:
#include "filedesc.h"
#define PROC_INITFDS 8
+#define PROC_MAXFDS 128
struct filedesc;
new = malloc(sizeof(*new));
if(new) {
- new->p_pid = pid;
-
memset(new, 0, sizeof(*new));
+ new->p_pid = pid;
+ new->p_maxfds = PROC_MAXFDS;
+
ret_val = cx_array_new(PROC_INITFDS, &new->p_fds);
if(!ret_val) {
if(proc && fd) {
ret_val = -EMFILE;
- if(proc->p_openfds <= proc->p_maxfds) {
+ if(proc->p_openfds < proc->p_maxfds) {
ret_val = cx_array_set(proc->p_fds, proc->p_nextfd, fd);
if(!ret_val) {
fd_ref(fd);
+ ret_val = proc->p_nextfd;
+
proc->p_nextfd++;
proc->p_openfds++;
}