Hi,
this patch adds the name of the group owning the device to the error message so the user does not have to look it up herself. I tested this on Mac, I hope it compiles (and works) on the other OSes. Best Robert |
From 9713e56d9616ac9e40a097142465a712384543e7 Mon Sep 17 00:00:00 2001 From: "Robert C. Helling" <[email protected]> Date: Mon, 28 Dec 2015 20:46:07 +0100 Subject: [PATCH] Show group owning device in error message To: [email protected]
We show an error message if we cannot open a device to read from a dive computer if we have insufficient privileges. This adds the name of the group owning this device. This should help the user to figure out to add herself to 'modem' or 'uucp' or whatever group. Signed-off-by: Robert C. Helling <[email protected]> --- subsurface-core/libdivecomputer.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/subsurface-core/libdivecomputer.c b/subsurface-core/libdivecomputer.c index 3990884..285f090 100644 --- a/subsurface-core/libdivecomputer.c +++ b/subsurface-core/libdivecomputer.c @@ -7,6 +7,10 @@ #include "device.h" #include "divelist.h" #include "display.h" +#include "sys/stat.h" +#include <grp.h> +#include <uuid/uuid.h> + #include "libdivecomputer.h" #include <libdivecomputer/uwatec.h> @@ -940,6 +944,15 @@ logfunc(dc_context_t *context, dc_loglevel_t loglevel, const char *file, unsigne } } +char *get_group_of_device(device_data_t *data) +{ + struct stat buf; + struct group *group; + stat(data->devname, &buf); + group = getgrgid(buf.st_gid); + return strdup(group->gr_name); +} + const char *do_libdivecomputer_import(device_data_t *data) { dc_status_t rc; @@ -990,8 +1003,12 @@ const char *do_libdivecomputer_import(device_data_t *data) #endif rc = dc_device_open(&data->device, data->context, data->descriptor, data->devname); - if (rc != DC_STATUS_SUCCESS && subsurface_access(data->devname, R_OK | W_OK) != 0) - err = translate("gettextFromC", "Insufficient privileges to open the device %s %s (%s)"); + if (rc != DC_STATUS_SUCCESS && subsurface_access(data->devname, R_OK | W_OK) != 0) { + char *buf; + asprintf(&buf, translate("gettextFromC", "Insufficient privileges to open the device %%s %%s (%%s) owned by group %s"), + get_group_of_device(data)); + err = buf; + } } if (rc == DC_STATUS_SUCCESS) { -- 2.5.4 (Apple Git-61)
signature.asc
Description: Message signed with OpenPGP using GPGMail
_______________________________________________ subsurface mailing list [email protected] http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface
