summaryrefslogtreecommitdiffstats
path: root/sbin/startslip/startslip.c
diff options
context:
space:
mode:
authorache <ache@FreeBSD.org>1995-09-16 05:18:20 +0000
committerache <ache@FreeBSD.org>1995-09-16 05:18:20 +0000
commitacf78c78b92f2e3540b8ad23c8a9c7b19844da6d (patch)
treee14f382c611a73f6db5c2df217604438038b2378 /sbin/startslip/startslip.c
parent7ab21f76508af2e4e10ea475050e6f5d831f556e (diff)
downloadFreeBSD-src-acf78c78b92f2e3540b8ad23c8a9c7b19844da6d.zip
FreeBSD-src-acf78c78b92f2e3540b8ad23c8a9c7b19844da6d.tar.gz
Use daemon() instead of fork/setsid/close.
Rearrange things to do fork as later as possible.
Diffstat (limited to 'sbin/startslip/startslip.c')
-rw-r--r--sbin/startslip/startslip.c41
1 files changed, 15 insertions, 26 deletions
diff --git a/sbin/startslip/startslip.c b/sbin/startslip/startslip.c
index b737aa1..0fcc2a2 100644
--- a/sbin/startslip/startslip.c
+++ b/sbin/startslip/startslip.c
@@ -30,7 +30,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: startslip.c,v 1.11 1995/09/15 20:34:55 ache Exp $
+ * $Id: startslip.c,v 1.12 1995/09/15 22:18:45 ache Exp $
*/
#ifndef lint
@@ -244,31 +244,25 @@ restart:
}
if (terminate)
goto restart;
- if (diali > 0)
- dialerstring = dials[dialc++ % diali];
-
- if (fork() > 0) {
- if (first)
- printd("parent exit\n");
- exit(0);
+ if (tries > 1) {
+ syslog(LOG_INFO, "sleeping %d seconds (%d tries)",
+ wait_time * (tries - 1), tries);
+ sleep(wait_time * (tries - 1));
+ if (terminate)
+ goto restart;
}
- if (setsid() < 0) {
- syslog(LOG_ERR, "setsid: %m");
+
+ if (daemon(1, debug) < 0) {
+ syslog(LOG_ERR, "daemon: %m");
down(2);
}
+
pid = getpid();
printd("restart: pid %ld: ", pid);
if ((pfd = fopen(pidfile, "w")) != NULL) {
fprintf(pfd, "%ld\n", pid);
fclose(pfd);
}
- if (tries > 1) {
- syslog(LOG_INFO, "sleeping %d seconds (%d tries)",
- wait_time * (tries - 1), tries);
- sleep(wait_time * (tries - 1));
- if (terminate)
- goto restart;
- }
printd("open");
if (uu_lock(dvname)) {
syslog(LOG_ERR, "can't lock %s", devicename);
@@ -341,7 +335,10 @@ restart:
syslog(LOG_ERR, "can't fdopen %s: %m", devicename);
down(2);
}
- setbuf(wfd, (char *)0);
+ setbuf(wfd, NULL);
+
+ if (diali > 0)
+ dialerstring = dials[dialc++ % diali];
if (dialerstring) {
printd("send dialstring: %s\\r", dialerstring);
fprintf(wfd, "%s\r", dialerstring);
@@ -424,14 +421,6 @@ restart:
down(2);
}
sprintf(unitname, "sl%d", unitnum);
- if (first && debug == 0) {
- close(0);
- close(1);
- close(2);
- (void) open("/dev/null", O_RDWR);
- (void) dup2(0, 1);
- (void) dup2(0, 2);
- }
sprintf(buf, "LINE=%d %s %s up &",
diali ? (dialc - 1) % diali : 0,
OpenPOWER on IntegriCloud