Skip to content
Snippets Groups Projects
Commit 637eeca2 authored by Simon McVittie's avatar Simon McVittie
Browse files

utils: Prepend basename of argv[0] to diagnostic messages


This allows them to be distinguished from messages logged by some
other executable invoked around the same time, and makes
`capsule_log( LOG_WARNING, ... )` a drop-in substitute for `warnx()`.

Signed-off-by: default avatarSimon McVittie <smcv@collabora.com>
parent b029b6fa
No related branches found
No related tags found
No related merge requests found
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
// License along with libcapsule. If not, see <http://www.gnu.org/licenses/>. // License along with libcapsule. If not, see <http://www.gnu.org/licenses/>.
#include <assert.h> #include <assert.h>
#include <errno.h>
#include <sys/param.h> #include <sys/param.h>
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
...@@ -733,6 +734,7 @@ _capsule_basename (const char *path) ...@@ -733,6 +734,7 @@ _capsule_basename (const char *path)
* @ap: Arguments for @fmt * @ap: Arguments for @fmt
* *
* Log the message @fmt, substituting the given arguments. * Log the message @fmt, substituting the given arguments.
* The basename of argv[0] is prepended, similar to warnx().
* A newline is appended automatically and should not be included in @fmt. * A newline is appended automatically and should not be included in @fmt.
* *
* Unlike `errx()` and `g_error()`, this does not immediately exit, * Unlike `errx()` and `g_error()`, this does not immediately exit,
...@@ -744,6 +746,7 @@ capsule_logv( int severity, const char *fmt, va_list ap ) ...@@ -744,6 +746,7 @@ capsule_logv( int severity, const char *fmt, va_list ap )
{ {
/* libcapsule tools are single-threaded, so it's an acceptable /* libcapsule tools are single-threaded, so it's an acceptable
* simplification that we do not emit the whole message atomically. */ * simplification that we do not emit the whole message atomically. */
fprintf( stderr, "%s: ", program_invocation_short_name );
vfprintf( stderr, fmt, ap ); vfprintf( stderr, fmt, ap );
fputc( '\n', stderr ); fputc( '\n', stderr );
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment