2 Unix SMB/Netbios implementation.
4 store smbd profiling information in shared memory
5 Copyright (C) Andrew Tridgell 1999
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 extern int DEBUGLEVEL;
30 #define IPC_PERMS ((SHM_R | SHM_W) | (SHM_R>>3) | (SHM_R>>6))
33 static BOOL read_only;
35 struct profile_struct *profile_p;
37 /*******************************************************************
38 open the profiling shared memory area
39 ******************************************************************/
40 BOOL profile_setup(BOOL rdonly)
42 struct shmid_ds shm_ds;
47 /* try to use an existing key */
48 shm_id = shmget(PROF_SHMEM_KEY, 0, 0);
50 /* if that failed then create one. There is a race condition here
51 if we are running from inetd. Bad luck. */
53 if (read_only) return False;
54 shm_id = shmget(PROF_SHMEM_KEY, sizeof(*profile_p),
55 IPC_CREAT | IPC_EXCL | IPC_PERMS);
59 DEBUG(0,("Can't create or use IPC area. Error was %s\n",
65 profile_p = (struct profile_struct *)shmat(shm_id, 0,
66 read_only?SHM_RDONLY:0);
67 if ((long)profile_p == -1) {
68 DEBUG(0,("Can't attach to IPC area. Error was %s\n",
73 /* find out who created this memory area */
74 if (shmctl(shm_id, IPC_STAT, &shm_ds) != 0) {
75 DEBUG(0,("ERROR shmctl : can't IPC_STAT. Error was %s\n",
80 if (shm_ds.shm_perm.cuid != 0 || shm_ds.shm_perm.cgid != 0) {
81 DEBUG(0,("ERROR: root did not create the shmem\n"));
85 if (shm_ds.shm_segsz != sizeof(*profile_p)) {
86 DEBUG(0,("WARNING: profile size is %d (expected %d). Deleting\n",
87 (int)shm_ds.shm_segsz, sizeof(*profile_p)));
88 if (shmctl(shm_id, IPC_RMID, &shm_ds) == 0) {
95 if (!read_only && (shm_ds.shm_nattch == 1)) {
96 memset((char *)profile_p, 0, sizeof(*profile_p));
97 profile_p->prof_shm_magic = PROF_SHM_MAGIC;
98 profile_p->prof_shm_version = PROF_SHM_VERSION;
99 DEBUG(3,("Initialised profile area\n"));
106 /* to keep compilers happy about empty modules */
107 void profile_dummy(void) {}