我已经为rsyslog配置了以下过滤器,将一些SSH消息定向到本地系统上的特定TCP端口5000,以便5000上运行的服务将进一步处理SSH消息.
if $fromhost-ip == '127.0.0.1' and ( ($msg contains 'SSH') and ($msg contains 'Test') ) then @@127.0.0.1:5000
Run Code Online (Sandbox Code Playgroud)
一切似乎都很好,但消息没有重定向到端口5000,如果我们将消息定向到UDP端口,它工作正常.
以下是指向UDP端口的消息的过滤器.
if $fromhost-ip == '127.0.0.1' and ( ($msg contains 'SSH') and ($msg contains 'Test') ) then @127.0.0.1:5000
Run Code Online (Sandbox Code Playgroud)
能不能让我知道,为什么TCP端口不起作用,UDP端口工作.
我写了一个小代码,当无法连接到 postgres 数据库时,使用 C Api 将消息发送到系统日志。
int main ( int argc, char **argv )
{
PGconn *psql;
PGresult *res;
int flag = 0;
openlog ( "postgres", LOG_NDELAY, LOG_SYSLOG );
psql = PQconnectdb("hostaddr = '127.0.0.0' port = '5432' dbname = 'RtpDb' user = 'rtp_user_99' password = 'rtp_user' connect_timeout = '10'");
if ( PQstatus(psql) != CONNECTION_OK )
{
//Send an event to syslog for DB Connection Failure
syslog (LOG_EMERG, "%s", PQerrorMessage(psql) )
}
closelog ();
PQclear(res);
PQfinish(psql);
}
Run Code Online (Sandbox Code Playgroud)
当 postgres 数据库连接失败时,即使在 openlog …
请告诉我堆栈和堆之间的区别与下面的代码
int main()
{
int arr[3];
int *a;
arr [5] = 6; // out of bound but it will not give error.
arr [3000] = 8 ; //SIGSEGV
a = malloc (sizeof (int));
a[4] = 6;
a[4000] = 8; //No error
}
Run Code Online (Sandbox Code Playgroud)
我知道arr是一个静态数组,当我执行arr [3000]时会访问其他进程的地址,这会给出SIGSEGV错误.但我不明白为什么[4000]不会给我任何运行时错误,即SIGSEGV信号.
谢谢
以下是代码段.
#define TABLE_DELIMITER "::"
int parse_n_store ( char *line )
{
int i = 0;
char *p = NULL;
CPTR sensor_number = NULL , event_catagory = NULL, sensor_type = NULL, event_state= NULL, assertion = NULL, message_number = NULL, short_text = NULL;
for (p = strtok(line,TABLE_DELIMITER); p != NULL; p = strtok(NULL, TABLE_DELIMITER), i++ )
{
if ( i == 0 )
sensor_number=p;
else if ( i == 1 )
sensor_type = p;
else if ( i == 2 )
event_catagory …Run Code Online (Sandbox Code Playgroud) 下面是源代码的一小部分fclose导致错误的地方?此函数并不总是被调用,在某些特定条件下会调用此函数。
int write_into_file (char * file_name)
{
FILE * fp = NULL ;
if (file_name == NULL)
{
return FAIL ;
}
if ((fp = fopen (file_name , "r")) == NULL)
{
if ((fp = fopen (file_name, "w")) == NULL)
{
return FAIL ;
}
}
fclose (fp) ;
fp = NULL ;
return SUCESS;
}
Run Code Online (Sandbox Code Playgroud)
我们将大小为 1024 的字符缓冲区传递给 file_name。请谁能告诉我为什么 fclose 会导致分段错误?
我是Perl剧本的新手.
我想对文件进行读写操作.我将以读写模式(+ <)打开文件,并写入文件.现在,我想读取以前写过的文件.以下是我的代码:
#!/usr/bin/perl
`touch file.txt`; #Create a file as opening the file in +< mode
open (OUTFILE, "+<file.txt") or die "Can't open file : $!";
print OUTFILE "Hello, welcome to File handling operations in perl\n"; #write into the file
$line = <OUTFILE>; #read from the file
print "$line\n"; #display the read contents.
Run Code Online (Sandbox Code Playgroud)
当我显示阅读内容时,它显示一个空白行.但是文件"file.txt"有数据
Hello, welcome to File handling operations in perl
Run Code Online (Sandbox Code Playgroud)
为什么我无法阅读内容.我的代码是错误的还是我错过了什么.
Below is my code snippet.
int main ( )
{
some instructions;
while ( 1 )
{
/* Block 1 : Starts*/
if ( selection == 1 )
{
ret = pthread_create ( &tid, NULL, &select_n_process_req, NULL );
if ( ret != 0 )
{
printf ("Error Creating Thread");
}
}
/* Block 1 : Ends*/
/* Block 2 : Starts*/
printf ("Sleeping for [%d]", retry_time * 60 * 60);
for ( i = 0; i < retry_time * 60 …Run Code Online (Sandbox Code Playgroud) 为什么以下代码会出现分段错误?
int main()
{
char *t = "Working on RedHat Linux";
char *s;
s = malloc (8000 * sizeof(char));
memcpy(s,t,7000);
printf("s = %s\nt = %s\n",s,t);
free(s);
}
Run Code Online (Sandbox Code Playgroud)
我为's'分配了8000bytes.并且仅将't'复制到s直到7000字节.虽然我为's'分配了8000个字节,为什么它会给出分段错误?