diff -ru openrc-orig/src/includes/rc-misc.h openrc-0.34.11/src/includes/rc-misc.h --- openrc-orig/src/includes/rc-misc.h 2017-11-29 23:10:02.000000000 +0100 +++ openrc-0.34.11/src/includes/rc-misc.h 2018-01-12 01:32:50.508998843 +0100 @@ -32,6 +32,7 @@ #define RC_LEVEL_DEFAULT "default" #define RC_DEPTREE_CACHE RC_SVCDIR "/deptree" +#define RC_DEPTREE_CACHE_BOOT RC_SYSCONFDIR "/rc_deptree_boot" #define RC_DEPTREE_SKEWED RC_SVCDIR "/clock-skewed" #define RC_KRUNLEVEL RC_SVCDIR "/krunlevel" #define RC_STARTING RC_SVCDIR "/rc.starting" diff -ru openrc-orig/src/rc/rc-misc.c openrc-0.34.11/src/rc/rc-misc.c --- openrc-orig/src/rc/rc-misc.c 2017-11-29 23:10:02.000000000 +0100 +++ openrc-0.34.11/src/rc/rc-misc.c 2018-01-22 01:20:08.152241549 +0100 @@ -354,6 +354,8 @@ RC_DEPTREE * _rc_deptree_load(int force, int *regen) { int fd; + int fd_boot; + char ch; int retval; int serrno = errno; int merrno; @@ -362,16 +364,37 @@ struct stat st; struct utimbuf ut; FILE *fp; + + struct timeval t_b, t_a, t_r; + /* Test if we have permission to update the deptree */ + fd = open(RC_DEPTREE_CACHE, O_WRONLY | O_NOFOLLOW); + merrno = errno; + errno = serrno; + if (fd == -1 && merrno == EACCES) + return rc_deptree_load(); + close(fd); + + /* bench */ + gettimeofday(&t_b, NULL); + + /* If RC_DEPTREE_CACHE_BOOT exists and RC_DEPTREE_CACHE doesn't exists, we're booting and we will reuse RC_DEPTREE_CACHE_BOOT */ + if (!exists(RC_DEPTREE_CACHE) && exists(RC_DEPTREE_CACHE_BOOT)) { + fd_boot = fopen(RC_DEPTREE_CACHE_BOOT, "r"); + if (fd_boot != NULL) { + fd = fopen(RC_DEPTREE_CACHE, "w"); + if (fd != NULL) { + ebegin("Reusing service dependencies cache"); + while( ( ch = fgetc(fd_boot) ) != EOF ) + fputc(ch, fd); + fclose(fd); + } + fclose(fd_boot); + } + } + t = 0; if (rc_deptree_update_needed(&t, file) || force != 0) { - /* Test if we have permission to update the deptree */ - fd = open(RC_DEPTREE_CACHE, O_WRONLY); - merrno = errno; - errno = serrno; - if (fd == -1 && merrno == EACCES) - return rc_deptree_load(); - close(fd); if (regen) *regen = 1; @@ -380,7 +403,10 @@ eend (retval, "Failed to update the dependency tree"); if (retval == 0) { - stat(RC_DEPTREE_CACHE, &st); + if (stat(RC_DEPTREE_CACHE, &st) != 0) { + eerror("stat(%s): %s", RC_DEPTREE_CACHE, strerror(errno)); + return NULL; + } if (st.st_mtime < t) { eerror("Clock skew detected with `%s'", file); eerrorn("Adjusting mtime of `" RC_DEPTREE_CACHE @@ -401,6 +427,9 @@ if (force == -1 && regen != NULL) *regen = retval; } + gettimeofday(&t_a, NULL); + timersub(&t_a, &t_b, &t_r); + ebegin("Time elapsed: %ld.%06ld\n", (long int)t_r.tv_sec, (long int)t_r.tv_usec); return rc_deptree_load(); }