container_of()Linux内核中的宏定义为:
#define container_of(ptr, type, member) ({ \
const typeof( ((type*)0)->member) * __mptr =(ptr);\
(type*)( (char*)__mptr - offsetof(type,member) );})
Run Code Online (Sandbox Code Playgroud)
为什么这样使用((type*)0)->member,不是(type*)->member吗?
include/linux/typecheck.hLinux内核4.16 的文件包含此代码.
#define typecheck(type,x) \
({ type __dummy; \
typeof(x) __dummy2; \
(void)(&__dummy == &__dummy2); \
1; \
}
Run Code Online (Sandbox Code Playgroud)
检查if x是否与参数的类型相同type.
但我无法理解这一行:
(void)(&__dummy == &__dummy2);
Run Code Online (Sandbox Code Playgroud)
如何比较两个变量的第一个地址有帮助吗?
我使用find命令,例如:
find . -name "*.log" -exec grep "running" {} \;
Run Code Online (Sandbox Code Playgroud)
为什么找到需要的命令{},一个空白和\?
我通过这种方式创建日志文件:
global logger
logger = logging.getLogger("plus_dig_cname")
logger.setLevel(logging.DEBUG)
fh = logging.FileHandler( fdoc_log + "/plus_dig_cname.log" )
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
fh.setFormatter(formatter)
logger.addHandler(fh)
Run Code Online (Sandbox Code Playgroud)
当plus_dig_cname.log的大小大于300MB时,我用shell脚本处理它,主要过程是:
mv $LOG_DIR/$1 $LOG_DIR/$1.bk
[ $? -ne 0 ] && return 1
touch $LOG_DIR/$1
[ $? -ne 0 ] && return 1
chmod 666 $LOG_DIR/$1
[ $? -ne 0 ] && return 1
Run Code Online (Sandbox Code Playgroud)
只是它和它触摸一个新的.
问题是记录器不能在plus_dig_cname.log文件中包含任何内容.日志记录无法正常工作.
也许它可以通过以下方式解决:
with open( "plus_dig_cname.log", "w" ):
pass
Run Code Online (Sandbox Code Playgroud)
这种方式可以通过Python获取新的日志文件.但我想通过Bash获取新的日志文件.
那么,为什么在"mv touch chmod"之后日志记录无法工作?
谢谢
linux-2.6.16/include/linux/stddef.h中的代码是:
#undef offsetof
#ifdef __compiler_offsetof
#define offsetof(TYPE,MEMBER) __compiler_offsetof(TYPE,MEMBER)
#else
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
#endif
#define DNAME_INLINE_LEN (sizeof(struct dentry)-offsetof(struct dentry,d_iname))
Run Code Online (Sandbox Code Playgroud)
如何理解"((size_t)&((TYPE*)0) - >会员)"?
谢谢
我想用来gdb调试代码.当我写命令时:
gdb gdns_processor
Run Code Online (Sandbox Code Playgroud)
它将从gdb以下位置输出警告消息:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /usr/local/gdnscenter/bin/gdns_processor...
warning: the debug information found in "/usr/lib/debug//usr/local/gdnscenter/bin/gdns_processor.debug" does not match "/usr/local/gdnscenter/bin/gdns_processor" (CRC mismatch).
warning: the debug information found in "/usr/lib/debug/usr/local/gdnscenter/bin/gdns_processor.debug" does not match "/usr/local/gdnscenter/bin/gdns_processor" (CRC mismatch).
(no debugging symbols found)...done.
Run Code Online (Sandbox Code Playgroud)
我不明白CRC不匹配.为什么gdb找不到符号?
PS:我的gcc选择设置了-g标志.
CPPFLAGS="-D_LIBC_REENTRANT $CPPFLAGS -g"
Run Code Online (Sandbox Code Playgroud) 代码:
extern inline int strncmp(const char * cs, const char * ct, int count)
{
register int __res;
__asm__("cld\n"
"1:\tdecl %3\n\t"
"js 2f\n\t"
"lodsb\n\t"
"scasb\n\t"
"jne 3f\n\t"
"testb %%al, %%al\n\t"
"jne 1b\n"
"2:\txorl %%eax,%%eax\n\t"
"jmp 4f\n"
"3:\tmovl $1,%%eax\n\t"
"j1 4f\n\t"
"negl %%eax\n"
"4:"
:"=a" (__res):"D" (cs), "S" (ct), "c" (count):"si","di","cx");
return __res;
}
Run Code Online (Sandbox Code Playgroud)
我不理解" js 2f \n\t "中的f和" jne 1b \n "中的b,如何理解这一点?我应该看哪本书?谢谢.
lib_xml.py的模块:
import conf_store
def hello():
print conf_store.logger
conf_store.logger.debug('why')
print 'where'
Run Code Online (Sandbox Code Playgroud)
conf_store.py的模块:
#! /usr/bin/python
import os, subprocess, logging, time, shutil, fcntl
import lib_xml
def log():
"""
a log handle
"""
import logging.handlers
global logger
LOG_PATH = "/opt/conf_store.log"
logger = logging.getLogger('conf_store')
logger.setLevel(logging.DEBUG)
ch = logging.handlers.WatchedFileHandler(LOG_PATH)
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
logger.addHandler(ch)
if __name__ == "__main__":
log()
while(True):
lib_xml.hello()
logger.debug('what')
Run Code Online (Sandbox Code Playgroud)
如何共享loggerlib_xml.py和conf_store.py之间的对象?
我是一个使用PHP的新人.我想在PHP中使用awk.我有一个名为的文件a.内容是:
www.b.com * record=600,IN,A,1.2.3.4record=600,IN,A,5.6.7.8
www.1.com u record=600,IN,A,1.2.3.4
www.1.com w record=600,IN,A,1.2.3.4
Run Code Online (Sandbox Code Playgroud)
现在我使用PHP来处理它.
<?php
$dn = "www.1.com";
$hello = shell_exec("awk '{ if ( $1==".$dn.")print $1}' a") ;
echo $hello;
?>
Run Code Online (Sandbox Code Playgroud)
它不起作用 - 你能告诉我为什么吗?如果我以其他方式使用它,它确实有用.
$hello = shell_exec("awk '{ if ( $1==\"www.b.com\")print $1}' a") ;
Run Code Online (Sandbox Code Playgroud)