1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/b2g/gaia/run-b2g.c Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,47 @@ 1.4 +#include <stdio.h> 1.5 +#include <stdlib.h> 1.6 +#include <unistd.h> 1.7 +#include <string.h> 1.8 +#include <libgen.h> 1.9 + 1.10 +#ifndef B2G_NAME 1.11 +#define B2G_NAME "b2g-bin" 1.12 +#endif 1.13 +#ifndef GAIA_PATH 1.14 +#define GAIA_PATH "gaia/profile" 1.15 +#endif 1.16 +#define NOMEM "Could not allocate enough memory" 1.17 + 1.18 +void error(char* msg){ 1.19 + fprintf(stderr, "ERROR: %s\n", msg); 1.20 +} 1.21 + 1.22 +int main(int argc, char* argv[], char* envp[]){ 1.23 + char* cwd = NULL; 1.24 + char* full_path = NULL; 1.25 + char* full_profile_path = NULL; 1.26 + printf("Starting %s\n", B2G_NAME); 1.27 + cwd = realpath(dirname(argv[0]), NULL); 1.28 + full_path = (char*) malloc(strlen(cwd) + strlen(B2G_NAME) + 2); 1.29 + if (!full_path) { 1.30 + error(NOMEM); 1.31 + return -2; 1.32 + } 1.33 + full_profile_path = (char*) malloc(strlen(cwd) + strlen(GAIA_PATH) + 2); 1.34 + if (!full_profile_path) { 1.35 + error(NOMEM); 1.36 + return -2; 1.37 + } 1.38 + sprintf(full_path, "%s/%s", cwd, B2G_NAME); 1.39 + sprintf(full_profile_path, "%s/%s", cwd, GAIA_PATH); 1.40 + free(cwd); 1.41 + printf("Running: %s -profile %s\n", full_path, full_profile_path); 1.42 + fflush(stdout); 1.43 + fflush(stderr); 1.44 + execle(full_path, full_path, "-profile", full_profile_path, NULL, envp); 1.45 + error("unable to start"); 1.46 + perror(argv[0]); 1.47 + free(full_path); 1.48 + free(full_profile_path); 1.49 + return -1; 1.50 +}