fanrey的博客
fanrey · 共 84 篇文章
奇怪的linker问题
下面这个linker的问题找了3个小时: gcc -o example example.o -Wl -L/home/kensey/cdev/lib -L/usr/lib/x86_64-linux-gnu -lmysqlclient -lpthread -lz -L/usr/lib/x86_64-linux-gnu -lm -lrt -ldl -lcdev -L/home/kensey/www.tools/gplot-lib -lgplot -L/home/kensey/www.tools/gd1_3ret -lgd -lxml2 -lcurl /usr/bin/ld: /home/kense…
2014-09-23 14:56 · linux · 评论(0)
write error: Bad file descriptor
int pip; pipe(pip); fork(); /* parent process / / Close Read end of the pipe */ close(pip); /* child process / / Close Write end of the pipe */ close(pip); strace结果显示错把标准输出关掉了: pipe() close(1) = 0 close(11) = 0
2014-05-12 17:13 · C/C++ · 评论(0)
coredump with calloc()
Program terminated with signal 11, Segmentation fault. #0 0x0e0ec2e8 in malloc_consolidate () from /lib/libc.so.6 #1 0x0e0ef21c in _int_malloc () from /lib/libc.so.6 #2 0x0e0f078c in calloc () from /lib/libc.so.6 用valgrind的memcheck检测到有个内存malloc后free了两次,导致再次分配内存就会coredump.
2014-04-29 14:23 · linux · 评论(0)
pthread_create: Resource temporarily unavailable (errno = 11)
原来是pthread_create后没有调pthread_join或者pthread_detach, 导致memory leak. A thread may either be joinable or detached. If a thread is joinable, then another thread can call pthread_join(3) to wait for the thread to terminate and fetch its exit status. Only when a terminated joinable thread has been joined …
2014-04-29 14:21 · linux · 评论(0)
agentx协议格式
agentx协议格式: AgentX PDU Header +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | h.version | h.type | h.flags | | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | h.sessionID | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | h.transactionID | …
2014-04-22 22:23 · snmp · 评论(0)
GCC __attribute__((mode(XX))
用gcc -E可以得到下面的预编译结果: typedef unsigned int u_int8_t attribute (( mode ( QI ))); typedef unsigned int u_int16_t attribute (( mode ( HI ))); typedef unsigned int u_int32_t attribute (( mode ( SI ))); typedef unsigned int u_int64_t attribute (( mode ( DI ))); QI: An integer that is as wide as the small…
2014-03-21 10:34 · C/C++ · 评论(0)
读锁和写锁的区别
共享锁(S锁)又称读锁,若事务T对数据对象A加上S锁,则事务T可以读A但不能修改A,其他事务只能再对A加S锁,而不能加X锁,直到T释放A上的S 锁。这保证了其他事务可以读A,但在T释放A上的S锁之前不能对A做任何修改。 排他锁(X锁)又称写锁。若事务T对数据对象A加上X锁,事务T可以读A也可以修改A,其他事务不能再对A加任何锁,直到T释放A上的锁。这保证了其他事务在T释放A上的锁之前不能再读取和修改A。
2014-03-03 10:20 · linux · 评论(0)
nux下共享库(SO)有关的几个环境变量 zz
Linux支持共享库已经有悠久的历史了,不再是什么新概念了。大家都知道如何编译、连接以及动态加载(dlopen/dlsym/dlclose) 共享库。但是,可能很多人,甚至包括一些高手,对共享库相关的一些环境变量认识模糊。当然,不知道这些环境变量,也可以用共享库,但是,若知道它们,可能就会用得更好。下面介绍一些常用的环境变量,希望对家有所帮助: LD_LIBRARY_PATH 这个环境变量是大家最为熟悉的,它告诉loader:在哪些目录中可以找到共享库。可以设置多个搜索目录,这些目录之间用冒号分隔开。在linux下,还提供了另外一种方式来完成同样的功能,你可以把这些目录加到/etc/ld.s…
2014-01-06 10:32 · linux · 评论(0)
NSS环境下getpwnam_r总是返回NULL的问题(busybox的login.c)
用了6个小时解决这个问题. 下面是busybox的login.c的code: pw = NULL; getpwnam_r(username, &pwdstruct, pwdbuf, sizeof(pwdbuf), &pw); if (!pw) goto auth_failed; getpwnam_r()总是返回NULL, 换成getpwnam()也是一样的。 但是自己类似busybox写的下面的代码运行没问题: #include <sys/types.h> #include <stdio.h> #include <pwd.h> #include <security/pam_appl.h> #…
2014-01-04 17:52 · busybox · 评论(0)
c语言数组排序小结(转载)
c语言数组排序小结(for beginner) 很多朋友是以谭浩强老师编的《c语言教程》作为学习c语言的入门教程的。书中涉及排序问题一般都以“冒泡法”和“选择法”实现。为了扩大视野,增加学习编程的兴趣,我参阅了有关书籍,整理了几种排序法,写出来同大家共勉。(高手们不要笑,这篇文章是写给出学者的,而且我自己也是只菜鸟,虽然内容陈旧,但值得初学者一看)。 让我们先定义一个整型数组a,下面用五种方法对其从小到大排序。 (1)“冒泡法” 冒泡法大家都较熟悉。其原理为从a开始,依次将其和后面的元素比较,若a>a*,则交换它们,一直比较到a。同理对a,a,...a处理,即完成排序。下面列出其代码: vo…
2013-12-30 20:59 · C/C++ · 评论(0)
syslog协议介绍
1、介绍 在Unix类操作系统上,syslog广泛应用于系统日志。syslog日志消息既可以记录在本地文件中,也可以通过网络发送到接收syslog的服务器。接收syslog的服务器可以对多个设备的syslog消息进行统一的存储,或者解析其中的内容做相应的处理。常见的应用场景是网络管理工具、安全管理系统、日志审计系统。 完整的syslog日志中包含产生日志的程序模块(Facility)、严重性(Severity或 Level)、时间、主机名或IP、进程名、进程ID和正文。在Unix类操作系统上,能够按Facility和Severity的组合来决定什么样的日志消息是否需要记录,记录到什么地方,是…
2013-12-20 11:01 · syslog · 评论(0)
The TACACS+ Protocol
IETF protocol: http://tools.ietf.org/html/draft-grant-tacacs-02 A free tacacs+ server: http://tacacs.net/ The TACACS+ Protocol Version 1.78 Status of This Memo This memo provides information for the Internet community. This memo does not specify an Internet standard of any kind. Distribution of thi…
2013-12-08 10:20 · AAA · 评论(0)
radius协议(转载)
转自: http://blog.csdn.net/zhaori/article/details/554004 1、 RADIUS协议的包格式 RADIUS数据包是被封装在UDP的数据域中的。 RADIUS的包数据格式如下所示,各域(Fields)的先后次序是从左到右。 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Code | Identifier | Leng…
2013-12-08 10:08 · AAA · 评论(0)
gprof(转载)
CPU profiling tool: O'profile, kernel shark, trace-cmd, gprof, perf. Memory tool: mpatrol: mem leak detection glibc-util: gprof 1.1 简介 gprof实际上只是一个用于读取profile结果文件的工具。gprof采用混合方法来收集程序的统计信息,他使用检测方法,在编译过程中在函数入口处插入计数器用于收集每个函数的被调用情况和被调用次数;也使用采样方法,在运行时按一定间隔去检查程序计数器并在分析时找出程序计数器对应的函数来统计函数占用的时间。 Gprof具有以下优缺…
2013-10-23 11:07 · linux · 评论(0)
转载: PAM验证
转载 一.PAM简介 Linux-PAM(linux可插入认证模块)是一套共享库,使本地系统管理员可以随意选择程序的认证方式. 换句话说,不用(重新编写和)重新编译一个包含PAM功能的应用程序,就可以改变它使用的认证机制. 这种方式下,就算升级本地认证机制,也不用修改程序. PAM使用配置文件/etc/pam.conf(或/etc/pam.d/下的文件),来管理对程序的认证方式.应用程序 调用相应的配置文件,从而调用本地的认证模块.模块放置在/lib/security下,以加载动态库的形式进 行调用(dlopen(3)). 像我们使用su命令时,系统会提示你输入root用户的密码.这就是su…
2013-10-10 14:49 · linux · 评论(0)