MCPcopy Create free account
hub / github.com/arvidn/libtorrent / async_run

Function async_run

test/setup_transfer.cpp:540–603  ·  view source on GitHub ↗

returns 0 on failure, otherwise pid

Source from the content-addressed store, hash-verified

538
539// returns 0 on failure, otherwise pid
540pid_type async_run(char const* cmdline)
541{
542#ifdef _WIN32
543 char buf[2048];
544 std::snprintf(buf, sizeof(buf), "%s", cmdline);
545
546 std::printf("CreateProcess %s\n", buf);
547 PROCESS_INFORMATION pi;
548 STARTUPINFOA startup{};
549 startup.cb = sizeof(startup);
550 startup.dwFlags = STARTF_USESTDHANDLES;
551 startup.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
552 startup.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
553 startup.hStdError = GetStdHandle(STD_OUTPUT_HANDLE);
554 int const ret = CreateProcessA(nullptr, buf, nullptr, nullptr, TRUE
555 , 0, nullptr, nullptr, &startup, &pi);
556
557 if (ret == 0)
558 {
559 int const error = GetLastError();
560 std::printf("ERROR: (%d) %s\n", error, error_code(error, system_category()).message().c_str());
561 return 0;
562 }
563
564 DWORD len = sizeof(buf);
565 if (QueryFullProcessImageNameA(pi.hProcess, PROCESS_NAME_NATIVE, buf, &len) == 0)
566 {
567 int const error = GetLastError();
568 std::printf("ERROR: QueryFullProcessImageName (%d) %s\n", error
569 , error_code(error, system_category()).message().c_str());
570 }
571 else
572 {
573 std::printf("launched: %s\n", buf);
574 }
575 return pi.dwProcessId;
576#else
577 pid_type p;
578 char arg_storage[4096];
579 char* argp = arg_storage;
580 std::vector<char*> argv;
581 argv.push_back(argp);
582 for (char const* in = cmdline; *in != '\0'; ++in)
583 {
584 if (*in != ' ')
585 {
586 *argp++ = *in;
587 continue;
588 }
589 *argp++ = '\0';
590 argv.push_back(argp);
591 }
592 *argp = '\0';
593 argv.push_back(nullptr);
594
595 int ret = posix_spawnp(&p, argv[0], nullptr, nullptr, &argv[0], nullptr);
596 if (ret != 0)
597 {

Callers 2

start_proxyFunction · 0.85
start_web_serverFunction · 0.85

Calls 2

push_backMethod · 0.80
messageMethod · 0.45

Tested by

no test coverage detected