Пример #1
0
int main(int argc, char *argv[])
{
    uv_setup_args(argc, argv); // no-op on Windows
#else
int wmain(int argc, wchar_t *argv[], wchar_t *envp[])
{
    int i;
    for (i=0; i<argc; i++) { // write the command line to UTF8
        wchar_t *warg = argv[i];
        size_t len = WideCharToMultiByte(CP_UTF8, 0, warg, -1, NULL, 0, NULL, NULL);
        if (!len) return 1;
        char *arg = (char*)alloca(len);
        if (!WideCharToMultiByte(CP_UTF8, 0, warg, -1, arg, len, NULL, NULL)) return 1;
        argv[i] = (wchar_t*)arg;
    }
#endif
    libsupport_init();
    parse_opts(&argc, (char***)&argv);
    if (lisp_prompt) {
        jl_lisp_prompt();
        return 0;
    }
    julia_init(imagepathspecified ? JL_IMAGE_CWD : JL_IMAGE_JULIA_HOME);
    int ret = true_main(argc, (char**)argv);
    julia_save();
    jl_atexit_hook();
    return ret;
}
Пример #2
0
static void
setup_args(void)
{
    int r, argc;
    char **argv;
    void (*Py_GetArgcArgv)(int *argc, char ***argv);
    uv_lib_t dlmain;

    r = uv_dlopen(NULL, &dlmain);
    if (r != 0) {
        return;
    }

    r = uv_dlsym(&dlmain, "Py_GetArgcArgv", (void **)&Py_GetArgcArgv);
    if (r != 0) {
        uv_dlclose(&dlmain);
        return;
    }

    Py_GetArgcArgv(&argc, &argv);
    uv_dlclose(&dlmain);

    uv_setup_args(argc, argv);
    setup_args_called = True;
}
Пример #3
0
int main(int argc, char *argv[])
{
    uv_setup_args(argc, argv); // no-op on Windows
#else
static void lock_low32() {
#if defined(_P64) && defined(JL_DEBUG_BUILD)
    // block usage of the 32-bit address space on win64, to catch pointer cast errors
    char *const max32addr = (char*)0xffffffffL;
    SYSTEM_INFO info;
    MEMORY_BASIC_INFORMATION meminfo;
    GetNativeSystemInfo(&info);
    memset(&meminfo, 0, sizeof(meminfo));
    meminfo.BaseAddress = info.lpMinimumApplicationAddress;
    while ((char*)meminfo.BaseAddress < max32addr) {
        VirtualQuery(meminfo.BaseAddress, &meminfo, sizeof(meminfo));
        if (meminfo.State == MEM_FREE) { // reserve all free pages in the first 4GB of memory
            char *first = (char*)meminfo.BaseAddress;
            char *last = first + meminfo.RegionSize;
            char *p;
            if (last > max32addr)
                last = max32addr;
            // adjust first up to the first allocation granularity boundary
            // adjust last down to the last allocation granularity boundary
            first = (char*)(((long long)first + info.dwAllocationGranularity - 1) & ~(info.dwAllocationGranularity - 1));
            last = (char*)((long long)last & ~(info.dwAllocationGranularity - 1));
            if (last != first) {
                p = VirtualAlloc(first, last - first, MEM_RESERVE, PAGE_NOACCESS); // reserve all memory in between
                assert(p == first);
            }
        }
        meminfo.BaseAddress += meminfo.RegionSize;
    }
#endif
}
Пример #4
0
int main(int argc, char **argv) {
  argv = uv_setup_args(argc, argv);

  run_bench_oscillate();
  run_bench_oscillate2();

  return 0;
}
Пример #5
0
int main(int argc, char **argv) {
  argv = uv_setup_args(argc, argv);

  run_bench_oscillate();
  run_bench_oscillate_multi();
  run_bench_enqueue_work();

  return 0;
}
Пример #6
0
void rtScriptDuk::init2(int argc, char** argv)
#endif
{
  // Hack around with the argv pointer. Used for process.title = "blah".
#ifdef ENABLE_DEBUG_MODE
  g_argvduk = uv_setup_args(g_argcduk, g_argvduk);
#else
  argv = uv_setup_args(argc, argv);
#endif

  rtLogInfo(__FUNCTION__);

#if 0
#warning Using DEBUG AGENT...
  use_debug_agent = true; // JUNK
#endif

  if(duk_is_initialized == false)
  {
    duk_is_initialized = true;

    uv_loop_t *dukLoop = new uv_loop_t();
    uv_loop_init(dukLoop);
    //uv_loop_t dukLoop = uv_default_loop();
    dukCtx = duk_create_heap(NULL, NULL, NULL, dukLoop, NULL);
    if (!dukCtx) {
	    rtLogWarn("Problem initiailizing duktape heap\n");
	    return;
    }

    dukLoop->data = dukCtx;
    uvLoops.push_back(dukLoop);

    {
      duk_push_thread_stash(dukCtx, dukCtx);
      duk_push_pointer(dukCtx, (void*)dukLoop);
      duk_bool_t rc = duk_put_prop_string(dukCtx, -2, "__duk_loop");
      assert(rc);
      duk_pop(dukCtx);
    }

    rtScriptDukUtils::rtSetupJsModuleBindings(dukCtx);
  }
}
Пример #7
0
int main(int argc, char **argv) {
  argv = uv_setup_args(argc, argv);

  run_test_timer_huge_timeout();
  run_test_timer_huge_repeat();
  run_test_timer_run_once();
  run_test_timer_run_once_multi();

  return 0;
}
Пример #8
0
Файл: main.c Проект: kidaa/luvi
int main(int argc, char* argv[] ) {

  lua_State* L;
  int index;
  int res;

  // Hooks in libuv that need to be done in main.
  argv = uv_setup_args(argc, argv);

  // Create the lua state.
  L = vm_acquire(); 
  if (L == NULL) {
    fprintf(stderr, "luaL_newstate has failed\n");
    return 1;
  }

  luv_set_thread_cb(vm_acquire, vm_release);

#ifdef WITH_WINSVC
  // Store luvi module definition at preload.openssl
  lua_pushcfunction(L, luaopen_winsvc);
  lua_setfield(L, -2, "winsvc");
  lua_pushcfunction(L, luaopen_winsvcaux);
  lua_setfield(L, -2, "winsvcaux");
#endif

  // Load the init.lua script
  if (luaL_loadstring(L, "return require('init')(...)")) {
    fprintf(stderr, "%s\n", lua_tostring(L, -1));
    return -1;
  }

  // Pass the command-line arguments to init as a zero-indexed table
  lua_createtable (L, argc, 0);
  for (index = 0; index < argc; index++) {
    lua_pushstring(L, argv[index]);
    lua_rawseti(L, -2, index);
  }

  // Start the main script.
  if (lua_pcall(L, 1, 1, 0)) {
    fprintf(stderr, "%s\n", lua_tostring(L, -1));
    return -1;
  }

  // Use the return value from the script as process exit code.
  res = 0;
  if (lua_type(L, -1) == LUA_TNUMBER) {
    res = lua_tointeger(L, -1);
  }
  vm_release(L);
  return res;
}
Пример #9
0
int main(int argc, char **argv) {
  platform_init(argc, argv);

  argv = uv_setup_args(argc, argv);

  switch (argc) {
  case 1: return run_tests(TEST_TIMEOUT, 0);
  case 2: return maybe_run_test(argc, argv);
  case 3: return run_test_part(argv[1], argv[2]);
  default:
    LOGF("Too many arguments.\n");
    return 1;
  }
}
Пример #10
0
int main(int argc, char *argv[])
{
    auto dispatcher = new qtjs::EventDispatcherLibUv();

    QCoreApplication::setEventDispatcher(dispatcher);

    QApplication app(argc, argv);

    dispatcher->setFinalise();

    argv = uv_setup_args(argc, argv);

    int exec_argc = 0;
    const char **exec_argv = NULL;

    node::Init(&argc, const_cast<const char **>(argv), &exec_argc, &exec_argv);

    v8::Platform* platform = v8::platform::CreateDefaultPlatform(THREAD_POOL_SIZE);
    v8::V8::InitializePlatform(platform);
	v8::V8::Initialize();

    v8::Isolate* isolate = v8::Isolate::New();

    new v8::Locker(isolate);
    new v8::Isolate::Scope(isolate);

    {
        v8::HandleScope handle_scope(isolate);
        v8::Handle<v8::Context> context = v8::Context::New(isolate);

        node::Environment *env = node::CreateEnvironment(isolate, uv_default_loop(), context, argc, argv, exec_argc, exec_argv);

        new v8::Context::Scope(context);

        node::LoadEnvironment(env);

        QCoreApplication::exec();

        node::RunAtExit(env);
        env->context()->Global().Clear();
    }

    v8::V8::Dispose();

    return 0;
}
Пример #11
0
int main(int argc, char **argv) {
  if (platform_init(argc, argv))
    return EXIT_FAILURE;

  argv = uv_setup_args(argc, argv);

  switch (argc) {
  case 1: return run_tests(0);
  case 2: return maybe_run_test(argc, argv);
  case 3: return run_test_part(argv[1], argv[2]);
  default:
    LOGF("Too many arguments.\n");
    return EXIT_FAILURE;
  }

  return EXIT_SUCCESS;
}
Пример #12
0
int main(int argc, char *argv[])
{
  lua_State *L;
  uv_loop_t *loop;

  argv = uv_setup_args(argc, argv);

  L = luaL_newstate();
  if (L == NULL) {
    fprintf(stderr, "luaL_newstate has failed\n");
    return 1;
  }

  luaL_openlibs(L);

  loop = uv_default_loop();

#ifdef LUV_EXPORTS
  luvit__suck_in_symbols();
#endif

#ifdef USE_OPENSSL
  luvit_init_ssl();
#endif

  if (luvit_init(L, loop, argc, argv)) {
    fprintf(stderr, "luvit_init has failed\n");
    return 1;
  }

  /* Run the main lua script */
  if (luvit_run(L)) {
    int saved_flags = fcntl(STDOUT_FILENO, F_GETFL);
    fcntl(STDOUT_FILENO, F_SETFL, saved_flags & ~O_NONBLOCK);
    fprintf(stderr, "%s\n", lua_tostring(L, -1));
    lua_pop(L, 1);
    lua_close(L);
    return -1;
  }

  lua_close(L);
  int saved_flags = fcntl(STDOUT_FILENO, F_GETFL);
  fcntl(STDOUT_FILENO, F_SETFL, saved_flags & ~O_NONBLOCK);
  return 0;
}
Пример #13
0
int main(int argc, char **argv) {
  if (platform_init(argc, argv))
    return EXIT_FAILURE;

  argv = uv_setup_args(argc, argv);

  switch (argc) {
  case 1: return run_tests(0);
  case 2: return maybe_run_test(argc, argv);
  case 3: return run_test_part(argv[1], argv[2]);
  case 4: return maybe_run_test(argc, argv);
  default:
    fprintf(stderr, "Too many arguments.\n");
    fflush(stderr);
    return EXIT_FAILURE;
  }

#ifndef __SUNPRO_C
  return EXIT_SUCCESS;
#endif
}
Пример #14
0
int Start(int argc, char *originalArgv[]) {
    TRACEIN;
// ERZ mod, don't copy -psn_ arg, which Mac OS X generates for
// double-clickable applications
// now make a copy of the args and pretend main.js was requested on the command line
	bool needMainJs = (getScriptPassedInArgs(argc, (const char**)originalArgv) == 0);
    int i = 0;
    int j = 0;
    char* sMainJsStr = (char*) std::malloc(10);
    std::strcpy(sMainJsStr, "main.js");
    char** argv = (char**)std::malloc(sizeof(char*)*(argc+2));
    for (i = 0; i<argc; i++, j++) {
        argv[j] = originalArgv[i];
        if (std::strncmp(originalArgv[i], "-psn_", 4) == 0) {
            j--; // overwrite the -psn arg
		} else if (strcmp(originalArgv[i], "--version") == 0 || strcmp(originalArgv[i], "-v") == 0) {
		  printf("PDG v%s\nNode.js %s\n", PDG_VERSION, NODE_VERSION);
		  exit(0);
		} else if (strcmp(originalArgv[i], "--help") == 0) {
		  printf("Usage: pdg [options] [script.js] [arguments] \n"
				 "\n"
				 "If script is not specified, pdg will search for main.js \n"
				 "\n"
				 "Options:\n"
				 "  -v, --version        print pdg's version\n"
				 "  --no-deprecation     silence deprecation warnings\n"
				 "  --trace-deprecation  show stack traces on deprecations\n"
				 "  --v8-options         print v8 command line options\n"
				 "  --max-stack-size=val set max v8 stack size (bytes)\n"
				 "\n"
				 "Environment variables:\n"
		#ifdef _WIN32
				 "NODE_PATH              ';'-separated list of directories\n"
		#else
				 "NODE_PATH              ':'-separated list of directories\n"
		#endif
				 "                       prefixed to the module search path.\n"
				 "NODE_DEBUG             Set to \"module\" to debug module loading.\n"
				 "NODE_DISABLE_COLORS    Set to 1 to disable colors in the REPL\n"
				 "\n"
				 "PDG Documentation is at http://ezavada.com/pdg/\n"
				 "Node.js Documentation can be found at http://nodejs.org/\n");
		  exit(0);
        }
    }
    argc -= (i-j); // adjust for argument(s) removed
    if (needMainJs) {
		argv[argc] = sMainJsStr;
		argc++;
    }
    argv[argc] = 0;  // guard

    // uv_setup_args() won't like our non-contigous argv memory, so make a copy
  char **argv_clean = copy_argv(argc, argv);

  // Hack aroung with the argv pointer. Used for process.title = "blah".
  argv = uv_setup_args(argc, argv_clean);


  // Logic to duplicate argv as Init() modifies arguments
  // that are passed into it.
  char **argv_copy = copy_argv(argc, argv);

    TRACE("calling node::Init()..");
  // This needs to run *before* V8::Initialize()
  // Use copy here as to not modify the original argv:
  node::Init(argc, argv_copy);

    TRACE("calling v8::Initialize()..");
  v8::V8::Initialize();
  {
    v8::Locker locker;
    v8::HandleScope handle_scope;

    // Create the one and only Context.
    v8::Persistent<v8::Context> context = v8::Context::New();
    v8::Context::Scope context_scope(context);

    node::process_symbol = NODE_PSYMBOL("process");
    node::domain_symbol = NODE_PSYMBOL("domain");

      TRACE("calling node::SetupProcessObject()..");
   // Use original argv, as we're just copying values out of it.
    v8::Handle<v8::Object> process_l = node::SetupProcessObject(argc, argv);
      TRACE("calling v8_typed_array::AttachBindings()..");
    v8_typed_array::AttachBindings(context->Global());

	// bypass the usual bootstrap and use ours instead
    pdg::setupThirdPartyMain(process_l);

    // Create all the objects, load modules, do everything.
    // so your next reading stop should be node::Load()!
      TRACE("calling node::Load()..");
    node::Load(process_l);
    
    // ERZ modification to standard node Start(), to support loading pdg modules
      TRACE("calling pdg::installIntoNodeApplication()..");
      pdg::installIntoNodeApplication();

    // All our arguments are loaded. We've evaluated all of the scripts. We
    // might even have created TCP servers. Now we enter the main eventloop. If
    // there are no watchers on the loop (except for the ones that were
    // uv_unref'd) then this function exits. As long as there are active
    // watchers, it blocks.
      TRACE("calling uv_run()..");
    uv_run(uv_default_loop(), UV_RUN_DEFAULT);

      TRACE("calling node::EmitExit()..");
    node::EmitExit(process_l);
      TRACE("calling node::RunAtExit()..");
    node::RunAtExit();

#ifndef NDEBUG
    context.Dispose();
#endif
  }

#ifndef NDEBUG
  // Clean up. Not strictly necessary.
  v8::V8::Dispose();
#endif  // NDEBUG

  // Clean up the copy:
  free(argv_copy);
    TRACEOUT;
  return 0;
}
Пример #15
0
int main(int argc, char *argv[])
{
	char **newargv = uv_setup_args(argc, argv);
	char *server_listen = SERVER_LISTEN;
	int server_port = SERVER_PORT;
	uint8_t *password = (uint8_t *)PASSWORD;
	uint8_t crypt_method = CRYPTO_METHOD;
	char *pid_path = PID_FILE;

	char opt;
	while((opt = getopt(argc, newargv, "l:p:k:f:m:")) != -1) { // not portable to windows
		switch(opt) {
			case 'l':
			    server_listen = optarg;
			    break;
			case 'p':
			    server_port = atoi(optarg);
			    break;
			case 'k':
			    password = (uint8_t *)optarg;
			    break;
			case 'f':
			    pid_path = optarg;
			    break;
			case 'm':
			    if (!strcmp("rc4", optarg))
			    	crypt_method = METHOD_RC4;
			    else if (!strcmp("shadow", optarg))
			    	crypt_method = METHOD_SHADOWCRYPT;
			    break;
			default:
				fprintf(stderr, USAGE, newargv[0]);
				abort();
		}
	}

	FILE *pid_file = fopen(pid_path, "wb");
	if (!pid_file)
		FATAL("fopen failed, %s", strerror(errno));
	fprintf(pid_file, "%d", getpid());
	fclose(pid_file);

	char *process_title = malloc(PROCESS_TITLE_LENGTH); // we do not like waste memory
	if (!process_title)
		FATAL("malloc() failed!");
	snprintf(process_title, PROCESS_TITLE_LENGTH, PROCESS_TITLE, server_port);
	uv_set_process_title(process_title);
	free(process_title);

	LOGI(WELCOME_MESSAGE);

	if (crypt_method == METHOD_SHADOWCRYPT)
		LOGI("Using shadowcrypt crypto");
	else if (crypt_method == METHOD_RC4)
		LOGI("Using RC4 crypto");
	else
		FATAL("Crypto unknown!");

	make_encryptor(NULL, &crypto, crypt_method, password);

	LOGI("Crypto ready");
	
	int n;
	uv_loop_t *loop = uv_default_loop();
	uv_tcp_t listener;

	struct sockaddr_in6 addr = uv_ip6_addr(server_listen, server_port);

	n = uv_tcp_init(loop, &listener);
	if (n)
		SHOW_UV_ERROR_AND_EXIT(loop);

	n = uv_tcp_bind6(&listener, addr);
	if (n)
		SHOW_UV_ERROR_AND_EXIT(loop);

	n = uv_listen((uv_stream_t*)(void *)&listener, 5, connect_cb);
	if (n)
		SHOW_UV_ERROR_AND_EXIT(loop);
	LOGI("Listening on %s:%d", server_listen, server_port);

	#ifndef NDEBUG
	setup_signal_handler(loop);
	#endif /* !NDEBUG */

	return uv_run(loop);
}
Пример #16
0
int codatunnel_fork(int argc, char **argv,
                    const char *tcp_bindaddr,
                    const char *udp_bindaddr,
                    const char *bind_service,
		    int onlytcp)
{
    /*
       Create the Coda tunnel process.  Returns 0 on success, -1 on error.
       Invoked before RPC2_Init() by the Coda client or server.

       tcp_bindaddr is the IP address to be used to bind the TCP listen
       socket to.  This parameter should be NULL on the client as it is
       is expected to initiate new TCP connections.  On the server this
       can be set to "" (empty string) to bind to the wildcard address.

       udp_bindaddr is the IP address to be used to bind the UDP listen
       socket for communicating with legacy clients and servers that are
       not using codatunnel.  This can be set to "" (empty string) to
       bind to the wildcard address.

       bind_service is the port number to use; on the Coda client, this
       may be the value of the variable "masquerade_port" or NULL to
       bind to any available port.  On Coda servers, this is usually
       specified as "codasrv" which is specified as an IANA reserved
       port number in /etc/services.

       onlytcp is a flag.  If non-zero it suppresses use of UDP as fallback.
    */
    int rc, sockfd[2];

    DEBUG("codatunnel_fork(\"%s:%s\", \"%s:%s\", %d)\n",
          tcp_bindaddr, bind_service, udp_bindaddr, bind_service, onlytcp);

    /* codatunnel is enabled when the daemon process is forked */
    codatunnel_enable_codatunnel = 1;


    /* Create socketpair for host-facing UDP communication */
    rc = socketpair(AF_UNIX, SOCK_SEQPACKET, 0, sockfd);
    if (rc < 0) {
        perror("codatunnel_fork: socketpair() failed: ");
        return -1;
    }

    DEBUG("hfsocket_fdpair after socketpair() is: [%d, %d]\n", sockfd[0], sockfd[1]);
    codatunnel_vside_sockfd = sockfd[0];


    /* fork, and then invoke codatunneld */
    rc = fork();
    if (rc < 0) {
        perror("codatunnel_fork: fork() failed: ");
        return -1;
    }

    if (rc > 0) { /* I am the parent. */
        DEBUG("Parent: fork succeeded, child pid is %d\n", rc);
        close(sockfd[1]);
        return 0;  /* this is the only success return */
    }

    /* If I get here, I must be the newborn child */
    DEBUG("Child: codatunneld fork succeeded\n");
    close(sockfd[0]); /* codatunnel_vside_sockfd */


    /* if possible, rename child's command line for "ps ax" */
    if (argc) {
        uv_setup_args(argc, argv);
        uv_set_process_title("codatunneld");
    }

    /* launch the tunnel and never return */
    codatunneld(sockfd[1], tcp_bindaddr, udp_bindaddr, bind_service, onlytcp);
    __builtin_unreachable(); /* should never reach here */
}
Пример #17
0
int main(int argc, char *argv[])
{
	char *server_listen = SERVER_LISTEN;
	int server_port = SERVER_PORT;
	uint8_t *password = (uint8_t *)PASSWORD;
	char *pid_path = PID_FILE;

	char opt;
	while((opt = getopt(argc, argv, "l:p:k:f:")) != -1) { // not portable to windows
		switch(opt) {
			case 'l':
			    server_listen = optarg;
			    break;
			case 'p':
			    server_port = atoi(optarg);
			    break;
			case 'k':
				password = malloc(strlen(optarg + 1));
				strcpy((char *)password, optarg);
			    break;
			case 'f':
			    pid_path = optarg;
			    break;
			default:
				fprintf(stderr, USAGE, argv[0]);
				abort();
		}
	}

	FILE *pid_file = fopen(pid_path, "wb");
	if (!pid_file)
		FATAL("fopen failed, %s", strerror(errno));
	fprintf(pid_file, "%d", getpid());
	fclose(pid_file);

	char *process_title = malloc(PROCESS_TITLE_LENGTH); // we do not like waste memory
	if (!process_title)
		FATAL("malloc() failed!");
	snprintf(process_title, PROCESS_TITLE_LENGTH, PROCESS_TITLE, server_port);
	uv_setup_args(argc, argv);
	uv_set_process_title(process_title);
	free(process_title);

	LOGI(WELCOME_MESSAGE);
	make_tables(password, encrypt_table, decrypt_table);
	LOGI("Encrypt and decrypt table generated");
	
	int n;
	uv_loop_t *loop = uv_default_loop();
	uv_tcp_t listener;

	struct sockaddr_in addr = uv_ip4_addr(server_listen, server_port);

	n = uv_tcp_init(loop, &listener);
	if (n)
		SHOW_UV_ERROR_AND_EXIT(loop);

	n = uv_tcp_bind(&listener, addr);
	if (n)
		SHOW_UV_ERROR_AND_EXIT(loop);

	n = uv_listen((uv_stream_t*)(void *)&listener, 5, connect_cb);
	if (n)
		SHOW_UV_ERROR_AND_EXIT(loop);
	LOGI("Listening on %s:%d", server_listen, server_port);

	#ifndef NDEBUG
	setup_signal_handler(loop);
	#endif /* !NDEBUG */

	return uv_run(loop);
}