예제 #1
0
const char *Platform::defaultConfigName()
{
    size_t size = 520;

    if (*m_defaultConfigName) {
        return m_defaultConfigName;
    }

    if (uv_exepath(m_defaultConfigName, &size) < 0) {
        return nullptr;
    }

    if (size < 500) {
#       ifdef WIN32
        char *p = strrchr(m_defaultConfigName, '\\');
#       else
        char *p = strrchr(m_defaultConfigName, '/');
#       endif

        if (p) {
            strcpy(p + 1, "config.json");
            return m_defaultConfigName;
        }
    }

    *m_defaultConfigName = '\0';
    return nullptr;
}
예제 #2
0
파일: misc.c 프로젝트: runner-mei/luv
static int luv_exepath(lua_State* L) {
  size_t size = 2*PATH_MAX;
  char exe_path[2*PATH_MAX];
  int ret = uv_exepath(exe_path, &size);
  if (ret < 0) return luv_error(L, ret);
  lua_pushlstring(L, exe_path, size);
  return 1;
}
예제 #3
0
파일: main.c 프로젝트: cloud-hot/libuv-dox
char* exepath_for_worker() {
  int r;
  size_t size = PATH_MAX;

  r = uv_exepath(exepath, &size);
  if (r) ERROR("getting executable path", r);
  strcpy(exepath + (strlen(exepath) - strlen("main")), "worker");
  return exepath;
}
예제 #4
0
파일: luv_misc.c 프로젝트: brimworks/luvit
int luv_execpath(lua_State* L) {
  size_t size = 2*PATH_MAX;
  char exec_path[size];
  if (uv_exepath(exec_path, &size)) {
    uv_err_t err = uv_last_error(uv_default_loop());
    return luaL_error(L, "tcp_bind6: %s", uv_strerror(err));
  }
  lua_pushlstring(L, exec_path, size);
  return 1;
}
예제 #5
0
int luv_execpath(lua_State* L) {
  size_t size = 2*PATH_MAX;
  char exec_path[2*PATH_MAX];
  if (uv_exepath(exec_path, &size)) {
    uv_err_t err = uv_last_error(luv_get_loop(L));
    return luaL_error(L, "uv_exepath: %s", uv_strerror(err));
  }
  lua_pushlstring(L, exec_path, size);
  return 1;
}
예제 #6
0
static void init_process_options(char* test, uv_exit_cb exit_cb) {
    int r = uv_exepath(exepath, &exepath_size);
    ASSERT(r == 0);
    exepath[exepath_size] = '\0';
    args[0] = exepath;
    args[1] = test;
    args[2] = NULL;
    options.file = exepath;
    options.args = args;
    options.exit_cb = exit_cb;
}
예제 #7
0
파일: test-spawn.c 프로젝트: dakatsuka/node
static void init_process_options(char* test, uv_exit_cb exit_cb) {
  /* Note spawn_helper1 defined in test/run-tests.c */
  int r = uv_exepath(exepath, &exepath_size);
  ASSERT(r == 0);
  exepath[exepath_size] = '\0';
  args[0] = exepath;
  args[1] = test;
  args[2] = NULL;
  options.file = exepath;
  options.args = args;
  options.exit_cb = exit_cb;
}
예제 #8
0
파일: jlapi.c 프로젝트: dhiltonp/julia
DLLEXPORT char *jl_locate_sysimg(char *jlhome, char* imgpath)
{
    if (jlhome == NULL) {
        char *julia_path = (char*)malloc(512);
        size_t path_size = 512;
        uv_exepath(julia_path, &path_size);
        julia_home = strdup(dirname(julia_path));
        free(julia_path);
    }
    else {
        julia_home = jlhome;
    }
    char path[512];
    snprintf(path, sizeof(path), "%s%s%s",
             julia_home, PATHSEPSTRING, imgpath);
    return strdup(path);
}
예제 #9
0
파일: main.c 프로젝트: sunnyboy00/uvbook
void setup_workers() {
    size_t path_size = 500;
    uv_exepath(worker_path, &path_size);
    strcpy(worker_path + (strlen(worker_path) - strlen("multi-echo-server")), "worker");
    fprintf(stderr, "Worker path: %s\n", worker_path);

    char* args[2];
    args[0] = worker_path;
    args[1] = NULL;

    round_robin_counter = 0;

    // ...

    // launch same number of workers as number of CPUs
    uv_cpu_info_t *info;
    int cpu_count;
    uv_cpu_info(&info, &cpu_count);
    uv_free_cpu_info(info, cpu_count);

    child_worker_count = cpu_count;

    workers = calloc(sizeof(struct child_worker), cpu_count);
    while (cpu_count--) {
        struct child_worker *worker = &workers[cpu_count];
        uv_pipe_init(loop, &worker->pipe, 1);

        uv_stdio_container_t child_stdio[3];
        child_stdio[0].flags = UV_CREATE_PIPE | UV_READABLE_PIPE;
        child_stdio[0].data.stream = (uv_stream_t*) &worker->pipe;
        child_stdio[1].flags = UV_IGNORE;
        child_stdio[2].flags = UV_INHERIT_FD;
        child_stdio[2].data.fd = 2;

        worker->options.stdio = child_stdio;
        worker->options.stdio_count = 3;

        worker->options.exit_cb = close_process_handle;
        worker->options.file = args[0];
        worker->options.args = args;

        uv_spawn(loop, &worker->req, worker->options); 
        fprintf(stderr, "Started worker %d\n", worker->req.pid);
    }
}
예제 #10
0
MgErr ftw_libuv_lib_path(LStrHandle path)
{
    MgErr lv_err;
    size_t sz;
    char buffer[32768];
    int rc;

    sz = 32768;
    rc = uv_exepath(buffer, &sz);
    if (rc) {
        return bogusError;
    }

    lv_err = ftw_support_buffer_to_LStrHandle(&path, buffer, sz);

    return lv_err;

}
예제 #11
0
/*
 * Class:     com_iwebpp_libuvpp_LibUV
 * Method:    _exe_path
 * Signature: ()Ljava/lang/String;
 */
