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