2 meinOS - A unix-like x86 microkernel operating system
3 Copyright (C) 2008 Janosch Gräf <janosch.graef@gmx.net>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include <sys/types.h>
26 * Creates a new process from executable file
27 * @param path Path to executable
28 * @param argv Argument vector
29 * @param _stdin Reference for filehandle for stdin of new process
30 * @param _stdout Reference for filehandle for stdout of new process
31 * @param _stderr Reference for filehandle for stderr of new process
32 * @return PID of new process
35 pid_t
execute(const char *path
,char *argv
[],const char *_stdin
,const char *_stdout
,const char *_stderr
) {
36 size_t shmsize
= sizeof(struct process_data
);
38 struct process_data
*data
;
42 for (i
=0;argv
[i
];i
++) shmsize
+= strlen(argv
[i
])+1;
44 if (_stdin
!=NULL
) shmsize
+= strlen(_stdin
);
45 if (_stdout
!=NULL
) shmsize
+= strlen(_stdout
);
46 if (_stderr
!=NULL
) shmsize
+= strlen(_stderr
);
47 shmid
= shmget(IPC_PRIVATE
,shmsize
,0);
50 data
= shmat(shmid
,NULL
,0);
55 for (i
=0;argv
[i
];i
++) {
56 strcpy(data
->cmdline
+j
,argv
[i
]);
57 j
+= strlen(data
->cmdline
+j
)+1;
63 data
->has_stdin
= (_stdin
!=NULL
);
65 strcpy(data
->stdio
+j
,_stdin
);
66 j
+= strlen(data
->stdio
+j
)+1;
69 data
->has_stdout
= (_stdout
!=NULL
);
71 strcpy(data
->stdio
+j
,_stdout
);
72 j
+= strlen(data
->stdio
+j
)+1;
75 data
->has_stderr
= (_stderr
!=NULL
);
77 strcpy(data
->stdio
+j
,_stderr
);
78 j
+= strlen(data
->stdio
+j
)+1;
83 return rpc_call("proc_execute",0,path
,shmid
);