b2g/gaia/run-b2g.c

branch
TOR_BUG_9701
changeset 14
925c144e1f1f
equal deleted inserted replaced
-1:000000000000 0:64745659fd6a
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <string.h>
5 #include <libgen.h>
6
7 #ifndef B2G_NAME
8 #define B2G_NAME "b2g-bin"
9 #endif
10 #ifndef GAIA_PATH
11 #define GAIA_PATH "gaia/profile"
12 #endif
13 #define NOMEM "Could not allocate enough memory"
14
15 void error(char* msg){
16 fprintf(stderr, "ERROR: %s\n", msg);
17 }
18
19 int main(int argc, char* argv[], char* envp[]){
20 char* cwd = NULL;
21 char* full_path = NULL;
22 char* full_profile_path = NULL;
23 printf("Starting %s\n", B2G_NAME);
24 cwd = realpath(dirname(argv[0]), NULL);
25 full_path = (char*) malloc(strlen(cwd) + strlen(B2G_NAME) + 2);
26 if (!full_path) {
27 error(NOMEM);
28 return -2;
29 }
30 full_profile_path = (char*) malloc(strlen(cwd) + strlen(GAIA_PATH) + 2);
31 if (!full_profile_path) {
32 error(NOMEM);
33 return -2;
34 }
35 sprintf(full_path, "%s/%s", cwd, B2G_NAME);
36 sprintf(full_profile_path, "%s/%s", cwd, GAIA_PATH);
37 free(cwd);
38 printf("Running: %s -profile %s\n", full_path, full_profile_path);
39 fflush(stdout);
40 fflush(stderr);
41 execle(full_path, full_path, "-profile", full_profile_path, NULL, envp);
42 error("unable to start");
43 perror(argv[0]);
44 free(full_path);
45 free(full_profile_path);
46 return -1;
47 }

mercurial