]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/journal/journald-stream.c
util-lib: split our string related calls from util.[ch] into its own file string...
[thirdparty/systemd.git] / src / journal / journald-stream.c
index c038b4cced949cbb08eaf6bf3460f0846444b126..e06be6267f77a11d9547edd285b990c7b089009a 100644 (file)
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include <unistd.h>
 #include <stddef.h>
+#include <unistd.h>
 
 #ifdef HAVE_SELINUX
 #include <selinux/selinux.h>
 #endif
 
-#include "sd-event.h"
 #include "sd-daemon.h"
-#include "socket-util.h"
-#include "selinux-util.h"
-#include "mkdir.h"
+#include "sd-event.h"
+
+#include "escape.h"
 #include "fileio.h"
+#include "journald-console.h"
+#include "journald-kmsg.h"
 #include "journald-server.h"
-#include "journald-stream.h"
 #include "journald-syslog.h"
-#include "journald-kmsg.h"
-#include "journald-console.h"
 #include "journald-wall.h"
+#include "mkdir.h"
+#include "selinux-util.h"
+#include "socket-util.h"
+#include "string-util.h"
+#include "journald-stream.h"
 
 #define STDOUT_STREAMS_MAX 4096
 
@@ -142,7 +145,7 @@ static int stdout_stream_save(StdoutStream *s) {
 
         r = fopen_temporary(s->state_file, &f, &temp_path);
         if (r < 0)
-                goto finish;
+                goto fail;
 
         fprintf(f,
                 "# This is private data. Do not parse\n"
@@ -163,7 +166,7 @@ static int stdout_stream_save(StdoutStream *s) {
                 escaped = cescape(s->identifier);
                 if (!escaped) {
                         r = -ENOMEM;
-                        goto finish;
+                        goto fail;
                 }
 
                 fprintf(f, "IDENTIFIER=%s\n", escaped);
@@ -175,7 +178,7 @@ static int stdout_stream_save(StdoutStream *s) {
                 escaped = cescape(s->unit_id);
                 if (!escaped) {
                         r = -ENOMEM;
-                        goto finish;
+                        goto fail;
                 }
 
                 fprintf(f, "UNIT=%s\n", escaped);
@@ -183,16 +186,13 @@ static int stdout_stream_save(StdoutStream *s) {
 
         r = fflush_and_check(f);
         if (r < 0)
-                goto finish;
+                goto fail;
 
         if (rename(temp_path, s->state_file) < 0) {
                 r = -errno;
-                goto finish;
+                goto fail;
         }
 
-        free(temp_path);
-        temp_path = NULL;
-
         /* Store the connection fd in PID 1, so that we get it passed
          * in again on next start */
         if (!s->fdstore) {
@@ -200,14 +200,15 @@ static int stdout_stream_save(StdoutStream *s) {
                 s->fdstore = true;
         }
 
-finish:
-        if (temp_path)
-                unlink(temp_path);
+        return 0;
 
-        if (r < 0)
-                log_error_errno(r, "Failed to save stream data %s: %m", s->state_file);
+fail:
+        (void) unlink(s->state_file);
+
+        if (temp_path)
+                (void) unlink(temp_path);
 
-        return r;
+        return log_error_errno(r, "Failed to save stream data %s: %m", s->state_file);
 }
 
 static int stdout_stream_log(StdoutStream *s, const char *p) {