1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-11-17 10:35:10 +00:00

Make conky resolve symlinks before using them. (#238)

* Make dev_name resolve symlinks before resolving the name.

- When symlinks are not resolved first, you will get an error on startup when
  using path in /dev/disk/by-id, for example, in diskiograph_*.

* Improve diskio device name resolution by always resolving symlinks.

- Any device path will be resolved of any symlinks before getting the usual
  checks for labels et device name.

* Check if diskio device is really a block device, not only if it exists.

- Current check would succeed in case the device is a path, like when using
  label: with an empty argument.
This commit is contained in:
Jérôme Poulin 2016-05-03 08:04:14 -04:00 committed by Brenden Matthews
parent d8c659e7de
commit 48122dcf82
2 changed files with 13 additions and 16 deletions

View File

@ -122,17 +122,15 @@
*/
const char *dev_name(const char *path)
{
static char buf[255]; /* should be enough for pathnames */
ssize_t buflen;
static char buf[PATH_MAX];
if (!path)
return NULL;
#define DEV_NAME(x) \
x != NULL && strlen(x) > 5 && strncmp(x, "/dev/", 5) == 0 ? x + 5 : x
if ((buflen = readlink(path, buf, 254)) == -1)
if (realpath(path, buf) == NULL)
return DEV_NAME(path);
buf[buflen] = '\0';
return DEV_NAME(buf);
#undef DEV_NAME
}

View File

@ -60,23 +60,22 @@ struct diskio_stat *prepare_diskio_stat(const char *s)
struct stat sb;
std::vector<char> stat_name(text_buffer_size.get(*state)), device_name(text_buffer_size.get(*state)), device_s(text_buffer_size.get(*state));
struct diskio_stat *cur = &stats;
char * rpbuf;
if (!s) {
return &stats;
} else {
strncpy(&(device_s[0]), s, text_buffer_size.get(*state));
}
if (strncmp(&(device_s[0]), "label:", 6) == 0) {
snprintf(&(device_name[0]), text_buffer_size.get(*state), "/dev/disk/by-label/%s", &(device_s[6]));
char * rpbuf;
if (strncmp(s, "label:", 6) == 0) {
snprintf(&(device_name[0]), text_buffer_size.get(*state), "/dev/disk/by-label/%s", s+6);
rpbuf = realpath(&device_name[0], NULL);
if (rpbuf) {
strncpy(&device_s[0], rpbuf, text_buffer_size.get(*state));
}
free(rpbuf);
} else {
rpbuf = realpath(s, NULL);
}
if (rpbuf) {
strncpy(&device_s[0], rpbuf, text_buffer_size.get(*state));
free(rpbuf);
} else {
strncpy(&device_s[0], s, text_buffer_size.get(*state));
}
@ -90,8 +89,8 @@ struct diskio_stat *prepare_diskio_stat(const char *s)
snprintf(&(stat_name[0]), text_buffer_size.get(*state), "/dev/%s", &(device_name[0]));
if (stat(&(stat_name[0]), &sb)) {
NORM_ERR("diskio device '%s' does not exist", s);
if (stat(&(stat_name[0]), &sb) || !S_ISBLK(sb.st_mode)) {
NORM_ERR("diskio device '%s' does not exist", &device_s[0]);
}
/* lookup existing */