summaryrefslogtreecommitdiff
path: root/src/librc
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2008-07-03 13:11:47 +0000
committerRoy Marples <roy@marples.name>2008-07-03 13:11:47 +0000
commita88a177f991527e545e75588013afd16c647e656 (patch)
treef759fbfc83664f9c5f502904c917c3c4ee8d6ca8 /src/librc
parentd61f8318962346b3b2a3f13e7b489d2c0c397b94 (diff)
downloadopenrc-a88a177f991527e545e75588013afd16c647e656.tar.gz
openrc-a88a177f991527e545e75588013afd16c647e656.tar.bz2
openrc-a88a177f991527e545e75588013afd16c647e656.tar.xz
Add older_than function to complement newer_than function. Also make the userland instance reversed to be compatable with current baselayout, which truely does suck.
Diffstat (limited to 'src/librc')
-rw-r--r--src/librc/librc-depend.c42
-rw-r--r--src/librc/librc.h1
-rw-r--r--src/librc/rc.h.in5
-rw-r--r--src/librc/rc.map1
4 files changed, 38 insertions, 11 deletions
diff --git a/src/librc/librc-depend.c b/src/librc/librc-depend.c
index 5b7de42..145bdde 100644
--- a/src/librc/librc-depend.c
+++ b/src/librc/librc-depend.c
@@ -553,12 +553,12 @@ rc_deptree_order(const RC_DEPTREE *deptree, const char *runlevel, int options)
}
librc_hidden_def(rc_deptree_order)
-bool
-rc_newer_than(const char *source, const char *target)
+static bool
+mtime_check(const char *source, const char *target, bool newer)
{
struct stat buf;
time_t mtime;
- bool newer = true;
+ bool retval = true;
DIR *dp;
struct dirent *d;
char path[PATH_MAX];
@@ -569,32 +569,52 @@ rc_newer_than(const char *source, const char *target)
return false;
mtime = buf.st_mtime;
- /* Of course we are newer than targets that don't exist
- such as broken symlinks */
+ /* If target does not exist, return true to mimic shell test */
if (stat(target, &buf) != 0)
return true;
- if (mtime < buf.st_mtime)
- return false;
+
+ if (newer) {
+ if (mtime < buf.st_mtime)
+ return false;
+ } else {
+ if (mtime > buf.st_mtime)
+ return false;
+ }
+
/* If not a dir then reset errno */
if (!(dp = opendir(target))) {
errno = serrno;
return true;
}
- /* Check if we're newer than all the entries in the dir */
+ /* Check all the entries in the dir */
while ((d = readdir(dp))) {
if (d->d_name[0] == '.')
continue;
snprintf(path, sizeof(path), "%s/%s", target, d->d_name);
- newer = rc_newer_than(source, path);
- if (! newer)
+ retval = mtime_check(source, path, newer);
+ if (!retval)
break;
}
closedir(dp);
- return newer;
+ return retval;
+}
+
+bool
+rc_newer_than(const char *source, const char *target)
+{
+
+ return mtime_check(source, target, true);
}
librc_hidden_def(rc_newer_than)
+bool
+rc_older_than(const char *source, const char *target)
+{
+ return mtime_check(source, target, false);
+}
+librc_hidden_def(rc_older_than)
+
typedef struct deppair
{
const char *depend;
diff --git a/src/librc/librc.h b/src/librc/librc.h
index 353b592..e75ebec 100644
--- a/src/librc/librc.h
+++ b/src/librc/librc.h
@@ -86,6 +86,7 @@ librc_hidden_proto(rc_deptree_update_needed)
librc_hidden_proto(rc_find_pids)
librc_hidden_proto(rc_getline)
librc_hidden_proto(rc_newer_than)
+librc_hidden_proto(rc_older_than)
librc_hidden_proto(rc_runlevel_exists)
librc_hidden_proto(rc_runlevel_get)
librc_hidden_proto(rc_runlevel_list)
diff --git a/src/librc/rc.h.in b/src/librc/rc.h.in
index 7c94c3e..30fbfd0 100644
--- a/src/librc/rc.h.in
+++ b/src/librc/rc.h.in
@@ -306,6 +306,11 @@ typedef void *RC_DEPTREE;
* @return true if source is newer than target, otherwise false */
bool rc_newer_than(const char *, const char *);
+/*! Check to see if source is newer than target.
+ * If target is a directory then we traverse it and it's children.
+* @return true if source is newer than target, otherwise false */
+bool rc_older_than(const char *, const char *);
+
/*! Update the cached dependency tree if it's older than any init script,
* its configuration file or an external configuration file the init script
* has specified.
diff --git a/src/librc/rc.map b/src/librc/rc.map
index 8a803f3..e1dd843 100644
--- a/src/librc/rc.map
+++ b/src/librc/rc.map
@@ -13,6 +13,7 @@ global:
rc_environ_fd;
rc_find_pids;
rc_newer_than;
+ rc_older_than;
rc_runlevel_exists;
rc_runlevel_get;
rc_runlevel_list;