b2g/gaia/run-b2g.c
author Mike Hommey <mh+mozilla@glandium.org>
Thu, 04 Sep 2014 17:44:01 +0900
changeset 203606 17e91b558001d3aa1deb44f5c4a6751df92d2300
parent 104618 8253d8caa1b8e19e472caa22b04912bca14ca46e
child 223715 cb44ac1b1f1ee093f7f15ae586e69d113db1c2e3
permissions -rw-r--r--
Bug 1062219 - Don't build build/clang-plugin as an external directory. r=jcranmer

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <libgen.h>

#ifndef B2G_NAME
#define B2G_NAME "b2g-bin"
#endif
#ifndef GAIA_PATH
#define GAIA_PATH "gaia/profile"
#endif
#define NOMEM "Could not allocate enough memory"

void error(char* msg){
    fprintf(stderr, "ERROR: %s\n", msg);
}

int main(int argc, char* argv[], char* envp[]){
    char* cwd = NULL;
    char* full_path = NULL;
    char* full_profile_path = NULL;
    printf("Starting %s\n", B2G_NAME);
    cwd = realpath(dirname(argv[0]), NULL);
    full_path = (char*) malloc(strlen(cwd) + strlen(B2G_NAME) + 2);
    if (!full_path) {
        error(NOMEM);
        return -2;
    }
    full_profile_path = (char*) malloc(strlen(cwd) + strlen(GAIA_PATH) + 2);
    if (!full_profile_path) {
        error(NOMEM);
        return -2;
    }
    sprintf(full_path, "%s/%s", cwd, B2G_NAME);
    sprintf(full_profile_path, "%s/%s", cwd, GAIA_PATH);
    free(cwd);
    printf("Running: %s -profile %s\n", full_path, full_profile_path);
    fflush(stdout);
    fflush(stderr);
    execle(full_path, full_path, "-profile", full_profile_path, NULL, envp);
    error("unable to start");
    perror(argv[0]);
    free(full_path);
    free(full_profile_path);
    return -1;
}