2008-08-16 02:57:09 +02:00
|
|
|
--- makeboot.c
|
2009-02-09 10:47:55 +01:00
|
|
|
+++ makeboot.c 2009/02/05 23:36:16
|
2008-08-16 02:57:09 +02:00
|
|
|
@@ -13,6 +13,12 @@
|
|
|
|
#include <errno.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include "makeboot.h"
|
|
|
|
+#if defined _XOPEN_SOURCE && (_XOPEN_SOURCE - 0) >= 600
|
|
|
|
+# include <sys/types.h>
|
|
|
|
+# include <sys/stat.h>
|
|
|
|
+# include <fcntl.h>
|
|
|
|
+static int o_flags = O_RDONLY;
|
|
|
|
+#endif
|
|
|
|
|
|
|
|
|
|
|
|
int tree_entries = 0;
|
2009-02-09 10:47:55 +01:00
|
|
|
@@ -95,6 +101,7 @@
|
|
|
|
/*
|
|
|
|
* check whether the given target would create an infinte loop
|
|
|
|
*/
|
|
|
|
+static int loop;
|
|
|
|
static int check_loop(struct makenode *dep, struct makenode *src)
|
|
|
|
{
|
|
|
|
struct makelist *s;
|
|
|
|
@@ -103,6 +110,8 @@
|
2009-01-29 01:08:29 +01:00
|
|
|
fprintf(stderr, "loop exists %s in %s!\n", dep->name, src->name);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
+ if (loop++ > 999)
|
|
|
|
+ return 1;
|
|
|
|
if (check_loop(s->node, src))
|
|
|
|
return 1;
|
|
|
|
}
|
2009-02-09 10:47:55 +01:00
|
|
|
@@ -117,6 +126,7 @@
|
2009-01-29 01:08:29 +01:00
|
|
|
struct makenode *dep;
|
|
|
|
|
|
|
|
dep = add_target(dst);
|
|
|
|
+ loop = 0;
|
|
|
|
if (check_loop(dep, node))
|
|
|
|
return;
|
|
|
|
dep->select = new_list(node, dep->select);
|
2009-02-09 10:47:55 +01:00
|
|
|
@@ -158,11 +168,28 @@
|
2008-08-16 02:57:09 +02:00
|
|
|
char *s, *strp, *p;
|
|
|
|
struct makenode *node;
|
|
|
|
|
|
|
|
- if ((fp = fopen(path, "r")) == NULL) {
|
|
|
|
+#if defined _XOPEN_SOURCE && (_XOPEN_SOURCE - 0) >= 600
|
|
|
|
+ int fd;
|
|
|
|
+
|
|
|
|
+ if (getuid() == (uid_t)0)
|
|
|
|
+ o_flags |= O_NOATIME;
|
|
|
|
+ if ((fd = open(path, o_flags)) < 0) {
|
2009-01-29 01:08:29 +01:00
|
|
|
fprintf(stderr, "Can't open %s: %s\n", path, strerror(errno));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
-
|
2008-08-16 02:57:09 +02:00
|
|
|
+ (void)posix_fadvise(fd, 0, 0, POSIX_FADV_WILLNEED);
|
|
|
|
+ (void)posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL);
|
|
|
|
+ (void)posix_fadvise(fd, 0, 0, POSIX_FADV_NOREUSE);
|
|
|
|
+
|
|
|
|
+ if ((fp = fdopen(fd, "r")) == NULL)
|
|
|
|
+#else
|
|
|
|
+ if ((fp = fopen(path, "r")) == NULL)
|
|
|
|
+#endif
|
|
|
|
+ {
|
2009-01-29 01:08:29 +01:00
|
|
|
+ fprintf(stderr, "Can't open %s: %s\n", path, strerror(errno));
|
|
|
|
+ exit(1);
|
|
|
|
+ }
|
2008-08-16 02:57:09 +02:00
|
|
|
+
|
|
|
|
while (fgets(buf, sizeof(buf), fp)) {
|
|
|
|
for (s = buf; *s && isspace(*s); s++)
|
|
|
|
;
|
2009-02-09 10:47:55 +01:00
|
|
|
@@ -198,6 +225,11 @@
|
2008-08-16 02:57:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
+
|
|
|
|
+#if defined _XOPEN_SOURCE && (_XOPEN_SOURCE - 0) >= 600
|
|
|
|
+ (void)posix_fadvise(fd, 0, 0, POSIX_FADV_DONTNEED);
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
for (node = tree_list; node; node = node->next) {
|
2009-02-09 10:47:55 +01:00
|
|
|
@@ -234,7 +266,17 @@
|
2008-08-16 02:57:09 +02:00
|
|
|
|
|
|
|
filter_prefix = prefix;
|
|
|
|
snprintf(path, sizeof(path), "/etc/init.d/%s.d", dir);
|
|
|
|
+#if defined _XOPEN_SOURCE && (_XOPEN_SOURCE - 0) >= 600
|
|
|
|
+ if ((i = open(path, o_flags|O_DIRECTORY|O_LARGEFILE)) >= 0) {
|
|
|
|
+ (void)posix_fadvise(i, 0, 0, POSIX_FADV_SEQUENTIAL);
|
|
|
|
+ (void)posix_fadvise(i, 0, 0, POSIX_FADV_NOREUSE);
|
|
|
|
+ }
|
|
|
|
+#endif
|
|
|
|
ndirs = scandir(path, &dirlist, dirfilter, alphasort);
|
|
|
|
+#if defined _XOPEN_SOURCE && (_XOPEN_SOURCE - 0) >= 600
|
|
|
|
+ if (i >= 0)
|
|
|
|
+ (void)posix_fadvise(i, 0, 0, POSIX_FADV_DONTNEED);
|
|
|
|
+#endif
|
|
|
|
/* mark all matching nodes */
|
|
|
|
for (i = 0; i < ndirs; i++) {
|
|
|
|
t = lookup_target(dirlist[i]->d_name + 3);
|
2009-02-09 10:47:55 +01:00
|
|
|
@@ -342,6 +384,17 @@
|
2008-08-16 02:57:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (best) {
|
|
|
|
+#if defined _XOPEN_SOURCE && (_XOPEN_SOURCE - 0) >= 600
|
|
|
|
+ char path[128];
|
|
|
|
+ int fd;
|
|
|
|
+ snprintf(path, sizeof(path), "/etc/init.d/%s", best->name);
|
|
|
|
+ if ((fd = open(path, o_flags|O_DIRECT)) >= 0) {
|
|
|
|
+ (void)posix_fadvise(fd, 0, 0, POSIX_FADV_WILLNEED);
|
|
|
|
+ (void)posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL);
|
|
|
|
+ (void)posix_fadvise(fd, 0, 0, POSIX_FADV_NOREUSE);
|
|
|
|
+ close(fd);
|
|
|
|
+ }
|
|
|
|
+#endif
|
|
|
|
blogger("service %s", best->name);
|
|
|
|
best->status = T_RUNNING;
|
|
|
|
}
|
2009-02-09 10:47:55 +01:00
|
|
|
@@ -359,6 +412,17 @@
|
2008-08-16 02:57:09 +02:00
|
|
|
return;
|
|
|
|
for (n = node->select; n; n = n->next)
|
|
|
|
n->node->num_deps--;
|
|
|
|
+#if defined _XOPEN_SOURCE && (_XOPEN_SOURCE - 0) >= 600
|
|
|
|
+ {
|
|
|
|
+ char path[128];
|
|
|
|
+ int fd;
|
|
|
|
+ snprintf(path, sizeof(path), "/etc/init.d/%s", node->name);
|
|
|
|
+ if ((fd = open(path, o_flags|O_DIRECT)) >= 0) {
|
|
|
|
+ (void)posix_fadvise(fd, 0, 0, POSIX_FADV_DONTNEED);
|
|
|
|
+ close(fd);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+#endif
|
|
|
|
node->status = T_FINISHED;
|
|
|
|
blogger("service %s done", node->name);
|
|
|
|
}
|