journal-gatewayd: factor out opening of temp file
Also use our own mkostemp wrapper, which tries to use O_TMPFILE.
This commit is contained in:
@@ -121,6 +121,26 @@ static int open_journal(RequestMeta *m) {
|
|||||||
return sd_journal_open(&m->journal, SD_JOURNAL_LOCAL_ONLY|SD_JOURNAL_SYSTEM);
|
return sd_journal_open(&m->journal, SD_JOURNAL_LOCAL_ONLY|SD_JOURNAL_SYSTEM);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int request_meta_ensure_tmp(RequestMeta *m) {
|
||||||
|
if (m->tmp)
|
||||||
|
rewind(m->tmp);
|
||||||
|
else {
|
||||||
|
int fd;
|
||||||
|
|
||||||
|
fd = open_tmpfile("/tmp", O_RDWR|O_CLOEXEC);
|
||||||
|
if (fd < 0)
|
||||||
|
return fd;
|
||||||
|
|
||||||
|
m->tmp = fdopen(fd, "rw");
|
||||||
|
if (!m->tmp) {
|
||||||
|
safe_close(fd);
|
||||||
|
return -errno;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static ssize_t request_reader_entries(
|
static ssize_t request_reader_entries(
|
||||||
void *cls,
|
void *cls,
|
||||||
uint64_t pos,
|
uint64_t pos,
|
||||||
@@ -194,14 +214,10 @@ static ssize_t request_reader_entries(
|
|||||||
|
|
||||||
m->n_skip = 0;
|
m->n_skip = 0;
|
||||||
|
|
||||||
if (m->tmp)
|
r = request_meta_ensure_tmp(m);
|
||||||
rewind(m->tmp);
|
if (r < 0) {
|
||||||
else {
|
log_error_errno(r, "Failed to create temporary file: %m");
|
||||||
m->tmp = tmpfile();
|
return MHD_CONTENT_READER_END_WITH_ERROR;
|
||||||
if (!m->tmp) {
|
|
||||||
log_error_errno(errno, "Failed to create temporary file: %m");
|
|
||||||
return MHD_CONTENT_READER_END_WITH_ERROR;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
r = output_journal(m->tmp, m->journal, m->mode, 0, OUTPUT_FULL_WIDTH, NULL);
|
r = output_journal(m->tmp, m->journal, m->mode, 0, OUTPUT_FULL_WIDTH, NULL);
|
||||||
@@ -555,14 +571,10 @@ static ssize_t request_reader_fields(
|
|||||||
if (m->n_fields_set)
|
if (m->n_fields_set)
|
||||||
m->n_fields -= 1;
|
m->n_fields -= 1;
|
||||||
|
|
||||||
if (m->tmp)
|
r = request_meta_ensure_tmp(m);
|
||||||
rewind(m->tmp);
|
if (r < 0) {
|
||||||
else {
|
log_error_errno(r, "Failed to create temporary file: %m");
|
||||||
m->tmp = tmpfile();
|
return MHD_CONTENT_READER_END_WITH_ERROR;
|
||||||
if (!m->tmp) {
|
|
||||||
log_error_errno(errno, "Failed to create temporary file: %m");
|
|
||||||
return MHD_CONTENT_READER_END_WITH_ERROR;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
r = output_field(m->tmp, m->mode, d, l);
|
r = output_field(m->tmp, m->mode, d, l);
|
||||||
|
|||||||
Reference in New Issue
Block a user