]> git.ipfire.org Git - collecty.git/blob - src/_collecty/utils.c
latency: Silence "no replies received" when no IPv6 connectivity
[collecty.git] / src / _collecty / utils.c
1 /*
2 * collecty
3 * Copyright (C) 2015 IPFire Team (www.ipfire.org)
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include <Python.h>
20 #include <mntent.h>
21
22 #include "_collectymodule.h"
23
24 int _collecty_mountpoint_is_virtual(const struct mntent* mp) {
25 // Ignore all ramdisks
26 if (mp->mnt_fsname[0] != '/')
27 return 1;
28
29 // Ignore network mounts
30 if (hasmntopt(mp, "_netdev") != NULL)
31 return 1;
32
33 return 0;
34 }
35
36 PyObject* _collecty_get_mountpoints() {
37 FILE* fp = setmntent(_PATH_MOUNTED, "r");
38 if (!fp)
39 return NULL;
40
41 PyObject* list = PyList_New(0);
42 int r = 0;
43
44 struct mntent* mountpoint = getmntent(fp);
45 while (mountpoint) {
46 if (!_collecty_mountpoint_is_virtual(mountpoint)) {
47 // Create a tuple with the information of the mountpoint
48 PyObject* mp = PyTuple_New(4);
49 PyTuple_SET_ITEM(mp, 0, PyUnicode_FromString(mountpoint->mnt_fsname));
50 PyTuple_SET_ITEM(mp, 1, PyUnicode_FromString(mountpoint->mnt_dir));
51 PyTuple_SET_ITEM(mp, 2, PyUnicode_FromString(mountpoint->mnt_type));
52 PyTuple_SET_ITEM(mp, 3, PyUnicode_FromString(mountpoint->mnt_opts));
53
54 // Append the tuple to the list
55 r = PyList_Append(list, mp);
56 if (r)
57 break;
58 }
59
60 // Move on to the next mountpoint
61 mountpoint = getmntent(fp);
62 }
63
64 endmntent(fp);
65
66 if (r) {
67 Py_DECREF(list);
68 return NULL;
69 }
70
71 return list;
72 }