File: 0027-runsv.c-sv.c-properly-wait-for-log-on-exit.patch

package info (click to toggle)
runit 2.2.0-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,424 kB
  • sloc: ansic: 6,071; sh: 2,614; makefile: 399
file content (144 lines) | stat: -rw-r--r-- 4,240 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
Description: runsv.c, sv.c: on exit, properly wait for log service to terminate.
 When runsv is told to exit, it now no longer processes any control
 characters read from the control pipe (it still does for the log
 service).  It waits until the log service has terminated and then
 exits.  The sv program now properly reports this through the status
command.
Author: Gerrit Pape <pape@smarden.org>
Origin: upstream
Bug: https://www.mail-archive.com/supervision@list.skarnet.org/msg00121.html
Forwarded: not-needed
Last-Update: 2025-04-29
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/runit-2.2.0/man/runsv.8
+++ b/runit-2.2.0/man/runsv.8
@@ -148,6 +148,7 @@
 If the service is down and a log service exists,
 .B runsv
 closes the standard input of the log service, and waits for it to terminate.
+No more control characters will be processed.
 If the log service is down,
 .B runsv
 exits.
--- a/runit-2.2.0/man/sv.8
+++ b/runit-2.2.0/man/sv.8
@@ -78,6 +78,7 @@
 If the service is down and a log service exists,
 .BR runsv (8)
 closes the standard input of the log service and waits for it to terminate.
+No more commands will be processed.
 If the log service is down,
 .BR runsv (8)
 exits.
--- a/runit-2.2.0/src/runsv.c
+++ b/runit-2.2.0/src/runsv.c
@@ -31,6 +31,7 @@
 #define S_DOWN 0
 #define S_RUN 1
 #define S_FINISH 2
+#define S_WAIT 3
 /* ctrl */
 #define C_NOOP 0
 #define C_TERM 1
@@ -149,18 +150,20 @@
   case S_FINISH:
     buffer_puts(&b, "finish");
     break;
+  case S_WAIT:
+    buffer_puts(&b, "wait");
+    break;
   }
   if (s->ctrl & C_PAUSE) buffer_puts(&b, ", paused");
   if (s->ctrl & C_TERM) buffer_puts(&b, ", got TERM");
-  if (s->state != S_DOWN)
-    switch(s->want) {
-    case W_DOWN:
-      buffer_puts(&b, ", want down");
-      break;
-    case W_EXIT:
-      buffer_puts(&b, ", want exit");
-      break;
-    }
+  switch(s->want) {
+  case W_DOWN:
+    if (s->state != S_DOWN) buffer_puts(&b, ", want down");
+    break;
+  case W_EXIT:
+    buffer_puts(&b, ", want exit");
+    break;
+  }
   buffer_puts(&b, "\n");
   buffer_flush(&b);
   close(fd);
@@ -182,6 +185,7 @@
     status[17] ='u';
   else
     status[17] ='d';
+  if (!s->pid) if (s->state == S_WAIT) status[17] ='x';
   if (s->ctrl & C_TERM)
     status[18] =1;
   else
@@ -586,22 +590,24 @@
         }
       }
     }
-    if (read(svd[0].fdcontrol, &ch, 1) == 1) ctrl(&svd[0], ch);
+    if (read(svd[0].fdcontrol, &ch, 1) == 1)
+      if (svd[0].state != S_WAIT) ctrl(&svd[0], ch);
     if (haslog)
       if (read(svd[1].fdcontrol, &ch, 1) == 1) ctrl(&svd[1], ch);
 
     if (sigterm) { ctrl(&svd[0], 'x'); sigterm =0; }
 
-    if ((svd[0].want == W_EXIT) && (svd[0].state == S_DOWN)) {
-      if (svd[1].pid == 0) _exit(0);
-      if (svd[1].want != W_EXIT) {
+    if (! svd[0].pid && (svd[0].want == W_EXIT))
+      if (svd[0].state != S_WAIT) {
+        svd[0].state =S_WAIT;
+        update_status(&svd[0]);
         svd[1].want =W_EXIT;
-        /* stopservice(&svd[1]); */
         update_status(&svd[1]);
-        if (close(logpipe[1]) == -1) warn("unable to close logpipe[1]");
-        if (close(logpipe[0]) == -1) warn("unable to close logpipe[0]");
+        if (close(logpipe[1]) == -1)
+          if (errno != EBADF) warn("unable to close logpipe[1]");
       }
-    }
+
+    if (svd[0].state == S_WAIT) if (svd[1].pid == 0) _exit(0);
   }
   _exit(0);
 }
--- a/runit-2.2.0/src/sv.c
+++ b/runit-2.2.0/src/sv.c
@@ -27,6 +27,7 @@
 #define RUN     "run: "
 #define FINISH  "finish: "
 #define DOWN    "down: "
+#define WAIT    "wait: "
 #define TIMEOUT "timeout: "
 #define KILL    "kill: "
 
@@ -135,9 +136,10 @@
   case 0: outs(DOWN); break;
   case 1: outs(RUN); break;
   case 2: outs(FINISH); break;
+  case 3: outs(WAIT); break;
   }
   outs(m); outs(": ");
-  if (svstatus[19]) {
+  if (pid) {
     outs("(pid "); sulong[fmt_ulong(sulong, pid)] =0;
     outs(sulong); outs(") ");
   }
@@ -149,6 +151,7 @@
   if (pid && svstatus[16]) outs(", paused");
   if (!pid && (svstatus[17] == 'u')) outs(", want up");
   if (pid && (svstatus[17] == 'd')) outs(", want down");
+  if (svstatus[19] == 3) outs(", want exit");
   if (pid && svstatus[18]) outs(", got TERM");
   return(pid ? 1 : 2);
 }