From: Pierre Ossman Date: Thu, 11 Mar 2021 09:00:05 +0000 (+0100) Subject: Fix logging in daemonized tl-session X-Git-Tag: v1.11.90~59 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=cd2a882e53d9a7b65b320832da60c307a13c6745;p=tigervnc.git Fix logging in daemonized tl-session stderr has been redirected to /dev/null so all logging needs to go to syslog. --- diff --git a/unix/vncserver/vncsession.c b/unix/vncserver/vncsession.c index 956a8f4b..784d5dae 100644 --- a/unix/vncserver/vncsession.c +++ b/unix/vncserver/vncsession.c @@ -102,6 +102,12 @@ begin_daemon(void) if (pid != 0) _exit(0); + /* A safe working directory */ + if (chdir("/") < 0) { + perror("chdir"); + return -1; + } + /* Send all stdio to /dev/null */ devnull = open("/dev/null", O_RDWR); if (devnull < 0) { @@ -117,12 +123,6 @@ begin_daemon(void) if (devnull > 2) close(devnull); - /* A safe working directory */ - if (chdir("/") < 0) { - perror("chdir"); - return -1; - } - return 0; } @@ -318,19 +318,19 @@ switch_user(const char *username, uid_t uid, gid_t gid) { // We must change group stuff first, because only root can do that. if (setgid(gid) < 0) { - perror(": setgid"); + syslog(LOG_CRIT, "setgid: %s", strerror(errno)); _exit(EX_OSERR); } // Supplementary groups. if (initgroups(username, gid) < 0) { - perror("initgroups"); + syslog(LOG_CRIT, "initgroups: %s", strerror(errno)); _exit(EX_OSERR); } // Set euid, ruid and suid if (setuid(uid) < 0) { - perror("setuid"); + syslog(LOG_CRIT, "setuid: %s", strerror(errno)); _exit(EX_OSERR); } } @@ -344,11 +344,11 @@ redir_stdio(const char *homedir, const char *display) fd = open("/dev/null", O_RDONLY); if (fd == -1) { - perror("open"); + syslog(LOG_CRIT, "Failure redirecting stdin: open: %s", strerror(errno)); _exit(EX_OSERR); } if (dup2(fd, 0) == -1) { - perror("dup2"); + syslog(LOG_CRIT, "Failure redirecting stdin: dup2: %s", strerror(errno)); _exit(EX_OSERR); } close(fd); @@ -356,13 +356,13 @@ redir_stdio(const char *homedir, const char *display) snprintf(logfile, sizeof(logfile), "%s/.vnc", homedir); if (mkdir(logfile, 0755) == -1) { if (errno != EEXIST) { - perror("mkdir"); + syslog(LOG_CRIT, "Failure creating \"%s\": %s", logfile, strerror(errno)); _exit(EX_OSERR); } } if (gethostname(hostname, sizeof(hostname)) == -1) { - perror("gethostname"); + syslog(LOG_CRIT, "gethostname: %s", strerror(errno)); _exit(EX_OSERR); } @@ -370,11 +370,11 @@ redir_stdio(const char *homedir, const char *display) homedir, hostname, display); fd = open(logfile, O_CREAT | O_WRONLY | O_TRUNC, 0644); if (fd == -1) { - perror("open"); + syslog(LOG_CRIT, "Failure creating log file \"%s\": %s", logfile, strerror(errno)); _exit(EX_OSERR); } if ((dup2(fd, 1) == -1) || (dup2(fd, 2) == -1)) { - perror("dup2"); + syslog(LOG_CRIT, "Failure redirecting stdout or stderr: %s", strerror(errno)); _exit(EX_OSERR); } close(fd); @@ -388,7 +388,7 @@ close_fds(void) dir = opendir("/proc/self/fd"); if (dir == NULL) { - perror("opendir"); + syslog(LOG_CRIT, "opendir: %s", strerror(errno)); _exit(EX_OSERR); } @@ -468,7 +468,7 @@ run_script(const char *username, const char *display, char **envp) execvp(child_argv[0], (char*const*)child_argv); // execvp failed - perror("execvp"); + syslog(LOG_CRIT, "execvp: %s", strerror(errno)); _exit(EX_OSERR); }