]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/journal/journald-stream.c
util-lib: split string parsing related calls from util.[ch] into parse-util.[ch]
[thirdparty/systemd.git] / src / journal / journald-stream.c
index db2f5819722c9791d0bffce1a470f24da0aa9133..6745864da11a0080100ab5046d16dfd557422896 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 "fd-util.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 "parse-util.h"
+#include "selinux-util.h"
+#include "socket-util.h"
+#include "string-util.h"
 
 #define STDOUT_STREAMS_MAX 4096
 
@@ -142,7 +147,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 +168,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 +180,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 +188,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 +202,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);
 
-        return r;
+        if (temp_path)
+                (void) unlink(temp_path);
+
+        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) {
@@ -629,7 +632,7 @@ static int stdout_stream_restore(Server *s, const char *fname, int fd) {
         return 0;
 }
 
-static int server_restore_streams(Server *s, FDSet *fds) {
+int server_restore_streams(Server *s, FDSet *fds) {
         _cleanup_closedir_ DIR *d = NULL;
         struct dirent *de;
         int r;
@@ -683,7 +686,7 @@ fail:
         return log_error_errno(errno, "Failed to read streams directory: %m");
 }
 
-int server_open_stdout_socket(Server *s, FDSet *fds) {
+int server_open_stdout_socket(Server *s) {
         int r;
 
         assert(s);
@@ -719,8 +722,5 @@ int server_open_stdout_socket(Server *s, FDSet *fds) {
         if (r < 0)
                 return log_error_errno(r, "Failed to adjust priority of stdout server event source: %m");
 
-        /* Try to restore streams, but don't bother if this fails */
-        (void) server_restore_streams(s, fds);
-
         return 0;
 }