mirror of
https://github.com/systemd/systemd.git
synced 2025-01-07 21:18:41 +03:00
commit
50891a20ea
@ -222,24 +222,31 @@ CurlGlue *curl_glue_unref(CurlGlue *g) {
|
||||
|
||||
int curl_glue_new(CurlGlue **glue, sd_event *event) {
|
||||
_cleanup_(curl_glue_unrefp) CurlGlue *g = NULL;
|
||||
_cleanup_(curl_multi_cleanupp) CURL *c = NULL;
|
||||
_cleanup_(sd_event_unrefp) sd_event *e = NULL;
|
||||
int r;
|
||||
|
||||
g = new0(CurlGlue, 1);
|
||||
if (!g)
|
||||
return -ENOMEM;
|
||||
|
||||
if (event)
|
||||
g->event = sd_event_ref(event);
|
||||
e = sd_event_ref(event);
|
||||
else {
|
||||
r = sd_event_default(&g->event);
|
||||
r = sd_event_default(&e);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
g->curl = curl_multi_init();
|
||||
if (!g->curl)
|
||||
c = curl_multi_init();
|
||||
if (!c)
|
||||
return -ENOMEM;
|
||||
|
||||
g = new(CurlGlue, 1);
|
||||
if (!g)
|
||||
return -ENOMEM;
|
||||
|
||||
*g = (CurlGlue) {
|
||||
.event = TAKE_PTR(e),
|
||||
.curl = TAKE_PTR(c),
|
||||
};
|
||||
|
||||
if (curl_multi_setopt(g->curl, CURLMOPT_SOCKETDATA, g) != CURLM_OK)
|
||||
return -EINVAL;
|
||||
|
||||
@ -258,9 +265,8 @@ int curl_glue_new(CurlGlue **glue, sd_event *event) {
|
||||
}
|
||||
|
||||
int curl_glue_make(CURL **ret, const char *url, void *userdata) {
|
||||
_cleanup_(curl_easy_cleanupp) CURL *c = NULL;
|
||||
const char *useragent;
|
||||
CURL *c;
|
||||
int r;
|
||||
|
||||
assert(ret);
|
||||
assert(url);
|
||||
@ -271,33 +277,21 @@ int curl_glue_make(CURL **ret, const char *url, void *userdata) {
|
||||
|
||||
/* curl_easy_setopt(c, CURLOPT_VERBOSE, 1L); */
|
||||
|
||||
if (curl_easy_setopt(c, CURLOPT_URL, url) != CURLE_OK) {
|
||||
r = -EIO;
|
||||
goto fail;
|
||||
}
|
||||
if (curl_easy_setopt(c, CURLOPT_URL, url) != CURLE_OK)
|
||||
return -EIO;
|
||||
|
||||
if (curl_easy_setopt(c, CURLOPT_PRIVATE, userdata) != CURLE_OK) {
|
||||
r = -EIO;
|
||||
goto fail;
|
||||
}
|
||||
if (curl_easy_setopt(c, CURLOPT_PRIVATE, userdata) != CURLE_OK)
|
||||
return -EIO;
|
||||
|
||||
useragent = strjoina(program_invocation_short_name, "/" PACKAGE_VERSION);
|
||||
if (curl_easy_setopt(c, CURLOPT_USERAGENT, useragent) != CURLE_OK) {
|
||||
r = -EIO;
|
||||
goto fail;
|
||||
}
|
||||
if (curl_easy_setopt(c, CURLOPT_USERAGENT, useragent) != CURLE_OK)
|
||||
return -EIO;
|
||||
|
||||
if (curl_easy_setopt(c, CURLOPT_FOLLOWLOCATION, 1L) != CURLE_OK) {
|
||||
r = -EIO;
|
||||
goto fail;
|
||||
}
|
||||
if (curl_easy_setopt(c, CURLOPT_FOLLOWLOCATION, 1L) != CURLE_OK)
|
||||
return -EIO;
|
||||
|
||||
*ret = c;
|
||||
return 0;
|
||||
|
||||
fail:
|
||||
curl_easy_cleanup(c);
|
||||
return r;
|
||||
}
|
||||
|
||||
int curl_glue_add(CurlGlue *g, CURL *c) {
|
||||
|
@ -35,4 +35,5 @@ int curl_header_strdup(const void *contents, size_t sz, const char *field, char
|
||||
int curl_parse_http_time(const char *t, usec_t *ret);
|
||||
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(CURL*, curl_easy_cleanup);
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(CURL*, curl_multi_cleanup);
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(struct curl_slist*, curl_slist_free_all);
|
||||
|
@ -86,16 +86,19 @@ int raw_export_new(
|
||||
|
||||
assert(ret);
|
||||
|
||||
e = new0(RawExport, 1);
|
||||
e = new(RawExport, 1);
|
||||
if (!e)
|
||||
return -ENOMEM;
|
||||
|
||||
e->output_fd = e->input_fd = -1;
|
||||
e->on_finished = on_finished;
|
||||
e->userdata = userdata;
|
||||
*e = (RawExport) {
|
||||
.output_fd = -1,
|
||||
.input_fd = -1,
|
||||
.on_finished = on_finished,
|
||||
.userdata = userdata,
|
||||
.last_percent = (unsigned) -1,
|
||||
};
|
||||
|
||||
RATELIMIT_INIT(e->progress_rate_limit, 100 * USEC_PER_MSEC, 1);
|
||||
e->last_percent = (unsigned) -1;
|
||||
|
||||
if (event)
|
||||
e->event = sd_event_ref(event);
|
||||
|
@ -88,17 +88,20 @@ int tar_export_new(
|
||||
|
||||
assert(ret);
|
||||
|
||||
e = new0(TarExport, 1);
|
||||
e = new(TarExport, 1);
|
||||
if (!e)
|
||||
return -ENOMEM;
|
||||
|
||||
e->output_fd = e->tar_fd = -1;
|
||||
e->on_finished = on_finished;
|
||||
e->userdata = userdata;
|
||||
e->quota_referenced = (uint64_t) -1;
|
||||
*e = (TarExport) {
|
||||
.output_fd = -1,
|
||||
.tar_fd = -1,
|
||||
.on_finished = on_finished,
|
||||
.userdata = userdata,
|
||||
.quota_referenced = (uint64_t) -1,
|
||||
.last_percent = (unsigned) -1,
|
||||
};
|
||||
|
||||
RATELIMIT_INIT(e->progress_rate_limit, 100 * USEC_PER_MSEC, 1);
|
||||
e->last_percent = (unsigned) -1;
|
||||
|
||||
if (event)
|
||||
e->event = sd_event_ref(event);
|
||||
|
@ -94,26 +94,33 @@ int raw_import_new(
|
||||
void *userdata) {
|
||||
|
||||
_cleanup_(raw_import_unrefp) RawImport *i = NULL;
|
||||
_cleanup_free_ char *root = NULL;
|
||||
bool grow;
|
||||
int r;
|
||||
|
||||
assert(ret);
|
||||
|
||||
i = new0(RawImport, 1);
|
||||
root = strdup(image_root ?: "/var/lib/machines");
|
||||
if (!root)
|
||||
return -ENOMEM;
|
||||
|
||||
grow = path_startswith(root, "/var/lib/machines");
|
||||
|
||||
i = new(RawImport, 1);
|
||||
if (!i)
|
||||
return -ENOMEM;
|
||||
|
||||
i->input_fd = i->output_fd = -1;
|
||||
i->on_finished = on_finished;
|
||||
i->userdata = userdata;
|
||||
*i = (RawImport) {
|
||||
.input_fd = -1,
|
||||
.output_fd = -1,
|
||||
.on_finished = on_finished,
|
||||
.userdata = userdata,
|
||||
.last_percent = (unsigned) -1,
|
||||
.image_root = TAKE_PTR(root),
|
||||
.grow_machine_directory = grow,
|
||||
};
|
||||
|
||||
RATELIMIT_INIT(i->progress_rate_limit, 100 * USEC_PER_MSEC, 1);
|
||||
i->last_percent = (unsigned) -1;
|
||||
|
||||
i->image_root = strdup(image_root ?: "/var/lib/machines");
|
||||
if (!i->image_root)
|
||||
return -ENOMEM;
|
||||
|
||||
i->grow_machine_directory = path_startswith(i->image_root, "/var/lib/machines");
|
||||
|
||||
if (event)
|
||||
i->event = sd_event_ref(event);
|
||||
|
@ -101,26 +101,33 @@ int tar_import_new(
|
||||
void *userdata) {
|
||||
|
||||
_cleanup_(tar_import_unrefp) TarImport *i = NULL;
|
||||
_cleanup_free_ char *root = NULL;
|
||||
bool grow;
|
||||
int r;
|
||||
|
||||
assert(ret);
|
||||
|
||||
i = new0(TarImport, 1);
|
||||
root = strdup(image_root ?: "/var/lib/machines");
|
||||
if (!root)
|
||||
return -ENOMEM;
|
||||
|
||||
grow = path_startswith(root, "/var/lib/machines");
|
||||
|
||||
i = new(TarImport, 1);
|
||||
if (!i)
|
||||
return -ENOMEM;
|
||||
|
||||
i->input_fd = i->tar_fd = -1;
|
||||
i->on_finished = on_finished;
|
||||
i->userdata = userdata;
|
||||
*i = (TarImport) {
|
||||
.input_fd = -1,
|
||||
.tar_fd = -1,
|
||||
.on_finished = on_finished,
|
||||
.userdata = userdata,
|
||||
.last_percent = (unsigned) -1,
|
||||
.image_root = TAKE_PTR(root),
|
||||
.grow_machine_directory = grow,
|
||||
};
|
||||
|
||||
RATELIMIT_INIT(i->progress_rate_limit, 100 * USEC_PER_MSEC, 1);
|
||||
i->last_percent = (unsigned) -1;
|
||||
|
||||
i->image_root = strdup(image_root ?: "/var/lib/machines");
|
||||
if (!i->image_root)
|
||||
return -ENOMEM;
|
||||
|
||||
i->grow_machine_directory = path_startswith(i->image_root, "/var/lib/machines");
|
||||
|
||||
if (event)
|
||||
i->event = sd_event_ref(event);
|
||||
|
@ -146,15 +146,17 @@ static int transfer_new(Manager *m, Transfer **ret) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
t = new0(Transfer, 1);
|
||||
t = new(Transfer, 1);
|
||||
if (!t)
|
||||
return -ENOMEM;
|
||||
|
||||
t->type = _TRANSFER_TYPE_INVALID;
|
||||
t->log_fd = -1;
|
||||
t->stdin_fd = -1;
|
||||
t->stdout_fd = -1;
|
||||
t->verify = _IMPORT_VERIFY_INVALID;
|
||||
*t = (Transfer) {
|
||||
.type = _TRANSFER_TYPE_INVALID,
|
||||
.log_fd = -1,
|
||||
.stdin_fd = -1,
|
||||
.stdout_fd = -1,
|
||||
.verify = _IMPORT_VERIFY_INVALID,
|
||||
};
|
||||
|
||||
id = m->current_transfer_id + 1;
|
||||
|
||||
|
@ -537,27 +537,32 @@ static int pull_job_progress_callback(void *userdata, curl_off_t dltotal, curl_o
|
||||
|
||||
int pull_job_new(PullJob **ret, const char *url, CurlGlue *glue, void *userdata) {
|
||||
_cleanup_(pull_job_unrefp) PullJob *j = NULL;
|
||||
_cleanup_free_ char *u = NULL;
|
||||
|
||||
assert(url);
|
||||
assert(glue);
|
||||
assert(ret);
|
||||
|
||||
j = new0(PullJob, 1);
|
||||
u = strdup(url);
|
||||
if (u)
|
||||
return -ENOMEM;
|
||||
|
||||
j = new(PullJob, 1);
|
||||
if (!j)
|
||||
return -ENOMEM;
|
||||
|
||||
j->state = PULL_JOB_INIT;
|
||||
j->disk_fd = -1;
|
||||
j->userdata = userdata;
|
||||
j->glue = glue;
|
||||
j->content_length = (uint64_t) -1;
|
||||
j->start_usec = now(CLOCK_MONOTONIC);
|
||||
j->compressed_max = j->uncompressed_max = 64LLU * 1024LLU * 1024LLU * 1024LLU; /* 64GB safety limit */
|
||||
j->style = VERIFICATION_STYLE_UNSET;
|
||||
|
||||
j->url = strdup(url);
|
||||
if (!j->url)
|
||||
return -ENOMEM;
|
||||
*j = (PullJob) {
|
||||
.state = PULL_JOB_INIT,
|
||||
.disk_fd = -1,
|
||||
.userdata = userdata,
|
||||
.glue = glue,
|
||||
.content_length = (uint64_t) -1,
|
||||
.start_usec = now(CLOCK_MONOTONIC),
|
||||
.compressed_max = 64LLU * 1024LLU * 1024LLU * 1024LLU, /* 64GB safety limit */
|
||||
.uncompressed_max = 64LLU * 1024LLU * 1024LLU * 1024LLU, /* 64GB safety limit */
|
||||
.style = VERIFICATION_STYLE_UNSET,
|
||||
.url = TAKE_PTR(u),
|
||||
};
|
||||
|
||||
*ret = TAKE_PTR(j);
|
||||
|
||||
|
@ -115,36 +115,46 @@ int raw_pull_new(
|
||||
RawPullFinished on_finished,
|
||||
void *userdata) {
|
||||
|
||||
_cleanup_(curl_glue_unrefp) CurlGlue *g = NULL;
|
||||
_cleanup_(sd_event_unrefp) sd_event *e = NULL;
|
||||
_cleanup_(raw_pull_unrefp) RawPull *i = NULL;
|
||||
_cleanup_free_ char *root = NULL;
|
||||
bool grow;
|
||||
int r;
|
||||
|
||||
assert(ret);
|
||||
|
||||
i = new0(RawPull, 1);
|
||||
if (!i)
|
||||
root = strdup(image_root ?: "/var/lib/machines");
|
||||
if (!root)
|
||||
return -ENOMEM;
|
||||
|
||||
i->on_finished = on_finished;
|
||||
i->userdata = userdata;
|
||||
|
||||
i->image_root = strdup(image_root ?: "/var/lib/machines");
|
||||
if (!i->image_root)
|
||||
return -ENOMEM;
|
||||
|
||||
i->grow_machine_directory = path_startswith(i->image_root, "/var/lib/machines");
|
||||
grow = path_startswith(root, "/var/lib/machines");
|
||||
|
||||
if (event)
|
||||
i->event = sd_event_ref(event);
|
||||
e = sd_event_ref(event);
|
||||
else {
|
||||
r = sd_event_default(&i->event);
|
||||
r = sd_event_default(&e);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
r = curl_glue_new(&i->glue, i->event);
|
||||
r = curl_glue_new(&g, e);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
i = new(RawPull, 1);
|
||||
if (!i)
|
||||
return -ENOMEM;
|
||||
|
||||
*i = (RawPull) {
|
||||
.on_finished = on_finished,
|
||||
.userdata = userdata,
|
||||
.image_root = TAKE_PTR(root),
|
||||
.grow_machine_directory = grow,
|
||||
.event = TAKE_PTR(e),
|
||||
.glue = TAKE_PTR(g),
|
||||
};
|
||||
|
||||
i->glue->on_finished = pull_job_curl_on_finished;
|
||||
i->glue->userdata = i;
|
||||
|
||||
|
@ -108,36 +108,46 @@ int tar_pull_new(
|
||||
TarPullFinished on_finished,
|
||||
void *userdata) {
|
||||
|
||||
_cleanup_(curl_glue_unrefp) CurlGlue *g = NULL;
|
||||
_cleanup_(sd_event_unrefp) sd_event *e = NULL;
|
||||
_cleanup_(tar_pull_unrefp) TarPull *i = NULL;
|
||||
_cleanup_free_ char *root = NULL;
|
||||
bool grow;
|
||||
int r;
|
||||
|
||||
assert(ret);
|
||||
|
||||
i = new0(TarPull, 1);
|
||||
if (!i)
|
||||
root = strdup(image_root ?: "/var/lib/machines");
|
||||
if (!root)
|
||||
return -ENOMEM;
|
||||
|
||||
i->on_finished = on_finished;
|
||||
i->userdata = userdata;
|
||||
|
||||
i->image_root = strdup(image_root ?: "/var/lib/machines");
|
||||
if (!i->image_root)
|
||||
return -ENOMEM;
|
||||
|
||||
i->grow_machine_directory = path_startswith(i->image_root, "/var/lib/machines");
|
||||
grow = path_startswith(root, "/var/lib/machines");
|
||||
|
||||
if (event)
|
||||
i->event = sd_event_ref(event);
|
||||
e = sd_event_ref(event);
|
||||
else {
|
||||
r = sd_event_default(&i->event);
|
||||
r = sd_event_default(&e);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
r = curl_glue_new(&i->glue, i->event);
|
||||
r = curl_glue_new(&g, e);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
i = new(TarPull, 1);
|
||||
if (!i)
|
||||
return -ENOMEM;
|
||||
|
||||
*i = (TarPull) {
|
||||
.on_finished = on_finished,
|
||||
.userdata = userdata,
|
||||
.image_root = TAKE_PTR(root),
|
||||
.grow_machine_directory = grow,
|
||||
.event = TAKE_PTR(e),
|
||||
.glue = TAKE_PTR(g),
|
||||
};
|
||||
|
||||
i->glue->on_finished = pull_job_curl_on_finished;
|
||||
i->glue->userdata = i;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user