patch for backtick process handling

[email protected]
Newsgroups gmane.comp.gnu.screen
Message-ID <[email protected]>
At Sat, 29 Nov 2003 16:36:11 +0900,
[email protected] wrote:
> BTW, I can made a Japanese Input framework with backtick and exec.
> http://www.daionet.gr.jp/~knok/screen/uim.html (Written in Japanese)

When screen was finished, I found a staied process forked by backtick.
I checked the source and it seems no care about process handling on
backtick, so I made a patch.

If it is merged into the original source, I would be happy.
-- 
NOKUBI Takatsugu
E-mail: [email protected]
	[email protected] / [email protected]

------------------------ Yahoo! Groups Sponsor ---------------------~-->
Buy Ink Cartridges or Refill Kits for your HP, Epson, Canon or Lexmark
Printer at MyInks.com. Free s/h on orders $50 or more to the US & Canada.
http://www.c1tracking.com/l.asp?cid=5511
http://us.click.yahoo.com/mOAaAA/3exGAA/qnsNAA/NhFolB/TM
---------------------------------------------------------------------~->

 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
screen-backtick-pid.diff (application/octet-stream, 3.3 KB)
diff -ur orig/screen-4.0.1/extern.h screen-4.0.1/extern.h
--- orig/screen-4.0.1/extern.h	2003-08-22 21:27:57.000000000 +0900
+++ screen-4.0.1/extern.h	2003-12-09 15:47:48.000000000 +0900
@@ -74,7 +74,7 @@
 extern char *ReadFile __P((char *, int *));
 extern void  KillBuffers __P((void));
 extern int   printpipe __P((struct win *, char *));
-extern int   readpipe __P((char **));
+extern int   readpipe __P((char **, int *));
 extern void  RunBlanker __P((char **));
 extern void  do_source __P((char *));
 
diff -ur orig/screen-4.0.1/fileio.c screen-4.0.1/fileio.c
--- orig/screen-4.0.1/fileio.c	2003-09-08 23:25:28.000000000 +0900
+++ screen-4.0.1/fileio.c	2003-12-09 15:56:44.000000000 +0900
@@ -789,17 +789,19 @@
 }
 
 int
-readpipe(cmdv)
+readpipe(cmdv, pidp)
 char **cmdv;
+int *pidp;
 {
   int pi[2];
+  int pid = -2;
 
   if (pipe(pi))
     {
       Msg(errno, "pipe");
       return -1;
     }
-  switch (fork())
+  switch (pid = fork())
     {
     case -1:
       Msg(errno, "fork");
@@ -832,5 +834,7 @@
       break;
     }
   close(pi[1]);
+  if (pidp != NULL)
+    *pidp = pid;
   return pi[0];
 }
diff -ur orig/screen-4.0.1/screen.c screen-4.0.1/screen.c
--- orig/screen-4.0.1/screen.c	2003-09-08 23:26:41.000000000 +0900
+++ screen-4.0.1/screen.c	2003-12-09 16:24:39.000000000 +0900
@@ -232,6 +232,21 @@
 struct win *windows;
 struct win *console_window;
 
+struct backtick {
+  struct backtick *next;
+  int num;
+  int tick;
+  int lifespan;
+  time_t bestbefore;
+  char result[MAXSTR];
+  char **cmdv;
+  struct event ev;
+  char *buf;
+  int bufi;
+  int pid;
+};
+
+struct backtick *backticks;
 
 
 /*
@@ -1645,6 +1660,7 @@
     }
   for (display = displays; display; display = display->d_next)
     {
+      struct backtick *bt;
       if (D_status)
 	RemoveStatus();
       FinitTerm();
@@ -1653,6 +1669,8 @@
 #endif
       AddStr("[screen is terminating]\r\n");
       Flush();
+      for (bt = backticks; bt; bt = bt->next)
+	kill(bt->pid, SIGTERM);
       SetTTY(D_userfd, &D_OldMode);
       fcntl(D_userfd, F_SETFL, 0);
       freetty();
@@ -2067,21 +2085,6 @@
   return pn2;
 }
 
-struct backtick {
-  struct backtick *next;
-  int num;
-  int tick;
-  int lifespan;
-  time_t bestbefore;
-  char result[MAXSTR];
-  char **cmdv;
-  struct event ev;
-  char *buf;
-  int bufi;
-};
-
-struct backtick *backticks;
-
 static void
 backtick_filter(bt)
 struct backtick *bt;
@@ -2178,6 +2181,7 @@
     }
   if (bt && !cmdv)
     {
+      kill(bt->pid, SIGTERM);
       *btp = bt->next;
       free(bt);
       return;
@@ -2194,6 +2198,10 @@
       bt->next = 0;
       *btp = bt;
     }
+  else
+    {
+      kill(bt->pid, SIGTERM);
+    }
   bt->num = num;
   bt->tick = tick;
   bt->lifespan = lifespan;
@@ -2214,7 +2222,7 @@
           return;
 	}
       bt->ev.type = EV_READ;
-      bt->ev.fd = readpipe(bt->cmdv);
+      bt->ev.fd = readpipe(bt->cmdv, &bt->pid);
       bt->ev.handler = backtick_fn;
       bt->ev.data = (char *)bt;
       if (bt->ev.fd >= 0)
@@ -2239,7 +2247,7 @@
       debug1("returning old result (%d)\n", bt->lifespan);
       return bt->result;
     }
-  f = readpipe(bt->cmdv);
+  f = readpipe(bt->cmdv, &bt->pid);
   if (f == -1)
     return bt->result;
   i = 0;
@@ -2773,6 +2781,7 @@
       ev->timeout = now;
       debug2("NEW timeout %d %d\n", ev->timeout.tv_sec, tick);
     }
+      debug1("MakeWinMsgEv: %s\n", winmsg_buf); /* XXX */
   return winmsg_buf;
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.