[BACK]Return to popen.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / mail

Diff for /src/usr.bin/mail/popen.c between version 1.5 and 1.6

version 1.5, 1997/05/30 08:51:43 version 1.6, 1997/07/13 21:21:15
Line 1 
Line 1 
 /*      $OpenBSD$       */  /*      $OpenBSD$       */
 /*      $NetBSD: popen.c,v 1.4 1996/06/08 19:48:35 christos Exp $       */  /*      $NetBSD: popen.c,v 1.6 1997/05/13 06:48:42 mikel Exp $  */
   
 /*  /*
  * Copyright (c) 1980, 1993   * Copyright (c) 1980, 1993
Line 81 
Line 81 
                 register_file(fp, 0, 0);                  register_file(fp, 0, 0);
                 (void) fcntl(fileno(fp), F_SETFD, 1);                  (void) fcntl(fileno(fp), F_SETFD, 1);
         }          }
         return fp;          return(fp);
 }  }
   
 FILE *  FILE *
Line 95 
Line 95 
                 register_file(fp, 0, 0);                  register_file(fp, 0, 0);
                 (void) fcntl(fileno(fp), F_SETFD, 1);                  (void) fcntl(fileno(fp), F_SETFD, 1);
         }          }
         return fp;          return(fp);
 }  }
   
 int  int
Line 103 
Line 103 
         FILE *fp;          FILE *fp;
 {  {
         unregister_file(fp);          unregister_file(fp);
         return fclose(fp);          return(fclose(fp));
 }  }
   
 FILE *  FILE *
Line 118 
Line 118 
         FILE *fp;          FILE *fp;
   
         if (pipe(p) < 0)          if (pipe(p) < 0)
                 return NULL;                  return(NULL);
         (void) fcntl(p[READ], F_SETFD, 1);          (void) fcntl(p[READ], F_SETFD, 1);
         (void) fcntl(p[WRITE], F_SETFD, 1);          (void) fcntl(p[WRITE], F_SETFD, 1);
         if (*mode == 'r') {          if (*mode == 'r') {
Line 132 
Line 132 
         }          }
         sigemptyset(&nset);          sigemptyset(&nset);
         if ((pid = start_command(cmd, &nset, fd0, fd1, NOSTR, NOSTR, NOSTR)) < 0) {          if ((pid = start_command(cmd, &nset, fd0, fd1, NOSTR, NOSTR, NOSTR)) < 0) {
                 close(p[READ]);                  (void)close(p[READ]);
                 close(p[WRITE]);                  (void)close(p[WRITE]);
                 return NULL;                  return(NULL);
         }          }
         (void) close(hisside);          (void)close(hisside);
         if ((fp = fdopen(myside, mode)) != NULL)          if ((fp = fdopen(myside, mode)) != NULL)
                 register_file(fp, 1, pid);                  register_file(fp, 1, pid);
         return fp;          return(fp);
 }  }
   
 int  int
Line 151 
Line 151 
   
         i = file_pid(ptr);          i = file_pid(ptr);
         unregister_file(ptr);          unregister_file(ptr);
         (void) fclose(ptr);          (void)fclose(ptr);
         sigemptyset(&nset);          sigemptyset(&nset);
         sigaddset(&nset, SIGINT);          sigaddset(&nset, SIGINT);
         sigaddset(&nset, SIGHUP);          sigaddset(&nset, SIGHUP);
         sigprocmask(SIG_BLOCK, &nset, &oset);          sigprocmask(SIG_BLOCK, &nset, &oset);
         i = wait_child(i);          i = wait_child(i);
         sigprocmask(SIG_SETMASK, &oset, NULL);          sigprocmask(SIG_SETMASK, &oset, NULL);
         return i;          return(i);
 }  }
   
 void  void
Line 167 
Line 167 
   
         while (fp_head)          while (fp_head)
                 if (fp_head->pipe)                  if (fp_head->pipe)
                         (void) Pclose(fp_head->fp);                          (void)Pclose(fp_head->fp);
                 else                  else
                         (void) Fclose(fp_head->fp);                          (void)Fclose(fp_head->fp);
 }  }
   
 void  void
Line 179 
Line 179 
 {  {
         struct fp *fpp;          struct fp *fpp;
   
         if ((fpp = (struct fp *) malloc(sizeof *fpp)) == NULL)          if ((fpp = (struct fp *) malloc(sizeof(*fpp))) == NULL)
                 panic("Out of memory");                  panic("Out of memory");
         fpp->fp = fp;          fpp->fp = fp;
         fpp->pipe = pipe;          fpp->pipe = pipe;
Line 211 
Line 211 
   
         for (p = fp_head; p; p = p->link)          for (p = fp_head; p; p = p->link)
                 if (p->fp == fp)                  if (p->fp == fp)
                         return (p->pid);                          return(p->pid);
         panic("Invalid file pointer");          panic("Invalid file pointer");
         /*NOTREACHED*/          /*NOTREACHED*/
 }  }
Line 234 
Line 234 
         int pid;          int pid;
   
         if ((pid = start_command(cmd, mask, infd, outfd, a0, a1, a2)) < 0)          if ((pid = start_command(cmd, mask, infd, outfd, a0, a1, a2)) < 0)
                 return -1;                  return(-1);
         return wait_command(pid);          return(wait_command(pid));
 }  }
   
 /*VARARGS4*/  /*VARARGS4*/
