Fix is_older_than a little better, and make is_newer_than correct.

This commit is contained in:
Roy Marples 2008-07-03 13:30:17 +00:00
parent a88a177f99
commit 157db50df7
2 changed files with 18 additions and 11 deletions

View File

@ -22,7 +22,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE. .\" SUCH DAMAGE.
.\" .\"
.Dd Jun 03, 2008 .Dd Jul 03, 2008
.Dt RUNSCRIPT 8 SMM .Dt RUNSCRIPT 8 SMM
.Os OpenRC .Os OpenRC
.Sh NAME .Sh NAME
@ -214,7 +214,7 @@ is a directory, then check all it's contents too.
.It Ic is_older_than Ar file1 Ar file2 ... .It Ic is_older_than Ar file1 Ar file2 ...
If If
.Ar file1 .Ar file1
is older than is newer than
.Ar file2 .Ar file2
return 0, otherwise 1. return 0, otherwise 1.
If If
@ -441,6 +441,10 @@ show()
} }
.Ed .Ed
.Sh BUGS
is_older_than should return 0 on success.
Instead we return 1 to be compliant with Gentoo baselayout.
Users are encouraged to use the is_newer_than function which returns correctly.
.Sh SEE ALSO .Sh SEE ALSO
.Xr einfo 3 , .Xr einfo 3 ,
.Xr rc 8 , .Xr rc 8 ,

View File

@ -408,7 +408,6 @@ 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 (*is_than) (const char *, const char *);
char *p; char *p;
pid_t pid = 0; pid_t pid = 0;
@ -439,21 +438,25 @@ void run_applets(int argc, char **argv)
/* This test is perverted - historically the baselayout function /* This test is perverted - historically the baselayout function
* returns 0 on *failure*, which is plain wrong */ * returns 0 on *failure*, which is plain wrong */
if (strcmp(applet, "is_newer_than") == 0 || if (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)
is_than = &rc_older_than;
else
is_than = &rc_newer_than;
while (i < argc) { while (i < argc) {
if (!is_than(argv[1], argv[i++])) if (!rc_newer_than(argv[1], argv[i++]))
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
}; };
/* This tets is correct as it's not present in baselayout */
if (strcmp(applet, "is_newer_than") == 0) {
if (argc < 3)
exit (EXIT_FAILURE);
while (i < argc) {
if (!rc_newer_than(argv[1], argv[i++]))
exit(EXIT_FAILURE);
}
exit(EXIT_SUCCESS);
};
if (applet[0] == 'e' || (applet[0] == 'v' && applet[1] == 'e')) if (applet[0] == 'e' || (applet[0] == 'v' && applet[1] == 'e'))
exit(do_e(argc, argv)); exit(do_e(argc, argv));