Print this page
10143 smatch fix for ttymon


   8  *
   9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10  * or http://www.opensolaris.org/os/licensing.
  11  * See the License for the specific language governing permissions
  12  * and limitations under the License.
  13  *
  14  * When distributing Covered Code, include this CDDL HEADER in each
  15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16  * If applicable, add the following below this CDDL HEADER, with the
  17  * fields enclosed by brackets "[]" replaced with your own identifying
  18  * information: Portions Copyright [yyyy] [name of copyright owner]
  19  *
  20  * CDDL HEADER END
  21  */
  22 /*
  23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T     */
  27 /*        All Rights Reserved   */



  28 
  29 
  30 #pragma ident   "%Z%%M% %I%     %E% SMI"
  31 
  32 
  33 #include <stdlib.h>
  34 #include <stdio.h>
  35 #include <fcntl.h>
  36 #include <errno.h>
  37 #include <poll.h>
  38 #include <string.h>
  39 #include <termio.h>
  40 #include <signal.h>
  41 #include <sys/types.h>
  42 #include <sys/stropts.h>
  43 #include <unistd.h>
  44 #include <sys/wait.h>
  45 #include "ttymon.h"
  46 #include "tmstruct.h"
  47 #include "tmextern.h"
  48 #include "sac.h"
  49 
  50 extern  int     Retry;
  51 static  struct  pmtab   *find_pid();
  52 static  void    kill_children();


 616                 (void)sigemptyset(&sigact.sa_mask);
 617                 (void)sigaction(SIGALRM, &sigact, NULL);
 618                 (void)alarm(ALARMTIME);
 619         }
 620         else {
 621                 sigact.sa_flags = 0;
 622                 sigact.sa_handler = SIG_IGN;
 623                 (void)sigemptyset(&sigact.sa_mask);
 624                 (void)sigaction(SIGALRM, &sigact, NULL);
 625         }
 626 }
 627 
 628 /*
 629  * pcsync_close -  For the child process close all open fd's except
 630  * the one that is passed to the routine. Coordinate the reads and
 631  * writes to the pipes by the parent and child process to ensure
 632  * the parent and child processes have closed all the file descriptors
 633  * that are not needed any more.
 634  */
 635 static void
 636 pcsync_close(p0, p1, pid, fd)
 637 int     *p0;
 638 int     *p1;
 639 int     pid;
 640 {
 641         char    ch;
 642 
 643         if (pid == 0) {                         /* Child */
 644                 struct  pmtab   *tp;
 645                 for (tp = PMtab; tp; tp = tp->p_next)
 646                         if ((tp->p_fd > 0) && (tp->p_fd != fd))
 647                                 close(tp->p_fd);
 648                 close(p0[1]); close(p1[0]);
 649                 if (read(p0[0], &ch, 1) == 1)
 650                         write(p1[1], "a", 1);
 651                 close(p0[0]); close(p1[1]);
 652         } else {                                /* Parent */
 653                 close(p0[0]); close(p1[1]);
 654                 if (write(p0[1], "a", 1) == 1)
 655                         read(p1[0], &ch, 1);
 656                 close(p0[1]); close(p1[0]);
 657         }
 658 }


   8  *
   9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10  * or http://www.opensolaris.org/os/licensing.
  11  * See the License for the specific language governing permissions
  12  * and limitations under the License.
  13  *
  14  * When distributing Covered Code, include this CDDL HEADER in each
  15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16  * If applicable, add the following below this CDDL HEADER, with the
  17  * fields enclosed by brackets "[]" replaced with your own identifying
  18  * information: Portions Copyright [yyyy] [name of copyright owner]
  19  *
  20  * CDDL HEADER END
  21  */
  22 /*
  23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T     */
  27 /*        All Rights Reserved   */
  28 /*
  29  * Copyright (c) 2018, Joyent, Inc.
  30  */
  31 
  32 



  33 #include <stdlib.h>
  34 #include <stdio.h>
  35 #include <fcntl.h>
  36 #include <errno.h>
  37 #include <poll.h>
  38 #include <string.h>
  39 #include <termio.h>
  40 #include <signal.h>
  41 #include <sys/types.h>
  42 #include <sys/stropts.h>
  43 #include <unistd.h>
  44 #include <sys/wait.h>
  45 #include "ttymon.h"
  46 #include "tmstruct.h"
  47 #include "tmextern.h"
  48 #include "sac.h"
  49 
  50 extern  int     Retry;
  51 static  struct  pmtab   *find_pid();
  52 static  void    kill_children();


 616                 (void)sigemptyset(&sigact.sa_mask);
 617                 (void)sigaction(SIGALRM, &sigact, NULL);
 618                 (void)alarm(ALARMTIME);
 619         }
 620         else {
 621                 sigact.sa_flags = 0;
 622                 sigact.sa_handler = SIG_IGN;
 623                 (void)sigemptyset(&sigact.sa_mask);
 624                 (void)sigaction(SIGALRM, &sigact, NULL);
 625         }
 626 }
 627 
 628 /*
 629  * pcsync_close -  For the child process close all open fd's except
 630  * the one that is passed to the routine. Coordinate the reads and
 631  * writes to the pipes by the parent and child process to ensure
 632  * the parent and child processes have closed all the file descriptors
 633  * that are not needed any more.
 634  */
 635 static void
 636 pcsync_close(int *p0, int *p1, int pid, int fd)



 637 {
 638         char    ch;
 639 
 640         if (pid == 0) {                         /* Child */
 641                 struct  pmtab   *tp;
 642                 for (tp = PMtab; tp; tp = tp->p_next)
 643                         if ((tp->p_fd > 0) && (tp->p_fd != fd))
 644                                 close(tp->p_fd);
 645                 close(p0[1]); close(p1[0]);
 646                 if (read(p0[0], &ch, 1) == 1)
 647                         write(p1[1], "a", 1);
 648                 close(p0[0]); close(p1[1]);
 649         } else {                                /* Parent */
 650                 close(p0[0]); close(p1[1]);
 651                 if (write(p0[1], "a", 1) == 1)
 652                         read(p1[0], &ch, 1);
 653                 close(p0[1]); close(p1[0]);
 654         }
 655 }