extern "C" JNIEXPORT  jstring JNICALL Java_com_iwebpp_libuvpp_LibUV__1exe_1path
(JNIEnv *env, jclass cls) {

#ifdef _WIN32
    /* MAX_PATH is in characters, not bytes. Make sure we have enough headroom. */
    char buf[MAX_PATH * 4 + 1];
#else
    char buf[PATH_MAX + 1];
#endif

    size_t size = ARRAY_SIZE(buf);
    int r = uv_exepath(buf, &size);
    if (r) {
        ThrowException(env, r, "uv_exepath");
        return NULL;
    }
    return env->NewStringUTF(buf);
}
예제 #12
0
파일: util.cpp 프로젝트: builden/node.cpp
  void Assert(const char* const (*args)[4]) {
    auto filename = (*args)[0];
    auto linenum = (*args)[1];
    auto message = (*args)[2];
    auto function = (*args)[3];

    char exepath[256];
    size_t exepath_size = sizeof(exepath);
    if (uv_exepath(exepath, &exepath_size))
      snprintf(exepath, sizeof(exepath), "node");

    char pid[12] = { 0 };

    fprintf(stderr, "%s%s: %s:%s:%s%s Assertion `%s' failed.\n",
      exepath, pid, filename, linenum,
      function, *function ? ":" : "", message);
    fflush(stderr);

    Abort();
  }
