michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: #ifndef B2G_NAME michael@0: #define B2G_NAME "b2g-bin" michael@0: #endif michael@0: #ifndef GAIA_PATH michael@0: #define GAIA_PATH "gaia/profile" michael@0: #endif michael@0: #define NOMEM "Could not allocate enough memory" michael@0: michael@0: void error(char* msg){ michael@0: fprintf(stderr, "ERROR: %s\n", msg); michael@0: } michael@0: michael@0: int main(int argc, char* argv[], char* envp[]){ michael@0: char* cwd = NULL; michael@0: char* full_path = NULL; michael@0: char* full_profile_path = NULL; michael@0: printf("Starting %s\n", B2G_NAME); michael@0: cwd = realpath(dirname(argv[0]), NULL); michael@0: full_path = (char*) malloc(strlen(cwd) + strlen(B2G_NAME) + 2); michael@0: if (!full_path) { michael@0: error(NOMEM); michael@0: return -2; michael@0: } michael@0: full_profile_path = (char*) malloc(strlen(cwd) + strlen(GAIA_PATH) + 2); michael@0: if (!full_profile_path) { michael@0: error(NOMEM); michael@0: return -2; michael@0: } michael@0: sprintf(full_path, "%s/%s", cwd, B2G_NAME); michael@0: sprintf(full_profile_path, "%s/%s", cwd, GAIA_PATH); michael@0: free(cwd); michael@0: printf("Running: %s -profile %s\n", full_path, full_profile_path); michael@0: fflush(stdout); michael@0: fflush(stderr); michael@0: execle(full_path, full_path, "-profile", full_profile_path, NULL, envp); michael@0: error("unable to start"); michael@0: perror(argv[0]); michael@0: free(full_path); michael@0: free(full_profile_path); michael@0: return -1; michael@0: }