Git init
[external/insserv.git] / debian / patches / 94_v1_12_2.patch
1 Patch from upstream to detect and reject loops in virtual
2 facilities (#541613) and warn about indirect dependencies to $all.
3
4 Index: insserv/insserv.c
5 ===================================================================
6 --- insserv.orig/insserv.c      2009-09-26 22:35:39.000000000 +0200
7 +++ insserv/insserv.c   2009-09-26 22:35:39.000000000 +0200
8 @@ -233,6 +233,7 @@
9  typedef struct repl {
10      list_t     r_list;
11      string_t    r[1];
12 +    ushort     flags;
13  } __align repl_t;
14  #define getrepl(arg)   list_entry((arg), struct repl, r_list)
15  
16 @@ -1946,6 +1947,7 @@
17                                 if (posix_memalign((void*)&subst, sizeof(void*), alignof(repl_t)) != 0)
18                                     error("%s", strerror(errno));
19                                 insert(&subst->r_list, r_list->prev);
20 +                               subst->flags = 0;
21                                 r = &subst->r[0];
22                                 if (posix_memalign((void*)&r->ref, sizeof(void*), alignof(typeof(r->ref))+strsize(token)) != 0)
23                                     error("%s", strerror(errno));
24 @@ -1975,6 +1977,7 @@
25                                 error("%s", strerror(errno));
26                             insert(&subst->r_list, r_list->prev);
27                             r = &subst->r[0];
28 +                           subst->flags = 0;
29                             if (posix_memalign((void*)&r->ref, sizeof(void*), alignof(typeof(r->ref))+strsize(token)) != 0)
30                                 error("%s", strerror(errno));
31                             *r->ref = 1;
32 @@ -2127,13 +2130,19 @@
33  
34         list_for_each_safe(tmp, safe, ptr) {
35             repl_t * rnxt = getrepl(tmp);
36 +           if (rnxt->flags & 0x0001) {
37 +               error("Loop detected during expanding system facilities in the insserv.conf file(s): %s\n",
38 +                     rnxt->r[0].name);
39 +           }
40             if (*rnxt->r[0].name == '$') {
41                 if (*deep > 10) {
42                     warn("The nested level of the system facilities in the insserv.conf file(s) is to large\n");
43                     goto out;
44                 }
45                 (*deep)++;
46 +               rnxt->flags |= 0x0001;
47                 expand_faci(tmp, head, deep);
48 +               rnxt->flags &= ~0x0001;
49                 (*deep)--;
50             } else if (*deep > 0) {
51                 repl_t *restrict subst;
52 @@ -2154,9 +2163,12 @@
53      list_for_each(ptr, sysfaci_start) {
54         list_t * rlist, * safe, * head = &getfaci(ptr)->replace;
55         list_for_each_safe(rlist, safe, head) {
56 -           if (*getrepl(rlist)->r[0].name == '$') {
57 +           repl_t * tmp = getrepl(rlist);
58 +           if (*tmp->r[0].name == '$') {
59                 int deep = 0;
60 +               tmp->flags |= 0x0001;
61                 expand_faci(rlist, rlist, &deep);
62 +               tmp->flags &= ~0x0001;
63             }
64         }
65      }
66 Index: insserv/listing.c
67 ===================================================================
68 --- insserv.orig/listing.c      2009-09-26 22:35:24.000000000 +0200
69 +++ insserv/listing.c   2009-09-26 22:35:39.000000000 +0200
70 @@ -398,6 +398,12 @@
71                 break;                          /* Loop detected, stop recursion */
72             }
73  
74 +           if ((mode == 'S') && (attof(tmp)->flags & SERV_ALL)) {
75 +               warn("%s depends on %s and therefore on system facility `$all' which can not be true!\n",
76 +                    target->script ? target->script : target->name, tmp->script ? tmp->script : tmp->name);
77 +               continue;
78 +           }
79 +
80             if (ptrg->deep >= deep)             /* Nothing new */
81                 continue;
82                                                 /* The inner recursion */