#include <utmp.h>
#include <ctype.h>
#include <stdarg.h>
+#include <sys/ttydefaults.h>
#include <sys/syslog.h>
#include <sys/time.h>
f = fdopen(fd, "r");
- if (get_cmd(f) != C_VER)
+ if (get_cmd(f) != C_VER) {
+ fclose(f);
return -1;
+ }
get_string(old_version, sizeof(old_version), f);
oops_error = 0;
for (pp = &family; (*pp = get_record(f)) != NULL; pp = &((*pp)->next))
rlim.rlim_cur = RLIM_INFINITY;
rlim.rlim_max = RLIM_INFINITY;
setrlimit(RLIMIT_CORE, &rlim);
- chdir("/");
+ if (0 != chdir("/"))
+ initlog(L_VB, "unable to chdir to /: %s",
+ strerror(errno));
signal(SIGSEGV, SIG_DFL);
raise(SIGSEGV);
* to be its controlling tty.
*/
if (strchr("*#sS", runlevel) && ch->flags & WAITING) {
+ int ftty; /* Handler for tty controlling */
/*
* We fork once extra. This is so that we can
* wait and change the process group and session
* of the console after exit of the leader.
*/
setsid();
- if ((f = console_open(O_RDWR|O_NOCTTY)) >= 0) {
+ if ((ftty = console_open(O_RDWR|O_NOCTTY)) >= 0) {
/* Take over controlling tty by force */
- (void)ioctl(f, TIOCSCTTY, 1);
- dup(f);
- dup(f);
+ (void)ioctl(ftty, TIOCSCTTY, 1);
+
+ if(dup(ftty) < 0){
+ initlog(L_VB, "cannot duplicate console fd");
+ }
+
+ if(dup(ftty) < 0){
+ initlog(L_VB, "cannot duplicate console fd");
+ }
+
}
/*
* Small optimization. See if stealing
* controlling tty back is needed.
*/
- pgrp = tcgetpgrp(f);
+ pgrp = tcgetpgrp(ftty);
if (pgrp != getpid())
exit(0);
}
if (pid == 0) {
setsid();
- (void)ioctl(f, TIOCSCTTY, 1);
+ (void)ioctl(ftty, TIOCSCTTY, 1);
exit(0);
}
while((rc = waitpid(pid, &st, 0)) != pid)
/* Set ioctl settings to default ones */
console_stty();
- } else {
+ } else { /* parent */
+ int fd;
setsid();
- if ((f = console_open(O_RDWR|O_NOCTTY)) < 0) {
+ if ((fd = console_open(O_RDWR|O_NOCTTY)) < 0) {
initlog(L_VB, "open(%s): %s", console_dev,
strerror(errno));
- f = open("/dev/null", O_RDWR);
+ fd = open("/dev/null", O_RDWR);
}
- dup(f);
- dup(f);
+
+ if(dup(fd) < 0) {
+ initlog(L_VB, "cannot duplicate /dev/null fd");
+ }
+
+ if(dup(fd) < 0) {
+ initlog(L_VB, "cannot duplicate /dev/null fd");
+ }
+
}
/*
case POWEROKWAIT:
case CTRLALTDEL:
if (!(ch->flags & XECUTED)) ch->flags |= WAITING;
+ /* Fall through */
case KBREQUEST:
case BOOT:
case POWERFAIL:
if (rlevel && strlen(rlevel) > 11)
strcpy(err, "rlevel field too long (max 11 characters)");
if (process && strlen(process) > 127)
- strcpy(err, "process field too long");
+ strcpy(err, "process field too long (max 127 characters)");
if (action && strlen(action) > 32)
strcpy(err, "action field too long");
if (err[0] != 0) {
if (!strchr("0123456789SsQqAaBbCcUu", argv[optind][0]))
usage(progname);
request.cmd = INIT_CMD_RUNLVL;
- request.runlevel = env ? 0 : argv[optind][0];
+ request.runlevel = argv[optind][0];
request.sleeptime = sltime;
}
/* Change to the root directory. */
- chdir("/");
+ if (0 != chdir("/"))
+ initlog(L_VB, "unable to chdir to /: %s",
+ strerror(errno));
/* Open the fifo and write a command. */
/* Make sure we don't hang on opening /dev/initctl */