错误 - Could not find the index entry for RID

本文记录了一次SQL Server数据库中出现的特定错误——错误644,详细描述了该错误发生的时间、受影响的数据库及具体错误信息。通过分析,可以为遇到相同问题的技术人员提供解决方案。

Event Type: Error
Event Source: MSSQLSERVER
Event Category: (2)
Event ID: 17052
Date:  6/19/2009
Time:  9:10:48 PM
User:  N/A
Computer: MXPSV-EFOXDB01
Description:
Error: 644, Severity: 21, State: 3
Could not find the index entry for RID '3601000001001400303030313330363735363932' in index page (1:2286685), index ID 0, database 'eFoxSFCMAX2'.

For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.
Data:
0000: 84 02 00 00 15 00 00 00   .......
0008: 0f 00 00 00 4d 00 58 00   ....M.X.
0010: 50 00 53 00 56 00 2d 00   P.S.V.-.
0018: 45 00 46 00 4f 00 58 00   E.F.O.X.
0020: 44 00 42 00 30 00 31 00   D.B.0.1.
0028: 00 00 0c 00 00 00 65 00   ......e.
0030: 46 00 6f 00 78 00 53 00   F.o.x.S.
0038: 46 00 43 00 4d 00 41 00   F.C.M.A.
0040: 58 00 32 00 00 00         X.2... 

 

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/35489/viewspace-607001/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/35489/viewspace-607001/

