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.
This commit is contained in:
parent
d61f831896
commit
a88a177f99
@ -553,12 +553,12 @@ rc_deptree_order(const RC_DEPTREE *deptree, const char *runlevel, int options)
|
|||||||
}
|
}
|
||||||
librc_hidden_def(rc_deptree_order)
|
librc_hidden_def(rc_deptree_order)
|
||||||
|
|
||||||
bool
|
static bool
|
||||||
rc_newer_than(const char *source, const char *target)
|
mtime_check(const char *source, const char *target, bool newer)
|
||||||
{
|
{
|
||||||
struct stat buf;
|
struct stat buf;
|
||||||
time_t mtime;
|
time_t mtime;
|
||||||
bool newer = true;
|
bool retval = true;
|
||||||
DIR *dp;
|
DIR *dp;
|
||||||
struct dirent *d;
|
struct dirent *d;
|
||||||
char path[PATH_MAX];
|
char path[PATH_MAX];
|
||||||
@ -569,32 +569,52 @@ rc_newer_than(const char *source, const char *target)
|
|||||||
return false;
|
return false;
|
||||||
mtime = buf.st_mtime;
|
mtime = buf.st_mtime;
|
||||||
|
|
||||||
/* Of course we are newer than targets that don't exist
|
/* If target does not exist, return true to mimic shell test */
|
||||||
such as broken symlinks */
|
|
||||||
if (stat(target, &buf) != 0)
|
if (stat(target, &buf) != 0)
|
||||||
return true;
|
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 not a dir then reset errno */
|
||||||
if (!(dp = opendir(target))) {
|
if (!(dp = opendir(target))) {
|
||||||
errno = serrno;
|
errno = serrno;
|
||||||
return true;
|
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))) {
|
while ((d = readdir(dp))) {
|
||||||
if (d->d_name[0] == '.')
|
if (d->d_name[0] == '.')
|
||||||
continue;
|
continue;
|
||||||
snprintf(path, sizeof(path), "%s/%s", target, d->d_name);
|
snprintf(path, sizeof(path), "%s/%s", target, d->d_name);
|
||||||
newer = rc_newer_than(source, path);
|
retval = mtime_check(source, path, newer);
|
||||||
if (! newer)
|
if (!retval)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
closedir(dp);
|
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)
|
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
|
typedef struct deppair
|
||||||
{
|
{
|
||||||
const char *depend;
|
const char *depend;
|
||||||
|
@ -86,6 +86,7 @@ librc_hidden_proto(rc_deptree_update_needed)
|
|||||||
librc_hidden_proto(rc_find_pids)
|
librc_hidden_proto(rc_find_pids)
|
||||||
librc_hidden_proto(rc_getline)
|
librc_hidden_proto(rc_getline)
|
||||||
librc_hidden_proto(rc_newer_than)
|
librc_hidden_proto(rc_newer_than)
|
||||||
|
librc_hidden_proto(rc_older_than)
|
||||||
librc_hidden_proto(rc_runlevel_exists)
|
librc_hidden_proto(rc_runlevel_exists)
|
||||||
librc_hidden_proto(rc_runlevel_get)
|
librc_hidden_proto(rc_runlevel_get)
|
||||||
librc_hidden_proto(rc_runlevel_list)
|
librc_hidden_proto(rc_runlevel_list)
|
||||||
|
@ -306,6 +306,11 @@ typedef void *RC_DEPTREE;
|
|||||||
* @return true if source is newer than target, otherwise false */
|
* @return true if source is newer than target, otherwise false */
|
||||||
bool rc_newer_than(const char *, const char *);
|
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,
|
/*! Update the cached dependency tree if it's older than any init script,
|
||||||
* its configuration file or an external configuration file the init script
|
* its configuration file or an external configuration file the init script
|
||||||
* has specified.
|
* has specified.
|
||||||
|
@ -13,6 +13,7 @@ global:
|
|||||||
rc_environ_fd;
|
rc_environ_fd;
|
||||||
rc_find_pids;
|
rc_find_pids;
|
||||||
rc_newer_than;
|
rc_newer_than;
|
||||||
|
rc_older_than;
|
||||||
rc_runlevel_exists;
|
rc_runlevel_exists;
|
||||||
rc_runlevel_get;
|
rc_runlevel_get;
|
||||||
rc_runlevel_list;
|
rc_runlevel_list;
|
||||||
|
@ -408,7 +408,7 @@ static int do_shell_var(int argc, char **argv)
|
|||||||
void run_applets(int argc, char **argv)
|
void run_applets(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int i = 2;
|
int i = 2;
|
||||||
bool match = false;
|
bool (*is_than) (const char *, const char *);
|
||||||
char *p;
|
char *p;
|
||||||
pid_t pid = 0;
|
pid_t pid = 0;
|
||||||
|
|
||||||
@ -437,18 +437,22 @@ void run_applets(int argc, char **argv)
|
|||||||
if (strcmp(applet, "shell_var") == 0)
|
if (strcmp(applet, "shell_var") == 0)
|
||||||
exit(do_shell_var(argc, argv));
|
exit(do_shell_var(argc, argv));
|
||||||
|
|
||||||
|
/* This test is perverted - historically the baselayout function
|
||||||
|
* returns 0 on *failure*, which is plain wrong */
|
||||||
if (strcmp(applet, "is_newer_than") == 0 ||
|
if (strcmp(applet, "is_newer_than") == 0 ||
|
||||||
strcmp(applet, "is_older_than") == 0)
|
strcmp(applet, "is_older_than") == 0)
|
||||||
{
|
{
|
||||||
if (argc < 3)
|
if (argc < 3)
|
||||||
exit (EXIT_FAILURE);
|
exit (EXIT_FAILURE);
|
||||||
if (strcmp(applet, "is_newer_than") == 0)
|
if (strcmp(applet, "is_newer_than") == 0)
|
||||||
match = true;
|
is_than = &rc_older_than;
|
||||||
|
else
|
||||||
|
is_than = &rc_newer_than;
|
||||||
while (i < argc) {
|
while (i < argc) {
|
||||||
if (rc_newer_than(argv[1], argv[i++]) != match)
|
if (!is_than(argv[1], argv[i++]))
|
||||||
exit (EXIT_FAILURE);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_FAILURE);
|
||||||
};
|
};
|
||||||
|
|
||||||
if (applet[0] == 'e' || (applet[0] == 'v' && applet[1] == 'e'))
|
if (applet[0] == 'e' || (applet[0] == 'v' && applet[1] == 'e'))
|
||||||
|
@ -11,6 +11,7 @@ rc_deptree_update_needed
|
|||||||
rc_find_pids
|
rc_find_pids
|
||||||
rc_getline
|
rc_getline
|
||||||
rc_newer_than
|
rc_newer_than
|
||||||
|
rc_older_than
|
||||||
rc_runlevel_exists
|
rc_runlevel_exists
|
||||||
rc_runlevel_get
|
rc_runlevel_get
|
||||||
rc_runlevel_list
|
rc_runlevel_list
|
||||||
|
@ -22,6 +22,8 @@ rc_find_pids
|
|||||||
rc_find_pids@@RC_1.0
|
rc_find_pids@@RC_1.0
|
||||||
rc_newer_than
|
rc_newer_than
|
||||||
rc_newer_than@@RC_1.0
|
rc_newer_than@@RC_1.0
|
||||||
|
rc_older_than
|
||||||
|
rc_older_than@@RC_1.0
|
||||||
rc_runlevel_exists
|
rc_runlevel_exists
|
||||||
rc_runlevel_exists@@RC_1.0
|
rc_runlevel_exists@@RC_1.0
|
||||||
rc_runlevel_get
|
rc_runlevel_get
|
||||||
|
Loading…
x
Reference in New Issue
Block a user