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

vncsession: Move existing log to log.old if present #1801

Merged
merged 1 commit into from
Aug 14, 2024

Conversation

jcpunk
Copy link
Contributor

@jcpunk jcpunk commented Jul 31, 2024

This is my attempt to resolve #1145

Copy link
Member

@CendioOssman CendioOssman left a comment

Choose a reason for hiding this comment

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

Looks good! Thanks!

I just want to do a test run and then this can be merged.

@CendioOssman
Copy link
Member

It seems gcc is unhappy with the changes, unfortunately. :/

I'm unable to reproduce the issue here with gcc 13. I wonder if gcc 11 is more aggressive with this warning.

@jcpunk
Copy link
Contributor Author

jcpunk commented Aug 2, 2024

I'll rework to completely copy this string generation.

Copy link
Member

@CendioOssman CendioOssman left a comment

Choose a reason for hiding this comment

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

I'm afraid the adjusted code does not work:

Aug 06 10:55:30 ubuntu2404 vncsession[3089]: Failure renaming log file "/home/tltest/.local/state/tigervnc/ubuntu2404:2.log" to "/ubuntu2404:2.log.old": Permission denied

I would suggest splitting out the base directory to a separate variable. That should make things more clear, and avoid such mistakes.

@jcpunk
Copy link
Contributor Author

jcpunk commented Aug 6, 2024

I'm out of the office right now but took a quick stab at it... might be garbage but wanted to try...

@CendioOssman
Copy link
Member

I figured out why the errors are only shown sporadically. Apparently, they go away if you build with any optimisation flags. Weird.

Still, it looks like some error handling is needed here. Probably best to add it to all the snprintf() calls there.

@jcpunk
Copy link
Contributor Author

jcpunk commented Aug 11, 2024

I'll confess I don't understand what is required.

@CendioOssman
Copy link
Member

CendioOssman commented Aug 12, 2024

Something like this:

diff --git a/unix/vncserver/vncsession.c b/unix/vncserver/vncsession.c
index 98a0432aa..8fbcb7703 100644
--- a/unix/vncserver/vncsession.c
+++ b/unix/vncserver/vncsession.c
@@ -408,10 +408,19 @@ redir_stdio(const char *homedir, const char *display, char **envp)
     close(fd);
 
     xdgstate = getenvp("XDG_STATE_HOME", envp);
-    if (xdgstate != NULL && xdgstate[0] == '/')
-        snprintf(logfile, sizeof(logfile), "%s/tigervnc", xdgstate);
-    else
-        snprintf(logfile, sizeof(logfile), "%s/.local/state/tigervnc", homedir);
+    if (xdgstate != NULL && xdgstate[0] == '/') {
+        size_t len = snprintf(logfile, sizeof(logfile), "%s/tigervnc", xdgstate);
+        if (len >= sizeof(logfile)) {
+            syslog(LOG_CRIT, "Log path too long");
+            _exit(EX_OSERR);
+        }
+    } else {
+        size_t len = snprintf(logfile, sizeof(logfile), "%s/.local/state/tigervnc", homedir);
+        if (len >= sizeof(logfile)) {
+            syslog(LOG_CRIT, "Log path too long");
+            _exit(EX_OSERR);
+        }
+    }
 
     snprintf(legacy, sizeof(legacy), "%s/.vnc", homedir);
     if (stat(logfile, &st) != 0 && stat(legacy, &st) == 0) {

@jcpunk
Copy link
Contributor Author

jcpunk commented Aug 13, 2024

Hopefully the current patch is closer to what you expect.

Copy link
Member

@CendioOssman CendioOssman left a comment

Choose a reason for hiding this comment

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

Nice! Everything seems to work nicely when I do test run on a Ubuntu 24.04 machine here.

Thanks for getting this through to the end!

@CendioOssman CendioOssman merged commit 242488d into TigerVNC:master Aug 14, 2024
11 checks passed
@jcpunk jcpunk deleted the old-log branch August 14, 2024 14:24
@samhed samhed added the enhancement New feature or request label Aug 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Keep one '.log.old' behind
3 participants