propose-patch
[org.ibex.core.git] / src / org / xwt / plat / POSIX.cc
1 // Copyright 2002 Adam Megacz, see the COPYING file for licensing [LGPL]
2 // see below for copyright information on the second portion of this file
3
4 #include "GCJ.cc"
5
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <unistd.h>
9 #include <sys/ipc.h>
10 #include <sys/shm.h>
11 #include <sys/types.h>
12 #include <signal.h>
13 #include <java/lang/String.h>
14
15 // FIXME: we don't need all these
16 #include <java/lang/String.h>
17 #include <org/xwt/Surface.h>
18 #include <org/xwt/Picture.h>
19 #include <org/xwt/js/JS.h>
20 #include <org/xwt/Box.h>
21 #include <org/xwt/util/Semaphore.h>
22 #include <org/xwt/Platform.h>
23 #include <java/lang/Long.h>
24 #include <java/util/Hashtable.h>
25 #include <org/xwt/util/Log.h>
26 #include <org/xwt/plat/POSIX.h>
27 #include <java/lang/System.h>
28 #include <java/io/PrintStream.h>
29
30 jstring org::xwt::plat::POSIX::_getEnv(jstring key) {
31     int len = JvGetStringUTFLength(key);
32     char buf[len + 1];
33     JvGetStringUTFRegion(key, 0, len, buf);
34     buf[len] = '\0';
35     char* envstr = getenv(buf);
36     return envstr == NULL ? NULL : JvNewStringLatin1(envstr);
37 }
38
39 void org::xwt::plat::POSIX::spawnChildProcess(JArray<jstring>* cmd) {
40     jstring* cmdstrings = elements(cmd);
41     char* cmd2[cmd->length + 1];
42     cmd2[cmd->length] = NULL;
43     for(int i=0; i<cmd->length; i++) {
44         cmd2[i] = (char*)malloc(JvGetStringUTFLength(cmdstrings[i]));
45         JvGetStringUTFRegion(cmdstrings[i], 0, JvGetStringUTFLength(cmdstrings[i]), cmd2[i]);
46     }
47
48     if (!fork()) {
49         signal(SIGHUP, SIG_IGN);
50         signal(SIGQUIT, SIG_IGN);
51         signal(SIGINT, SIG_IGN);
52         signal(SIGTERM, SIG_IGN);
53
54         // ignore SIGPIPE in case we were launched from a browser and the browser closed
55         signal(SIGPIPE, SIG_IGN);
56
57         execvp(cmd2[0], cmd2);
58     }
59 }
60