/***
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 "sd-id128.h"
#include "alloc-util.h"
#include "dirent-util.h"
#include "fd-util.h"
#include "journal-def.h"
#include "journal-file.h"
#include "journal-vacuum.h"
#include "parse-util.h"
#include "string-util.h"
#include "util.h"
#include "xattr-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(
int fd,
const char *fn,
unsigned long long *realtime) {
/* 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... */
}
}
ssize_t n;
if (fd < 0) {
/* Maybe failed due to O_NOATIME and lack of privileges? */
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;
return 0;
if (max_retention_usec > 0) {
else
}
if (!d)
return -errno;
_cleanup_free_ char *p = NULL;
bool have_seqnum;
size_t q;
continue;
}
continue;
/* Vacuum archived files. Active files are
* left around */
if (q < 1 + 32 + 1 + 16 + 1 + 16 + 8) {
continue;
}
continue;
}
if (!p) {
r = -ENOMEM;
goto finish;
}
continue;
}
continue;
}
have_seqnum = true;
unsigned long long tmp;
/* Vacuum corrupted files */
if (q < 1 + 16 + 1 + 16 + 8 + 1) {
n_active_files ++;
continue;
}
n_active_files ++;
continue;
}
if (!p) {
r = -ENOMEM;
goto finish;
}
n_active_files ++;
continue;
}
have_seqnum = false;
} else {
/* We do not vacuum unknown files! */
continue;
}
r = journal_file_empty(dirfd(d), p);
if (r < 0) {
log_debug_errno(r, "Failed check if %s is empty, ignoring: %m", p);
continue;
}
if (r > 0) {
/* Always vacuum empty non-online files. */
"Deleted empty archived journal %s/%s (%s).", directory, p, format_bytes(sbytes, sizeof(sbytes), size));
continue;
}
r = -ENOMEM;
goto finish;
}
n_list ++;
p = NULL;
}
for (i = 0; i < n_list; i++) {
unsigned left;
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);
}
r = 0;
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;
}