annotate src/master/sysinfo-get.c @ 8971:163c3f85a3aa HEAD

namespaces: list=children wasn't working correctly.
author Timo Sirainen <tss@iki.fi>
date Mon, 20 Apr 2009 13:28:00 -0400
parents b9faf4db2a9f
children 00cd9aacd03c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8590
b9faf4db2a9f Updated copyright notices to include year 2009.
Timo Sirainen <tss@iki.fi>
parents: 8357
diff changeset
1 /* Copyright (c) 2008-2009 Dovecot authors, see the included COPYING file */
8354
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
3 #include "lib.h"
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
4 #include "mountpoint.h"
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
5 #include "strescape.h"
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
6 #include "sysinfo-get.h"
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
7
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
8 #include <unistd.h>
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
9 #include <fcntl.h>
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
10 #include <sys/stat.h>
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
11 #ifdef HAVE_SYS_UTSNAME_H
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
12 # include <sys/utsname.h>
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
13 #endif
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
14
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
15 static bool readfile(const char *path, const char **data_r)
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
16 {
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
17 char buf[1024];
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
18 int fd, ret;
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
19
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
20 fd = open(path, O_RDONLY);
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
21 if (fd == -1)
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
22 return FALSE;
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
23 ret = read(fd, buf, sizeof(buf));
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
24 (void)close(fd);
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
25 if (ret <= 0)
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
26 return FALSE;
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
27
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
28 *data_r = t_strndup(buf, ret);
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
29 return TRUE;
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
30 }
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
31
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
32 static bool lsb_distro_get(const char *path, const char **name_r)
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
33 {
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
34 const char *data, *const *p, *str, *end;
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
35
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
36 if (!readfile(path, &data))
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
37 return FALSE;
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
38
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
39 for (p = t_strsplit(data, "\n"); *p != '\0'; p++) {
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
40 if (strncmp(*p, "DISTRIB_DESCRIPTION=", 20) == 0)
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
41 break;
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
42 }
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
43 if (*p == '\0')
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
44 return FALSE;
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
45
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
46 str = t_strcut(*p + 20, '\n');
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
47 if (*str != '"')
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
48 *name_r = str;
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
49 else {
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
50 end = strrchr(++str, '"');
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
51 *name_r = str_unescape(p_strdup_until(unsafe_data_stack_pool,
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
52 str, end));
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
53 }
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
54 return TRUE;
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
55 }
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
56
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
57 static const char *distro_get(void)
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
58 {
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
59 static const char *files[] = {
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
60 "", "/etc/redhat-release",
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
61 "", "/etc/SuSE-release",
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
62 "", "/etc/mandriva-release",
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
63 "", "/etc/fedora-release",
8355
3a0101119ae3 dovecot -n/-a: Added more Linux distros.
Timo Sirainen <tss@iki.fi>
parents: 8354
diff changeset
64 "", "/etc/sourcemage-release",
3a0101119ae3 dovecot -n/-a: Added more Linux distros.
Timo Sirainen <tss@iki.fi>
parents: 8354
diff changeset
65 "", "/etc/slackware-version",
8357
a66bd1e629a2 dovecot -n/-a: Added Gentoo check.
Timo Sirainen <tss@iki.fi>
parents: 8356
diff changeset
66 "", "/etc/gentoo-release",
8354
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
67 "Debian ", "/etc/debian_version",
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
68 NULL
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
69 };
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
70 const char *name;
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
71 unsigned int i;
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
72
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
73 if (lsb_distro_get("/etc/lsb-release", &name))
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
74 return name;
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
75 for (i = 0; files[i] != NULL; i += 2) {
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
76 if (readfile(files[i+1], &name)) {
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
77 return t_strconcat(files[i], t_strcut(name, '\n'),
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
78 NULL);
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
79 }
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
80 }
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
81 return "";
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
82 }
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
83
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
84 static const char *filesystem_get(const char *mail_location)
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
85 {
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
86 struct mountpoint mp;
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
87 const char *path;
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
88
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
89 path = strchr(mail_location, ':');
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
90 if (path == NULL)
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
91 path = mail_location;
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
92 else
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
93 path = t_strcut(path + 1, ':');
8356
125e530609d4 dovecot -n/-a: Fixes to printing which filesystem is being used.
Timo Sirainen <tss@iki.fi>
parents: 8355
diff changeset
94 if (*path == '~') {
125e530609d4 dovecot -n/-a: Fixes to printing which filesystem is being used.
Timo Sirainen <tss@iki.fi>
parents: 8355
diff changeset
95 /* we don't know where users' home dirs are */
125e530609d4 dovecot -n/-a: Fixes to printing which filesystem is being used.
Timo Sirainen <tss@iki.fi>
parents: 8355
diff changeset
96 return "";
125e530609d4 dovecot -n/-a: Fixes to printing which filesystem is being used.
Timo Sirainen <tss@iki.fi>
parents: 8355
diff changeset
97 }
125e530609d4 dovecot -n/-a: Fixes to printing which filesystem is being used.
Timo Sirainen <tss@iki.fi>
parents: 8355
diff changeset
98 path = t_strcut(path, '%');
125e530609d4 dovecot -n/-a: Fixes to printing which filesystem is being used.
Timo Sirainen <tss@iki.fi>
parents: 8355
diff changeset
99 if (strlen(path) <= 1)
125e530609d4 dovecot -n/-a: Fixes to printing which filesystem is being used.
Timo Sirainen <tss@iki.fi>
parents: 8355
diff changeset
100 return "";
8354
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
101
8356
125e530609d4 dovecot -n/-a: Fixes to printing which filesystem is being used.
Timo Sirainen <tss@iki.fi>
parents: 8355
diff changeset
102 /* all in all it seems we can support only /<path>/%u style location */
8354
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
103 if (mountpoint_get(path, pool_datastack_create(), &mp) < 0)
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
104 return "";
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
105 return mp.type == NULL ? "" : mp.type;
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
106 }
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
107
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
108 const char *sysinfo_get(const char *mail_location)
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
109 {
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
110 const char *distro = "", *fs, *uname_info = "";
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
111 #ifdef HAVE_SYS_UTSNAME_H
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
112 struct utsname u;
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
113
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
114 if (uname(&u) < 0)
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
115 i_error("uname() failed: %m");
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
116 else {
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
117 uname_info = t_strdup_printf("%s %s %s",
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
118 u.sysname, u.release, u.machine);
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
119 }
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
120 if (strcmp(u.sysname, "Linux") == 0)
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
121 distro = distro_get();
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
122 #endif
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
123 fs = filesystem_get(mail_location);
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
124 if (*uname_info == '\0' && *distro == '\0' && *fs == '\0')
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
125 return "";
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
126 return t_strdup_printf("OS: %s %s %s %s %s", u.sysname, u.release, u.machine, distro, fs);
5339d2ebeb56 dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
127 }