Line 249 
Line 249 
         int pid;          int pid;
   
         if ((pid = vfork()) < 0) {          if ((pid = vfork()) < 0) {
                 perror("fork");                  warn("fork");
                 return -1;                  return(-1);
         }          }
         if (pid == 0) {          if (pid == 0) {
                 char *argv[100];                  char *argv[100];
                 int i = getrawlist(cmd, argv, sizeof argv / sizeof *argv);                  int i = getrawlist(cmd, argv, sizeof(argv)/ sizeof(*argv));
   
                 if ((argv[i++] = a0) != NOSTR &&                  if ((argv[i++] = a0) != NOSTR &&
                     (argv[i++] = a1) != NOSTR &&                      (argv[i++] = a1) != NOSTR &&
Line 262 
Line 262 
                         argv[i] = NOSTR;                          argv[i] = NOSTR;
                 prepare_child(mask, infd, outfd);                  prepare_child(mask, infd, outfd);
                 execvp(argv[0], argv);                  execvp(argv[0], argv);
                 perror(argv[0]);                  warn(argv[0]);
                 _exit(1);                  _exit(1);
         }          }
         return pid;          return(pid);
 }  }
   
 void  void
Line 284 
Line 284 
                 dup2(infd, 0);                  dup2(infd, 0);
         if (outfd >= 0)          if (outfd >= 0)
                 dup2(outfd, 1);                  dup2(outfd, 1);
         if (nset) {          if (nset == NULL)
                   return;
           if (nset != NULL) {
                 for (i = 1; i < NSIG; i++)                  for (i = 1; i < NSIG; i++)
                         if (sigismember(nset, i))                          if (sigismember(nset, i))
                                 (void) signal(i, SIG_IGN);                                  (void) signal(i, SIG_IGN);
                 if (!sigismember(nset, SIGINT))  
                         (void) signal(SIGINT, SIG_DFL);  
         }          }
           if (nset == NULL || !sigismember(nset, SIGINT))
                   (void) signal(SIGINT, SIG_DFL);
         sigfillset(&fset);          sigfillset(&fset);
         (void) sigprocmask(SIG_UNBLOCK, &fset, NULL);          (void) sigprocmask(SIG_UNBLOCK, &fset, NULL);
 }  }
Line 301 
Line 303 
 {  {
   
         if (wait_child(pid) < 0) {          if (wait_child(pid) < 0) {
                 printf("Fatal error in process.\n");                  puts("Fatal error in process.");
                 return -1;                  return(-1);
         }          }
         return 0;          return(0);
 }  }
   
 static struct child *  static struct child *
Line 317 
Line 319 
              cpp = &(*cpp)->link)               cpp = &(*cpp)->link)
                         ;                          ;
         if (*cpp == NULL) {          if (*cpp == NULL) {
                 *cpp = (struct child *) malloc(sizeof (struct child));                  *cpp = (struct child *) malloc(sizeof(struct child));
                 (*cpp)->pid = pid;                  (*cpp)->pid = pid;
                 (*cpp)->done = (*cpp)->free = 0;                  (*cpp)->done = (*cpp)->free = 0;
                 (*cpp)->link = NULL;                  (*cpp)->link = NULL;
         }          }
         return *cpp;          return(*cpp);
 }  }
   
 static void  static void
Line 377 
Line 379 
         wait_status = cp->status;          wait_status = cp->status;
         delchild(cp);          delchild(cp);
         sigprocmask(SIG_SETMASK, &oset, NULL);          sigprocmask(SIG_SETMASK, &oset, NULL);
         return wait_status.w_status ? -1 : 0;          return(wait_status.w_status ? -1 : 0);
 }  }
   
 /*  /*
Line 415 
Line 417 
         if (action == 0) {          if (action == 0) {
                 /* Clear the lock */                  /* Clear the lock */
                 if (lockfp == NULL) {                  if (lockfp == NULL) {
                         fprintf(stderr,                          fputs("handle_spool_locks: no spool lock to remove.\n",
                             "handle_spool_locks: no spool lock to remove.\n");                              stderr);
                         return (-1);                          return(-1);
                 }                  }
                 (void)kill(lock_pid, SIGTERM);                  (void)kill(lock_pid, SIGTERM);
                 Pclose(lockfp);                  (void)Pclose(lockfp);
                 lockfp = NULL;                  lockfp = NULL;
         } else if (action == 1) {          } else if (action == 1) {
                 /* Create the lock */                  /* Create the lock */
Line 430 
Line 432 
                 if ((lockfp = Popen(cmd, "r")) == NULL || getc(lockfp) != '1') {                  if ((lockfp = Popen(cmd, "r")) == NULL || getc(lockfp) != '1') {
                         lockfp = NULL;                          lockfp = NULL;
                         free(cmd);                          free(cmd);
                         return (0);                          return(0);
                 }                  }
   
                 lock_pid = fp_head->pid;        /* new entries added at head */                  lock_pid = fp_head->pid;        /* new entries added at head */
Line 438 
Line 440 
         } else {          } else {
                 fprintf(stderr, "handle_spool_locks: unknown action %d\n",                  fprintf(stderr, "handle_spool_locks: unknown action %d\n",
                     action);                      action);
                 return (-1);                  return(-1);
         }          }
   
         return (1);          return(1);
 }  }
   
 int  int

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6