tags 458224 +patch
thanks

I believe the attached patch implement the feature I want.  I also
included a test case.  Would like to get input from upstream and SuSe
before implementing a new keyword in Debian, in case they have better
naming suggestions.

Happy hacking,
-- 
Petter Reinholdtsen
Index: debian/run-testsuite
===================================================================
--- debian/run-testsuite        (revision 891)
+++ debian/run-testsuite        (working copy)
@@ -1782,7 +1782,73 @@
 rm $initddir/../rcS.d/S06badboy
 }
 ##########################################################################
+test_x_interactive() {
+echo
+echo "info: Check if X-Interactive header work"
+echo "BTS #458224"
+echo
+  
+initdir_purge
 
+# Insert a few scripts to flesh out $initdir
+insertscript first <<EOF || true
+### BEGIN INIT INFO
+# Provides:          first
+# Required-Start:
+# Required-Stop:
+# Default-Start:     2
+# Default-Stop:      0
+### END INIT INFO
+EOF
+
+# This test if X-Interactive work with existing scripts when a new
+# script is inserted.
+insertscript alone1 <<'EOF' || true
+### BEGIN INIT INFO
+# Provides:          alone1
+# Required-Start:    first
+# Required-Stop:     first
+# Default-Start:     2
+# Default-Stop:      0
+# X-Interactive:     true
+### END INIT INFO
+EOF
+
+insertscript after <<'EOF' || true
+### BEGIN INIT INFO
+# Provides:          after
+# Required-Start:    first
+# Required-Stop:     first
+# Default-Start:     2
+# Default-Stop:      0
+### END INIT INFO
+EOF
+
+# This test if X-Interactive work with new scripts too.  The code
+# paths in insserv are different for the two cases.
+insertscript alone2 <<'EOF' || true
+### BEGIN INIT INFO
+# Provides:          alone2
+# Required-Start:    first
+# Required-Stop:     first
+# Default-Start:     2
+# Default-Stop:      0
+# X-Interactive:     true
+### END INIT INFO
+EOF
+
+list_rclinks
+
+check_script_present 2 first
+check_script_present 2 after
+check_script_present 2 alone1
+check_order 2 first after
+check_order 2 first alone1
+${severity}_order 2 alone1 after # This is not guaranteed
+${severity}_order 2 alone2 after # This is not guaranteed
+}
+##########################################################################
+
 update_conf
 test_normal_sequence
 test_override_files
@@ -1817,3 +1883,4 @@
 test_all_keyword
 test_early_all
 test_script_in_runlevel
+test_x_interactive
Index: insserv.c
===================================================================
--- insserv.c   (revision 885)
+++ insserv.c   (working copy)
@@ -97,6 +97,7 @@
 #define DEFAULT_START  DEFAULT  START VALUE
 #define DEFAULT_STOP   DEFAULT  STOP  VALUE
 #define DESCRIPTION    COMM "description" VALUE
+#define INTERACTIVE    COMM "x-interactive" VALUE
 
 /* System facility search within /etc/insserv.conf */
 #define EQSIGN         "([[:blank:]]*[=:][[:blank:]]*|[[:blank:]]+)"
@@ -133,6 +134,7 @@
     char *default_start;
     char *default_stop;
     char *description;
+    char *interactive;
 } attribute((aligned(sizeof(char*)))) lsb_t;
 
 /* Search results points here */
@@ -147,6 +149,7 @@
     regex_t def_start;
     regex_t def_stop;
     regex_t desc;
+    regex_t interact;
 } attribute((aligned(sizeof(regex_t)))) reg_t;
 
 typedef struct creg_struct {
@@ -1132,6 +1135,7 @@
     regcompiler(&reg.def_start, DEFAULT_START,  
REG_EXTENDED|REG_ICASE|REG_NEWLINE);
     regcompiler(&reg.def_stop,  DEFAULT_STOP,   
REG_EXTENDED|REG_ICASE|REG_NEWLINE);
     regcompiler(&reg.desc,      DESCRIPTION,    
REG_EXTENDED|REG_ICASE|REG_NEWLINE);
+    regcompiler(&reg.interact,  INTERACTIVE,    
REG_EXTENDED|REG_ICASE|REG_NEWLINE);
 }
 
 static inline void scan_script_reset(void) attribute((always_inline));
@@ -1147,6 +1151,7 @@
     xreset(script_inf.default_start);
     xreset(script_inf.default_stop);
     xreset(script_inf.description);
+    xreset(script_inf.interactive);
 }
 
 #define FOUND_LSB_HEADER   0x01
@@ -1177,6 +1182,7 @@
 #define default_start  script_inf.default_start
 #define default_stop   script_inf.default_stop
 #define description    script_inf.description
+#define interactive    script_inf.interactive
 
     info("Loading %s\n", path);
 
@@ -1273,6 +1279,14 @@
                description = empty;
        }
 
+       if (!interactive    && regexecutor(&reg.interact,      COMMON_ARGS) == 
true) {
+           if (val->rm_so < val->rm_eo) {
+               *(pbuf+val->rm_eo) = '\0';
+               interactive = xstrdup(pbuf+val->rm_so);
+           } else
+               interactive = empty;
+       }
+
        /* Skip scanning below from LSB magic end */
        if ((end = strstr(buf, "### END INIT INFO")))
            break;
@@ -1341,6 +1355,7 @@
 #undef default_start
 #undef default_stop
 #undef description
+#undef interactive
     return ret;
 }
 
@@ -1503,6 +1518,7 @@
     regfree(&reg.def_start);
     regfree(&reg.def_stop);
     regfree(&reg.desc);
+    regfree(&reg.interact);
 }
 
 static struct {
@@ -1776,6 +1792,9 @@
                if (script_inf.stop_after && script_inf.stop_after != empty) {
                    reversereq(service, REQ_SHLD|REQ_KILL, 
script_inf.stop_after);
                }
+               if (script_inf.interactive && script_inf.interactive != empty) {
+                   service->attr.flags |= SERV_INTRACT;
+               }
            }
 
            if (name) 
@@ -2807,6 +2826,9 @@
                        if (script_inf.should_stop && script_inf.should_stop != 
empty) {
                            rememberreq(service, REQ_SHLD|REQ_KILL, 
script_inf.should_stop);
                        }
+                       if (script_inf.interactive && script_inf.interactive != 
empty) {
+                           service->attr.flags |= SERV_INTRACT;
+                       }
                    }
 
                    if (script_inf.start_before && script_inf.start_before != 
empty) {

Reply via email to