1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <kernel/OS.h>
28 int main(int argc, char *argv[]) {
29 /* we expect the following...
32 * argv[1] = directory to run in...
33 * argv[2] = progname to execute
34 * rest of arguments to be passed to program
36 char *progname = argv[2];
37 char *directory = argv[1];
44 newargs = (char**)malloc(sizeof(char*) * (argc - 1));
46 buffer = (void*)malloc(sizeof(struct pipefd));
47 /* this will block until we get the data */
48 receive_data(&sender, buffer, sizeof(struct pipefd));
49 pfd = (struct pipefd*)buffer;
51 if (pfd->in > STDERR_FILENO) {
52 if (dup2(pfd->in, STDIN_FILENO) != STDIN_FILENO) return (-1);
55 if (pfd->out > STDERR_FILENO) {
56 if (dup2(pfd->out, STDOUT_FILENO) != STDOUT_FILENO) return (-1);
59 if (pfd->err > STDERR_FILENO) {
60 if (dup2(pfd->err, STDERR_FILENO) != STDERR_FILENO) return (-1);
64 for (i=3;i<=argc;i++){
65 newargs[i-3] = argv[i];
68 /* tell the caller we're OK to start */
69 send_data(sender,1,NULL,0);
71 if (directory != NULL)
73 execve (progname, newargs, environ);