*/
#ifndef lint
-static char rcsid[] = "$Id: main.c,v 1.45 1998/03/25 01:28:14 paulus Exp $";
+static char rcsid[] = "$Id: main.c,v 1.46 1998/03/26 04:46:04 paulus Exp $";
#endif
#include <stdio.h>
int hungup; /* terminal has been hung up */
int privileged; /* we're running as real uid root */
int need_holdoff; /* need holdoff period before restarting */
+int detached; /* have detached from terminal */
int phase; /* where the link is at */
int kill_link;
int open_ccp_flag;
-int redirect_stderr; /* Connector's stderr should go to file */
char **script_env; /* Env. variable values for scripts */
int s_env_nalloc; /* # words avail at script_env */
*/
if (!default_device && strcmp(devnam, default_devnam) == 0)
default_device = 1;
- redirect_stderr = !nodetach || default_device;
+ if (default_device)
+ nodetach = 1;
/*
* Initialize system-dependent stuff and magic number package.
* Detach ourselves from the terminal, if required,
* and identify who is running us.
*/
- if (!default_device && !nodetach && daemon(0, 0) < 0) {
- perror("Couldn't detach from controlling terminal");
- exit(1);
- }
+ if (nodetach == 0)
+ detach();
pid = getpid();
p = getlogin();
if (p == NULL) {
return 0;
}
+/*
+ * detach - detach us from the controlling terminal.
+ */
+void
+detach()
+{
+ if (detached)
+ return;
+ if (daemon(0, 0) < 0) {
+ perror("Couldn't detach from controlling terminal");
+ die(1);
+ }
+ detached = 1;
+}
+
/*
* holdoff_end - called via a timeout when the holdoff period ends.
*/
close(out);
}
}
- if (redirect_stderr) {
+ if (nodetach == 0) {
close(2);
errfd = open(_PATH_CONNERRS, O_WRONLY | O_APPEND | O_CREAT, 0600);
if (errfd >= 0 && errfd != 2) {