PATCH: PR27784 debuginfod: notify interactive clients one time about usage
Frank Ch. Eigler
fche@redhat.com
Thu Apr 29 18:44:12 GMT 2021
Hi -
Another request from fedora fesco. (I don't have anything else on the
queue for the next elfutils release.)
commit be5ebebb1f12134b673c5b8cbede62390d077b0d
Author: Frank Ch. Eigler <fche@redhat.com>
Date: Thu Apr 29 14:34:06 2021 -0400
PR27784 debuginfod: notify interactive clients one time about usage
Because debuginfod-client functionality makes a user dependent on the
correct operation of remote debuginfod server, it was suggested that
new users be notified of this. This patch adds a one-time
notification to stderr if it isatty(), commemorated by a new cache
notify_p file. (It cannot easily be tested because our test scripts
run without pty/tty enclosure.)
Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
diff --git a/debuginfod/ChangeLog b/debuginfod/ChangeLog
index 20744497e383..800709416c61 100644
--- a/debuginfod/ChangeLog
+++ b/debuginfod/ChangeLog
@@ -1,3 +1,9 @@
+2021-04-29 Frank Ch. Eigler <fche@redhat.com>
+
+ PR27784
+ * debuginfod-client.c (debuginfod_query_server): Notify interactive
+ users, one time, about impending debuginfod-client usage.
+
2021-04-29 Frank Ch. Eigler <fche@redhat.com>
PR27783
diff --git a/debuginfod/debuginfod-client.c b/debuginfod/debuginfod-client.c
index e65aac8b4c1c..d3fbf7caae6d 100644
--- a/debuginfod/debuginfod-client.c
+++ b/debuginfod/debuginfod-client.c
@@ -141,6 +141,10 @@ static const time_t cache_clean_default_interval_s = 86400; /* 1 day */
static const char *cache_max_unused_age_filename = "max_unused_age_s";
static const time_t cache_default_max_unused_age_s = 604800; /* 1 week */
+/* The cache_notified_p_filename file within the cache indicates the user has
+ received a one-time notification of debuginfod client operation on a TTY. */
+static const char *cache_notified_p_filename = "notified_p";
+
/* Location of the cache of files downloaded from debuginfods.
The default parent directory is $HOME, or '/' if $HOME doesn't exist. */
static const char *cache_default_name = ".debuginfod_client_cache";
@@ -503,6 +507,7 @@ debuginfod_query_server (debuginfod_client *c,
char *urls_envvar;
char *cache_path = NULL;
char *maxage_path = NULL;
+ char *notified_p_path = NULL;
char *interval_path = NULL;
char *target_cache_dir = NULL;
char *target_cache_path = NULL;
@@ -678,7 +683,28 @@ debuginfod_query_server (debuginfod_client *c,
/* XXX combine these */
xalloc_str (interval_path, "%s/%s", cache_path, cache_clean_interval_filename);
xalloc_str (maxage_path, "%s/%s", cache_path, cache_max_unused_age_filename);
+ xalloc_str (notified_p_path, "%s/%s", cache_path, cache_notified_p_filename);
+
+
+ /* If on a TTY, notify the user if this is the first time
+ debuginfod-client is activated. */
+ if (isatty (STDERR_FILENO) &&
+ access (notified_p_path, R_OK))
+ {
+ int fd = open (notified_p_path, O_CREAT | O_RDWR, 0400);
+ if (fd >= 0)
+ close (fd);
+ if (vfd >= 0)
+ dprintf (vfd, "recorded first notification %s\n", notified_p_path);
+
+ fprintf (stderr,
+ "\nNOTICE: This system is configured to auto-download debuginfo from:\n%s\n\n",
+ urls_envvar);
+ fflush (stderr);
+ sleep (3);
+ }
+
if (vfd >= 0)
dprintf (vfd, "checking cache dir %s\n", cache_path);
@@ -1112,6 +1138,7 @@ debuginfod_query_server (debuginfod_client *c,
}
free (cache_path);
+ free (notified_p_path);
free (maxage_path);
free (interval_path);
free (target_cache_dir);
diff --git a/tests/ChangeLog b/tests/ChangeLog
index bc2016f40203..1f1b2dd8695b 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,8 @@
+2021-04-29 Frank Ch. Eigler <fche@redhat.com>
+
+ PR27784
+ * run-debuginfod-find.sh: Don't test tty first-use notification.
+
2021-04-29 Frank Ch. Eigler <fche@redhat.com>
PR27783
diff --git a/tests/run-debuginfod-find.sh b/tests/run-debuginfod-find.sh
index 9a217121b7e2..cc364c861ca4 100755
--- a/tests/run-debuginfod-find.sh
+++ b/tests/run-debuginfod-find.sh
@@ -384,6 +384,12 @@ wait_ready $PORT1 'groomed_total{decision="stale"}' 4
rm -rf $DEBUGINFOD_CACHE_PATH # clean it from previous tests
+# check for first-use notice; don't bother run this one under valgrind, to collect stderr
+# ... but need a pty/tty to trigger the message, so just comment this out for now
+# ${abs_top_builddir}/debuginfod/debuginfod-find executable 0000111122223333 2>errfile && false || true
+# tempfiles errfile
+# grep NOTICE errfile
+
# this is one of the buildids from the groom-deleted rpms
testrun ${abs_top_builddir}/debuginfod/debuginfod-find executable $RPM_BUILDID && false || true
# but this one was not deleted so should be still around
More information about the Elfutils-devel
mailing list