Fix sysinit_add().

- Don't include multiple copies of the previous sysinit in the new one.
- Leave space for and explicitly null terminate the new list.
This commit is contained in:
Peter Wemm 1998-10-15 17:09:19 +00:00
parent f03d6f87b3
commit ddd62546e1
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=40394

View File

@ -39,7 +39,7 @@
* SUCH DAMAGE.
*
* @(#)init_main.c 8.9 (Berkeley) 1/21/94
* $Id: init_main.c,v 1.97 1998/10/06 11:55:40 dfr Exp $
* $Id: init_main.c,v 1.98 1998/10/09 23:42:47 peter Exp $
*/
#include "opt_devfs.h"
@ -143,26 +143,30 @@ sysinit_add(set)
struct sysinit **xipp;
int count = 0;
for (sipp = sysinit; *sipp; sipp++)
count++;
if (newsysinit)
for (sipp = newsysinit; *sipp; sipp++)
count++;
else
for (sipp = sysinit; *sipp; sipp++)
count++;
for (sipp = set; *sipp; sipp++)
count++;
if (newsysinit)
for (sipp = set; *sipp; sipp++)
count++;
count++; /* Trailing NULL */
newset = malloc(count * sizeof(*sipp), M_TEMP, M_NOWAIT);
if (newset == NULL)
panic("cannot malloc for sysinit");
xipp = newset;
for (sipp = sysinit; *sipp; sipp++)
*xipp++ = *sipp;
for (sipp = set; *sipp; sipp++)
*xipp++ = *sipp;
if (newsysinit) {
if (newsysinit)
for (sipp = newsysinit; *sipp; sipp++)
*xipp++ = *sipp;
free(newset, M_TEMP);
}
else
for (sipp = sysinit; *sipp; sipp++)
*xipp++ = *sipp;
for (sipp = set; *sipp; sipp++)
*xipp++ = *sipp;
*xipp = NULL;
if (newsysinit)
free(newsysinit, M_TEMP);
newsysinit = newset;
}