]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.sbin/daemon/daemon.c
daemon: use braces with 'if' consistently
[FreeBSD/FreeBSD.git] / usr.sbin / daemon / daemon.c
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 1999 Berkeley Software Design, Inc. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. Berkeley Software Design Inc's name may not be used to endorse or
15  *    promote products derived from this software without specific prior
16  *    written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY BERKELEY SOFTWARE DESIGN INC ``AS IS'' AND
19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED.  IN NO EVENT SHALL BERKELEY SOFTWARE DESIGN INC BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  *
30  *      From BSDI: daemon.c,v 1.2 1996/08/15 01:11:09 jch Exp
31  */
32
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
35
36 #include <sys/param.h>
37 #include <sys/mman.h>
38 #include <sys/wait.h>
39
40 #include <fcntl.h>
41 #include <err.h>
42 #include <errno.h>
43 #include <getopt.h>
44 #include <libutil.h>
45 #include <login_cap.h>
46 #include <paths.h>
47 #include <pwd.h>
48 #include <signal.h>
49 #include <stdio.h>
50 #include <stdlib.h>
51 #include <unistd.h>
52 #include <string.h>
53 #include <strings.h>
54 #define SYSLOG_NAMES
55 #include <syslog.h>
56 #include <time.h>
57 #include <assert.h>
58
59 #define LBUF_SIZE 4096
60
61 struct log_params {
62         int dosyslog;
63         int logpri;
64         int noclose;
65         int outfd;
66         const char *outfn;
67 };
68
69 static void restrict_process(const char *);
70 static void handle_term(int);
71 static void handle_chld(int);
72 static void handle_hup(int);
73 static int open_log(const char *);
74 static void reopen_log(struct log_params *);
75 static int  listen_child(int, struct log_params *);
76 static int  get_log_mapping(const char *, const CODE *);
77 static void open_pid_files(const char *, const char *, struct pidfh **,
78                            struct pidfh **);
79 static void do_output(const unsigned char *, size_t, struct log_params *);
80 static void daemon_sleep(time_t, long);
81
82 static volatile sig_atomic_t terminate = 0, child_gone = 0, pid = 0,
83   do_log_reopen = 0;
84
85 static const char shortopts[] = "+cfHSp:P:ru:o:s:l:t:m:R:T:h";
86
87 static const struct option longopts[] = {
88         { "change-dir",         no_argument,            NULL,           'c' },
89         { "close-fds",          no_argument,            NULL,           'f' },
90         { "sighup",             no_argument,            NULL,           'H' },
91         { "syslog",             no_argument,            NULL,           'S' },
92         { "output-file",        required_argument,      NULL,           'o' },
93         { "output-mask",        required_argument,      NULL,           'm' },
94         { "child-pidfile",      required_argument,      NULL,           'p' },
95         { "supervisor-pidfile", required_argument,      NULL,           'P' },
96         { "restart",            no_argument,            NULL,           'r' },
97         { "restart-delay",      required_argument,      NULL,           'R' },
98         { "title",              required_argument,      NULL,           't' },
99         { "user",               required_argument,      NULL,           'u' },
100         { "syslog-priority",    required_argument,      NULL,           's' },
101         { "syslog-facility",    required_argument,      NULL,           'l' },
102         { "syslog-tag",         required_argument,      NULL,           'T' },
103         { "help",               no_argument,            NULL,           'h' },
104         { NULL,                 0,                      NULL,            0  }
105 };
106
107 static _Noreturn void
108 usage(int exitcode)
109 {
110         (void)fprintf(stderr,
111             "usage: daemon [-cfHrS] [-p child_pidfile] [-P supervisor_pidfile]\n"
112             "              [-u user] [-o output_file] [-t title]\n"
113             "              [-l syslog_facility] [-s syslog_priority]\n"
114             "              [-T syslog_tag] [-m output_mask] [-R restart_delay_secs]\n"
115             "command arguments ...\n");
116
117         (void)fprintf(stderr,
118             "  --change-dir         -c         Change the current working directory to root\n"
119             "  --close-fds          -f         Set stdin, stdout, stderr to /dev/null\n"
120             "  --sighup             -H         Close and re-open output file on SIGHUP\n"
121             "  --syslog             -S         Send output to syslog\n"
122             "  --output-file        -o <file>  Append output of the child process to file\n"
123             "  --output-mask        -m <mask>  What to send to syslog/file\n"
124             "                                  1=stdout, 2=stderr, 3=both\n"
125             "  --child-pidfile      -p <file>  Write PID of the child process to file\n"
126             "  --supervisor-pidfile -P <file>  Write PID of the supervisor process to file\n"
127             "  --restart            -r         Restart child if it terminates (1 sec delay)\n"
128             "  --restart-delay      -R <N>     Restart child if it terminates after N sec\n"
129             "  --title              -t <title> Set the title of the supervisor process\n"
130             "  --user               -u <user>  Drop privileges, run as given user\n"
131             "  --syslog-priority    -s <prio>  Set syslog priority\n"
132             "  --syslog-facility    -l <flty>  Set syslog facility\n"
133             "  --syslog-tag         -T <tag>   Set syslog tag\n"
134             "  --help               -h         Show this help\n");
135
136         exit(exitcode);
137 }
138
139 int
140 main(int argc, char *argv[])
141 {
142         const char *pidfile, *ppidfile, *title, *user, *outfn, *logtag;
143         int ch, nochdir, noclose, restart, dosyslog, child_eof;
144         sigset_t mask_susp, mask_orig, mask_read, mask_term;
145         struct log_params logpar;
146         int pfd[2] = { -1, -1 }, outfd = -1;
147         int stdmask, logpri, logfac, log_reopen;
148         struct pidfh *ppfh, *pfh;
149         char *p;
150
151         memset(&logpar, 0, sizeof(logpar));
152         stdmask = STDOUT_FILENO | STDERR_FILENO;
153         ppidfile = pidfile = user = NULL;
154         nochdir = noclose = 1;
155         logpri = LOG_NOTICE;
156         logfac = LOG_DAEMON;
157         logtag = "daemon";
158         restart = 0;
159         dosyslog = 0;
160         log_reopen = 0;
161         outfn = NULL;
162         title = NULL;
163         while ((ch = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) {
164                 switch (ch) {
165                 case 'c':
166                         nochdir = 0;
167                         break;
168                 case 'f':
169                         noclose = 0;
170                         break;
171                 case 'H':
172                         log_reopen = 1;
173                         break;
174                 case 'l':
175                         logfac = get_log_mapping(optarg, facilitynames);
176                         if (logfac == -1) {
177                                 errx(5, "unrecognized syslog facility");
178                         }
179                         dosyslog = 1;
180                         break;
181                 case 'm':
182                         stdmask = strtol(optarg, &p, 10);
183                         if (p == optarg || stdmask < 0 || stdmask > 3) {
184                                 errx(6, "unrecognized listening mask");
185                         }
186                         break;
187                 case 'o':
188                         outfn = optarg;
189                         break;
190                 case 'p':
191                         pidfile = optarg;
192                         break;
193                 case 'P':
194                         ppidfile = optarg;
195                         break;
196                 case 'r':
197                         restart = 1;
198                         break;
199                 case 'R':
200                         restart = strtol(optarg, &p, 0);
201                         if (p == optarg || restart < 1) {
202                                 errx(6, "invalid restart delay");
203                         }
204                         break;
205                 case 's':
206                         logpri = get_log_mapping(optarg, prioritynames);
207                         if (logpri == -1) {
208                                 errx(4, "unrecognized syslog priority");
209                         }
210                         dosyslog = 1;
211                         break;
212                 case 'S':
213                         dosyslog = 1;
214                         break;
215                 case 't':
216                         title = optarg;
217                         break;
218                 case 'T':
219                         logtag = optarg;
220                         dosyslog = 1;
221                         break;
222                 case 'u':
223                         user = optarg;
224                         break;
225                 case 'h':
226                         usage(0);
227                         __builtin_unreachable();
228                 default:
229                         usage(1);
230                 }
231         }
232         argc -= optind;
233         argv += optind;
234
235         if (argc == 0) {
236                 usage(1);
237         }
238
239         if (!title) {
240                 title = argv[0];
241         }
242
243         if (outfn) {
244                 outfd = open_log(outfn);
245                 if (outfd == -1) {
246                         err(7, "open");
247                 }
248         }
249
250         if (dosyslog) {
251                 openlog(logtag, LOG_PID | LOG_NDELAY, logfac);
252         }
253
254         ppfh = pfh = NULL;
255         /*
256          * Try to open the pidfile before calling daemon(3),
257          * to be able to report the error intelligently
258          */
259         open_pid_files(pidfile, ppidfile, &pfh, &ppfh);
260         if (daemon(nochdir, noclose) == -1) {
261                 warn("daemon");
262                 goto exit;
263         }
264         /* Write out parent pidfile if needed. */
265         pidfile_write(ppfh);
266         /*
267          * If the pidfile or restart option is specified the daemon
268          * executes the command in a forked process and wait on child
269          * exit to remove the pidfile or restart the command. Normally
270          * we don't want the monitoring daemon to be terminated
271          * leaving the running process and the stale pidfile, so we
272          * catch SIGTERM and forward it to the children expecting to
273          * get SIGCHLD eventually. We also must fork() to obtain a
274          * readable pipe with the child for writing to a log file
275          * and syslog.
276          */
277         pid = -1;
278         if (pidfile || ppidfile || restart || outfd != -1 || dosyslog) {
279                 struct sigaction act_term, act_chld, act_hup;
280
281                 /* Avoid PID racing with SIGCHLD and SIGTERM. */
282                 memset(&act_term, 0, sizeof(act_term));
283                 act_term.sa_handler = handle_term;
284                 sigemptyset(&act_term.sa_mask);
285                 sigaddset(&act_term.sa_mask, SIGCHLD);
286
287                 memset(&act_chld, 0, sizeof(act_chld));
288                 act_chld.sa_handler = handle_chld;
289                 sigemptyset(&act_chld.sa_mask);
290                 sigaddset(&act_chld.sa_mask, SIGTERM);
291
292                 memset(&act_hup, 0, sizeof(act_hup));
293                 act_hup.sa_handler = handle_hup;
294                 sigemptyset(&act_hup.sa_mask);
295
296                 /* Block these when avoiding racing before sigsuspend(). */
297                 sigemptyset(&mask_susp);
298                 sigaddset(&mask_susp, SIGTERM);
299                 sigaddset(&mask_susp, SIGCHLD);
300                 /* Block SIGTERM when we lack a valid child PID. */
301                 sigemptyset(&mask_term);
302                 sigaddset(&mask_term, SIGTERM);
303                 /*
304                  * When reading, we wish to avoid SIGCHLD. SIGTERM
305                  * has to be caught, otherwise we'll be stuck until
306                  * the read() returns - if it returns.
307                  */
308                 sigemptyset(&mask_read);
309                 sigaddset(&mask_read, SIGCHLD);
310                 /* Block SIGTERM to avoid racing until we have forked. */
311                 if (sigprocmask(SIG_BLOCK, &mask_term, &mask_orig)) {
312                         warn("sigprocmask");
313                         goto exit;
314                 }
315                 if (sigaction(SIGTERM, &act_term, NULL) == -1) {
316                         warn("sigaction");
317                         goto exit;
318                 }
319                 if (sigaction(SIGCHLD, &act_chld, NULL) == -1) {
320                         warn("sigaction");
321                         goto exit;
322                 }
323                 /*
324                  * Try to protect against pageout kill. Ignore the
325                  * error, madvise(2) will fail only if a process does
326                  * not have superuser privileges.
327                  */
328                 (void)madvise(NULL, 0, MADV_PROTECT);
329                 logpar.outfd = outfd;
330                 logpar.dosyslog = dosyslog;
331                 logpar.logpri = logpri;
332                 logpar.noclose = noclose;
333                 logpar.outfn = outfn;
334                 if (log_reopen && outfd >= 0 &&
335                     sigaction(SIGHUP, &act_hup, NULL) == -1) {
336                         warn("sigaction");
337                         goto exit;
338                 }
339 restart:
340                 if (pipe(pfd)) {
341                         err(1, "pipe");
342                 }
343                 /*
344                  * Spawn a child to exec the command.
345                  */
346                 child_gone = 0;
347                 pid = fork();
348                 if (pid == -1) {
349                         warn("fork");
350                         goto exit;
351                 } else if (pid > 0) {
352                         /*
353                          * Unblock SIGTERM after we know we have a valid
354                          * child PID to signal.
355                          */
356                         if (sigprocmask(SIG_UNBLOCK, &mask_term, NULL)) {
357                                 warn("sigprocmask");
358                                 goto exit;
359                         }
360                         close(pfd[1]);
361                         pfd[1] = -1;
362                 }
363         }
364         if (pid <= 0) {
365                 /* Now that we are the child, write out the pid. */
366                 pidfile_write(pfh);
367
368                 if (user != NULL) {
369                         restrict_process(user);
370                 }
371                 /*
372                  * When forking, the child gets the original sigmask,
373                  * and dup'd pipes.
374                  */
375                 if (pid == 0) {
376                         close(pfd[0]);
377                         if (sigprocmask(SIG_SETMASK, &mask_orig, NULL)) {
378                                 err(1, "sigprogmask");
379                         }
380                         if (stdmask & STDERR_FILENO) {
381                                 if (dup2(pfd[1], STDERR_FILENO) == -1) {
382                                         err(1, "dup2");
383                                 }
384                         }
385                         if (stdmask & STDOUT_FILENO) {
386                                 if (dup2(pfd[1], STDOUT_FILENO) == -1) {
387                                         err(1, "dup2");
388                                 }
389                         }
390                         if (pfd[1] != STDERR_FILENO &&
391                             pfd[1] != STDOUT_FILENO) {
392                                 close(pfd[1]);
393                         }
394                 }
395                 execvp(argv[0], argv);
396                 /*
397                  * execvp() failed -- report the error. The child is
398                  * now running, so the exit status doesn't matter.
399                  */
400                 err(1, "%s", argv[0]);
401         }
402         setproctitle("%s[%d]", title, (int)pid);
403         /*
404          * As we have closed the write end of pipe for parent process,
405          * we might detect the child's exit by reading EOF. The child
406          * might have closed its stdout and stderr, so we must wait for
407          * the SIGCHLD to ensure that the process is actually gone.
408          */
409         child_eof = 0;
410         for (;;) {
411                 /*
412                  * We block SIGCHLD when listening, but SIGTERM we accept
413                  * so the read() won't block if we wish to depart.
414                  *
415                  * Upon receiving SIGTERM, we have several options after
416                  * sending the SIGTERM to our child:
417                  * - read until EOF
418                  * - read until EOF but only for a while
419                  * - bail immediately
420                  *
421                  * We go for the third, as otherwise we have no guarantee
422                  * that we won't block indefinitely if the child refuses
423                  * to depart. To handle the second option, a different
424                  * approach would be needed (procctl()?)
425                  */
426                 if (child_gone && child_eof) {
427                         break;
428                 } else if (terminate) {
429                         goto exit;
430                 } else if (!child_eof) {
431                         if (sigprocmask(SIG_BLOCK, &mask_read, NULL)) {
432                                 warn("sigprocmask");
433                                 goto exit;
434                         }
435                         child_eof = !listen_child(pfd[0], &logpar);
436                         if (sigprocmask(SIG_UNBLOCK, &mask_read, NULL)) {
437                                 warn("sigprocmask");
438                                 goto exit;
439                         }
440                 } else {
441                         if (sigprocmask(SIG_BLOCK, &mask_susp, NULL)) {
442                                 warn("sigprocmask");
443                                 goto exit;
444                         }
445                         while (!terminate && !child_gone)
446                                 sigsuspend(&mask_orig);
447                         if (sigprocmask(SIG_UNBLOCK, &mask_susp, NULL)) {
448                                 warn("sigprocmask");
449                                 goto exit;
450                         }
451                 }
452         }
453         if (restart && !terminate) {
454                 daemon_sleep(restart, 0);
455         }
456         if (sigprocmask(SIG_BLOCK, &mask_term, NULL)) {
457                 warn("sigprocmask");
458                 goto exit;
459         }
460         if (restart && !terminate) {
461                 close(pfd[0]);
462                 pfd[0] = -1;
463                 goto restart;
464         }
465 exit:
466         close(outfd);
467         close(pfd[0]);
468         close(pfd[1]);
469         if (dosyslog) {
470                 closelog();
471         }
472         pidfile_remove(pfh);
473         pidfile_remove(ppfh);
474         exit(1); /* If daemon(3) succeeded exit status does not matter. */
475 }
476
477 static void
478 daemon_sleep(time_t secs, long nsecs)
479 {
480         struct timespec ts = { secs, nsecs };
481
482         while (!terminate && nanosleep(&ts, &ts) == -1) {
483                 if (errno != EINTR) {
484                         err(1, "nanosleep");
485                 }
486         }
487 }
488
489 static void
490 open_pid_files(const char *pidfile, const char *ppidfile,
491                struct pidfh **pfh, struct pidfh **ppfh)
492 {
493         pid_t fpid;
494         int serrno;
495
496         if (pidfile) {
497                 *pfh = pidfile_open(pidfile, 0600, &fpid);
498                 if (*pfh == NULL) {
499                         if (errno == EEXIST) {
500                                 errx(3, "process already running, pid: %d",
501                                     fpid);
502                         }
503                         err(2, "pidfile ``%s''", pidfile);
504                 }
505         }
506         /* Do the same for the actual daemon process. */
507         if (ppidfile) {
508                 *ppfh = pidfile_open(ppidfile, 0600, &fpid);
509                 if (*ppfh == NULL) {
510                         serrno = errno;
511                         pidfile_remove(*pfh);
512                         errno = serrno;
513                         if (errno == EEXIST) {
514                                 errx(3, "process already running, pid: %d",
515                                      fpid);
516                         }
517                         err(2, "ppidfile ``%s''", ppidfile);
518                 }
519         }
520 }
521
522 static int
523 get_log_mapping(const char *str, const CODE *c)
524 {
525         const CODE *cp;
526         for (cp = c; cp->c_name; cp++)
527                 if (strcmp(cp->c_name, str) == 0) {
528                         return cp->c_val;
529                 }
530         return -1;
531 }
532
533 static void
534 restrict_process(const char *user)
535 {
536         struct passwd *pw = NULL;
537
538         pw = getpwnam(user);
539         if (pw == NULL) {
540                 errx(1, "unknown user: %s", user);
541         }
542
543         if (setusercontext(NULL, pw, pw->pw_uid, LOGIN_SETALL) != 0) {
544                 errx(1, "failed to set user environment");
545         }
546
547         setenv("USER", pw->pw_name, 1);
548         setenv("HOME", pw->pw_dir, 1);
549         setenv("SHELL", *pw->pw_shell ? pw->pw_shell : _PATH_BSHELL, 1);
550 }
551
552 /*
553  * We try to collect whole lines terminated by '\n'. Otherwise we collect a
554  * full buffer, and then output it.
555  *
556  * Return value of 0 is assumed to mean EOF or error, and 1 indicates to
557  * continue reading.
558  */
559 static int
560 listen_child(int fd, struct log_params *logpar)
561 {
562         static unsigned char buf[LBUF_SIZE];
563         static size_t bytes_read = 0;
564         int rv;
565
566         assert(logpar);
567         assert(bytes_read < LBUF_SIZE - 1);
568
569         if (do_log_reopen) {
570                 reopen_log(logpar);
571         }
572         rv = read(fd, buf + bytes_read, LBUF_SIZE - bytes_read - 1);
573         if (rv > 0) {
574                 unsigned char *cp;
575
576                 bytes_read += rv;
577                 assert(bytes_read <= LBUF_SIZE - 1);
578                 /* Always NUL-terminate just in case. */
579                 buf[LBUF_SIZE - 1] = '\0';
580                 /*
581                  * Chomp line by line until we run out of buffer.
582                  * This does not take NUL characters into account.
583                  */
584                 while ((cp = memchr(buf, '\n', bytes_read)) != NULL) {
585                         size_t bytes_line = cp - buf + 1;
586                         assert(bytes_line <= bytes_read);
587                         do_output(buf, bytes_line, logpar);
588                         bytes_read -= bytes_line;
589                         memmove(buf, cp + 1, bytes_read);
590                 }
591                 /* Wait until the buffer is full. */
592                 if (bytes_read < LBUF_SIZE - 1) {
593                         return 1;
594                 }
595                 do_output(buf, bytes_read, logpar);
596                 bytes_read = 0;
597                 return 1;
598         } else if (rv == -1) {
599                 /* EINTR should trigger another read. */
600                 if (errno == EINTR) {
601                         return 1;
602                 } else {
603                         warn("read");
604                         return 0;
605                 }
606         }
607         /* Upon EOF, we have to flush what's left of the buffer. */
608         if (bytes_read > 0) {
609                 do_output(buf, bytes_read, logpar);
610                 bytes_read = 0;
611         }
612         return 0;
613 }
614
615 /*
616  * The default behavior is to stay silent if the user wants to redirect
617  * output to a file and/or syslog. If neither are provided, then we bounce
618  * everything back to parent's stdout.
619  */
620 static void
621 do_output(const unsigned char *buf, size_t len, struct log_params *logpar)
622 {
623         assert(len <= LBUF_SIZE);
624         assert(logpar);
625
626         if (len < 1) {
627                 return;
628         }
629         if (logpar->dosyslog) {
630                 syslog(logpar->logpri, "%.*s", (int)len, buf);
631         }
632         if (logpar->outfd != -1) {
633                 if (write(logpar->outfd, buf, len) == -1)
634                         warn("write");
635         }
636         if (logpar->noclose && !logpar->dosyslog && logpar->outfd == -1) {
637                 printf("%.*s", (int)len, buf);
638         }
639 }
640
641 /*
642  * We use the global PID acquired directly from fork. If there is no valid
643  * child pid, the handler should be blocked and/or child_gone == 1.
644  */
645 static void
646 handle_term(int signo)
647 {
648         if (pid > 0 && !child_gone) {
649                 kill(pid, signo);
650         }
651         terminate = 1;
652 }
653
654 static void
655 handle_chld(int signo __unused)
656 {
657
658         for (;;) {
659                 int rv = waitpid(-1, NULL, WNOHANG);
660                 if (pid == rv) {
661                         child_gone = 1;
662                         break;
663                 } else if (rv == -1 && errno != EINTR) {
664                         warn("waitpid");
665                         return;
666                 }
667         }
668 }
669
670 static void
671 handle_hup(int signo __unused)
672 {
673
674         do_log_reopen = 1;
675 }
676
677 static int
678 open_log(const char *outfn)
679 {
680
681         return open(outfn, O_CREAT | O_WRONLY | O_APPEND | O_CLOEXEC, 0600);
682 }
683
684 static void
685 reopen_log(struct log_params *lpp)
686 {
687         int outfd;
688
689         do_log_reopen = 0;
690         outfd = open_log(lpp->outfn);
691         if (lpp->outfd >= 0) {
692                 close(lpp->outfd);
693         }
694         lpp->outfd = outfd;
695 }
696