| 1126 | |
| 1127 | #ifdef _WIN32 |
| 1128 | static bool bootstrap_production_spawn(void *context, |
| 1129 | const cbm_daemon_bootstrap_launch_spec_t *spec) { |
| 1130 | bootstrap_production_context_t *production = context; |
| 1131 | if (production) { |
| 1132 | production->spawn_error = ERROR_SUCCESS; |
| 1133 | } |
| 1134 | if (!spec || !spec->detached || spec->inherit_standard_handles || spec->use_shell) { |
| 1135 | if (production) { |
| 1136 | production->spawn_error = ERROR_INVALID_PARAMETER; |
| 1137 | } |
| 1138 | return false; |
| 1139 | } |
| 1140 | char command_line[BOOTSTRAP_PATH_CAP * 2]; |
| 1141 | if (!cbm_build_win_cmdline(command_line, sizeof(command_line), spec->argv)) { |
| 1142 | if (production) { |
| 1143 | production->spawn_error = ERROR_INVALID_PARAMETER; |
| 1144 | } |
| 1145 | return false; |
| 1146 | } |
| 1147 | wchar_t *application = cbm_utf8_to_wide(spec->executable_path); |
| 1148 | wchar_t *command = cbm_utf8_to_wide(command_line); |
| 1149 | if (!application || !command) { |
| 1150 | if (production) { |
| 1151 | production->spawn_error = ERROR_NOT_ENOUGH_MEMORY; |
| 1152 | } |
| 1153 | free(application); |
| 1154 | free(command); |
| 1155 | return false; |
| 1156 | } |
| 1157 | STARTUPINFOW startup; |
| 1158 | PROCESS_INFORMATION child; |
| 1159 | ZeroMemory(&startup, sizeof(startup)); |
| 1160 | ZeroMemory(&child, sizeof(child)); |
| 1161 | startup.cb = sizeof(startup); |
| 1162 | DWORD flags = DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP | CREATE_NO_WINDOW; |
| 1163 | /* A managed frontend payload is intentionally contained in the permanent |
| 1164 | * launcher's kill-on-close job. The account daemon outlives that one |
| 1165 | * frontend and therefore uses breakaway when the containing job explicitly |
| 1166 | * permits it. Do not request breakaway from an unrelated restrictive job: |
| 1167 | * CreateProcess would fail and regress portable/package-manager payloads. */ |
| 1168 | BOOL in_job = FALSE; |
| 1169 | JOBOBJECT_EXTENDED_LIMIT_INFORMATION job_limits; |
| 1170 | memset(&job_limits, 0, sizeof(job_limits)); |
| 1171 | if (IsProcessInJob(GetCurrentProcess(), NULL, &in_job) && in_job && |
| 1172 | QueryInformationJobObject(NULL, JobObjectExtendedLimitInformation, &job_limits, |
| 1173 | sizeof(job_limits), NULL) && |
| 1174 | (job_limits.BasicLimitInformation.LimitFlags & |
| 1175 | (JOB_OBJECT_LIMIT_BREAKAWAY_OK | JOB_OBJECT_LIMIT_SILENT_BREAKAWAY_OK)) != 0) { |
| 1176 | flags |= CREATE_BREAKAWAY_FROM_JOB; |
| 1177 | } |
| 1178 | BOOL created = CreateProcessW(application, command, NULL, NULL, FALSE, flags, NULL, NULL, |
| 1179 | &startup, &child); |
| 1180 | DWORD spawn_error = created ? ERROR_SUCCESS : GetLastError(); |
| 1181 | free(application); |
| 1182 | free(command); |
| 1183 | if (production) { |
| 1184 | production->spawn_error = spawn_error; |
| 1185 | } |
nothing calls this directly
no test coverage detected