mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-11-18 02:55:12 +00:00
Handle if popen should fail
This commit is contained in:
parent
febc5306e2
commit
4d37d021e1
14
src/conky.c
14
src/conky.c
@ -642,12 +642,16 @@ static struct text_object global_root_object;
|
|||||||
static inline void read_exec(const char *data, char *buf, const int size)
|
static inline void read_exec(const char *data, char *buf, const int size)
|
||||||
{
|
{
|
||||||
FILE *fp = popen(data, "r");
|
FILE *fp = popen(data, "r");
|
||||||
int length = fread(buf, 1, size, fp);
|
if(fp) {
|
||||||
|
int length = fread(buf, 1, size, fp);
|
||||||
|
|
||||||
pclose(fp);
|
pclose(fp);
|
||||||
buf[length] = '\0';
|
buf[length] = '\0';
|
||||||
if (length > 0 && buf[length - 1] == '\n') {
|
if (length > 0 && buf[length - 1] == '\n') {
|
||||||
buf[length - 1] = '\0';
|
buf[length - 1] = '\0';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
buf[0] = '\0';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user