OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [net/] [snmp/] [agent/] [v2_0/] [src/] [kernel.c] - Blame information for rev 174

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
//==========================================================================
2
//
3
//      ./agent/current/src/kernel.c
4
//
5
//
6
//==========================================================================
7
//####ECOSGPLCOPYRIGHTBEGIN####
8
// -------------------------------------------
9
// This file is part of eCos, the Embedded Configurable Operating System.
10
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
11
//
12
// eCos is free software; you can redistribute it and/or modify it under
13
// the terms of the GNU General Public License as published by the Free
14
// Software Foundation; either version 2 or (at your option) any later version.
15
//
16
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
17
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
18
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19
// for more details.
20
//
21
// You should have received a copy of the GNU General Public License along
22
// with eCos; if not, write to the Free Software Foundation, Inc.,
23
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
24
//
25
// As a special exception, if other files instantiate templates or use macros
26
// or inline functions from this file, or you compile this file and link it
27
// with other works to produce a work based on this file, this file does not
28
// by itself cause the resulting work to be covered by the GNU General Public
29
// License. However the source code for this file must still be made available
30
// in accordance with section (3) of the GNU General Public License.
31
//
32
// This exception does not invalidate any other reasons why a work based on
33
// this file might be covered by the GNU General Public License.
34
//
35
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
36
// at http://sources.redhat.com/ecos/ecos-license/
37
// -------------------------------------------
38
//####ECOSGPLCOPYRIGHTEND####
39
//####UCDSNMPCOPYRIGHTBEGIN####
40
//
41
// -------------------------------------------
42
//
43
// Portions of this software may have been derived from the UCD-SNMP
44
// project,  <http://ucd-snmp.ucdavis.edu/>  from the University of
45
// California at Davis, which was originally based on the Carnegie Mellon
46
// University SNMP implementation.  Portions of this software are therefore
47
// covered by the appropriate copyright disclaimers included herein.
48
//
49
// The release used was version 4.1.2 of May 2000.  "ucd-snmp-4.1.2"
50
// -------------------------------------------
51
//
52
//####UCDSNMPCOPYRIGHTEND####
53
//==========================================================================
54
//#####DESCRIPTIONBEGIN####
55
//
56
// Author(s):    hmt
57
// Contributors: hmt
58
// Date:         2000-05-30
59
// Purpose:      Port of UCD-SNMP distribution to eCos.
60
// Description:  
61
//              
62
//
63
//####DESCRIPTIONEND####
64
//
65
//==========================================================================
66
/********************************************************************
67
       Copyright 1989, 1991, 1992 by Carnegie Mellon University
68
 
69
                          Derivative Work -
70
Copyright 1996, 1998, 1999, 2000 The Regents of the University of California
71
 
72
                         All Rights Reserved
73
 
74
Permission to use, copy, modify and distribute this software and its
75
documentation for any purpose and without fee is hereby granted,
76
provided that the above copyright notice appears in all copies and
77
that both that copyright notice and this permission notice appear in
78
supporting documentation, and that the name of CMU and The Regents of
79
the University of California not be used in advertising or publicity
80
pertaining to distribution of the software without specific written
81
permission.
82
 
83
CMU AND THE REGENTS OF THE UNIVERSITY OF CALIFORNIA DISCLAIM ALL
84
WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
85
WARRANTIES OF MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL CMU OR
86
THE REGENTS OF THE UNIVERSITY OF CALIFORNIA BE LIABLE FOR ANY SPECIAL,
87
INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
88
FROM THE LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
89
CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
90
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
91
*********************************************************************/
92
 
93
/*
94
 *  13 Jun 91  wsak (wk0x@andrew) added mips support
95
 */
96
 
97
#include <config.h>
98
 
99
#ifdef CAN_USE_NLIST
100
 
101
#include <sys/types.h>
102
#if HAVE_UNISTD_H
103
#include <unistd.h>
104
#endif
105
#include <stdio.h>
106
#include <errno.h>
107
#if HAVE_STRING_H
108
#include <string.h>
109
#endif
110
#if HAVE_FCNTL_H
111
#include <fcntl.h>
112
#endif
113
#if HAVE_NETINET_IN_H
114
#include <netinet/in.h>
115
#endif
116
#if HAVE_KVM_H
117
#include <kvm.h>
118
#endif
119
 
120
#include "asn1.h"
121
#include "snmp_api.h"
122
#include "snmp_impl.h"
123
#include "snmp_logging.h"
124
#include "default_store.h"
125
 
126
#include "kernel.h"
127
#include "ds_agent.h"
128
 
129
#ifndef NULL
130
#define NULL 0
131
#endif
132
 
133
 
134
#if HAVE_KVM_H
135
kvm_t *kd;
136
 
137
void
138
init_kmem(const char *file)
139
{
140
#if HAVE_KVM_OPENFILES
141
    char err[4096];
142
    kd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, err);
