From 2b4ae24f791935e4ad0688095371b97f91edafb0 Mon Sep 17 00:00:00 2001 From: jilles Date: Mon, 23 Dec 2013 22:38:41 +0000 Subject: [PATCH] MFC r256060,r256650: kldxref: Do not depend on the directory order. Sort the filenames to get a consistent result between machines of the same architecture. Also, sort FTS_D entries after other entries so kldxref -R works properly in the uncommon case that a directory contains both subdirectories and modules. Previously, this may have happened to work, depending on the order of files in the directory. PR: bin/182098 Submitted by: Derek Schrock (original version) Tested by: Derek Schrock git-svn-id: svn://svn.freebsd.org/base/stable/9@259799 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- usr.sbin/kldxref/kldxref.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/usr.sbin/kldxref/kldxref.c b/usr.sbin/kldxref/kldxref.c index 16b9058d4..9144ba030 100644 --- a/usr.sbin/kldxref/kldxref.c +++ b/usr.sbin/kldxref/kldxref.c @@ -274,6 +274,16 @@ usage(void) exit(1); } +static int +compare(const FTSENT *const *a, const FTSENT *const *b) +{ + if ((*a)->fts_info == FTS_D && (*b)->fts_info != FTS_D) + return 1; + if ((*a)->fts_info != FTS_D && (*b)->fts_info == FTS_D) + return -1; + return strcmp((*a)->fts_name, (*b)->fts_name); +} + int main(int argc, char *argv[]) { @@ -315,7 +325,7 @@ main(int argc, char *argv[]) err(1, "%s", argv[0]); } - ftsp = fts_open(argv, fts_options, 0); + ftsp = fts_open(argv, fts_options, compare); if (ftsp == NULL) exit(1); -- 2.45.0