diff options
author | David Kaspar [Dee'Kej] <dkaspar@redhat.com> | 2018-08-03 12:24:23 +0200 |
---|---|---|
committer | Dee'Kej <deekej@linuxmail.org> | 2018-08-03 13:06:43 +0200 |
commit | 5936ddaea95efcbff1a925b2d675c6e0c50e6f45 (patch) | |
tree | af8dd18391fcfe27e105a0b95107406897972737 /src/usleep.c | |
parent | 335a6a84f618515c6902d374e391a301d0f43f6c (diff) | |
download | initscripts-5936ddaea95efcbff1a925b2d675c6e0c50e6f45.tar initscripts-5936ddaea95efcbff1a925b2d675c6e0c50e6f45.tar.gz initscripts-5936ddaea95efcbff1a925b2d675c6e0c50e6f45.tar.bz2 initscripts-5936ddaea95efcbff1a925b2d675c6e0c50e6f45.tar.xz initscripts-5936ddaea95efcbff1a925b2d675c6e0c50e6f45.zip |
consoletype/genhostid/usleep: allow disabling of deprecation warnings
... by checking existence of /etc/sysconfig/disable-deprecation-warnings
Diffstat (limited to 'src/usleep.c')
-rw-r--r-- | src/usleep.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/usleep.c b/src/usleep.c index 58ab2d79..2c8ea33f 100644 --- a/src/usleep.c +++ b/src/usleep.c @@ -21,6 +21,7 @@ */ +#include <errno.h> #include <unistd.h> #include <stdlib.h> #include <string.h> @@ -77,8 +78,19 @@ int main(const int argc, const char **argv) { else count = strtoul(countStr, NULL, 0); - fprintf(stderr, "warning: usleep is deprecated, and will be removed in near future!\n" - "warning: use \"sleep %.7g\" instead...\n", count / 1e6); + errno = 0; + + /* + * access() returns -1 if the file does not exist or upon error. + * We should display the deprecation warning only when we are sure the + * file does not exist. In case of different error, silently ignore it + * and do not print anything - to not pollute users' scripts unnecessarily. + */ + if (access("/etc/sysconfig/disable-deprecation-warnings", F_OK) == -1 + && errno == ENOENT) { + fprintf(stderr, "warning: usleep is deprecated, and will be removed in near future!\n" + "warning: use \"sleep %.7g\" instead...\n", count / 1e6); + } usleep(count); return 0; |