143
    if (kd == NULL && !ds_get_boolean(DS_APPLICATION_ID, DS_AGENT_NO_ROOT_ACCESS)) {
144
        snmp_log(LOG_CRIT, "init_kmem: kvm_openfiles failed: %s\n", err);
145
        exit(1);
146
    }
147
#else
148
    kd = kvm_open(NULL, NULL, NULL, O_RDONLY, NULL);
149
    if (!kd && !ds_get_boolean(DS_APPLICATION_ID, DS_AGENT_NO_ROOT_ACCESS)) {
150
        snmp_log(LOG_CRIT, "init_kmem: kvm_open failed: %s\n", strerror(errno));
151
        exit(1);
152
    }
153
#endif  /* HAVE_KVM_OPENFILES */
154
}
155
 
156
 
157
/*
158
 *  klookup:
159
 *
160
 *  It seeks to the location  off  in kmem
161
 *  It does a read into  target  of  siz  bytes.
162
 *
163
 *  Return 0 on failure and 1 on sucess.
164
 *
165
 */
166
 
167
 
168
int
169
klookup(unsigned long off,
170
        char   *target,
171
        int     siz)
172
{
173
    int result;
174
    if (kd == NULL) return 0;
175
    result = kvm_read(kd, off, target, siz);
176
    if (result != siz) {
177
#if HAVE_KVM_OPENFILES
178
 snmp_log(LOG_ERR,"kvm_read(*, %lx, %p, %d) = %d: %s\n", off, target, siz,
179
                result, kvm_geterr(kd));
180
#else
181
 snmp_log(LOG_ERR,"kvm_read(*, %lx, %p, %d) = %d: ", off, target, siz,
182
                result);
183
        snmp_log_perror("klookup");
184
#endif
185
        return 0;
186
    }
187
    return 1;
188
}
189
 
190
#else /* HAVE_KVM_H */
191
 
192
static off_t klseek (off_t);
193
static int klread (char *, int);
194
int swap, mem, kmem;
195
 
196
void
197
init_kmem(const char *file)
198
{
199
  kmem = open(file, O_RDONLY);
200
  if (kmem < 0 && !ds_get_boolean(DS_APPLICATION_ID, DS_AGENT_NO_ROOT_ACCESS)){
201
    snmp_log_perror(file);
202
    exit(1);
203
  }
204
  fcntl(kmem,F_SETFD,1);
205
  mem = open("/dev/mem",O_RDONLY);
206
  if (mem < 0 && !ds_get_boolean(DS_APPLICATION_ID, DS_AGENT_NO_ROOT_ACCESS)){
207
    snmp_log_perror("/dev/mem");
208
    exit(1);
209
  }
210
  fcntl(mem,F_SETFD,1);
211
#ifdef DMEM_LOC
212
  swap = open(DMEM_LOC,O_RDONLY);
213
  if (swap < 0 && !ds_get_boolean(DS_APPLICATION_ID, DS_AGENT_NO_ROOT_ACCESS)){
214
    snmp_log_perror(DMEM_LOC);
215
    exit(1);
216
  }
217
  fcntl(swap,F_SETFD,1);
218
#endif
219
}
220
 
221
 
222
/*
223
 *  Seek into the kernel for a value.
224
 */
225
static off_t
226
klseek(off_t base)
227
{
228
  return (lseek(kmem, (off_t)base, SEEK_SET));
229
}
230
 
231
 
232
/*
233
 *  Read from the kernel
234
 */
235
static int
236
klread(char *buf,
237
       int buflen)
238
{
239
  return (read(kmem, buf, buflen));
240
}
241
 
242
 
243
/*
244
 *  klookup:
245
 *
246
 *  It seeks to the location  off  in kmem
247
 *  It does a read into  target  of  siz  bytes.
248
 *
249
 *  Return 0 on failure and 1 on sucess.
250
 *
251
 */
252
 
253
 
254
int
255
klookup(unsigned long off,
256
        char   *target,
257
        int     siz)
258
{
259
  long retsiz;
260
 
261
  if (kmem < 0) return 0;
262
 
263
  if ((retsiz = klseek((off_t) off)) != off) {
264
    snmp_log(LOG_ERR, "klookup(%lx, %p, %d): ", off, target, siz);
265
    snmp_log_perror("klseek");
266
#ifdef EXIT_ON_BAD_KLREAD
267
    exit(1);
268
#endif
269
    return (0);
270
  }
271
  if ((retsiz = klread(target, siz)) != siz ) {
272
    if (snmp_get_do_debugging()) {
273
    /* these happen too often on too many architectures to print them
274
       unless we're in debugging mode. People get very full log files. */
275
      snmp_log(LOG_ERR, "klookup(%lx, %p, %d): ", off, target, siz);
276
      snmp_log_perror("klread");
277
    }
278
#ifdef EXIT_ON_BAD_KLREAD
279
    exit(1);
280
#endif
281
    return(0);
282
  }
283
  return (1);
284
}
285
 
286
#endif /* HAVE_KVM_H */
287
 
288
#endif /* CAN_USE_NLIST */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.