Skip to content

Commit 6b22a3e

Browse files
committed
translation/Response: move fields to struct ExecuteOptions
1 parent 378d3ae commit 6b22a3e

File tree

3 files changed

+30
-21
lines changed

3 files changed

+30
-21
lines changed

src/cron/Workplace.cxx

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "AllocatorPtr.hxx"
1313
#include "translation/CronGlue.hxx"
1414
#include "translation/Response.hxx"
15+
#include "translation/ExecuteOptions.hxx"
1516
#include "lib/fmt/RuntimeError.hxx"
1617
#include "spawn/Prepared.hxx"
1718
#include "spawn/Interface.hxx"
@@ -175,10 +176,9 @@ MakeSpawnOperator(EventLoop &event_loop, SpawnService &spawn_service,
175176
LazyDomainLogger &logger,
176177
AllocatorPtr alloc,
177178
const CronJob &job, const char *command,
178-
const TranslateResponse &response)
179+
const ExecuteOptions &options,
180+
const char *_site)
179181
{
180-
assert(response.status == HttpStatus{});
181-
182182
/* prepare the child process */
183183

184184
FdHolder close_fds;
@@ -190,33 +190,33 @@ MakeSpawnOperator(EventLoop &event_loop, SpawnService &spawn_service,
190190
p.args.push_back(command);
191191
}
192192

193-
if (response.child_options.uid_gid.IsEmpty() && !debug_mode)
193+
if (options.child_options.uid_gid.IsEmpty() && !debug_mode)
194194
throw std::runtime_error("No UID_GID from translation server");
195195

196196
if (command == nullptr) {
197-
if (response.execute == nullptr)
197+
if (options.execute == nullptr)
198198
throw std::runtime_error("No EXECUTE from translation server");
199199

200-
p.args.push_back(response.execute);
200+
p.args.push_back(options.execute);
201201

202-
for (const char *arg : response.args) {
202+
for (const char *arg : options.args) {
203203
if (p.args.size() >= 4096)
204204
throw std::runtime_error("Too many APPEND packets from translation server");
205205

206206
p.args.push_back(arg);
207207
}
208208
}
209209

210-
response.child_options.CopyTo(p, close_fds);
210+
options.child_options.CopyTo(p, close_fds);
211211

212212
if (p.cgroup != nullptr && p.cgroup->name != nullptr)
213213
p.cgroup_session = job.id.c_str();
214214

215215
/* create operator object */
216216

217217
std::string_view site = job.account_id;
218-
if (response.site != nullptr)
219-
site = response.site;
218+
if (_site != nullptr)
219+
site = _site;
220220

221221
auto o = std::make_unique<CronSpawnOperator>(logger);
222222
co_await o->Spawn(event_loop, spawn_service, alloc,
@@ -270,23 +270,28 @@ CronWorkplace::Running::MakeOperator(SocketAddress translation_socket,
270270
static_cast<unsigned>(response.status));
271271
}
272272

273+
if (response.execute_options == nullptr)
274+
throw std::runtime_error{"No spawner options from translation server"};
275+
276+
const auto &options = *response.execute_options;
277+
273278
if (response.site != nullptr)
274279
site = response.site;
275280

276-
if (!response.child_options.tag.empty())
277-
tag = response.child_options.tag;
281+
if (!options.child_options.tag.empty())
282+
tag = options.child_options.tag;
278283

279284
if (response.timeout.count() > 0)
280285
timeout_event.Schedule(response.timeout);
281286

282-
child_options = {ShallowCopy{}, response.child_options};
287+
child_options = {ShallowCopy{}, options.child_options};
283288

284289
if (IsURL(job.command))
285290
co_return co_await MakeCurlOperator(GetEventLoop(),
286291
workplace.GetSpawnService(),
287292
job,
288293
job.command.c_str(),
289-
response.child_options);
294+
options.child_options);
290295
else
291296
co_return co_await MakeSpawnOperator(GetEventLoop(),
292297
workplace.GetSpawnService(),
@@ -295,7 +300,7 @@ CronWorkplace::Running::MakeOperator(SocketAddress translation_socket,
295300
alloc,
296301
job,
297302
uri == nullptr ? job.command.c_str() : nullptr,
298-
response);
303+
options, response.site);
299304
}
300305

301306
inline Co::InvokeTask

src/workshop/Operator.cxx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "Job.hxx"
1212
#include "LogBridge.hxx"
1313
#include "translation/Response.hxx"
14+
#include "translation/ExecuteOptions.hxx"
1415
#include "translation/SpawnClient.hxx"
1516
#include "lib/fmt/RuntimeError.hxx"
1617
#include "spawn/Interface.hxx"
@@ -275,30 +276,33 @@ DoSpawn(SpawnService &service, AllocatorPtr alloc,
275276
static_cast<unsigned>(response.status));
276277
}
277278

278-
if (response.execute == nullptr)
279+
if (response.execute_options == nullptr ||
280+
response.execute_options->execute == nullptr)
279281
throw std::runtime_error("No EXECUTE from translation server");
280282

281-
if (response.child_options.uid_gid.IsEmpty())
283+
const auto &options = *response.execute_options;
284+
285+
if (options.child_options.uid_gid.IsEmpty())
282286
throw std::runtime_error("No UID_GID from translation server");
283287

284288
FdHolder close_fds;
285289
PreparedChildProcess p;
286-
p.args.push_back(alloc.Dup(response.execute));
290+
p.args.push_back(alloc.Dup(options.execute));
287291

288292
if (stderr_w.IsDefined())
289293
p.stderr_fd = p.stdout_fd = stderr_w;
290294

291295
UniqueSocketDescriptor return_pidfd;
292296
std::tie(return_pidfd, p.return_pidfd) = CreateSocketPair(SOCK_SEQPACKET);
293297

294-
for (const char *arg : response.args) {
298+
for (const char *arg : options.args) {
295299
if (p.args.size() >= 4096)
296300
throw std::runtime_error("Too many APPEND packets from translation server");
297301

298302
p.args.push_back(alloc.Dup(arg));
299303
}
300304

301-
response.child_options.CopyTo(p, close_fds);
305+
options.child_options.CopyTo(p, close_fds);
302306

303307
if (p.umask == -1)
304308
p.umask = plan.umask;

0 commit comments

Comments
 (0)