@@ -128,6 +128,45 @@ WorkshopOperator::InitControl()
128128 return std::move (control_child);
129129}
130130
131+ static void
132+ PrepareChildProcess (AllocatorPtr alloc,
133+ PreparedChildProcess &p, const TranslateResponse &response,
134+ FdHolder &close_fds)
135+ {
136+ if (response.status != HttpStatus{}) {
137+ if (response.message != nullptr )
138+ throw FmtRuntimeError (" Status {} from translation server: {}" ,
139+ static_cast <unsigned >(response.status ),
140+ response.message );
141+
142+ throw FmtRuntimeError (" Status {} from translation server" ,
143+ static_cast <unsigned >(response.status ));
144+ }
145+
146+ if (response.execute_options == nullptr ||
147+ response.execute_options ->execute == nullptr )
148+ throw std::runtime_error (" No EXECUTE from translation server" );
149+
150+ const auto &options = *response.execute_options ;
151+
152+ if (options.child_options .uid_gid .IsEmpty () && !debug_mode)
153+ throw std::runtime_error (" No UID_GID from translation server" );
154+
155+
156+ p.args .push_back (alloc.Dup (options.execute ));
157+
158+ for (const char *arg : options.args ) {
159+ if (p.args .size () >= 4096 )
160+ throw std::runtime_error (" Too many APPEND packets from translation server" );
161+
162+ p.args .push_back (alloc.Dup (arg));
163+ }
164+
165+ options.child_options .CopyTo (p, close_fds);
166+
167+ p.no_new_privs = true ;
168+ }
169+
131170static void
132171PrepareChildProcess (PreparedChildProcess &p, const char *plan_name,
133172 const Plan &plan,
@@ -151,7 +190,6 @@ PrepareChildProcess(PreparedChildProcess &p, const char *plan_name,
151190 p.umask = plan.umask ;
152191 p.rlimits = plan.rlimits ;
153192 p.priority = plan.priority ;
154- p.sched_idle = plan.sched_idle ;
155193 p.ioprio_idle = plan.ioprio_idle ;
156194 p.ns .enable_network = plan.private_network ;
157195
@@ -460,51 +498,21 @@ DoSpawn(SpawnService &service, AllocatorPtr alloc,
460498 FileDescriptor stderr_w,
461499 const TranslateResponse &response)
462500{
463- if (response.status != HttpStatus{}) {
464- if (response.message != nullptr )
465- throw FmtRuntimeError (" Status {} from translation server: {}" ,
466- static_cast <unsigned >(response.status ),
467- response.message );
468-
469- throw FmtRuntimeError (" Status {} from translation server" ,
470- static_cast <unsigned >(response.status ));
471- }
472-
473- if (response.execute_options == nullptr ||
474- response.execute_options ->execute == nullptr )
475- throw std::runtime_error (" No EXECUTE from translation server" );
476-
477- const auto &options = *response.execute_options ;
478-
479- if (options.child_options .uid_gid .IsEmpty () && !debug_mode)
480- throw std::runtime_error (" No UID_GID from translation server" );
481-
482501 FdHolder close_fds;
483502 PreparedChildProcess p;
484- p. args . push_back (alloc. Dup (options. execute ) );
503+ PrepareChildProcess (alloc, p, response, close_fds );
485504
486505 if (stderr_w.IsDefined ())
487506 p.stderr_fd = p.stdout_fd = stderr_w;
488507
489508 UniqueSocketDescriptor return_pidfd;
490509 std::tie (return_pidfd, p.return_pidfd ) = CreateSocketPair (SOCK_SEQPACKET);
491510
492- for (const char *arg : options.args ) {
493- if (p.args .size () >= 4096 )
494- throw std::runtime_error (" Too many APPEND packets from translation server" );
495-
496- p.args .push_back (alloc.Dup (arg));
497- }
498-
499- options.child_options .CopyTo (p, close_fds);
500-
501511 if (p.umask == -1 )
502512 p.umask = plan.umask ;
503513
504514 p.priority = plan.priority ;
505515 p.sched_idle = plan.sched_idle ;
506- p.ioprio_idle = plan.ioprio_idle ;
507- p.no_new_privs = true ;
508516
509517 /* use the same per-plan cgroup as the orignal job process */
510518
0 commit comments