Git init
[external/insserv.git] / debian / patches / 95_stop_all.patch
1 Patch from upstream making $all work for stop sequences, placing
2 scripts first in the stop sequence.  This patch invalidates
3 60_all_keyword_start_only.patch
4
5 Fixes #542043
6
7 Index: insserv/insserv.c
8 ===================================================================
9 --- insserv.orig/insserv.c      2009-09-26 22:35:39.000000000 +0200
10 +++ insserv/insserv.c   2009-09-26 22:35:39.000000000 +0200
11 @@ -308,7 +308,10 @@
12             break;
13         case '$':
14             if (strcasecmp(token, "$all") == 0) {
15 -               serv->attr.flags |= SERV_ALL;
16 +               if (bit & REQ_KILL)
17 +                   serv->attr.flags |= SERV_FIRST;
18 +               else
19 +                   serv->attr.flags |= SERV_ALL;
20                 break;
21             }
22             /* Expand the `$' token recursively down */
23 @@ -630,8 +633,7 @@
24  }
25  
26  /*
27 - * Last but not least the `$all' scripts will be set to the
28 - * end of the current start order.
29 + * The `$all' scripts will be set to the end of the current start order.
30   */
31  static inline void all_script(void) attribute((always_inline));
32  static inline void all_script(void)
33 @@ -688,6 +690,50 @@
34  }
35  
36  /*
37 + * Last but not least the `$all' scripts will be set to the
38 + * beginning of the current stop order.
39 + */
40 +static inline void first_script(void) attribute((always_inline));
41 +static inline void first_script(void)
42 +{
43 +    list_t * pos;
44 +
45 +    list_for_each(pos, s_start) {
46 +       service_t * serv = getservice(pos);
47 +       list_t * tmp;
48 +
49 +       if (serv->attr.flags & SERV_DUPLET)
50 +           continue;                   /* Duplet */
51 +
52 +       if (!(serv->attr.flags & SERV_FIRST))
53 +           continue;
54 +
55 +       if (serv->attr.script == (char*)0)
56 +           continue;
57 +
58 +       list_for_each(tmp, s_start) {
59 +           service_t * cur = getservice(tmp);
60 +
61 +           if (cur->attr.flags & SERV_DUPLET)
62 +               continue;               /* Duplet */
63 +
64 +           if ((serv->start->lvl & cur->start->lvl) == 0)
65 +               continue;
66 +
67 +           if (cur == serv)
68 +               continue;
69 +
70 +           if (cur->attr.flags & SERV_FIRST)
71 +               continue;
72 +
73 +           rememberreq(serv, REQ_SHLD|REQ_KILL, cur->name);
74 +       }
75 +
76 +       setorder(serv->attr.script, 'K', 1, false);
77 +    }
78 +}
79 +
80 +/*
81   * Make the dependency files
82   */
83  static inline void makedep(void) attribute((always_inline));
84 @@ -3274,6 +3320,11 @@
85      nonlsb_script();
86  
87      /*
88 +     * Move the `$all' stop scripts to the very beginning
89 +     */
90 +    first_script();
91 +
92 +    /*
93       * Now generate for all scripts the dependencies
94       */
95      follow_all();
96 Index: insserv/listing.c
97 ===================================================================
98 --- insserv.orig/listing.c      2009-09-26 22:35:39.000000000 +0200
99 +++ insserv/listing.c   2009-09-26 22:35:39.000000000 +0200
100 @@ -317,6 +317,7 @@
101      }
102  
103      for (tmp = dir; tmp; tmp = getnextlink(l_list)) {
104 +       const typeof(attof(tmp)->flags) sflags = attof(tmp)->flags;
105         register boolean recursion = true;
106         handle_t * ptmp = (mode == 'K') ? &tmp->stopp : &tmp->start;
107         uchar  * order = &ptmp->deep;
108 @@ -381,6 +382,7 @@
109         np_list_for_each(dent, l_list) {
110             dir_t * target = getlink(dent)->target;
111             handle_t * ptrg = (mode == 'K') ? &target->stopp : &target->start;
112 +           const typeof(attof(target)->flags) kflags = attof(target)->flags;
113  
114             if ((peg->run.lvl & ptrg->run.lvl) == 0)
115                 continue;                       /* Not same boot level */
116 @@ -398,10 +400,18 @@
117                 break;                          /* Loop detected, stop recursion */
118             }
119  
120 -           if ((mode == 'S') && (attof(tmp)->flags & SERV_ALL)) {
121 -               warn("%s depends on %s and therefore on system facility `$all' which can not be true!\n",
122 -                    target->script ? target->script : target->name, tmp->script ? tmp->script : tmp->name);
123 -               continue;
124 +           if (mode == 'K') {
125 +               if (kflags & SERV_FIRST) {
126 +                   warn("Stopping %s depends on %s and therefore on system facility `$all' which can not be true!\n",
127 +                        tmp->script ? tmp->script : tmp->name, target->script ? target->script : target->name);
128 +                   continue;
129 +               }
130 +           } else {
131 +               if (sflags & SERV_ALL) {
132 +                   warn("Starting %s depends on %s and therefore on system facility `$all' which can not be true!\n",
133 +                        target->script ? target->script : target->name, tmp->script ? tmp->script : tmp->name);
134 +                   continue;
135 +               }
136             }
137  
138             if (ptrg->deep >= deep)             /* Nothing new */
139 @@ -847,7 +857,7 @@
140      list_for_each(tmp, d_start) {
141         maxorder = &maxstart;
142         guess_order(getdir(tmp), 'S');
143 -       maxorder = &maxstart;
144 +       maxorder = &maxstop;
145         guess_order(getdir(tmp), 'K');
146      }
147  }
148 Index: insserv/listing.h
149 ===================================================================
150 --- insserv.orig/listing.h      2009-09-26 22:35:39.000000000 +0200
151 +++ insserv/listing.h   2009-09-26 22:35:39.000000000 +0200
152 @@ -368,6 +368,7 @@
153  #define SERV_SCRIPT    0x0080
154  #define SERV_NOSTOP    0x0100
155  #define SERV_CMDLINE   0x0200
156 +#define SERV_FIRST     0x0400
157  
158  /*
159   * Bits of the runlevels