From 5936ddaea95efcbff1a925b2d675c6e0c50e6f45 Mon Sep 17 00:00:00 2001 From: "David Kaspar [Dee'Kej]" Date: Fri, 3 Aug 2018 12:24:23 +0200 Subject: consoletype/genhostid/usleep: allow disabling of deprecation warnings ... by checking existence of /etc/sysconfig/disable-deprecation-warnings --- src/consoletype.c | 17 +++++++++++++++-- src/genhostid.c | 16 ++++++++++++++-- src/usleep.c | 16 ++++++++++++++-- 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/src/consoletype.c b/src/consoletype.c index dc3bd119..20ce5a36 100644 --- a/src/consoletype.c +++ b/src/consoletype.c @@ -16,6 +16,7 @@ * */ +#include #include #include #include @@ -31,8 +32,19 @@ int main(int argc, char **argv) int maj, min, ret = 0, fg = -1; struct stat sb; - fprintf(stderr, "warning: consoletype is now deprecated, and will be removed in the near future!\n" - "warning: use tty (1) instead! More info: 'man 1 tty'\n"); + 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: consoletype is now deprecated, and will be removed in the near future!\n" + "warning: use tty (1) instead! More info: 'man 1 tty'\n"); + } fstat(0, &sb); maj = major(sb.st_rdev); @@ -47,6 +59,7 @@ int main(int argc, char **argv) char buf[65536]; fd = open("/proc/tty/drivers",O_RDONLY); + read(fd, buf, 65535); if (strstr(buf,"vioconsole /dev/tty")) { type = "vio"; diff --git a/src/genhostid.c b/src/genhostid.c index 79dcb92e..e17b9d7b 100644 --- a/src/genhostid.c +++ b/src/genhostid.c @@ -15,6 +15,7 @@ * */ +#include #include #include #include @@ -27,8 +28,19 @@ int main (void) struct stat st; long int n; - fprintf(stderr, "warning: genhostid is now deprecated, and will be removed in the near future!\n" - "warning: use systemd-machine-id-setup (1) instead! More info: 'man 5 machine-id'\n"); + 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: genhostid is now deprecated, and will be removed in the near future!\n" + "warning: use systemd-machine-id-setup (1) instead! More info: 'man 5 machine-id'\n"); + } /* * NOTE: gethostid() always returns 32-bit identifier, and st_size field 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 #include #include #include @@ -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; -- cgit v1.2.1