]> git.ipfire.org Git - people/ms/ipfire-3.x.git/blob - pkgs/lldpd/patches/lldpd-0.52.x-os-release.patch
Change file layout of the makefiles.
[people/ms/ipfire-3.x.git] / pkgs / lldpd / patches / lldpd-0.52.x-os-release.patch
1 commit ae87586a12eaf4e8329b88f6e0c629e7b14f27bc
2 Author: Michael Tremer <michael.tremer@ipfire.org>
3 Date: Sat May 28 14:29:33 2011 +0200
4
5 Add support to read /etc/os-release for system information.
6
7 /etc/os-release is introduced with systemd which will be in all the
8 major distributions, soon. For backwards-compatibility, the lsb_release
9 method is still there and will be used if no /etc/os-release is available.
10
11 diff --git a/src/lldpd.c b/src/lldpd.c
12 index b19af11..1641f13 100644
13 --- a/src/lldpd.c
14 +++ b/src/lldpd.c
15 @@ -89,6 +89,7 @@ static void lldpd_decode(struct lldpd *, char *, int,
16 static void lldpd_update_chassis(struct lldpd_chassis *,
17 const struct lldpd_chassis *);
18 static char *lldpd_get_lsb_release(void);
19 +static char *lldpd_get_os_release(void);
20 #ifdef ENABLE_LLDPMED
21 static void lldpd_med(struct lldpd_chassis *);
22 #endif
23 @@ -553,6 +554,46 @@ lldpd_get_lsb_release() {
24 return NULL;
25 }
26
27 +/* Same like lldpd_get_lsb_release but reads /etc/os-release for PRETTY_NAME=. */
28 +static char *
29 +lldpd_get_os_release() {
30 + static char release[1024];
31 +
32 + FILE *fp = fopen("/etc/os-release", "r");
33 + if (!fp) {
34 + LLOG_WARN("Could not open /etc/os-release to read system information");
35 + return NULL;
36 + }
37 +
38 + char line[1024];
39 + char *key, *val;
40 +
41 + while ((fgets(line, 1024, fp) != NULL)) {
42 + key = strtok(line, "=");
43 + val = strtok(NULL, "=");
44 +
45 + if (strncmp(key, "PRETTY_NAME", 1024) == 0) {
46 + strncpy(release, val, 1024);
47 + break;
48 + }
49 + }
50 + fclose(fp);
51 +
52 + /* Remove trailing newline and all " in the string. */
53 + char *ptr1 = release;
54 + char *ptr2 = release;
55 + while (*ptr1 != 0) {
56 + if ((*ptr1 == '"') || (*ptr1 == '\n')) {
57 + ++ptr1;
58 + } else {
59 + *ptr2++ = *ptr1++;
60 + }
61 + }
62 + *ptr2 = 0;
63 +
64 + return release;
65 +}
66 +
67 int
68 lldpd_callback_add(struct lldpd *cfg, int fd, void(*fn)(CALLBACK_SIG), void *data)
69 {
70 @@ -889,7 +930,7 @@ lldpd_update_localchassis(struct lldpd *cfg)
71 fatal("failed to set full system description");
72 } else {
73 if (cfg->g_advertise_version) {
74 - if (asprintf(&LOCAL_CHASSIS(cfg)->c_descr, "%s%s %s %s",
75 + if (asprintf(&LOCAL_CHASSIS(cfg)->c_descr, "%s %s %s %s",
76 cfg->g_lsb_release?cfg->g_lsb_release:"",
77 un.sysname, un.release, un.machine)
78 == -1)
79 @@ -1189,7 +1230,12 @@ lldpd_main(int argc, char *argv[])
80 close(pid);
81 }
82
83 - lsb_release = lldpd_get_lsb_release();
84 + /* Try to read system information from /etc/os-release if possible.
85 + Fall back to lsb_release for compatibility. */
86 + lsb_release = lldpd_get_os_release();
87 + if (!lsb_release) {
88 + lsb_release = lldpd_get_lsb_release();
89 + }
90
91 priv_init(PRIVSEP_CHROOT);
92