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) {
if (devnull > 2)
close(devnull);
- /* A safe working directory */
- if (chdir("/") < 0) {
- perror("chdir");
- return -1;
- }
-
return 0;
}
{
// 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);
}
}
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);
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);
}
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);
dir = opendir("/proc/self/fd");
if (dir == NULL) {
- perror("opendir");
+ syslog(LOG_CRIT, "opendir: %s", strerror(errno));
_exit(EX_OSERR);
}
execvp(child_argv[0], (char*const*)child_argv);
// execvp failed
- perror("execvp");
+ syslog(LOG_CRIT, "execvp: %s", strerror(errno));
_exit(EX_OSERR);
}