1 Purpose: Defend against undeterministic directory stream sequence
2 returned by readdir(3). Make sure script which is being
3 registered is processed before all others.
5 Status: Applied upstream.
7 Index: insserv/insserv.c
8 ===================================================================
9 --- insserv.orig/insserv.c 2009-09-26 22:35:25.000000000 +0200
10 +++ insserv/insserv.c 2009-09-26 22:35:44.000000000 +0200
13 boolean defaults = false;
14 boolean ignore = false;
15 + boolean loadarg = false;
17 myname = basename(*argv);
27 error("usage: %s [[-r] init_script|init_directory]\n", myname);
30 @@ -2490,17 +2493,45 @@
32 * Scan now all scripts found in the init.d/ directory
34 - while ((d = readdir(initdir)) != (struct dirent*)0) {
35 - const boolean isarg = chkfor(d->d_name, argv, argc);
37 service_t * service = (service_t*)0;
39 char * begin = (char*)0; /* hold start pointer of strings handled by strsep() */
41 + boolean isarg = false;
43 #if defined(DEBUG) && (DEBUG > 0)
47 + if ((d = readdir(initdir)) == (struct dirent*)0) {
49 + * If first script in argument list was loaded in advance, then
50 + * rewind the init.d/ directory stream and attempt to load all
61 + isarg = chkfor(d->d_name, argv, argc);
64 + * Load first script in argument list before all other scripts. This
65 + * avoids problems with loading scripts in underterministic sequence
66 + * returned by readdir(3).
68 + if (loadarg && !isarg)
70 + if (loadarg && isarg && (curr_argc != 0))
72 + if (!loadarg && isarg && (curr_argc == 0))
75 if (*d->d_name == '.')