예제 #13
0
void spawn_helper(uv_pipe_t* channel,
                  uv_process_t* process,
                  const char* helper) {
  uv_process_options_t options;
  size_t exepath_size;
  char exepath[1024];
  char* args[3];
  int r;
  uv_stdio_container_t stdio[3];

  r = uv_pipe_init(uv_default_loop(), channel, 1);
  ASSERT(r == 0);
  ASSERT(channel->ipc);

  exepath_size = sizeof(exepath);
  r = uv_exepath(exepath, &exepath_size);
  ASSERT(r == 0);

  exepath[exepath_size] = '\0';
  args[0] = exepath;
  args[1] = (char*)helper;
  args[2] = NULL;

  memset(&options, 0, sizeof(options));
  options.file = exepath;
  options.args = args;
  options.exit_cb = exit_cb;
  options.stdio = stdio;
  options.stdio_count = ARRAY_SIZE(stdio);

  stdio[0].flags = UV_CREATE_PIPE | UV_READABLE_PIPE | UV_WRITABLE_PIPE;
  stdio[0].data.stream = (uv_stream_t*) channel;
  stdio[1].flags = UV_INHERIT_FD;
  stdio[1].data.fd = 1;
  stdio[2].flags = UV_INHERIT_FD;
  stdio[2].data.fd = 2;

  r = uv_spawn(uv_default_loop(), process, &options);
  ASSERT(r == 0);
}
예제 #14
0
파일: repl.c 프로젝트: TimmyLiu/julia
void parse_opts(int *argcp, char ***argvp) {
    static char* shortopts = "+H:T:hJ:";
    static struct option longopts[] = {
        { "home",        required_argument, 0, 'H' },
        { "tab",         required_argument, 0, 'T' },
        { "build",       required_argument, 0, 'b' },
        { "lisp",        no_argument,       &lisp_prompt, 1 },
        { "help",        no_argument,       0, 'h' },
        { "sysimage",    required_argument, 0, 'J' },
        { 0, 0, 0, 0 }
    };
    int c;
    opterr = 0;
    int imagepathspecified=0;
    image_file = JL_SYSTEM_IMAGE_PATH;
    int skip = 0;
    int lastind = optind;
    while ((c = getopt_long(*argcp,*argvp,shortopts,longopts,0)) != -1) {
        switch (c) {
        case 0:
            break;
        case '?':
            if (optind != lastind) skip++;
            lastind = optind;
            break;
        case 'H':
            julia_home = strdup(optarg);
            break;
        case 'T':
            // TODO: more robust error checking.
            tab_width = atoi(optarg);
            break;
        case 'b':
            build_mode = strdup(optarg);
            if (!imagepathspecified)
                image_file = NULL;
            break;
        case 'J':
            image_file = strdup(optarg);
            imagepathspecified = 1;
            break;
        case 'h':
            printf("%s%s", usage, opts);
            exit(0);
        default:
            ios_printf(ios_stderr, "julia: unhandled option -- %c\n",  c);
            ios_printf(ios_stderr, "This is a bug, please report it.\n");
            exit(1);
        }
    }
    if (!julia_home) {
        julia_home = getenv("JULIA_HOME");
        if (julia_home) {
            julia_home = strdup(julia_home);
        } else {
            char *julia_path = (char*)malloc(PATH_MAX);
            size_t path_size = PATH_MAX;
            uv_exepath(julia_path, &path_size);
            julia_home = strdup(dirname(julia_path));
            free(julia_path);
        }
    }
    optind -= skip;
    *argvp += optind;
    *argcp -= optind;
    if (image_file==NULL && *argcp > 0) {
        if (strcmp((*argvp)[0], "-")) {
            program = (*argvp)[0];
        }
    }
    if (image_file) {
        if (image_file[0] != PATHSEP) {
            struct stat stbuf;
            char path[512];
            if (!imagepathspecified) {
                // build time path relative to JULIA_HOME
                snprintf(path, sizeof(path), "%s%s",
                         julia_home, PATHSEPSTRING JL_SYSTEM_IMAGE_PATH);
                image_file = strdup(path);
            }
            else if (jl_stat(image_file, (char*)&stbuf) != 0) {
                // otherwise try julia_home/../lib/julia/%s
                snprintf(path, sizeof(path), "%s%s%s",
                         julia_home,
                         PATHSEPSTRING ".." PATHSEPSTRING "lib" PATHSEPSTRING "julia" PATHSEPSTRING,
                         image_file);
                image_file = strdup(path);
            }
        }
    }
}
예제 #15
0
파일: process.c 프로젝트: ifzz/LuaIO
static int LuaIO_process_fork(lua_State* L) {
  if (lua_type(L, 1) != LUA_TTABLE) {
    return luaL_argerror(L, 1, "process.fork(options) error: options must be [table]\n"); 
  }

  if (!LuaIO_process_exepath_ptr) {
    size_t length = sizeof(LuaIO_process_exepath);
    int err = uv_exepath(LuaIO_process_exepath, &length);
    if (err < 0) {
      return luaL_error(L, "process.fork(options) uv_exepath() error: %s\n", uv_strerror(err));
    }

    LuaIO_process_exepath_ptr = LuaIO_process_exepath;
  }

  lua_getfield(L, 1, "file");
  const char* file;
  if (lua_type(L, -1) == LUA_TSTRING) {
    file = lua_tostring(L, -1);
  } else {
    return luaL_argerror(L, 2, "process.fork(options) error: options.file is required and must be [string]\n"); 
  }
  lua_pop(L, 1);

  lua_getfield(L, 1, "args");
  size_t args_length = 0;
  char** args = NULL;
  if (lua_type(L, -1) == LUA_TTABLE) {
    args_length = lua_rawlen(L, -1);
    /*execpath, file, null => args_length + 3*/
    args = LuaIO_malloc(sizeof(char*) * (args_length + 3));
    if (!args) {
      return luaL_error(L, "process.fork(options) error: no memory for args\n");
    }

    for (size_t i = 1; i <= args_length; ++i) {
      lua_rawgeti(L, -1, i);
      args[i + 1] = (char*)luaL_checkstring(L, -1);
      lua_pop(L, 1);
    }
  } else if (lua_type(L, -1) == LUA_TNIL) {
    /*execpath, file, null => args_length + 3*/
    args = LuaIO_malloc(sizeof(char*) * 3);
    if (!args) {
      return luaL_error(L, "process.fork(options) error: no memory for args\n");
    }
  } else {
    return luaL_argerror(L, 2, "process.fork(options) error: options.args must be [table]\n"); 
  }
  lua_pop(L, 1);

  args[0] = LuaIO_process_exepath_ptr;
  args[1] = (char*)file;
  args[args_length + 2] = NULL;

  if (!LuaIO_process_stdio_ptr) { 
    LuaIO_process_stdio[0].flags = UV_INHERIT_FD;
    LuaIO_process_stdio[0].data.fd = 0;
    LuaIO_process_stdio[1].flags = UV_INHERIT_FD;
    LuaIO_process_stdio[1].data.fd = 1;
    LuaIO_process_stdio[2].flags = UV_INHERIT_FD;
    LuaIO_process_stdio[2].data.fd = 2;
    LuaIO_process_stdio_ptr = LuaIO_process_stdio;
  }

  uv_process_options_t* options = LuaIO_malloc(sizeof(uv_process_options_t));
  if (!options) {
    LuaIO_free(args);
    return luaL_error(L, "process.fork(options) error: no memory for uv_process_options_t options\n");
  }
  LuaIO_memzero(options, sizeof(uv_process_options_t));
  options->exit_cb = LuaIO_process_onexit;
  options->file = LuaIO_process_exepath_ptr;
  options->args = args;
  options->stdio_count = 3;
  options->stdio = LuaIO_process_stdio_ptr;

  lua_getfield(L, 1, "uid");
  if (lua_type(L, -1) == LUA_TNUMBER) {
    options->uid = lua_tointeger(L, -1);
    options->flags |= UV_PROCESS_SETUID;
  } else if (lua_type(L, -1) != LUA_TNIL) {
    LuaIO_process_free_options(options);
    return luaL_argerror(L, 2, "process.fork(options) error: options.uid must be [number]\n"); 
  }
  lua_pop(L, 1);

  lua_getfield(L, 1, "gid");
  if (lua_type(L, -1) == LUA_TNUMBER) {
    options->gid = lua_tointeger(L, -1);
    options->flags |= UV_PROCESS_SETGID;
  } else if (lua_type(L, -1) != LUA_TNIL) {
    LuaIO_process_free_options(options);
    return luaL_argerror(L, 2, "process.fork(options) error: options.gid must be [number]\n"); 
  }
  lua_pop(L, 1);

  lua_getfield(L, 1, "detached");
  if (lua_toboolean(L, -1)) {
    options->flags |= UV_PROCESS_DETACHED;
  }
  lua_pop(L, 1);

  lua_getfield(L, 1, "forever");
  int forever = lua_toboolean(L, -1);
  lua_pop(L, 1);
  
  int cpu = -1; 
  lua_getfield(L, 1, "cpu");
  if (lua_type(L, -1) == LUA_TNUMBER) {
    cpu = lua_tointeger(L, -1);
  } else if (lua_type(L, -1) != LUA_TNIL) {
    LuaIO_process_free_options(options);
    return luaL_argerror(L, 2, "process.fork(options) error: options.cpu must be [number]\n"); 
  }
  lua_pop(L, 1);

  uv_process_t* handle = LuaIO_malloc(sizeof(uv_process_t));
  if (!handle) {
    LuaIO_process_free_options(options);
    return luaL_error(L, "process.fork(options) error: no memory for uv_process_t handle.\n");
  }
  LuaIO_memzero(handle, sizeof(uv_process_t));

  LuaIO_process_data_t* data = NULL;
  if (forever) {
    data = LuaIO_malloc(sizeof(LuaIO_process_data_t));
    if (!data) {
      LuaIO_process_free_options(options);
      return luaL_error(L, "process.fork(options) error:no memory for LuaIO_process_data_t data.\n");
    }
    
    lua_pushvalue(L, 1);
    data->options_ref = luaL_ref(L, LUA_REGISTRYINDEX);
    data->options = options;
    data->cpu = cpu;
    handle->data = data;
  }

  int ret = uv_spawn(uv_default_loop(), handle, options);
  if (ret < 0) {
    LuaIO_process_free_options(options);
    luaL_unref(L, LUA_REGISTRYINDEX, data->options_ref);
    LuaIO_free(data);
    uv_close((uv_handle_t*)handle, NULL);
    return luaL_error(L, "process.fork(options) uv_spawn() error: %s\n", uv_strerror(ret));
  }
  if (cpu >= 0) LuaIO_set_affinity(handle->pid, cpu);

  if (!LuaIO_process_signal_ptr) {
    uv_signal_init(uv_default_loop(), &LuaIO_process_signal);
    LuaIO_process_signal_ptr = &LuaIO_process_signal;
    uv_signal_start(LuaIO_process_signal_ptr, LuaIO_process_signal_callback, SIGQUIT);
  }

  lua_pushinteger(L, handle->pid);

  return 1;
}
예제 #16
0
파일: config.c 프로젝트: indutny/bud
bud_error_t bud_config_new(int argc, char** argv, bud_config_t** out) {
  bud_error_t err;
  bud_config_t* config;
  int i;
  int r;
  size_t path_len;
  int c;
  int index;
  int loaded;

  config = calloc(1, sizeof(*config));
  if (config == NULL)
    return bud_error_str(kBudErrNoMem, "bud_config_t");

  loaded = 0;
  do {
    index = 0;
    c = getopt_long(argc, argv, bud_long_flags, bud_long_options, &index);
    switch (c) {
      case 'v':
        bud_print_version();
        err = bud_error(kBudErrSkip);
        goto fatal;
#ifndef _WIN32
      case 'd':
        config->is_daemon = 1;
#endif  /* !_WIN32 */
        break;
      case 'p':
      case 'i':
      case 'c':
        if (loaded) {
          err = bud_error(kBudErrMultipleConfigs);
          goto fatal;
        }
        loaded = 1;

        if (c == 'p') {
          config->piped = 1;
          config->path = kPipedConfigPath;
        } else {
          config->piped = 0;
          config->path = optarg;
          config->inlined = c == 'i';
        }
        break;
      case 1000:
        config->is_worker = 1;
        break;
      case 1001:
        bud_config_print_default();
        err = bud_error(kBudErrSkip);
        goto fatal;
      default:
        if (loaded)
          break;

        bud_print_help(argc, argv);
        goto no_config;
    }
  } while (c != -1);

  if (!config->piped) {
    config->piped_index = -1;
  } else {
    /* get_opt does not provide the argc offset so must manually retrieve it */
    for (i = 0; i < argc; i++) {
      if (strcmp(argv[i], "--piped-config") == 0 ||
          strcmp(argv[i], "-p") == 0) {
        config->piped_index = i;
        break;
      }
    }
  }

  /* CLI options */
  config->argc = argc;
  config->argv = argv;

  /* Get executable path */
  path_len = sizeof(config->exepath);
  r = uv_exepath(config->exepath, &path_len);
  ASSERT(path_len < sizeof(config->exepath), "Exepath OOB");

  if (r != 0) {
    bud_config_free(config);
    config = NULL;
    return bud_error_num(kBudErrExePath, r);
  }

  err = bud_hashmap_init(&config->files.hashmap, kBudFileCacheSize);
  if (!bud_is_ok(err))
    goto fatal;

  *out = config;
  return bud_ok();

no_config:
  free(config);
  return bud_error(kBudErrNoConfig);

fatal:
  free(config);
  return err;
}
예제 #17
0
파일: config.c 프로젝트: aranhoide/bud
bud_config_t* bud_config_cli_load(uv_loop_t* loop,
                                  int argc,
                                  char** argv,
                                  bud_error_t* err) {
  int c;
  int r;
  int index;
  int is_daemon;
  int is_worker;
  size_t path_len;
  bud_config_t* config;

  struct option long_options[] = {
    { "version", 0, NULL, 'v' },
    { "config", 1, NULL, 'c' },
#ifndef _WIN32
    { "daemonize", 0, NULL, 'd' },
#endif  /* !_WIN32 */
    { "worker", 0, NULL, 1000 },
    { "default-config", 0, NULL, 1001 },
    { NULL, 0, NULL, 0 }
  };

  *err = bud_ok();
  config = NULL;
  is_daemon = 0;
  is_worker = 0;
  do {
    index = 0;
    c = getopt_long(argc, argv, "vc:d", long_options, &index);
    switch (c) {
      case 'v':
        bud_print_version();
        break;
      case 'c':
        config = bud_config_load(loop,optarg, err);
        if (config == NULL) {
          ASSERT(!bud_is_ok(*err), "Config load failed without error");
          c = -1;
          break;
        }
        if (is_daemon)
          config->is_daemon = 1;
        if (is_worker)
          config->is_worker = 1;
        break;
#ifndef _WIN32
      case 'd':
        is_daemon = 1;
        if (config != NULL)
          config->is_daemon = 1;
#endif  /* !_WIN32 */
        break;
      case 1000:
        is_worker = 1;
        if (config != NULL)
          config->is_worker = 1;
        break;
      case 1001:
        bud_config_print_default();
        c = -1;
        break;
      default:
        if (config == NULL)
          bud_print_help(argc, argv);
        c = -1;
        break;
    }
  } while (c != -1);

  if (config != NULL) {
    /* CLI options */
    config->argc = argc;
    config->argv = argv;

    /* Get executable path */
    path_len = sizeof(config->exepath);
    r = uv_exepath(config->exepath, &path_len);
    ASSERT(path_len < sizeof(config->exepath), "Exepath OOB");

    config->exepath[path_len] = 0;
    if (r != 0) {
      bud_config_free(config);
      config = NULL;
      *err = bud_error_num(kBudErrExePath, r);
    }

    /* Initialize config */
    *err = bud_config_init(config);
    if (!bud_is_ok(*err)) {
      bud_config_free(config);
      return NULL;
    }
  }

  return config;
}
예제 #18
0
파일: repl.c 프로젝트: CBaader/julia
void parse_opts(int *argcp, char ***argvp)
{
    static char* shortopts = "+H:T:hJ:";
    static struct option longopts[] = {
        { "home",          required_argument, 0, 'H' },
        { "tab",           required_argument, 0, 'T' },
        { "build",         required_argument, 0, 'b' },
        { "lisp",          no_argument,       &lisp_prompt, 1 },
        { "help",          no_argument,       0, 'h' },
        { "sysimage",      required_argument, 0, 'J' },
        { "code-coverage", optional_argument, 0, 'c' },
        { "track-allocation",required_argument, 0, 'm' },
        { "check-bounds",  required_argument, 0, 300 },
        { "int-literals",  required_argument, 0, 301 },
        { "dump-bitcode",  required_argument, 0, 302 },
        { "compile",       required_argument, 0, 303 },
        { 0, 0, 0, 0 }
    };
    int c;
    opterr = 0;
    int imagepathspecified=0;
    image_file = system_image;
    int skip = 0;
    int lastind = optind;
    while ((c = getopt_long(*argcp,*argvp,shortopts,longopts,0)) != -1) {
        switch (c) {
        case 0:
            break;
        case '?':
            if (optind != lastind) skip++;
            lastind = optind;
            break;
        case 'H':
            julia_home = strdup(optarg);
            break;
        case 'b':
            jl_compileropts.build_path = strdup(optarg);
            if (!imagepathspecified)
                image_file = NULL;
            break;
        case 'J':
            image_file = strdup(optarg);
            imagepathspecified = 1;
            break;
        case 'h':
            printf("%s%s", usage, opts);
            exit(0);
	case 'c':
	    if (optarg != NULL) {
		if (!strcmp(optarg,"user"))
		    codecov = JL_LOG_USER;
		else if (!strcmp(optarg,"all"))
		    codecov = JL_LOG_ALL;
		else if (!strcmp(optarg,"none"))
		    codecov = JL_LOG_NONE;
	        break;
	    }
	    else
		codecov = JL_LOG_USER;
	    break;
	case 'm':
	    if (optarg != NULL) {
		if (!strcmp(optarg,"user"))
		    malloclog = JL_LOG_USER;
		else if (!strcmp(optarg,"all"))
		    malloclog = JL_LOG_ALL;
		else if (!strcmp(optarg,"none"))
		    malloclog = JL_LOG_NONE;
	        break;
	    }
        case 300:
            if (!strcmp(optarg,"yes"))
                jl_compileropts.check_bounds = JL_COMPILEROPT_CHECK_BOUNDS_ON;
            else if (!strcmp(optarg,"no"))
                jl_compileropts.check_bounds = JL_COMPILEROPT_CHECK_BOUNDS_OFF;
            break;
        case 301:
            if (!strcmp(optarg,"32"))
                jl_compileropts.int_literals = 32;
            else if (!strcmp(optarg,"64"))
                jl_compileropts.int_literals = 64;
            else {
                ios_printf(ios_stderr, "julia: invalid integer literal size (%s)\n", optarg);
                exit(1);
            }
            break;
        case 302:
            if (!strcmp(optarg,"yes"))
                jl_compileropts.dumpbitcode = JL_COMPILEROPT_DUMPBITCODE_ON;
            else if (!strcmp(optarg,"no"))
                jl_compileropts.dumpbitcode = JL_COMPILEROPT_DUMPBITCODE_OFF;
            break;
        case 303:
            if (!strcmp(optarg,"yes"))
                jl_compileropts.compile_enabled = 1;
            else if (!strcmp(optarg,"no"))
                jl_compileropts.compile_enabled = 0;
            else if (!strcmp(optarg,"all"))
                jl_compileropts.compile_enabled = 2;
            else {
                ios_printf(ios_stderr, "julia: invalid argument to --compile (%s)\n", optarg);
                exit(1);
            }
            break;
        default:
            ios_printf(ios_stderr, "julia: unhandled option -- %c\n",  c);
            ios_printf(ios_stderr, "This is a bug, please report it.\n");
            exit(1);
        }
    }
    jl_compileropts.code_coverage = codecov;
    jl_compileropts.malloc_log    = malloclog;
    if (!julia_home) {
        julia_home = getenv("JULIA_HOME");
        if (julia_home) {
            julia_home = strdup(julia_home);
        }
        else {
            char *julia_path = (char*)malloc(PATH_MAX);
            size_t path_size = PATH_MAX;
            uv_exepath(julia_path, &path_size);
            julia_home = strdup(dirname(julia_path));
            free(julia_path);
        }
    }
    optind -= skip;
    *argvp += optind;
    *argcp -= optind;
    if (image_file==NULL && *argcp > 0) {
        if (strcmp((*argvp)[0], "-")) {
            program = (*argvp)[0];
        }
    }
    if (image_file) {
        if (image_file[0] != PATHSEP) {
            uv_stat_t stbuf;
            char path[512];
            if (!imagepathspecified) {
                // build time path relative to JULIA_HOME
                snprintf(path, sizeof(path), "%s%s%s",
                         julia_home, PATHSEPSTRING, system_image);
                image_file = strdup(path);
            }
            else if (jl_stat(image_file, (char*)&stbuf) != 0) {
                // otherwise try julia_home/../lib/julia/%s
                snprintf(path, sizeof(path), "%s%s%s",
                         julia_home,
                         PATHSEPSTRING ".." PATHSEPSTRING "lib" PATHSEPSTRING "julia" PATHSEPSTRING,
                         image_file);
                image_file = strdup(path);
            }
        }
    }
}