aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/c/exec.c
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/c/exec.c')
-rw-r--r--app/src/main/c/exec.c36
1 files changed, 18 insertions, 18 deletions
diff --git a/app/src/main/c/exec.c b/app/src/main/c/exec.c
index fdaec0f..a9871a5 100644
--- a/app/src/main/c/exec.c
+++ b/app/src/main/c/exec.c
@@ -3,32 +3,32 @@
3#include <stdlib.h> 3#include <stdlib.h>
4 4
5static inline const char **to_string_array(JNIEnv *env, jobjectArray ja) { 5static inline const char **to_string_array(JNIEnv *env, jobjectArray ja) {
6 const int len = (*env)->GetArrayLength(env, ja); 6 const int len = (*env)->GetArrayLength(env, ja);
7 const char **ca = calloc((size_t) len + 1, sizeof(char *)); 7 const char **ca = calloc((size_t) len + 1, sizeof(char *));
8 8
9 for (int i = 0; i < len; ++i) { 9 for (int i = 0; i < len; ++i) {
10 jstring jstr = (jstring) (*env)->GetObjectArrayElement(env, ja, i); 10 jstring jstr = (jstring) (*env)->GetObjectArrayElement(env, ja, i);
11 ca[i] = (*env)->GetStringUTFChars(env, jstr, NULL); 11 ca[i] = (*env)->GetStringUTFChars(env, jstr, NULL);
12 } 12 }
13 13
14 ca[len] = NULL; 14 ca[len] = NULL;
15 return ca; 15 return ca;
16} 16}
17 17
18static inline void exec(const char **argcv) { 18static inline void exec(const char **argcv) {
19 execv(argcv[0], (char *const *) argcv); 19 execv(argcv[0], (char *const *) argcv);
20 exit(1); 20 exit(1);
21} 21}
22 22
23JNIEXPORT jint JNICALL 23JNIEXPORT jint JNICALL
24Java_org_pacien_tincapp_commands_Executor_forkExec(JNIEnv *env, jclass class, jobjectArray argcv) { 24Java_org_pacien_tincapp_commands_Executor_forkExec(JNIEnv *env, jclass class, jobjectArray argcv) {
25 pid_t pid = fork(); 25 pid_t pid = fork();
26 switch (pid) { 26 switch (pid) {
27 case 0: 27 case 0:
28 exec(to_string_array(env, argcv)); 28 exec(to_string_array(env, argcv));
29 return 0; 29 return 0;
30 30
31 default: 31 default:
32 return pid; 32 return pid;
33 } 33 }
34} 34}