Magellan Linux

Diff of /trunk/mkinitrd-magellan/klibc/usr/dash/redir.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1121 by niro, Fri Apr 24 18:32:46 2009 UTC revision 1122 by niro, Wed Aug 18 21:11:40 2010 UTC
# Line 145  redirect(union node *redir, int flags) Line 145  redirect(union node *redir, int flags)
145   if (likely(i == EMPTY)) {   if (likely(i == EMPTY)) {
146   i = CLOSED;   i = CLOSED;
147   if (fd != newfd) {   if (fd != newfd) {
148   i = savefd(fd);   i = savefd(fd, fd);
149   fd = -1;   fd = -1;
150   }   }
151   }   }
# Line 192  openredirect(union node *redir) Line 192  openredirect(union node *redir)
192   break;   break;
193   case NFROMTO:   case NFROMTO:
194   fname = redir->nfile.expfname;   fname = redir->nfile.expfname;
195   if ((f = open64(fname, O_RDWR|O_CREAT|O_TRUNC, 0666)) < 0)   if ((f = open64(fname, O_RDWR|O_CREAT, 0666)) < 0)
196   goto ecreate;   goto ecreate;
197   break;   break;
198   case NTO:   case NTO:
# Line 295  err: Line 295  err:
295  STATIC int  STATIC int
296  openhere(union node *redir)  openhere(union node *redir)
297  {  {
298     char *p;
299   int pip[2];   int pip[2];
300   size_t len = 0;   size_t len = 0;
301    
302   if (pipe(pip) < 0)   if (pipe(pip) < 0)
303   sh_error("Pipe call failed");   sh_error("Pipe call failed");
304   if (redir->type == NHERE) {  
305   len = strlen(redir->nhere.doc->narg.text);   p = redir->nhere.doc->narg.text;
306   if (len <= PIPESIZE) {   if (redir->type == NXHERE) {
307   xwrite(pip[1], redir->nhere.doc->narg.text, len);   expandarg(redir->nhere.doc, NULL, EXP_QUOTED);
308   goto out;   p = stackblock();
309   }   }
310    
311     len = strlen(p);
312     if (len <= PIPESIZE) {
313     xwrite(pip[1], p, len);
314     goto out;
315   }   }
316    
317   if (forkshell((struct job *)NULL, (union node *)NULL, FORK_NOJOB) == 0) {   if (forkshell((struct job *)NULL, (union node *)NULL, FORK_NOJOB) == 0) {
318   close(pip[0]);   close(pip[0]);
319   signal(SIGINT, SIG_IGN);   signal(SIGINT, SIG_IGN);
# Line 316  openhere(union node *redir) Line 323  openhere(union node *redir)
323   signal(SIGTSTP, SIG_IGN);   signal(SIGTSTP, SIG_IGN);
324  #endif  #endif
325   signal(SIGPIPE, SIG_DFL);   signal(SIGPIPE, SIG_DFL);
326   if (redir->type == NHERE)   xwrite(pip[1], p, len);
  xwrite(pip[1], redir->nhere.doc->narg.text, len);  
  else  
  expandhere(redir->nhere.doc, pip[1]);  
327   _exit(0);   _exit(0);
328   }   }
329  out:  out:
# Line 395  RESET { Line 399  RESET {
399   */   */
400    
401  int  int
402  savefd(int from)  savefd(int from, int ofd)
403  {  {
404   int newfd;   int newfd;
405   int err;   int err;
# Line 403  savefd(int from) Line 407  savefd(int from)
407   newfd = fcntl(from, F_DUPFD, 10);   newfd = fcntl(from, F_DUPFD, 10);
408   err = newfd < 0 ? errno : 0;   err = newfd < 0 ? errno : 0;
409   if (err != EBADF) {   if (err != EBADF) {
410   close(from);   close(ofd);
411   if (err)   if (err)
412   sh_error("%d: %s", from, strerror(err));   sh_error("%d: %s", from, strerror(err));
413   else   else

Legend:
Removed from v.1121  
changed lines
  Added in v.1122