1 /* Copyright (C) 1998-99 Martin Baulig
2    This file is part of LibGTop 1.0.
3 
4    Contributed by Martin Baulig <martin@home-of-linux.org>, August 1998.
5 
6    LibGTop is free software; you can redistribute it and/or modify it
7    under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License,
9    or (at your option) any later version.
10 
11    LibGTop is distributed in the hope that it will be useful, but WITHOUT
12    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14    for more details.
15 
16    You should have received a copy of the GNU General Public License
17    along with LibGTop; see the file COPYING. If not, write to the
18    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19    Boston, MA 02110-1301, USA.
20 */
21 
22 #include <config.h>
23 #include <glibtop.h>
24 #include <glibtop/error.h>
25 #include <glibtop/shm_limits.h>
26 
27 #include <sys/types.h>
28 #include <sys/param.h>
29 #include <sys/sysctl.h>
30 
31 static unsigned long _glibtop_sysdeps_shm_limits =
32 (1L << GLIBTOP_IPC_SHMMAX) + (1L << GLIBTOP_IPC_SHMMIN) +
33 (1L << GLIBTOP_IPC_SHMMNI) + (1L << GLIBTOP_IPC_SHMSEG) +
34 (1L << GLIBTOP_IPC_SHMALL);
35 
36 /* Init function. */
37 
38 void
_glibtop_init_shm_limits_s(glibtop * server)39 _glibtop_init_shm_limits_s (glibtop *server)
40 {
41 	server->sysdeps.shm_limits = _glibtop_sysdeps_shm_limits;
42 }
43 
44 /* Provides information about sysv ipc limits. */
45 
46 void
glibtop_get_shm_limits_s(glibtop * server,glibtop_shm_limits * buf)47 glibtop_get_shm_limits_s (glibtop *server, glibtop_shm_limits *buf)
48 {
49 	size_t len;
50 #if __FreeBSD_version < 700002
51 	int shmmax, shmmin, shmmni, shmseg, shmall;
52 #else
53 	unsigned long shmmax, shmmin, shmmni, shmseg, shmall;
54 #endif
55 
56 	memset (buf, 0, sizeof (glibtop_shm_limits));
57 
58 	if (server->sysdeps.shm_limits == 0)
59 		return;
60 
61 	len = sizeof (shmmax);
62 	if (sysctlbyname ("kern.ipc.shmmax", &shmmax, &len, NULL, 0)) {
63 		glibtop_warn_io_r (server, "sysctl (kern.ipc.shmmax)");
64 		return;
65 	}
66 
67 	len = sizeof (shmmin);
68 	if (sysctlbyname ("kern.ipc.shmmin", &shmmin, &len, NULL, 0)) {
69 		glibtop_warn_io_r (server, "sysctl (kern.ipc.shmmin)");
70 		return;
71 	}
72 
73 	len = sizeof (shmmni);
74 	if (sysctlbyname ("kern.ipc.shmmni", &shmmni, &len, NULL, 0)) {
75 		glibtop_warn_io_r (server, "sysctl (kern.ipc.shmmni)");
76 		return;
77 	}
78 
79 	len = sizeof (shmseg);
80 	if (sysctlbyname ("kern.ipc.shmseg", &shmseg, &len, NULL, 0)) {
81 		glibtop_warn_io_r (server, "sysctl (kern.ipc.shmseg)");
82 		return;
83 	}
84 
85 	len = sizeof (shmall);
86 	if (sysctlbyname ("kern.ipc.shmall", &shmall, &len, NULL, 0)) {
87 		glibtop_warn_io_r (server, "sysctl (kern.ipc.shmall)");
88 		return;
89 	}
90 
91 	buf->shmmax = shmmax;
92 	buf->shmmin = shmmin;
93 	buf->shmmni = shmmni;
94 	buf->shmseg = shmseg;
95 	buf->shmall = shmall;
96 
97 	buf->flags = _glibtop_sysdeps_shm_limits;
98 }
99