diff --git a/src/ratbagd-device.c b/src/ratbagd-device.c index 45c17d99..8fb36684 100644 --- a/src/ratbagd-device.c +++ b/src/ratbagd-device.c @@ -216,8 +216,7 @@ static int ratbagd_device_get_active_profile(sd_bus *bus, return sd_bus_message_append(reply, "u", i); } - fprintf(stderr, "Unable to find active profile for %s\n", - device->name); + log_error("Unable to find active profile for %s\n", device->name); return sd_bus_message_append(reply, "u", 0); } @@ -322,9 +321,8 @@ int ratbagd_device_new(struct ratbagd_device **out, i); if (r < 0) { errno = -r; - fprintf(stderr, - "Cannot allocate profile for '%s': %m\n", - device->name); + log_error("Cannot allocate profile for '%s': %m\n", + device->name); } } @@ -448,9 +446,8 @@ void ratbagd_device_link(struct ratbagd_device *device) } if (r < 0) { errno = -r; - fprintf(stderr, - "Cannot register profile interfaces for '%s': %m\n", - device->name); + log_error("Cannot register profile interfaces for '%s': %m\n", + device->name); return; } @@ -459,9 +456,8 @@ void ratbagd_device_link(struct ratbagd_device *device) device, device->profiles[i]); if (r < 0) { - fprintf(stderr, - "Cannot register resolutions for '%s': %m\n", - device->name); + log_error("Cannot register resolutions for '%s': %m\n", + device->name); } r = ratbagd_profile_register_buttons(device->ctx->bus, diff --git a/src/ratbagd-profile.c b/src/ratbagd-profile.c index 0aa43622..3e463b14 100644 --- a/src/ratbagd-profile.c +++ b/src/ratbagd-profile.c @@ -136,8 +136,8 @@ static int ratbagd_profile_get_active_resolution(sd_bus *bus, return sd_bus_message_append(reply, "u", i); } - fprintf(stderr, "Unable to find active resolution for %s\n", - ratbagd_device_get_name(profile->device)); + log_error("Unable to find active resolution for %s\n", + ratbagd_device_get_name(profile->device)); return sd_bus_message_append(reply, "u", 0); } @@ -163,8 +163,8 @@ static int ratbagd_profile_get_default_resolution(sd_bus *bus, return sd_bus_message_append(reply, "u", i); } - fprintf(stderr, "Unable to find default resolution for %s\n", - ratbagd_device_get_name(profile->device)); + log_error("Unable to find default resolution for %s\n", + ratbagd_device_get_name(profile->device)); return sd_bus_message_append(reply, "u", 0); } @@ -299,9 +299,8 @@ int ratbagd_profile_new(struct ratbagd_profile **out, i); if (r < 0) { errno = -r; - fprintf(stderr, - "Cannot allocate resolution for '%s': %m\n", - ratbagd_device_get_name(device)); + log_error("Cannot allocate resolution for '%s': %m\n", + ratbagd_device_get_name(device)); } } @@ -317,9 +316,8 @@ int ratbagd_profile_new(struct ratbagd_profile **out, i); if (r < 0) { errno = -r; - fprintf(stderr, - "Cannot allocate button for '%s': %m\n", - ratbagd_device_get_name(device)); + log_error("Cannot allocate button for '%s': %m\n", + ratbagd_device_get_name(device)); } } @@ -431,9 +429,8 @@ int ratbagd_profile_register_resolutions(struct sd_bus *bus, } if (r < 0) { errno = -r; - fprintf(stderr, - "Cannot register resolutions for '%s': %m\n", - ratbagd_device_get_name(device)); + log_error("Cannot register resolutions for '%s': %m\n", + ratbagd_device_get_name(device)); } return 0; @@ -509,9 +506,8 @@ int ratbagd_profile_register_buttons(struct sd_bus *bus, } if (r < 0) { errno = -r; - fprintf(stderr, - "Cannot register buttons for '%s': %m\n", - ratbagd_device_get_name(device)); + log_error("Cannot register buttons for '%s': %m\n", + ratbagd_device_get_name(device)); } return 0; diff --git a/src/ratbagd.c b/src/ratbagd.c index 4fef42c9..ca5347ef 100644 --- a/src/ratbagd.c +++ b/src/ratbagd.c @@ -47,6 +47,16 @@ void log_verbose(const char *fmt, ...) va_end(args); } +void log_error(const char *fmt, ...) +{ + va_list args; + + va_start(args, fmt); + fprintf(stderr, "%s error: ", program_invocation_short_name); + vfprintf(stderr, fmt, args); + va_end(args); +} + static int ratbagd_find_device(sd_bus *bus, const char *path, const char *interface, @@ -214,7 +224,7 @@ static void ratbagd_process_device(struct ratbagd *ctx, ratbag_device_unref(lib_device); if (r < 0) { - fprintf(stderr, "Cannot track device '%s'\n", name); + log_error("Cannot track device '%s'\n", name); return; } @@ -488,8 +498,7 @@ exit: if (r < 0) { errno = -r; - fprintf(stderr, "%s: Failed: %m\n", - program_invocation_short_name); + log_error("Failed: %m\n"); return EXIT_FAILURE; } diff --git a/src/ratbagd.h b/src/ratbagd.h index 442f2e6f..01477f4f 100644 --- a/src/ratbagd.h +++ b/src/ratbagd.h @@ -43,6 +43,7 @@ struct ratbagd_resolution; struct ratbagd_button; void log_verbose(const char *fmt, ...) _printf_(1, 2); +void log_error(const char *fmt, ...) _printf_(1, 2); /* * Profiles