zsh-workers
 help / color / mirror / code / Atom feed
From: Louis.Granboulan@ens.fr (Louis Granboulan)
To: zsh-workers@math.gatech.edu
Subject: Re: Process substitution and shell functions
Date: Tue, 24 Sep 1996 18:47:36 +0200 (MET DST)	[thread overview]
Message-ID: <199609241647.SAA22028@pleurote.ens.fr> (raw)
In-Reply-To: <960920160213.ZM7718@candle.brasslantern.com> from "Bart Schaefer" at Sep 20, 96 04:02:13 pm

The removal of temporary files has many strange bugs.
At the end of this message, there is a patch that should fix all this.



The procedure deletepipejob (in exec.c) deletes a job without
deleting the filelist.  The variable last_file_list keeps track
of the filelist to delete. The value of last_file_list is
recovered in execpline.  It is saved and restored by execsave
and execrestore.

deletepipejob is called in execshfunc and execcursh.
The temporary files are removed at the end of the first command
called by zsh.

execshfunc
    This is the bug we've seen...
    First example:
	zsh% function foo { echo $1 ; cat $1 }
	zsh% foo =(echo hello world)
	/tmp/zsha24295
	cat: /tmp/zsha24295: No such file or directory
    Second example:
	zsh% autoload foobar
	zsh% foobar =(echo hello world)
	zsh: function not found: foobar
	zsh% ls -l /tmp/zsha21572
	-rw-------  1 granboul       12 Sep 24 18:01 /tmp/zsha21572
	zsh% ls -l /tmp/zsha21572
	/tmp/zsha21572 not found

execcursh
    I don't know why the removing of temporary files
    is delayed to the end of the first command.

My patch moves the recovering of last_file_list from execpline
to execshfunc.
I don't understand why this was in execpline...


*** Src/zsh.h.orig	Mon Aug 12 19:57:32 1996
--- Src/zsh.h	Tue Sep 24 18:08:07 1996
***************
*** 598,604 ****
      int list_pipe_child;
      int list_pipe_job;
      char list_pipe_text[JOBTEXTSIZE];
-     LinkList last_file_list;
      int lastval;
      int noeval;
      int badcshglob;
--- 598,603 ----
*** Src/exec.c.orig	Thu Aug 15 12:38:56 1996
--- Src/exec.c	Tue Sep 24 18:44:27 1996
***************
*** 119,136 ****
  static int nowait, pline_level = 0;
  static int list_pipe_child = 0, list_pipe_job;
  static char list_pipe_text[JOBTEXTSIZE];
- static LinkList last_file_list;
- 
- /**/
- void
- deletepipejob(void)
- {
-     if (!list_pipe) {
- 	last_file_list = jobtab[thisjob].filelist;
- 	jobtab[thisjob].filelist = NULL;
- 	deletejob(jobtab + thisjob);
-     }
- }
  
  /* execute a current shell command */
  
--- 119,124 ----
***************
*** 138,144 ****
  int
  execcursh(Cmd cmd)
  {
!     deletepipejob();
      execlist(cmd->u.list, 1, cmd->flags & CFLAG_EXEC);
      cmd->u.list = NULL;
      return lastval;
--- 126,132 ----
  int
  execcursh(Cmd cmd)
  {
!     if (!list_pipe) deletejob(jobtab + thisjob);
      execlist(cmd->u.list, 1, cmd->flags & CFLAG_EXEC);
      cmd->u.list = NULL;
      return lastval;
***************
*** 632,640 ****
      if (how & Z_TIMED)
  	jobtab[thisjob].stat |= STAT_TIMED;
  
-     jobtab[newjob].filelist = last_file_list;
-     last_file_list = NULL;
- 
      if (l->flags & PFLAG_COPROC) {
  	how = Z_ASYNC;
  	if (coprocin >= 0) {
--- 620,625 ----
***************
*** 2407,2416 ****
  {
      List funcdef;
      char *nam;
  
      if (errflag)
  	return;
!     deletepipejob();
  
      /* Are we dealing with an autoloaded shell function? */
      if (shf->flags & PM_UNDEFINED) {
--- 2392,2407 ----
  {
      List funcdef;
      char *nam;
+     LinkList last_file_list = NULL;
  
      if (errflag)
  	return;
! 
!     if (!list_pipe) {
! 	last_file_list = jobtab[thisjob].filelist;
! 	jobtab[thisjob].filelist = NULL;
! 	deletejob(jobtab + thisjob);
!     }
  
      /* Are we dealing with an autoloaded shell function? */
      if (shf->flags & PM_UNDEFINED) {
***************
*** 2418,2423 ****
--- 2409,2415 ----
  	if (!(funcdef = getfpfunc(nam))) {
  	    zerr("function not found: %s", nam, 0);
  	    lastval = 1;
+ 	    if (!list_pipe) deletefilelist(last_file_list);
  	    return;
  	}
  	PERMALLOC {
***************
*** 2433,2443 ****
--- 2425,2437 ----
  	if ((shf = (Shfunc) shfunctab->getnode(shfunctab, nam))
  	    && shf->funcdef && shf->funcdef != funcdef)
  	    doshfunc(shf->funcdef, cmd->args, shf->flags, 0);
+ 	if (!list_pipe) deletefilelist(last_file_list);
  	return;
      }
  
      /* Normal shell function execution */
      doshfunc(shf->funcdef, cmd->args, shf->flags, 0);
+     if (!list_pipe) deletefilelist(last_file_list);
  }
  
  /* execute a shell function */
***************
*** 2670,2676 ****
      es->list_pipe_child = list_pipe_child;
      es->list_pipe_job = list_pipe_job;
      strcpy(es->list_pipe_text, list_pipe_text);
-     es->last_file_list = last_file_list;
      es->lastval = lastval;
      es->noeval = noeval;
      es->badcshglob = badcshglob;
--- 2664,2669 ----
***************
*** 2698,2704 ****
      list_pipe_child = exstack->list_pipe_child;
      list_pipe_job = exstack->list_pipe_job;
      strcpy(list_pipe_text, exstack->list_pipe_text);
-     last_file_list = exstack->last_file_list;
      lastval = exstack->lastval;
      noeval = exstack->noeval;
      badcshglob = exstack->badcshglob;
--- 2691,2696 ----
*** Src/jobs.c.orig	Wed Jul 31 20:13:17 1996
--- Src/jobs.c	Tue Sep 24 18:38:04 1996
***************
*** 368,390 ****
  
  /**/
  void
  deletejob(Job jn)
  {
      struct process *pn, *nx;
-     char *s;
  
      for (pn = jn->procs; pn; pn = nx) {
  	nx = pn->next;
  	zfree(pn, sizeof(struct process));
      }
      zsfree(jn->pwd);
!     if (jn->filelist) {
! 	while ((s = (char *)getlinknode(jn->filelist))) {
! 	    unlink(s);
! 	    zsfree(s);
! 	}
! 	zfree(jn->filelist, sizeof(struct linklist));
!     }
      if (jn->ty)
  	zfree(jn->ty, sizeof(struct ttyinfo));
  
--- 368,399 ----
  
  /**/
  void
+ deletefilelist(LinkList file_list)
+ {
+     char *s;
+     if (file_list) {
+ 	while ((s = (char *)getlinknode(file_list))) {
+ 	    unlink(s);
+ 	    zsfree(s);
+ 	}
+ 	zfree(file_list, sizeof(struct linklist));
+     }
+ }
+ 
+ /**/
+ void
  deletejob(Job jn)
  {
      struct process *pn, *nx;
  
      for (pn = jn->procs; pn; pn = nx) {
  	nx = pn->next;
  	zfree(pn, sizeof(struct process));
      }
      zsfree(jn->pwd);
! 
!     deletefilelist(jn->filelist);
! 
      if (jn->ty)
  	zfree(jn->ty, sizeof(struct ttyinfo));
  


  parent reply	other threads:[~1996-09-24 16:59 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-09-20 23:02 Bart Schaefer
1996-09-21 18:39 ` Louis Granboulan
1996-09-24 16:47 ` Louis Granboulan [this message]
1996-09-24 18:01   ` Bart Schaefer
1996-09-25  8:51     ` Peter Stephenson
1996-09-26 18:32       ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=199609241647.SAA22028@pleurote.ens.fr \
    --to=louis.granboulan@ens.fr \
    --cc=zsh-workers@math.gatech.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).