diff options
author | Lennart Poettering <lennart@poettering.net> | 2013-11-06 17:34:54 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2013-11-06 17:34:54 +0100 |
commit | 4087cb9e8fb90957d90d577e62e8ba056c2258cf (patch) | |
tree | e9f2028fe045c1759fde5ca80277ef5b6f5f4dfa /src/shared/path-util.c | |
parent | 45a7c6b5d373170eda2fa7bdb8fa81b49865f316 (diff) |
path-util: paths_check_timestamp() opimizations
Diffstat (limited to 'src/shared/path-util.c')
-rw-r--r-- | src/shared/path-util.c | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/src/shared/path-util.c b/src/shared/path-util.c index fcacf541ed..6c4efbfd94 100644 --- a/src/shared/path-util.c +++ b/src/shared/path-util.c @@ -428,6 +428,8 @@ int path_is_os_tree(const char *path) { int find_binary(const char *name, char **filename) { assert(name); + assert(filename); + if (strchr(name, '/')) { char *p; @@ -474,33 +476,37 @@ int find_binary(const char *name, char **filename) { } } -bool paths_check_timestamp(char **paths, usec_t *timestamp, bool update) -{ - unsigned int i; +bool paths_check_timestamp(char **paths, usec_t *timestamp, bool update) { bool changed = false; + char **i; assert(timestamp); if (paths == NULL) - goto out; + return false; - for (i = 0; paths[i]; i++) { + STRV_FOREACH(i, paths) { struct stat stats; + usec_t u; - if (stat(paths[i], &stats) < 0) + if (stat(*i, &stats) < 0) continue; + u = timespec_load(&stats.st_mtim); + /* first check */ - if (*timestamp >= timespec_load(&stats.st_mtim)) + if (*timestamp >= u) continue; - log_debug("timestamp of '%s' changed\n", paths[i]); - changed = true; + log_debug("timestamp of '%s' changed\n", *i); /* update timestamp */ - if (update) - *timestamp = timespec_load(&stats.st_mtim); + if (update) { + *timestamp = u; + changed = true; + } else + return true; } -out: + return changed; } |