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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [net/] [snmp/] [agent/] [current/] [src/] [kernel.c] - Blame information for rev 786

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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