9155c804f707c1995e2f4cc41ab4ae2fcb2bce33
[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/Box.h>
20 #include <org/xwt/util/Semaphore.h>
21 #include <org/xwt/Platform.h>
22 #include <java/lang/Long.h>
23 #include <java/util/Hashtable.h>
24 #include <org/xwt/util/Log.h>
25 #include <org/xwt/plat/POSIX.h>
26 #include <java/lang/System.h>
27 #include <java/io/PrintStream.h>
28
29 jstring org::xwt::plat::POSIX::_getEnv(jstring key) {
30     int len = JvGetStringUTFLength(key);
31     char buf[len + 1];
32     JvGetStringUTFRegion(key, 0, len, buf);
33     buf[len] = '\0';
34     char* envstr = getenv(buf);
35     return envstr == NULL ? NULL : JvNewStringLatin1(envstr);
36 }
37
38 void org::xwt::plat::POSIX::spawnChildProcess(JArray<jstring>* cmd) {
39     jstring* cmdstrings = elements(cmd);
40     char* cmd2[cmd->length + 1];
41     cmd2[cmd->length] = NULL;
42     for(int i=0; i<cmd->length; i++) {
43         cmd2[i] = (char*)malloc(JvGetStringUTFLength(cmdstrings[i]));
44         JvGetStringUTFRegion(cmdstrings[i], 0, JvGetStringUTFLength(cmdstrings[i]), cmd2[i]);
45     }
46
47     if (!fork()) {
48         signal(SIGHUP, SIG_IGN);
49         signal(SIGQUIT, SIG_IGN);
50         signal(SIGINT, SIG_IGN);
51         signal(SIGTERM, SIG_IGN);
52
53         // ignore SIGPIPE in case we were launched from a browser and the browser closed
54         signal(SIGPIPE, SIG_IGN);
55
56         execvp(cmd2[0], cmd2);
57     }
58 }
59