Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vncsession: Move existing log to log.old if present
Browse files Browse the repository at this point in the history
jcpunk committed Aug 6, 2024

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
1 parent 4f6a352 commit fa4537c
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions unix/vncserver/vncsession.c
Original file line number Diff line number Diff line change
@@ -393,7 +393,7 @@ redir_stdio(const char *homedir, const char *display, char **envp)
int fd;
long hostlen;
char* hostname = NULL, *xdgstate;
char logfile[PATH_MAX], legacy[PATH_MAX];
char logdir[PATH_MAX], logfile[PATH_MAX], logfile_old[PATH_MAX], legacy[PATH_MAX];
struct stat st;

fd = open("/dev/null", O_RDONLY);
@@ -409,14 +409,14 @@ redir_stdio(const char *homedir, const char *display, char **envp)

xdgstate = getenvp("XDG_STATE_HOME", envp);
if (xdgstate != NULL && xdgstate[0] == '/')
snprintf(logfile, sizeof(logfile), "%s/tigervnc", xdgstate);
snprintf(logdir, sizeof(logdir), "%s/tigervnc", xdgstate);
else
snprintf(logfile, sizeof(logfile), "%s/.local/state/tigervnc", homedir);
snprintf(logdir, sizeof(logdir), "%s/.local/state/tigervnc", homedir);

snprintf(legacy, sizeof(legacy), "%s/.vnc", homedir);
if (stat(logfile, &st) != 0 && stat(legacy, &st) == 0) {
if (stat(logdir, &st) != 0 && stat(legacy, &st) == 0) {
syslog(LOG_WARNING, "~/.vnc is deprecated, please consult 'man vncsession' for paths to migrate to.");
strcpy(logfile, legacy);
strcpy(logdir, legacy);

#ifdef HAVE_SELINUX
/* this is only needed to handle historical type changes for the legacy dir */
@@ -431,9 +431,9 @@ redir_stdio(const char *homedir, const char *display, char **envp)
#endif
}

if (mkdir_p(logfile, 0755) == -1) {
if (mkdir_p(logdir, 0755) == -1) {
if (errno != EEXIST) {
syslog(LOG_CRIT, "Failure creating \"%s\": %s", logfile, strerror(errno));
syslog(LOG_CRIT, "Failure creating \"%s\": %s", logdir, strerror(errno));
_exit(EX_OSERR);
}
}
@@ -450,9 +450,15 @@ redir_stdio(const char *homedir, const char *display, char **envp)
_exit(EX_OSERR);
}

snprintf(logfile + strlen(logfile), sizeof(logfile) - strlen(logfile), "/%s%s.log",
hostname, display);
snprintf(logfile, sizeof(logfile), "/%s/%s%s.log", logdir, hostname, display);
snprintf(logfile_old, sizeof(logfile_old), "/%s/%s%s.log.old", logdir, hostname, display);
free(hostname);
if (stat(logfile, &st) == 0) {
if (rename(logfile, logfile_old) != 0) {
syslog(LOG_CRIT, "Failure renaming log file \"%s\" to \"%s\": %s", logfile, logfile_old, strerror(errno));
_exit(EX_OSERR);
}
}
fd = open(logfile, O_CREAT | O_WRONLY | O_TRUNC, 0644);
if (fd == -1) {
syslog(LOG_CRIT, "Failure creating log file \"%s\": %s", logfile, strerror(errno));

0 comments on commit fa4537c

Please sign in to comment.