]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/journal-remote/journal-upload.c
util-lib: split string parsing related calls from util.[ch] into parse-util.[ch]
[thirdparty/systemd.git] / src / journal-remote / journal-upload.c
index 75bb434c0861f44a9ca924682c07416f57ac3dc4..20e2a2f73bdde82037da4a59b5eeeb1f088e9cfb 100644 (file)
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include <stdio.h>
 #include <curl/curl.h>
-#include <sys/stat.h>
 #include <fcntl.h>
 #include <getopt.h>
+#include <stdio.h>
+#include <sys/stat.h>
 
 #include "sd-daemon.h"
-#include "log.h"
-#include "util.h"
-#include "build.h"
+
+#include "conf-parser.h"
+#include "fd-util.h"
 #include "fileio.h"
+#include "formats-util.h"
+#include "journal-upload.h"
+#include "log.h"
 #include "mkdir.h"
-#include "conf-parser.h"
+#include "parse-util.h"
 #include "sigbus.h"
-#include "journal-upload.h"
+#include "signal-util.h"
+#include "string-util.h"
+#include "util.h"
 
 #define PRIV_KEY_FILE CERTIFICATE_ROOT "/private/journal-upload.pem"
 #define CERT_FILE     CERTIFICATE_ROOT "/certs/journal-upload.pem"
@@ -124,26 +129,31 @@ static int update_cursor_state(Uploader *u) {
 
         r = fopen_temporary(u->state_file, &f, &temp_path);
         if (r < 0)
-                goto finish;
+                goto fail;
 
         fprintf(f,
                 "# This is private data. Do not parse.\n"
                 "LAST_CURSOR=%s\n",
                 u->last_cursor);
 
-        fflush(f);
+        r = fflush_and_check(f);
+        if (r < 0)
+                goto fail;
 
-        if (ferror(f) || rename(temp_path, u->state_file) < 0) {
+        if (rename(temp_path, u->state_file) < 0) {
                 r = -errno;
-                unlink(u->state_file);
-                unlink(temp_path);
+                goto fail;
         }
 
-finish:
-        if (r < 0)
-                log_error_errno(r, "Failed to save state %s: %m", u->state_file);
+        return 0;
 
-        return r;
+fail:
+        if (temp_path)
+                (void) unlink(temp_path);
+
+        (void) unlink(u->state_file);
+
+        return log_error_errno(r, "Failed to save state %s: %m", u->state_file);
 }
 
 static int load_cursor_state(Uploader *u) {
@@ -394,14 +404,11 @@ static int dispatch_sigterm(sd_event_source *event,
 }
 
 static int setup_signals(Uploader *u) {
-        sigset_t mask;
         int r;
 
         assert(u);
 
-        assert_se(sigemptyset(&mask) == 0);
-        sigset_add_many(&mask, SIGINT, SIGTERM, -1);
-        assert_se(sigprocmask(SIG_SETMASK, &mask, NULL) == 0);
+        assert_se(sigprocmask_many(SIG_SETMASK, NULL, SIGINT, SIGTERM, -1) >= 0);
 
         r = sd_event_add_signal(u->events, &u->sigterm_event, SIGTERM, dispatch_sigterm, u);
         if (r < 0)
@@ -615,9 +622,7 @@ static int parse_argv(int argc, char *argv[]) {
                         return 0 /* done */;
 
                 case ARG_VERSION:
-                        puts(PACKAGE_STRING);
-                        puts(SYSTEMD_FEATURES);
-                        return 0 /* done */;
+                        return version();
 
                 case 'u':
                         if (arg_url) {
@@ -824,7 +829,7 @@ int main(int argc, char **argv) {
                   "READY=1\n"
                   "STATUS=Processing input...");
 
-        while (true) {
+        for (;;) {
                 r = sd_event_get_state(u.events);
                 if (r < 0)
                         break;