Home > Back-end >  Could you tell me a question about time in the syslog record
Could you tell me a question about time in the syslog record

Time:03-21

There is a bug has not been solved in the past two days, please, help, analyse the
the main function is as follows:
Int main (int arg c, char * argv [])
{
Pthread_t tid_0 tid_1, tid_2 tid_3, tid_exit;
//ParaOfCommandPtr=createPetSystem ();
GlobalState=createPetSystem ();
Sigset_t set;
Sem_init (& amp; Sem_sym, 0, 0);
Sigemptyset (& amp; The set);
Sigaddset (& amp; The set, SIGALRM);
Sigaddset (& amp; The set, SIGPIPE);
Pthread_sigmask (SIG_SETMASK, & amp; Set to NULL);
Sleep (1);
Pthread_create (& amp; Tid_0, NULL, tcp_dispatch, NULL);
Pthread_create (& amp; Tid_1, NULL, local_dispatch, NULL);
Pthread_create (& amp; Tid_2, NULL, local_task_timer , argv [0]);
Local_unix_connfd=connnect_local_socket ();
Pthread_create (& amp; Tid_3, NULL, local_server_loop, NULL);
If (pthread_create (& amp; Tid_exit, NULL, wait_exit, argv [0]).=0) {
Perror (" pthread_exit_create ");
}
Tcp_server_loop (local_unix_connfd);
DestroyPetSystem (GlobalState);
return 0;
}

the local_task_timer function:
Void * local_task_timer (void * arg)
{
Int connect_fd;
int ret;
Char buffer [4]={0};
Char bufferReceive [4]={0};
The static struct sockaddr_un srv_addr;
Pthread_detach (pthread_self ());
Connect_fd=socket (PF_UNIX SOCK_STREAM, 0).
If (connect_fd & lt; 0 {
Perror (" always creat a socket ");
Pthread_exit (NULL);
}
Srv_addr. Sun_family=AF_UNIX;
Strcpy (srv_addr sun_path, UNIX_LOCAL_DOMAIN);
While (1)
{
Ret=connect (connect_fd, (struct sockaddr *) & amp; Srv_addr, sizeof (srv_addr));
If (ret<0 {
Perror (" always connect server ");
Sleep (1);
//close (connect_fd);
}
The else
break;
}
Printf (" timer connect success % d \ n ", ret);
If (arg!=NULL)
{
If (STRCMP (arg (char *), "swift"))
{
Mesgid2buffer (buffer, C_INIT);
}
The else
{
Mesgid2buffer (buffer, C_INIT_SWIFT);
}
}
//mesgid2buffer (buffer, C_INIT);
Send (connect_fd, buffer, 4, MSG_DONTWAIT);
Printf (" connect the local TCP server is % d \ n ", connect_fd);
Ret=read (connect_fd bufferReceive, sizeof (bufferReceive));
If (ret> 0)
Printf (" the receive init responce successfully. \ n ");
Int nbytes=0;
Struct timeval timeout={30, 0};
Fd_set fdR.
For (;; )
{
//printf (" system start. \ n ");
The timeout. Tv_sec=1;
The timeout. Tv_usec=0;
FD_ZERO (& amp; FdR);
FD_SET (connect_fd, & amp; FdR);
The switch (select (connect_fd + 1, & amp; FdR, NULL, NULL, & amp; The timeout))
{
Case 1:
DEV_PRINT (" no input \ n ");
Syslog (LOG_LOCAL0 | LOG_INFO, "UnixTimerState: socket no input.");
//goto disconnect;
break;
Case 0:
DEV_PRINT (" is out \ n ");
Mesgid2buffer (buffer, C_Read_SystemStatus ).
Send (connect_fd, buffer, 4, MSG_DONTWAIT);
Mesgid2buffer (buffer, C_SystemMonitor ).
Send (connect_fd, buffer, 4, MSG_DONTWAIT);
Mesgid2buffer (buffer, C_Internal_PscStatus);
Send (connect_fd, buffer, 4, MSG_DONTWAIT);
//syslog (LOG_LOCAL0 | LOG_INFO, "TcpState: Tcp connection time out.");
//goto disconnect;
continue;
Default:
If (FD_ISSET (connect_fd, & amp; FdR)==0)
{
DEV_PRINT (" nothing to read \ n ");
Syslog (LOG_LOCAL0 | LOG_INFO, "UnixTimerState: socket connection nothing to read.");
//goto disconnect;
}
//parsing packets
The else
{
If ((nbytes=read (connect_fd bufferReceive, sizeof (bufferReceive)))==1)//read failed
{
Fprintf (stderr, "Read Error: % s \ a \ n", the strerror (errno));
Syslog (LOG_LOCAL0 | LOG_INFO, "UnixTimerState: Socket Read Error. The TCP pthread exit.");
//goto disconnect;
}
Else if (nbytes==0)//read nothing
{
DEV_PRINT (" the transmit nothing. TCP connection broken \ n ");
Syslog (LOG_LOCAL0 | LOG_INFO, "UnixTimerState: the transmit nothing. The socket connection broken. The socket pthread release. \ n");
//goto disconnect;
}
The else//read success
{
Send (connect_fd, bufferReceive, 4, MSG_DONTWAIT);
}
}
}
}
/*
While (1)
{
Mesgid2buffer (buffer, C_Read_SystemStatus);
Send (connect_fd, buffer, 4, MSG_DONTWAIT);
Mesgid2buffer (buffer, C_SystemMonitor);
Send (connect_fd, buffer, 4, MSG_DONTWAIT);
Sleep (1);
}
*/
Close (connect_fd);
Pthread_exit (NULL);
}
This function is to send a times a second system state queries to oneself, the C_Read_SystemStatus and C_SystemMonitor to query the system state and system error information

Struct CommandIDAction CommandMap [COMMAND_COUNT]={
{C_ErrorMessage, errorSystem},
{C_SystemMode, configSystem},
{C_CTStart, ctonSystem},
{C_CTEnd, ctoffSystem},
{C_PETPlan, planSystem},
{C_PETPlay, playSystem},
{C_ACQRawData, acqSystem},
{C_Stop, stopSystem},
{C_EndExam, endSystem},
{C_ShutDown, shutSystem},
{C_Reboot, rebootSystem},
{C_WriteFlash, wflashSystem},
{C_ReadFlash, rflashSystem},
{C_FileImport, importSystem},
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related