]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/journal/coredump.c
util-lib: move a number of fs operations into fs-util.[ch]
[thirdparty/systemd.git] / src / journal / coredump.c
index 62483a2a05e9a9d754f17ff39b751d262ca5f3ed..1756a823a92d0f0df5f0cf1414cddc4a3fed937f 100644 (file)
 ***/
 
 #include <errno.h>
-#include <unistd.h>
 #include <stdio.h>
 #include <sys/prctl.h>
 #include <sys/xattr.h>
+#include <unistd.h>
 
 #ifdef HAVE_ELFUTILS
 #  include <dwarf.h>
 
 #include "sd-journal.h"
 #include "sd-login.h"
-#include "log.h"
-#include "util.h"
-#include "fileio.h"
-#include "strv.h"
-#include "macro.h"
-#include "mkdir.h"
-#include "special.h"
+
+#include "acl-util.h"
+#include "capability.h"
 #include "cgroup-util.h"
+#include "compress.h"
 #include "conf-parser.h"
 #include "copy.h"
-#include "stacktrace.h"
-#include "compress.h"
-#include "acl-util.h"
-#include "capability.h"
-#include "journald-native.h"
 #include "coredump-vacuum.h"
+#include "dirent-util.h"
+#include "escape.h"
+#include "fd-util.h"
+#include "fileio.h"
+#include "fs-util.h"
+#include "journald-native.h"
+#include "log.h"
+#include "macro.h"
+#include "mkdir.h"
+#include "parse-util.h"
 #include "process-util.h"
+#include "special.h"
+#include "stacktrace.h"
+#include "string-util.h"
+#include "strv.h"
+#include "user-util.h"
+#include "util.h"
 
 /* The maximum size up to which we process coredumps */
-#define PROCESS_SIZE_MAX ((off_t) (2LLU*1024LLU*1024LLU*1024LLU))
+#define PROCESS_SIZE_MAX ((uint64_t) (2LLU*1024LLU*1024LLU*1024LLU))
 
 /* The maximum size up to which we leave the coredump around on
  * disk */
@@ -97,21 +105,21 @@ static DEFINE_CONFIG_PARSE_ENUM(config_parse_coredump_storage, coredump_storage,
 
 static CoredumpStorage arg_storage = COREDUMP_STORAGE_EXTERNAL;
 static bool arg_compress = true;
-static off_t arg_process_size_max = PROCESS_SIZE_MAX;
-static off_t arg_external_size_max = EXTERNAL_SIZE_MAX;
+static uint64_t arg_process_size_max = PROCESS_SIZE_MAX;
+static uint64_t arg_external_size_max = EXTERNAL_SIZE_MAX;
 static size_t arg_journal_size_max = JOURNAL_SIZE_MAX;
-static off_t arg_keep_free = (off_t) -1;
-static off_t arg_max_use = (off_t) -1;
+static uint64_t arg_keep_free = (uint64_t) -1;
+static uint64_t arg_max_use = (uint64_t) -1;
 
 static int parse_config(void) {
         static const ConfigTableItem items[] = {
                 { "Coredump", "Storage",          config_parse_coredump_storage,  0, &arg_storage           },
                 { "Coredump", "Compress",         config_parse_bool,              0, &arg_compress          },
-                { "Coredump", "ProcessSizeMax",   config_parse_iec_off,           0, &arg_process_size_max  },
-                { "Coredump", "ExternalSizeMax",  config_parse_iec_off,           0, &arg_external_size_max },
+                { "Coredump", "ProcessSizeMax",   config_parse_iec_uint64,        0, &arg_process_size_max  },
+                { "Coredump", "ExternalSizeMax",  config_parse_iec_uint64,        0, &arg_external_size_max },
                 { "Coredump", "JournalSizeMax",   config_parse_iec_size,          0, &arg_journal_size_max  },
-                { "Coredump", "KeepFree",         config_parse_iec_off,           0, &arg_keep_free         },
-                { "Coredump", "MaxUse",           config_parse_iec_off,           0, &arg_max_use           },
+                { "Coredump", "KeepFree",         config_parse_iec_uint64,        0, &arg_keep_free         },
+                { "Coredump", "MaxUse",           config_parse_iec_uint64,        0, &arg_max_use           },
                 {}
         };
 
@@ -224,7 +232,7 @@ static int fix_permissions(
         return 0;
 }
 
-static int maybe_remove_external_coredump(const char *filename, off_t size) {
+static int maybe_remove_external_coredump(const char *filename, uint64_t size) {
 
         /* Returns 1 if might remove, 0 if will not remove, < 0 on error. */
 
@@ -285,7 +293,7 @@ static int save_external_coredump(
                 uid_t uid,
                 char **ret_filename,
                 int *ret_fd,
-                off_t *ret_size) {
+                uint64_t *ret_size) {
 
         _cleanup_free_ char *fn = NULL, *tmp = NULL;
         _cleanup_close_ int fd = -1;
@@ -372,9 +380,9 @@ static int save_external_coredump(
                 /* OK, this worked, we can get rid of the uncompressed version now */
                 unlink_noerrno(tmp);
 
-                *ret_filename = fn_compressed;    /* compressed */
-                *ret_fd = fd;                     /* uncompressed */
-                *ret_size = st.st_size;           /* uncompressed */
+                *ret_filename = fn_compressed;     /* compressed */
+                *ret_fd = fd;                      /* uncompressed */
+                *ret_size = (uint64_t) st.st_size; /* uncompressed */
 
                 fn_compressed = NULL;
                 fd = -1;
@@ -393,7 +401,7 @@ uncompressed:
 
         *ret_filename = fn;
         *ret_fd = fd;
-        *ret_size = st.st_size;
+        *ret_size = (uint64_t) st.st_size;
 
         fn = NULL;
         fd = -1;
@@ -512,8 +520,7 @@ static int compose_open_fds(pid_t pid, char **open_fds) {
         }
 
         errno = 0;
-        fclose(stream);
-        stream = NULL;
+        stream = safe_fclose(stream);
 
         if (errno != 0)
                 return -errno;
@@ -545,7 +552,7 @@ int main(int argc, char* argv[]) {
         _cleanup_close_ int coredump_fd = -1;
 
         struct iovec iovec[26];
-        off_t coredump_size;
+        uint64_t coredump_size;
         int r, j = 0;
         uid_t uid, owner_uid;
         gid_t gid;
@@ -841,7 +848,7 @@ log:
 
         /* Optionally store the entire coredump in the journal */
         if (IN_SET(arg_storage, COREDUMP_STORAGE_JOURNAL, COREDUMP_STORAGE_BOTH) &&
-            coredump_size <= (off_t) arg_journal_size_max) {
+            coredump_size <= arg_journal_size_max) {
                 size_t sz = 0;
 
                 /* Store the coredump itself in the journal */