diff options
author | Patrick Griffis <tingping@tingping.se> | 2017-11-18 20:47:32 -0500 |
---|---|---|
committer | Patrick Griffis <tingping@tingping.se> | 2017-11-18 20:47:32 -0500 |
commit | 3e53635dfbd30acb7b11f07a6f00071e7643867f (patch) | |
tree | 1afc36b91884d53e7cbabebb1119b6fe01697e45 /plugins/sysinfo | |
parent | 47b653cc7c981cb2a20dc2140c66d90b6f3088d0 (diff) |
sysinfo: Make libpci an optional dependency
Diffstat (limited to 'plugins/sysinfo')
-rw-r--r-- | plugins/sysinfo/meson.build | 9 | ||||
-rw-r--r-- | plugins/sysinfo/unix/parse.c | 30 |
2 files changed, 29 insertions, 10 deletions
diff --git a/plugins/sysinfo/meson.build b/plugins/sysinfo/meson.build index c589a590..5656724e 100644 --- a/plugins/sysinfo/meson.build +++ b/plugins/sysinfo/meson.build @@ -19,14 +19,17 @@ if system == 'linux' or system == 'darwin' ] if system == 'linux' - libpci = dependency('libpci') - sysinfo_deps += libpci + libpci = dependency('libpci', required: false) + if libpci.found() + sysinfo_deps += libpci + sysinfo_cargs += '-DHAVE_LIBPCI' + sysinfo_sources += 'unix/pci.c' + endif sysinfo_includes += 'unix' sysinfo_sources += [ 'unix/backend.c', 'unix/match.c', 'unix/parse.c', - 'unix/pci.c', ] picidsdir = libpci.get_pkgconfig_variable('idsdir') diff --git a/plugins/sysinfo/unix/parse.c b/plugins/sysinfo/unix/parse.c index 0e4e8877..30599068 100644 --- a/plugins/sysinfo/unix/parse.c +++ b/plugins/sysinfo/unix/parse.c @@ -132,21 +132,24 @@ gint64 xs_parse_uptime(void) if(fgets(buffer, bsize, fp) != NULL) uptime = g_ascii_strtoll(buffer, NULL, 0); - + fclose(fp); - + return uptime; } int xs_parse_sound(char *snd_card) { +#ifndef HAVE_LIBPCI + return 1; +#else char buffer[bsize], cards[bsize] = "\0", vendor[7] = "\0", device[7] = "\0", *pos; u16 class = PCI_CLASS_MULTIMEDIA_AUDIO; FILE *fp = NULL; if((fp = fopen("/proc/asound/cards", "r"))== NULL) { - if (pci_find_by_class(&class, vendor, device) == 0) + if (pci_find_by_class(&class, vendor, device) == 0) { pci_find_fullname(snd_card, vendor, device); return 0; @@ -154,8 +157,8 @@ int xs_parse_sound(char *snd_card) else return 1; } - - + + while(fgets(buffer, bsize, fp) != NULL) { if(isdigit(buffer[0]) || isdigit(buffer[1])) @@ -175,13 +178,17 @@ int xs_parse_sound(char *snd_card) } strcpy(snd_card, cards); - + fclose(fp); return 0; +#endif } int xs_parse_video(char *vid_card) { +#ifndef HAVE_LIBPCI + return 1; +#else char vendor[7] = "\0", device[7] = "\0"; u16 class = PCI_CLASS_DISPLAY_VGA; if (pci_find_by_class(&class, vendor, device)) @@ -189,10 +196,14 @@ int xs_parse_video(char *vid_card) else pci_find_fullname(vid_card, vendor, device); return 0; +#endif } int xs_parse_ether(char *ethernet_card) { +#ifndef HAVE_LIBPCI + return 1; +#else char vendor[7] = "\0", device[7] = "\0"; u16 class = PCI_CLASS_NETWORK_ETHERNET; if (pci_find_by_class(&class, vendor, device)) @@ -200,10 +211,14 @@ int xs_parse_ether(char *ethernet_card) else pci_find_fullname(ethernet_card, vendor, device); return 0; +#endif } int xs_parse_agpbridge(char *agp_bridge) { +#ifndef HAVE_LIBPCI + return 1; +#else char vendor[7] = "\0", device[7] = "\0"; u16 class = PCI_CLASS_BRIDGE_HOST; if (pci_find_by_class(&class, vendor, device)) @@ -211,6 +226,7 @@ int xs_parse_agpbridge(char *agp_bridge) else pci_find_fullname(agp_bridge, vendor, device); return 0; +#endif } int xs_parse_meminfo(unsigned long long *mem_tot, unsigned long long *mem_free, int swap) @@ -306,7 +322,7 @@ int xs_parse_distro(char *name) g_snprintf(buffer, bsize, "Unknown Distro"); if(fp != NULL) fclose(fp); - + pos=strchr(buffer, '\n'); if(pos != NULL) *pos = '\0'; |