Your feedback is requested on changes under consideration for SLF4J version 2.1.0. SLF4J warning or error messages and their meanings No SLF4J providers were found. This message is a warning and not an error. It is reported when no SLF4J providers could be found on the class path. SLF4J requires a logging provider because it is a logging API and not an logging implementation. Placing one (and only one) of the many available providers such as slf4j-nop.jar slf4j-simple.jar, slf4j-reload4j.jar, slf4j-jdk14.jar or logback-classic.jar on the class path will solve the problem. In the absence of a provider, SLF4J will default to a no-operation (NOP) logger provider. Please note that slf4j-api version 2.0.x and later use the ServiceLoader mechanism. Earlier versions relied on the static binder mechanism which is no longer honored by slf4j-api. Please read the FAQ entry What has changed in SLF4J version 2.0.0? for further important details. If you are responsible for packaging an application and do not care about logging, then placing slf4j-nop.jar on the class path of your application will get rid of this warning message. Note that embedded components such as libraries or frameworks should not declare a dependency on any SLF4J providers but only depend on slf4j-api. When a library declares a compile-time dependency on a SLF4J provider, it imposes that provider on the end-user, thus negating SLF4J's purpose. Class path contains SLF4J bindings targeting slf4j-api versions 1.7.x or earlier Planning for the advent of Jigsaw (Java 9), slf4j-api version 2.0.x and later use the ServiceLoader mechanism. Earlier versions of SLF4J relied on the static binder mechanism which is no longer honored by slf4j-api version 2.0.x. In case SLF4J 2.x finds no providers targeting SLF4J 2.x but finds instead bindings targeting SLF4J 1.7 or earlier, it will list the bindings it finds but otherwise will ignore them. This can be solved by placing an SLF4J provider on your classpath, such providers include logback version 1.3.x and later, as well as one of slf4j-reload4j, slf4j-jdk14, slf4j-simple version 2.0.0 or later. See also the FAQ entry What has changed in SLF4J version 2.0.0? for further important details. IllegalStateException: org.slf4j.LoggerFactory in failed state. Original exception was thrown EARLIER. This IllegalStateException is thrown post-initialization and informs the user that initialization of LoggerFactory has failed. Note It is important to realize that the exception causing the failure was thrown at an earlier stage. This earlier exception should provide more valuable information about the root cause of the problem. The method o.a.commons.logging.impl.SLF4FLogFactory#release was invoked. Given the structure of the commons-logging API, in particular as implemented by SLF4J, the o.a.commons.logging.impl.SLF4FLogFactory#release() method should never be called. However, depending on the deployment of commons-logging.jar files in your servlet container, release() method may be unexpectedly invoked by a copy of org.apache.commons.logging.LogFactory class shipping with commons-logging.jar. This is a relatively common occurrence with recent versions of Tomcat, especially if you place jcl-over-slf4j.jar in WEB-INF/lib directory of your web-application instead of $TOMCAT_HOME/common/lib, where $TOMCAT_HOME stands for the directory where Tomcat is installed. In order to fully benefit from the stability offered by jcl-over-slf4j.jar, we recommend that you place jcl-over-slf4j.jar in $TOMCAT_HOME/common/lib without placing a copy in your web-applications. Please also see bug #22. Operation [suchAndSuch] is not supported in jcl-over-slf4j. An UnsupportedOperationException is thrown whenever one of the protected methods introduced in JCL 1.1 are invoked. These methods are invoked by LogFactory implementations shipping with commons-logging.jar. However, the LogFactory implemented by jcl-over-slf4j.jar, namely SLF4FLogFactory, does not call any of these methods. If you observe this problem, then it is highly probable that you have a copy of commons-logging.jar in your class path overriding the classes shipping with jcl-over-slf4j.jar. Note that this issue is very similar in nature to the warning issued when the "o.a.commons.logging.impl.SLF4FLogFactory.release()" method is invoked, discussed in the previous item. Detected logger name mismatch Logger name mismatch warnings are printed only if the slf4j.detectLoggerNameMismatch system property is set to true. By default, this property is not set and no warnings will be printed even in case of a logger name mismatch. since 1.7.9 The warning will be printed in case the name of the logger specified via a class passed as an argument to the LoggerFactory.getLogger(Class) method differs from the name of the caller as computed internally by SLF4J. For example, the following code snippet package com.acme; import com.foo.Kangaroo; class Fruit { Logger logger = LoggerFactory.getLogger(Kangaroo.class); } will result in the warning SLF4J: Detected logger name mismatch. Given name: "com.foo.Kangaroo"; computed name: "com.acme.Fruit". but only if slf4j.detectLoggerNameMismatch system property is set to true. No warning will be issued for the special case where the class in which the logger is defined is a super-type of the class parameter passed as argument. For example, class A { Logger logger = LoggerFactory.getLogger(getClass()); } class B extends A { // no mismatch warning will be issued when B is instantiated // given that class A is a super-type of class B } If you come across a mismatch warning which cannot be explained, then you might have spotted a white elephant, that is a very rare occurrence where SLF4J cannot correctly compute the name of the class where a logger is defined. We are very interested to learn about such cases. If and when you spot an inexplicable mismatch, please do file a bug report with us. Failed to load class org.slf4j.impl.StaticLoggerBinder This warning message is reported by slf4j-api version 1.7.x and earlier when the org.slf4j.impl.StaticLoggerBinder class could not be loaded into memory. This happens when no appropriate SLF4J binding could be found on the class path. Placing one (and only one) of slf4j-nop.jar slf4j-simple.jar, slf4j-log4j12.jar, slf4j-jdk14.jar or logback-classic.jar on the class path should solve the problem. If you are seeing this message, then you are NOT using slf4j-api version 2.0 or later but slf4j-api version 1.7.x or earlier. Slf4j-api versions 2.0.x and later use the ServiceLoader mechanism. Backends such as logback 1.3 and later which target slf4j-api 2.x, do not ship with org.slf4j.impl.StaticLoggerBinder. If you place a logging backend which targets slf4j-api 2.0.x, you need slf4j-api-2.x.jar on the classpath. See also relevant faq entry. since 1.6.0 As of SLF4J version 1.6, in the absence of a binding, SLF4J will default to a no-operation (NOP) logger implementation. If you are responsible for packaging an application and do not care about logging, then placing slf4j-nop.jar on the class path of your application will get rid of this warning message. Note that embedded components such as libraries or frameworks should not declare a dependency on any SLF4J binding (or provider) but only depend on slf4j-api. When a library declares a compile-time dependency on a SLF4J binding (or provider), it imposes that binding (or provider) on the end-user, thus negating SLF4J's purpose. Multiple bindings were found on the class path SLF4J API is designed to bind with one and only one underlying logging framework at a time. If more than one binding is present on the class path, SLF4J will emit a warning, listing the location of those bindings. When multiple bindings are available on the class path, select one and only one binding you wish to use, and remove the other bindings. For example, if you have both slf4j-simple-2.0.17.jar and slf4j-nop-2.0.17.jar on the class path and you wish to use the nop (no-operation) binding, then remove slf4j-simple-2.0.17.jar from the class path. The list of locations that SLF4J provides in this warning usually provides sufficient information to identify the dependency transitively pulling in an unwanted SLF4J binding into your project. In your project's pom.xml file, exclude this SLF4J binding when declaring the unscrupulous dependency. For example, cassandra-all version 0.8.1 declares both log4j and slf4j-log4j12 as compile-time dependencies. Thus, when you include cassandra-all as a dependency in your project, the cassandra-all declaration will cause both slf4j-log4j12.jar and log4j.jar to be pulled in as dependencies. In case you do not wish to use log4j as the SLF4J backend, you can instruct Maven to exclude these two artifacts as shown next: <dependencies> <dependency> <groupId> org.apache.cassandra</groupId> <artifactId>cassandra-all</artifactId> <version>0.8.1</version> <exclusions> <exclusion> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> </exclusion> <exclusion> <groupId>log4j</groupId> <artifactId>log4j</artifactId> </exclusion> </exclusions> </dependency> </dependencies> Note The warning emitted by SLF4J is just that, a warning. Even when multiple bindings are present, SLF4J will pick one logging framework/implementation and bind with it. The way SLF4J picks a binding is determined by the JVM and for all practical purposes should be considered random. As of version 1.6.6, SLF4J will name the framework/implementation class it is actually bound to. Embedded components such as libraries or frameworks should not declare a dependency on any SLF4J binding but only depend on slf4j-api. When a library declares a compile-time dependency on a SLF4J binding, it imposes that binding on the end-user, thus negating SLF4J's purpose. When you come across an embedded component declaring a compile-time dependency on any SLF4J binding, please take the time to contact the authors of said component/library and kindly ask them to mend their ways. slf4j-api version does not match that of the binding An SLF4J binding designates an artifact such as slf4j-jdk14.jar or slf4j-log4j12.jar used to bind slf4j to an underlying logging framework, say, java.util.logging and respectively log4j. Mixing different versions of slf4j-api.jar and SLF4J binding (a.k.a. provider since 2.0.0) can cause problems. For example, if you are using slf4j-api-2.0.17.jar, then you should also use slf4j-simple-2.0.17.jar, using slf4j-simple-1.5.5.jar will not work. Note From the client's perspective all versions of slf4j-api are compatible. Client code compiled with slf4j-api-N.jar will run perfectly fine with slf4j-api-M.jar for any N and M. You only need to ensure that the version of your binding matches that of the slf4j-api.jar. You do not have to worry about the version of slf4j-api.jar used by a given dependency in your project. You can always use any version of slf4j-api.jar, and as long as the version of slf4j-api.jar and its binding match, you should be fine. At initialization time, if SLF4J suspects that there may be an api vs. binding version mismatch problem, it will emit a warning about the suspected mismatch. Logging factory implementation cannot be null This error is reported when the LoggerFactory class could not find an appropriate binding. Placing one (and only one) of slf4j-nop.jar, slf4j-simple.jar, slf4j-log4j12.jar, slf4j-jdk14.jar or logback-classic.jar on the class path should prove to be an effective remedy. Detected both log4j-over-slf4j.jar AND slf4j-reload4j on the class path, preempting StackOverflowError. The purpose of slf4j-reload4j module is to delegate or redirect calls made to an SLF4J logger to log4j/reload4j. The purpose of the log4j-over-slf4j module is to redirect calls made to a log4j logger to SLF4J. If SLF4J is bound withslf4j-reload4j.jar and log4j-over-slf4j.jar is also present on the class path, a StackOverflowError will inevitably occur immediately after the first invocation of an SLF4J or a log4j logger. Here is how the exception might look like: Exception in thread "main" java.lang.StackOverflowError at java.util.Hashtable.containsKey(Hashtable.java:306) at org.apache.log4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:36) at org.apache.log4j.LogManager.getLogger(LogManager.java:39) at org.slf4j.impl.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:73) at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:249) at org.apache.log4j.Category.<init>(Category.java:53) at org.apache.log4j.Logger..<init>(Logger.java:35) at org.apache.log4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:39) at org.apache.log4j.LogManager.getLogger(LogManager.java:39) at org.slf4j.impl.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:73) at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:249) at org.apache.log4j.Category..<init>(Category.java:53) at org.apache.log4j.Logger..<init>(Logger.java:35) at org.apache.log4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:39) at org.apache.log4j.LogManager.getLogger(LogManager.java:39) subsequent lines omitted... Since 1.5.11 SLF4J software preempts the inevitable stack overflow error by throwing an exception with details about the actual cause of the problem. This is deemed to be better than leaving the user wondering about the reasons of the StackOverflowError. Note that since reload4j provides the log4j 1.x API, reload4j.jar and log4j-over-slf4j.jar cannot be present simultaneously on your classpath. For more background on this topic see Bridging legacy APIs. Detected both jcl-over-slf4j.jar AND slf4j-jcl.jar on the class path, preempting StackOverflowError. The purpose of slf4j-jcl module is to delegate or redirect calls made to an SLF4J logger to jakarta commons logging (JCL). The purpose of the jcl-over-slf4j module is to redirect calls made to a JCL logger to SLF4J. If SLF4J is bound with slf4j-jcl.jar and jcl-over-slf4j.jar is also present on the class path, then a StackOverflowError will inevitably occur immediately after the first invocation of an SLF4J or a JCL logger. Here is how the exception might look like: Exception in thread "main" java.lang.StackOverflowError at java.lang.String.hashCode(String.java:1482) at java.util.HashMap.get(HashMap.java:300) at org.slf4j.impl.JCLLoggerFactory.getLogger(JCLLoggerFactory.java:67) at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:249) at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:155) at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:289) at org.slf4j.impl.JCLLoggerFactory.getLogger(JCLLoggerFactory.java:69) at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:249) at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:155) subsequent lines omitted... Since 1.5.11 SLF4J software preempts the inevitable stack overflow error by throwing an exception with details about the actual cause of the problem. This is deemed to be better than leaving the user wondering about the reasons of the StackOverflowError. For more background on this topic see Bridging legacy APIs. Exception in thread "main" java.lang.NoSuchFieldError: tlm Exception in thread "main" java.lang.NoSuchFieldError: tlm at org.apache.log4j.MDCFriend.fixForJava9(MDCFriend.java:11) at org.slf4j.impl.Log4jMDCAdapter.(Log4jMDCAdapter.java:38) at Main.main(Main.java:5) The NoSuchFieldError is thrown when slf4j-log4j12 attempts to access the 'tlm' package private field in org.apache.log4j.MDC which was specified as being of type java.lang.Object in log4j 1.2.x but was changed to java.lang.ThreadLocal in reload4j. Moreover, such access to package private fields from different modules is not authorized by default in modularized applications in Java 9 and later. To keep a long story short, the NoSuchFieldError can be avoided by using slf4j-reload4j.jar with reload4j.jar. Stated differently, org.slf4j.MDC cannot be used with the slf4j-log4j12.jar and reload4j.jar combination. Update: The issue described above was fixed in reload4j 1.2.21. Although it is still recommended that you use slf4j-reload4j as the preferred adapter for the slf4j/reload4j combination, with reload4j version 1.2.21 and later you can freely mix any version of slf4j-log4j12, if you need to. Failed to load class "org.slf4j.impl.StaticMDCBinder" This error indicates that appropriate SLF4J binding could not be found on the class path. Placing one (and only one) of slf4j-nop.jar, slf4j-simple.jar, slf4j-log4j12.jar, slf4j-jdk14.jar or logback-classic.jar on the class path should solve the problem. MDCAdapter cannot be null This error is reported when org.slf4j.MDC class has not been initialized correctly. Same cause and remedy as the previously listed item. A number (N) of logging calls during the initialization phase have been intercepted and are now being replayed. These are subject to the filtering rules of the underlying logging system. since 1.7.15 Logging calls made during the initialization phase are recorded and replayed post-initialization. Note that the replayed logging calls are subject to filtering by the underlying logging system. In principle, replaying only occurs for applications which are already multithreaded at the time the first logging call occurs. See also substitute loggers. Substitute loggers were created during the default configuration phase of the underlying logging system Highly configurable logging systems such as logback and log4j may create components which invoke loggers during their own initialization. See issue LOGBACK-127 for a typical occurrence. However, since the binding process with SLF4J has not yet completed (because the underlying logging system was not yet completely loaded into memory), it is not possible to honor such logger creation requests. To avoid this chicken-and-egg problem, SLF4J creates substitute loggers during this phase (initialization). Calls made to the substitute loggers during this phase are simply dropped. After the initialization completes, the substitute logger will delegate logging calls to the appropriate logger implementation and otherwise will function as any other logger returned by LoggerFactory. If any substitute logger had to be created, SLF4J will emit a listing of such loggers. This list is intended to let you know that any logging calls made to these loggers during initialization have been dropped. See also intercepted and replayed logging calls. SLF4J versions 1.4.0 and later requires log4j 1.2.12 or later The trace level was added to log4j in version 1.2.12 released on August 29, 2005. The trace level was added to the SLF4J API in version 1.4.0 on May 16th, 2007. Thus, starting with SLF4J 1.4.0, the log4j binding for SLF4J requires log4j version 1.2.12 or above. However, as reported in issue 59, in some environments it may be difficult to upgrade the log4j version. To accommodate such circumstances, SLF4J's Log4jLoggerAdapter will map the TRACE level as DEBUG. java.lang.NoClassDefFoundError: org/slf4j/event/LoggingEvent Logback-classic version 1.1.4 and later require slf4j-api version 1.7.15 or later. With an earlier slf4j-api.jar in the classpath, attempting introspection of a Logger instance returned by logback version 1.1.4 or later will result in a NoClassDefFoundError similar to that shown below. Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/event/LoggingEvent at java.lang.Class.getDeclaredMethods0(Native Method) at java.lang.Class.privateGetDeclaredMethods(Class.java:2451) at java.lang.Class.privateGetPublicMethods(Class.java:2571) at java.lang.Class.getMethods(Class.java:1429) at java.beans.Introspector.getPublicDeclaredMethods(Introspector.java:1261) at java.beans.Introspector.getTargetMethodInfo(Introspector.java:1122) at java.beans.Introspector.getBeanInfo(Introspector.java:414) at java.beans.Introspector.getBeanInfo(Introspector.java:161) Placing slf4j-api.jar version 1.7.15 or later in the classpath should solve the issue. Note that this problem only occurs with logback version 1.1.4 and later, other bindings such as slf4j-log4j, slf4j-jdk14 and slf4j-simple are unaffected.
最新发布
09-24
逐行解释代码,并说明 #define NUM_RRS 5 /*****************************************************************************/ struct dns_rr{ char name[NAME_SIZE]; uint16 type; uint16 class; uint32 ttl; uint16 rdatalen; char data[NAME_SIZE]; }; /*****************************************************************************/ union header_flags { uint16 flags; struct { unsigned short int rcode:4; unsigned short int unused:3; unsigned short int recursion_avail:1; unsigned short int want_recursion:1; unsigned short int truncated:1; unsigned short int authorative:1; unsigned short int opcode:4; unsigned short int question:1; } f; }; /*****************************************************************************/ struct dns_header_s{ uint16 id; union header_flags flags; uint16 qdcount; uint16 ancount; uint16 nscount; uint16 arcount; }; /*****************************************************************************/ struct dns_message{ struct dns_header_s header; struct dns_rr question[NUM_RRS]; struct dns_rr answer[NUM_RRS]; }; /*****************************************************************************/ typedef struct dns_request_s{ char cname[NAME_SIZE]; char ip[46]; /* by wdl, 01Mar11, change to 46 to fix IPv6 addr length * for example (xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255) */ int ttl; int time_pending; /* request age in seconds */ /* the actual dns request that was recieved */ struct dns_message message; /* where the request came from */ struct in6_addr src_addr; /* by wdl, 01Mar11, change to support ipv6 */ int src_port; /* the orginal packet */ char original_buf[MAX_PACKET_SIZE]; int numread; char *here; /* next node in list */ struct dns_request_s *next; }dns_request_t; /*****************************************************************************/ /* TYPE values */ enum{ A = 1, /* a host address */ NS, /* an authoritative name server */ MD, /* a mail destination (Obsolete - use MX) */ MF, /* */ CNAME, /* the canonical name for an alias */ SOA, /* marks the start of a zone of authority */ MB, /* a mailbox domain name (EXPERIMENTAL) */ MG, /* */ MR, /* */ NUL, /* */ WKS, /* a well known service description */ PTR, /* a domain name pointer */ HINFO, /* host information */ MINFO, /* mailbox or mail list information */ MX, /* mail exchange */ TXT, /* text strings */ AAAA = 0x1c /* IPv6 A */ }; /* CLASS values */ enum{ IN = 1, /* the Internet */ CS, CH, HS }; /* OPCODE values */ enum{ QUERY, IQUERY, STATUS }; /* ** ** cache.c - cache handling routines ** ** Part of the dproxy package by Matthew Pratt. ** ** Copyright 1999 Matthew Pratt <mattpratt@yahoo.com> ** ** This software is licensed under the terms of the GNU General ** Public License (GPL). Please see the file COPYING for details. ** ** */ #include <string.h> #include <stdlib.h> #include <stdio.h> #include <time.h> #include <sys/file.h> #include <sys/types.h> #include <dirent.h> #include <ctype.h> #include <unistd.h> #include <signal.h> #include "cache.h" #include "conf.h" /** function prototypes for private functions*/ static int cache_byname(FILE * , char *, char *); /***************************************************************************** * search for a host by its name. * * This function first searches the cache for an entry. If the entry * was not found there, we will look into a dhcp "leases" file. * * @arg name - name to find. * @arg ip - pointer to a buffer where to put the ip adress. * * @return 0 if an entry was found, 1 if not. *****************************************************************************/ int cache_lookup_name(char *name, char ip[BUF_SIZE]) { FILE * fp; debug( "cache_lookup_name(%s)\n", name); /** check the cache */ if( (fp = fopen( config.cache_file , "r")) != NULL) { int result = 0; result = cache_byname(fp,name, ip); fclose(fp); if( result > 0 ) { return 1; } } return 0; } /***************************************************************************** * lookup a hostname in the cache file. * * This function will not lock the cache ! * * @arg fp - open file pointer for the cache file. * @arg name - name to find. * @arg ip - pointer to a buffer where to put the ip adress. * * @return 0 if an entry was found, 1 if not. *****************************************************************************/ static int cache_byname(FILE * fp, char *name, char ip[BUF_SIZE]) { char line[BUF_SIZE]; char *token; int i = 0; ip[0] = 0; /** make shure we are at the start of the cache */ rewind(fp); while( fgets(line, BUF_SIZE, fp) ){ token = strtok( line, " "); if( !strcasecmp( token, name) ){ token = strtok( NULL, " "); while( isalnum(*token) || (*token=='.'))ip[i++] = *token++; ip[i] = 0; return 1; } } return 0; } /*****************************************************************************/ int cache_lookup_ip(char *ip, char result[BUF_SIZE]) { FILE *fp; char line[BUF_SIZE]; char *token; int i = 0; if( ip[0] == 0 )return 0; result[0] = 0; fp = fopen( config.cache_file , "r"); if(!fp)return 0; while( fgets(line, BUF_SIZE, fp) ){ strtok( line, " "); token = strtok( NULL, " "); if( !strncasecmp( token, ip, strlen(ip) ) ){ while( isalnum(line[i]) || (line[i]=='.') || (line[i] == '-'))result[i] = line[i++]; result[i] = 0; fclose(fp); return 1; } } fclose(fp); return 0; } #if 0 /***************************************************************************** * save the name to the list. * * *****************************************************************************/ void cache_name_append(char *name, char *ip) { FILE *fp; char dummy[BUF_SIZE]; fp = fopen( config.cache_file, "a"); if(!fp){ debug("Could not open cache file '%s' for writing", config.cache_file); return; } /** check if another process already added this host to the cache */ if( cache_byname(fp, name, dummy) != 0 ) { fclose(fp); return; } /** make shure that we at the end of the file. */ fseek(fp,0,SEEK_END); /** write new entry */ fprintf( fp, "%s %s %ld\n", name, ip, time(NULL) ); fclose(fp); } #endif /*****************************************************************************/ void cache_purge(int older_than) { FILE *in_fp, *out_fp; char line[BUF_SIZE]; char old_cache[1024]; char *name, *ip, *time_made; #if 0 //BRCM in_fp = fopen( config.cache_file , "r"); if(!in_fp){ debug_perror("Could not open old cache file"); /*return;*/ } if( in_fp ) { sprintf( old_cache, "%s.old", config.cache_file ); if( rename( config.cache_file, old_cache ) < 0 ){ debug_perror("Could not move cache file"); fclose(in_fp); return; } } #endif //printf("%s %d config.cache_file = %s\r\n",__FUNCTION__,__LINE__,config.cache_file); //out_fp = fopen(config.cache_file , "w"); /* changed by ZQQ, 19Apr2011 */ out_fp = fopen(config.cache_file , "w+"); if(!out_fp){ #if 0 //BRCM if( in_fp ) { fclose(in_fp); } #endif debug_perror("Could not open new cache file"); return; } /* changed by ZQQ, 20May2011 */ #if 0 cache_add_hosts_entries(out_fp); #endif cache_add_dhcp_entries(out_fp); #if 0 //BRCM if( in_fp ) { while( fgets(line, BUF_SIZE, in_fp) ){ name = strtok( line, " "); ip = strtok( NULL, " "); time_made = strtok( NULL, " "); if(!time_made)continue; if( time(NULL) - atoi( time_made ) < older_than ) fprintf( out_fp, "%s %s %s", name, ip, time_made ); } fclose(in_fp); unlink(old_cache); } #endif fclose(out_fp); } /*****************************************************************************/ void cache_add_hosts_entries(FILE *cache_file) { FILE *hosts_fp; char line[BUF_SIZE]; char *ip, *name; debug("cache_add_hosts_entreies()\n"); printf("%s %d config.hosts_file = %s\r\n", __FUNCTION__,__LINE__,config.hosts_file); hosts_fp = fopen( config.hosts_file , "r"); if( !hosts_fp ) { debug_perror("can not open 'hosts'-file "); return; } while( fgets(line, BUF_SIZE, hosts_fp) ){ line[strlen(line) - 1] = 0; /* get rid of '\n' */ ip = strtok( line, " \t"); if( ip == NULL ) continue; /* ignore blank lines */ if( ip[0] == '#' )continue; /* ignore comments */ while( (name = strtok( NULL, " \t" )) ){ if(name[0] == '#')break; fprintf( cache_file, "%s %s %ld\n", name, ip, 0L ); } } fclose(hosts_fp); debug("cache_add_hosts_entreies(): done\n"); } static void remove_delimitor( char *s) { char *p1, *p2; p1 = p2 = s; while ( *p1 != '\0' || *(p1+1) != '\0') { if (*p1 != '\0') { *p2 = *p1; p2++; } p1++; } *p2='\0'; } /* find_pid_by_name() * * This finds the pid of the specified process. * Currently, it's implemented by rummaging through * the proc filesystem. * * Returns a list of all matching PIDs */ #define READ_BUF_SIZE 128 static pid_t* find_pid_by_name( char* pidName) { DIR *dir; struct dirent *next; pid_t* pidList=NULL; int i=0; /*FILE *status */ FILE *cmdline; char filename[READ_BUF_SIZE]; char buffer[READ_BUF_SIZE]; /* char name[READ_BUF_SIZE]; */ dir = opendir("/proc"); if (!dir) { debug("Cannot open /proc"); return NULL; } while ((next = readdir(dir)) != NULL) { /* re-initialize buffers */ memset(filename, 0, sizeof(filename)); memset(buffer, 0, sizeof(buffer)); /* Must skip ".." since that is outside /proc */ if (strcmp(next->d_name, "..") == 0) continue; /* If it isn't a number, we don't want it */ if (!isdigit(*next->d_name)) continue; /* sprintf(filename, "/proc/%s/status", next->d_name); */ /* read /porc/<pid>/cmdline instead to get full cmd line */ sprintf(filename, "/proc/%s/cmdline", next->d_name); if (! (cmdline = fopen(filename, "r")) ) { continue; } if (fgets(buffer, READ_BUF_SIZE-1, cmdline) == NULL) { fclose(cmdline); continue; } fclose(cmdline); /* Buffer should contain a string like "Name: binary_name" */ /*sscanf(buffer, "%*s %s", name);*/ /* buffer contains full commandline params separted by '\0' */ remove_delimitor(buffer); if (strstr(buffer, pidName) != NULL) { pidList=realloc( pidList, sizeof(pid_t) * (i+2)); if (!pidList) { debug("Out of memeory!\n"); closedir(dir); return NULL; } pidList[i++]=strtol(next->d_name, NULL, 0); } } closedir(dir); if (pidList) pidList[i]=0; else if ( strcmp(pidName, "init")==0) { /* If we found nothing and they were trying to kill "init", * guess PID 1 and call it good... Perhaps we should simply * exit if /proc isn't mounted, but this will do for now. */ pidList=realloc( pidList, sizeof(pid_t)); if (!pidList) { debug("Out of memeory!\n"); return NULL; } pidList[0]=1; } else { pidList=realloc( pidList, sizeof(pid_t)); if (!pidList) { debug("Out of memeory!\n"); return NULL; } pidList[0]=-1; } return pidList; } static int bcmGetPid(char * command) { char cmdline[128], *p1, *p2; pid_t *pid = NULL; int ret = 0; p1 = command; p2 = cmdline; while ( *p1 != '\0') { if (*p1 != ' ') { *p2 = *p1; p2++; } p1++; } *p2='\0'; pid = find_pid_by_name(cmdline); if ( pid != NULL ) { ret = (int)(*pid); free(pid); } return ret; } struct lease_t { unsigned char chaddr[16]; u_int32_t yiaddr; u_int32_t expires; char hostname[64]; }; #define ETHER_ISNULLADDR(ea) ((((char *)(ea))[0] | \ ((char *)(ea))[1] | \ ((char *)(ea))[2] | \ ((char *)(ea))[3] | \ ((char *)(ea))[4] | \ ((char *)(ea))[5]) == 0) void cache_add_dhcp_entries(FILE *cache_file) { FILE *dhcpleases_fp; char line[BUF_SIZE]; char *ip, *name; struct lease_t lease; struct in_addr ipAddr; debug("cache_add_dhcp_entreies()\n"); int dpid = bcmGetPid("dhcpd"); if (dpid == -1) { // dhcp server not running return; } kill(dpid, SIGUSR1); printf("%s %d config.dhcp_lease_file = %s\r\n", __FUNCTION__, __LINE__, config.dhcp_lease_file); dhcpleases_fp = fopen( config.dhcp_lease_file , "r"); if( !dhcpleases_fp ) { debug_perror("can not open 'udhcpd_leases'-file "); return; } while (fread(&lease, sizeof(lease), 1, dhcpleases_fp)){ /* Do not display reserved leases */ if (ETHER_ISNULLADDR(lease.chaddr)) { continue; } ipAddr.s_addr = lease.yiaddr; fprintf( cache_file, "%s.%s %s %ld\n", lease.hostname, config.domain_name, inet_ntoa(ipAddr), 0L ); } fclose(dhcpleases_fp); debug("cache_add_dhcp_entreies(): done\n"); }
09-24
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值