journal-vacuum.c revision 56f64d95763a799ba4475daf44d8e9f72a1bd474
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2011 Lennart Poettering
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <fcntl.h>
#include <unistd.h>
#include "journal-def.h"
#include "journal-file.h"
#include "journal-vacuum.h"
#include "sd-id128.h"
#include "util.h"
struct vacuum_info {
char *filename;
bool have_seqnum;
};
const struct vacuum_info *a, *b;
a = _a;
b = _b;
if (a->have_seqnum && b->have_seqnum &&
return -1;
return 1;
else
return 0;
}
return -1;
return 1;
else if (a->have_seqnum && b->have_seqnum)
else
}
static void patch_realtime(
const char *dir,
const char *fn,
unsigned long long *realtime) {
usec_t x;
/* The timestamp was determined by the file name, but let's
* see if the file might actually be older than the file name
* suggested... */
if (x > 0 && x != USEC_INFINITY && x < *realtime)
*realtime = x;
if (x > 0 && x != USEC_INFINITY && x < *realtime)
*realtime = x;
if (x > 0 && x != USEC_INFINITY && x < *realtime)
*realtime = x;
/* Let's read the original creation time, if possible. Ideally
* we'd just query the creation time the FS might provide, but
* unfortunately there's currently no sane API to query
* it. Hence let's implement this manually... */
/* Unfortunately there is is not fgetxattrat(), so we need to
* go via path here. :-( */
if (!path)
return;
}
}
_cleanup_close_ int fd;
ssize_t n;
if (fd < 0)
return -errno;
return -errno;
/* If an offline file doesn't even have a header we consider it empty */
return 1;
/* If the number of entries is empty, we consider it empty, too */
if (n < 0)
return -errno;
if (n != sizeof(n_entries))
return -EIO;
}
const char *directory,
bool verbose) {
int r = 0;
unsigned n_list = 0, i;
size_t n_allocated = 0;
usec_t retention_limit = 0;
char sbytes[FORMAT_BYTES_MAX];
if (max_use <= 0 && max_retention_usec <= 0)
return 0;
if (max_retention_usec > 0) {
else
}
if (!d)
return -errno;
for (;;) {
size_t q;
char *p;
bool have_seqnum;
errno = 0;
r = -errno;
goto finish;
}
if (!de)
break;
continue;
continue;
/* Vacuum archived files */
if (q < 1 + 32 + 1 + 16 + 1 + 16 + 8)
continue;
continue;
if (!p) {
r = -ENOMEM;
goto finish;
}
free(p);
continue;
}
free(p);
continue;
}
have_seqnum = true;
unsigned long long tmp;
/* Vacuum corrupted files */
if (q < 1 + 16 + 1 + 16 + 8 + 1)
continue;
continue;
if (!p) {
r = -ENOMEM;
goto finish;
}
free(p);
continue;
}
have_seqnum = false;
} else
/* We do not vacuum active files or unknown files! */
continue;
if (journal_file_empty(dirfd(d), p)) {
/* Always vacuum empty non-online files. */
log_full(verbose ? LOG_INFO : LOG_DEBUG, "Deleted empty archived journal %s/%s (%s).", directory, p, format_bytes(sbytes, sizeof(sbytes), size));
free(p);
continue;
}
free(p);
r = -ENOMEM;
goto finish;
}
n_list ++;
}
for (i = 0; i < n_list; i++) {
break;
log_full(verbose ? LOG_INFO : LOG_DEBUG, "Deleted archived journal %s/%s (%s).", directory, list[i].filename, format_bytes(sbytes, sizeof(sbytes), list[i].usage));
else
sum = 0;
log_warning_errno(errno, "Failed to delete archived journal %s/%s: %m", directory, list[i].filename);
}
for (i = 0; i < n_list; i++)
log_full(verbose ? LOG_INFO : LOG_DEBUG, "Vacuuming done, freed %s of archived journals on disk.", format_bytes(sbytes, sizeof(sbytes), freed));
return r;
}