Replace fprintfs with a new log_error helper

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer
2016-02-19 14:06:04 +10:00
parent ce3038fd8e
commit 2138ab05e5
4 changed files with 32 additions and 30 deletions

View File

@@ -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,

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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