Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixos/xserver: fix X.org session script logging #29401

Closed
wants to merge 1 commit into from

Conversation

rnhmjoj
Copy link
Contributor

@rnhmjoj rnhmjoj commented Sep 14, 2017

Motivation for this change

Fix issue #29106

Things done
  • Tested via one or more NixOS test(s) if existing and applicable
  • Fits CONTRIBUTING.md.

@rnhmjoj rnhmjoj changed the title fix xserver.displayManager.job.logsXsession behaviour nixos/xserver: fix displayManager.job.logsXsession behaviour Sep 14, 2017
@Gerschtli
Copy link
Contributor

That would result in a breaking change. I think it has to be documented anywhere in the release notes, but I don't know what the workflow for breaking changes is.

@Gerschtli
Copy link
Contributor

Whats the state?

@@ -72,7 +72,7 @@ let
sessionType="$1"
if [ "$sessionType" = default ]; then sessionType=""; fi

${optionalString (!cfg.displayManager.job.logsXsession && !cfg.displayManager.logToJournal) ''
${optionalString cfg.displayManager.job.logsXsession ''
Copy link
Member

@rycee rycee Nov 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, if they are not mutually exclusive then in the case where both logsXsession and logToJournal are true wouldn't you need to both redirect stdout/stderr to the file and pass them on to the journal? Something like

exec > >(tee -i ~/.xsession-errors) 2> >(tee -i /dev/stderr >> ~/.xsession-errors)

Disclamer: I don't know if the above is correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rycee First, thank you for the review. Yes, you are correct.
I tried exec > >(tee -i ~/.xsession-errors) 2> >(tee -i ~/.xsession-errors >&2) and seems to work.
The problem is that the script is executed multiple times and worse, if both logXsession and logToJournal are false the script is not executed at all.

I'm not sure how to deal with this.

@rnhmjoj rnhmjoj changed the title nixos/xserver: fix displayManager.job.logsXsession behaviour nixos/xserver: fix X.org session script logging Nov 7, 2017
@rnhmjoj
Copy link
Contributor Author

rnhmjoj commented Nov 7, 2017

Ok, it took a little more effort than I initially expected.
I have tested every possible case and I'm confident the logging is now working as expected:
it's now possible to log to the journal, to .xsession-errors, to both, or none.

I have also renamed the options to be more consistent.

@Gerschtli
Copy link
Contributor

Hey, whats the state? Looks good to me

@@ -306,7 +307,7 @@ in
description = "Additional environment variables needed by the display manager.";
};

logsXsession = mkOption {
logToFile = mkOption {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you'll have to add something like

mkRenamedOptionModule [ "services" "xserver" "displayManager" "job" "logsXsession" ] [ "services" "xserver" "displayManager" "job" "logsToFile" ];

to rename.nix. Otherwise backwards compatibility is broken.

Same with logToJournal below.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That isn't a simple rename of logsXsession because of the logic bug.
That is something you need to take care of concering backwards compatibilty.

If logsXsession is true, logToFile needs to be false and vice versa to preserve the current behaviour.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rycee Thank you. It's done.
@Gerschtli The current behavior is wrong. It may be mentioned in the release changes but it makes no sense to keep it that way for compatibility.

@rycee
Copy link
Member

rycee commented Nov 26, 2017

@rnhmjoj As you've noticed in the Nix chat room I've been trying this out. Basically everything seems to work for me if I do these changes:

diff --git a/nixos/modules/services/x11/display-managers/default.nix b/nixos/modules/services/x11/display-managers/default.nix
index 15f7a1cca21..bfce4be6542 100644
--- a/nixos/modules/services/x11/display-managers/default.nix
+++ b/nixos/modules/services/x11/display-managers/default.nix
@@ -59,17 +59,6 @@ let
       # Now it should be safe to assume that the script was called with the
       # expected parameters.
 
-      ${optionalString cfg.displayManager.job.logToJournal ''
-        if [ -z "$_DID_SYSTEMD_CAT" ]; then
-          export _DID_SYSTEMD_CAT=1
-          exec &> >(tee >(${config.systemd.package}/bin/systemd-cat -t xsession))
-        fi
-      ''}
-
-      ${optionalString cfg.displayManager.job.logToFile ''
-        exec &> >(tee ~/.xsession-errors)
-      ''}
-
       . /etc/profile
       cd "$HOME"
 
@@ -83,6 +72,17 @@ let
         fi
       ''}
 
+      ${optionalString cfg.displayManager.job.logToJournal ''
+        if [ -z "$_DID_SYSTEMD_CAT" ]; then
+          export _DID_SYSTEMD_CAT=1
+          exec ${config.systemd.package}/bin/systemd-cat -t xsession "$0" "$sessionType"
+        fi
+      ''}
+
+      ${optionalString cfg.displayManager.job.logToFile ''
+        exec &> >(tee -a ~/.xsession-errors)
+      ''}
+
       # Start PulseAudio if enabled.
       ${optionalString (config.hardware.pulseaudio.enable) ''
         ${optionalString (!config.hardware.pulseaudio.systemWide)

The main difference is that the dbus-launch happens before the output redirection. Note, I also made two unrelated changes, one to remove the need for tee when calling systemd-cat and one to use appending when logging to ~/.xsession-errors.

@rnhmjoj
Copy link
Contributor Author

rnhmjoj commented Nov 26, 2017

@rycee Ok, I added your changes.

''}

${optionalString cfg.displayManager.job.logToFile ''
exec &> >(tee -a ~/.xsession-errors)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the old code for logging to file it seems to me like it actually didn't append. Perhaps it is best to not have -a here? Yes, I realize I added it, sorry!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@rycee
Copy link
Member

rycee commented Nov 27, 2017

Looking good :-) I've now rebased this into master in 13bb5ff. Thanks for your hard work and patience!

@rycee rycee closed this Nov 27, 2017
@rnhmjoj
Copy link
Contributor Author

rnhmjoj commented Nov 27, 2017

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants