diff --git a/man/systemd.exec.xml b/man/systemd.exec.xml
index 7821b69cd0..53daff0f64 100644
--- a/man/systemd.exec.xml
+++ b/man/systemd.exec.xml
@@ -2012,6 +2012,12 @@ CapabilityBoundingSet=~CAP_B CAP_C
$JOURNAL_STREAM is set at all as services might invoke external processes replacing their
standard output or standard error output, without unsetting the environment variable.
+ If both standard output and standard error of the executed processes are connected to the journal via a
+ stream socket, this environment variable will contain information about the standard error stream, as that's
+ usually the preferred destination for log data. (Note that typically the same stream is used for both standard
+ output and standard error, hence very likely the environment variable contains device and inode information
+ matching both stream file descriptors.)
+
This environment variable is primarily useful to allow services to optionally upgrade their used log
protocol to the native journal protocol (using
sd_journal_print3 and other
diff --git a/src/core/execute.c b/src/core/execute.c
index 9dcc02aaa4..e2d84feb0d 100644
--- a/src/core/execute.c
+++ b/src/core/execute.c
@@ -595,9 +595,13 @@ static int setup_output(
/* If we connected this fd to the journal via a stream, patch the device/inode into the passed
* parameters, but only then. This is useful so that we can set $JOURNAL_STREAM that permits
- * services to detect whether they are connected to the journal or not. */
+ * services to detect whether they are connected to the journal or not.
+ *
+ * If both stdout and stderr are connected to a stream then let's make sure to store the data
+ * about STDERR as that's usually the best way to do logging. */
- if (fstat(fileno, &st) >= 0) {
+ if (fstat(fileno, &st) >= 0 &&
+ (*journal_stream_ino == 0 || fileno == STDERR_FILENO)) {
*journal_stream_dev = st.st_dev;
*journal_stream_ino = st.st_ino;
}