MCPcopy Create free account
hub / github.com/antirez/ds4 / web_spawn_chrome

Function web_spawn_chrome

ds4_web.c:1023–1103  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1021#endif
1022
1023static bool web_spawn_chrome(ds4_web *web, char *err, size_t err_len) {
1024 if (!web_mkdir_p(web->profile_dir)) {
1025 web_set_err(err, err_len, "failed to create Chrome profile dir %s: %s",
1026 web->profile_dir, strerror(errno));
1027 return false;
1028 }
1029 char *exe = web_chrome_executable();
1030#ifdef __APPLE__
1031 const char *mac_app_name = web_macos_chrome_app_name();
1032 bool launched_via_open = mac_app_name != NULL && access("/usr/bin/open", X_OK) == 0;
1033#else
1034 bool launched_via_open = false;
1035#endif
1036 char port_arg[64], profile_arg[PATH_MAX + 64];
1037 snprintf(port_arg, sizeof(port_arg), "--remote-debugging-port=%d", web->port);
1038 snprintf(profile_arg, sizeof(profile_arg), "--user-data-dir=%s", web->profile_dir);
1039 pid_t pid = fork();
1040 if (pid < 0) {
1041 web_set_err(err, err_len, "failed to fork Chrome: %s", strerror(errno));
1042 free(exe);
1043 return false;
1044 }
1045 if (pid == 0) {
1046 int nullfd = open("/dev/null", O_RDWR);
1047 if (nullfd >= 0) {
1048 dup2(nullfd, STDOUT_FILENO);
1049 dup2(nullfd, STDERR_FILENO);
1050 if (nullfd > 2) close(nullfd);
1051 }
1052#ifdef __APPLE__
1053 if (launched_via_open) {
1054 execlp("/usr/bin/open", "open", "-g", "-na", mac_app_name,
1055 "--args", port_arg, "--remote-allow-origins=*",
1056 profile_arg, "--no-first-run", "--no-default-browser-check",
1057 "--disable-sync", "--use-mock-keychain", "--password-store=basic",
1058 "--mute-audio", "about:blank", (char *)NULL);
1059 } else {
1060 execlp(exe, exe, port_arg, "--remote-allow-origins=*",
1061 profile_arg, "--no-first-run", "--no-default-browser-check",
1062 "--disable-sync", "--use-mock-keychain", "--password-store=basic",
1063 "--mute-audio", "about:blank", (char *)NULL);
1064 }
1065#else
1066 if (geteuid() == 0) {
1067 execlp(exe, exe, port_arg, "--remote-allow-origins=*",
1068 profile_arg, "--no-first-run", "--no-default-browser-check",
1069 "--disable-sync", "--password-store=basic", "--no-sandbox",
1070 "--mute-audio", "about:blank", (char *)NULL);
1071 } else {
1072 execlp(exe, exe, port_arg, "--remote-allow-origins=*",
1073 profile_arg, "--no-first-run", "--no-default-browser-check",
1074 "--disable-sync", "--password-store=basic",
1075 "--mute-audio", "about:blank", (char *)NULL);
1076 }
1077#endif
1078 _exit(127);
1079 }
1080 free(exe);

Callers 1

web_ensure_browserFunction · 0.85

Calls 8

web_mkdir_pFunction · 0.85
web_set_errFunction · 0.85
web_chrome_executableFunction · 0.85
web_set_cancel_errFunction · 0.85
web_cdp_aliveFunction · 0.85
web_logFunction · 0.85
web_sleep_msFunction · 0.85

Tested by

no test coverage detected