예제 #1
0
파일: validate.c 프로젝트: KISSMonX/monit
/**
 * Test the connection and protocol
 */
static void check_connection(Service_T s, Port_T p) {
  Socket_T socket;
  volatile int rv = TRUE;
  char buf[STRLEN];
  char report[STRLEN] = {0};
  struct timeval t1;
  struct timeval t2;

  ASSERT(s && p);

  /* Get time of connection attempt beginning */
  gettimeofday(&t1, NULL);

  /* Open a socket to the destination INET[hostname:port] or UNIX[pathname] */
  socket = socket_create(p);
  if (!socket) {
    snprintf(report, STRLEN, "failed, cannot open a connection to %s", Util_portDescription(p, buf, sizeof(buf)));
    rv = FALSE;
    goto error;
  } else
    DEBUG("'%s' succeeded connecting to %s\n", s->name, Util_portDescription(p, buf, sizeof(buf)));

  /* Verify that the socket is ready for i|o. TCP sockets are checked anytime, UDP
   * sockets just when there is no specific protocol test used since the socket_is_ready()
   * adds 2s delay when used with UDP socket. When there is specific protocol used, we
   * don't need it for UDP, since the protocol test is sufficient */
  if ((socket_get_type(socket) != SOCK_DGRAM || p->protocol->check == check_default) && !socket_is_ready(socket)) {
    snprintf(report, STRLEN, "connection failed, %s is not ready for i|o -- %s", Util_portDescription(p, buf, sizeof(buf)), STRERROR);
    rv = FALSE;
    goto error;
  }

  /* Run the protocol verification routine through the socket */
  if (! p->protocol->check(socket)) {
    snprintf(report, STRLEN, "failed protocol test [%s] at %s", p->protocol->name, Util_portDescription(p, buf, sizeof(buf)));
    rv = FALSE;
    goto error;
  } else
    DEBUG("'%s' succeeded testing protocol [%s] at %s\n", s->name, p->protocol->name, Util_portDescription(p, buf, sizeof(buf)));

  /* Get time of connection attempt finish */
  gettimeofday(&t2, NULL);

  /* Get the response time */
  p->response = (double)(t2.tv_sec - t1.tv_sec) + (double)(t2.tv_usec - t1.tv_usec)/1000000;

  error:
  if (socket)
    socket_free(&socket);

  if (!rv) {
    p->response = -1;
    p->is_available = FALSE;
    Event_post(s, Event_Connection, STATE_FAILED, p->action, report);
  } else {
    p->is_available = TRUE;
    Event_post(s, Event_Connection, STATE_SUCCEEDED, p->action, "connection succeeded to %s", Util_portDescription(p, buf, sizeof(buf)));
  }
      
}
void common_wrapper(UArg arg0, UArg arg1)
{
	taskArgs* t = (taskArgs*)arg0 ;
	int tid = (int)arg1 ;
	int i, j, k ;
	
	for(i=0 ; i<NUM_ITER ; i++) {
		if(tid == 0) {
			callBarrier(0, /*lock_id=*/4) ;
		}

		callLocalBarrier() ;
		compute_histo(t->buffer1, t->buffer2, t->start_indx, t->end_indx) ;
		Cache_wbInv (t->buffer2, HISTO_SIZE*4, Cache_Type_ALL, FALSE) ;
		callLocalBarrier() ;
		if(tid == 0) {
			callBarrier(1, /*lock_id=*/4) ;
			compute_gray_level_mapping() ;
		}
		callLocalBarrier() ;
		compute_image(t->buffer1, m3_gray_level_mapping, t->start_indx, t->end_indx) ;

		if(tid == 0)
			Cache_wbInv (t->buffer1, IMG_SIZE*IMG_SIZE*4, Cache_Type_ALL, FALSE);
	}

	if(tid == 0)
		Event_post(edgeDetectEvent, Event_Id_00) ;
	else
		Event_post(edgeDetectEvent, Event_Id_01) ;
}
예제 #3
0
파일: validate.c 프로젝트: KISSMonX/monit
/**
 * Validate a given process service s. Events are posted according to 
 * its configuration. In case of a fatal event FALSE is returned.
 */
int check_process(Service_T s) {

  pid_t  pid = -1;
  Port_T pp = NULL;
  Resource_T pr = NULL;

  ASSERT(s);

  /* Test for running process */
  if (!(pid = Util_isProcessRunning(s, FALSE))) {
    Event_post(s, Event_Nonexist, STATE_FAILED, s->action_NONEXIST, "process is not running");
    return FALSE;
  } else
    Event_post(s, Event_Nonexist, STATE_SUCCEEDED, s->action_NONEXIST, "process is running with pid %d", (int)pid);

  if (Run.doprocess) {
    if (update_process_data(s, ptree, ptreesize, pid)) {
      check_process_state(s);
      check_process_pid(s);
      check_process_ppid(s);
      for (pr = s->resourcelist; pr; pr = pr->next)
        check_process_resources(s, pr);
    } else
      LogError("'%s' failed to get service data\n", s->name);
  }

  /* Test each host:port and protocol in the service's portlist */
  if (s->portlist)
    for (pp = s->portlist; pp; pp = pp->next)
      check_connection(s, pp);

  return TRUE;
  
}
void common_wrapper(UArg arg0, UArg arg1)
{
	taskArgs* t = (taskArgs*)arg0 ;
	int tid = (int)arg1 ;

	int* sum_tang = t->buffer1 ;
	int* mean = t->buffer2 ;
	int* diff = t->buffer3 ;
	int* sum_diff = t->buffer4 ;
	int* tmp = t->buffer5 ;
	int* path = t->buffer6 ;
	int start_indx = t->start_indx ;
	int end_indx = t->end_indx ;

	int i ;
	for(i=0 ; i<NUM_ITER ; i++) {
		if(tid == 0) {
			callBarrier(0, /*lock_id=*/4) ;
		}
		callLocalBarrier() ;
		parallel_kernel_reg_detect(tid, sum_tang, mean, diff, sum_diff, 
					tmp, path, start_indx, end_indx) ;
	}

	if(tid == 0)
		Event_post(edgeDetectEvent, Event_Id_00) ;
	else
		Event_post(edgeDetectEvent, Event_Id_01) ;
}
예제 #5
0
/*
 * This function waits for the process to change state. If the process state doesn't match the expectation,
 * a failed event is posted to notify the user. The time is saved on enter so in the case that the time steps
 * backwards/forwards, the wait_process will wait for absolute time and not stall or prematurely exit.
 * @param service A Service to wait for
 * @param expect A expected state (see Process_Status)
 * @return Either Process_Started if the process is running or Process_Stopped if it's not running
 */
static Process_Status wait_process(Service_T s, Process_Status expect) {
        int debug = Run.debug, isrunning = FALSE;
        unsigned long now = time(NULL) * 1000, wait = 50;
        assert(s->start || s->restart);
        unsigned long timeout = (s->start ? s->start->timeout : s->restart->timeout) * 1000 + now;
        ASSERT(s);
        do {
                Time_usleep(wait * USEC_PER_MSEC);
                now += wait ;
                wait = wait < 1000 ? wait * 2 : 1000; // double the wait during each cycle until 1s is reached
                isrunning = Util_isProcessRunning(s, TRUE);
                if ((expect == Process_Stopped && ! isrunning) || (expect == Process_Started && isrunning))
                        break;
                Run.debug = FALSE; // Turn off debug second time through to avoid flooding the log with pid file does not exist. This poll stuff here _will_ be refactored away
        } while (now < timeout && ! Run.stopped);
        Run.debug = debug; // restore the debug state
        if (isrunning) {
                if (expect == Process_Started)
                        Event_post(s, Event_Exec, STATE_SUCCEEDED, s->action_EXEC, "started");
                else
                        Event_post(s, Event_Exec, STATE_FAILED, s->action_EXEC, "failed to stop");
                return Process_Started;
        } else {
                if (expect == Process_Started)
                        Event_post(s, Event_Exec, STATE_FAILED, s->action_EXEC, "failed to start");
                else
                        Event_post(s, Event_Exec, STATE_SUCCEEDED, s->action_EXEC, "stopped");
                return Process_Stopped;
        }
}
예제 #6
0
파일: validate.c 프로젝트: KISSMonX/monit
/**
 * Validate a given file service s. Events are posted according to 
 * its configuration. In case of a fatal event FALSE is returned.
 */
int check_file(Service_T s) {
  struct stat stat_buf;

  ASSERT(s);

  if (stat(s->path, &stat_buf) != 0) {
    Event_post(s, Event_Nonexist, STATE_FAILED, s->action_NONEXIST, "file doesn't exist");
    return FALSE;
  } else {
    s->inf->st_mode = stat_buf.st_mode;
    if (s->inf->priv.file.st_ino == 0) {
      s->inf->priv.file.st_ino_prev = stat_buf.st_ino;
      s->inf->priv.file.readpos     = stat_buf.st_size;
    } else
      s->inf->priv.file.st_ino_prev = s->inf->priv.file.st_ino;
    s->inf->priv.file.st_ino  = stat_buf.st_ino;
    s->inf->st_uid            = stat_buf.st_uid;
    s->inf->st_gid            = stat_buf.st_gid;
    s->inf->priv.file.st_size = stat_buf.st_size;
    s->inf->timestamp         = MAX(stat_buf.st_mtime, stat_buf.st_ctime);
    DEBUG("'%s' file exists check succeeded\n", s->name);
    Event_post(s, Event_Nonexist, STATE_SUCCEEDED, s->action_NONEXIST, "file exist");
  }

  if (!S_ISREG(s->inf->st_mode)) {
    Event_post(s, Event_Invalid, STATE_FAILED, s->action_INVALID, "is not a regular file");
    return FALSE;
  } else {
    DEBUG("'%s' is a regular file\n", s->name);
    Event_post(s, Event_Invalid, STATE_SUCCEEDED, s->action_INVALID, "is a regular file");
  }

  if (s->checksum)
    check_checksum(s);

  if (s->perm)
    check_perm(s);

  if (s->uid)
    check_uid(s);

  if (s->gid)
    check_gid(s);

  if (s->sizelist)
    check_size(s);

  if (s->timestamplist)
    check_timestamp(s);

  if (s->matchlist)
    check_match(s);

  return TRUE;

}
예제 #7
0
파일: validate.c 프로젝트: KISSMonX/monit
/**
 * Test for associated path gid change
 */
static void check_gid(Service_T s) {
  ASSERT(s && s->gid);

  if (s->inf->st_gid != s->gid->gid )
    Event_post(s, Event_Gid, STATE_FAILED, s->gid->action, "gid test failed for %s -- current gid is %d", s->path, (int)s->inf->st_gid);
  else {
    DEBUG("'%s' gid check succeeded [current gid=%d]\n", s->name, (int)s->inf->st_gid);
    Event_post(s, Event_Gid, STATE_SUCCEEDED, s->gid->action, "gid succeeded");
  }
}
예제 #8
0
파일: validate.c 프로젝트: KISSMonX/monit
/**
 * Test for associated path permission change
 */
static void check_perm(Service_T s) {
  ASSERT(s && s->perm);

  if ((s->inf->st_mode & 07777) != s->perm->perm)
    Event_post(s, Event_Permission, STATE_FAILED, s->perm->action, "permission test failed for %s -- current permission is %04o", s->path, s->inf->st_mode&07777);
  else {
    DEBUG("'%s' permission check succeeded [current permission=%04o]\n", s->name, s->inf->st_mode&07777);
    Event_post(s, Event_Permission, STATE_SUCCEEDED, s->perm->action, "permission succeeded");
  }
}
예제 #9
0
파일: validate.c 프로젝트: KISSMonX/monit
/**
 * Validate a remote service.
 * @param s The remote service to validate
 * @return FALSE if there was an error otherwise TRUE
 */
int check_remote_host(Service_T s) {
  Port_T p = NULL;
  Icmp_T icmp = NULL;
  Icmp_T last_ping = NULL;

  ASSERT(s);

  /* Test each icmp type in the service's icmplist */
  if (s->icmplist) {
    for (icmp = s->icmplist; icmp; icmp = icmp->next) {

      switch(icmp->type) {
      case ICMP_ECHO:

        icmp->response = icmp_echo(s->path, icmp->timeout, icmp->count);

        if (icmp->response == -2) {
          icmp->is_available = TRUE;
          DEBUG("'%s' icmp ping skipped -- the monit user has no permission to create raw socket, please run monit as root or add privilege for net_icmpaccess\n", s->name);
        } else if (icmp->response == -1) {
          icmp->is_available = FALSE;
          DEBUG("'%s' icmp ping failed\n", s->name);
          Event_post(s, Event_Icmp, STATE_FAILED, icmp->action, "failed ICMP test [%s]", icmpnames[icmp->type]);
        } else {
          icmp->is_available = TRUE;
          DEBUG("'%s' icmp ping succeeded [response time %.3fs]\n", s->name, icmp->response);
          Event_post(s, Event_Icmp, STATE_SUCCEEDED, icmp->action, "succeeded ICMP test [%s]", icmpnames[icmp->type]);
        }
        last_ping = icmp;
        break;

      default:
        LogError("'%s' error -- unknown ICMP type: [%d]\n", s->name, icmp->type);
        return FALSE;

      }
    }
  }

  /* If we could not ping the host we assume it's down and do not
   * continue to check any port connections  */
  if (last_ping && !last_ping->is_available) {
    DEBUG("'%s' icmp ping failed, skipping any port connection tests\n", s->name);
    return FALSE;
  }

  /* Test each host:port and protocol in the service's portlist */
  if (s->portlist)
    for (p = s->portlist; p; p = p->next)
      check_connection(s, p);

  return TRUE;
  
}
예제 #10
0
파일: validate.c 프로젝트: KISSMonX/monit
/**
 * Test process state (e.g. Zombie)
 */
static void check_process_state(Service_T s) {

  ASSERT(s);

  if (s->inf->priv.process.status_flag & PROCESS_ZOMBIE)
    Event_post(s, Event_Data, STATE_FAILED, s->action_DATA, "process with pid %d is a zombie", s->inf->priv.process.pid);
  else {
    DEBUG("'%s' zombie check succeeded [status_flag=%04x]\n", s->name,  s->inf->priv.process.status_flag);
    Event_post(s, Event_Data, STATE_SUCCEEDED, s->action_DATA, "check process state succeeded");
  }

}
예제 #11
0
//*****************************************************************************
//
//! Festo Piece Callback.
//!
//! This function is executed when the piece enter the Festo
//! Station platform.
//!
//! \return None.
//
//*****************************************************************************
void _callback_Festo_Piece_In(void)
{
	GPIO_clearInt(Board_SENSE_SAMPLE_IN_PLACE);
 	if (GPIO_read(Board_SENSE_SAMPLE_IN_PLACE) > 0)
	{
 		Event_post(FestoEvents, FESTO_EVENT_PIECE_IN_PLACE);
	}
	else
	{
		Event_post(FestoEvents, FESTO_EVENT_PIECE_NOT_IN_PLACE);
	}
}
예제 #12
0
파일: validate.c 프로젝트: bumper-app/nicad
/**
 * Validate a given directory service s.  Events are posted according to 
 * its configuration.  In case of a fatal event FALSE is returned.
 */
int check_directory(Service_T s) {

  struct stat stat_buf;
  char report[STRLEN]= {0};

  if(stat(s->path, &stat_buf) != 0) {
    if(! s->event_handled) {
      Event_post(s, EVENT_START,
		 "Event: directory '%s' doesn't exist\n", s->name);
      s->event_handled= TRUE;
    }
    return FALSE;
  } else {
    s->event_handled= FALSE;
  }

  if(!S_ISDIR(stat_buf.st_mode)) {
    if(!s->event_handled) {
      Event_post(s, EVENT_UNMONITOR,
		 "Event: '%s' is not directory\n", s->name);
      s->event_handled= TRUE;
    }
    return FALSE;
  } else {
    s->event_handled= FALSE;
  }
  
  if(check_perm(s, stat_buf.st_mode, report)) {
    s->perm->event_flag= TRUE;
    if(! eval_actions(s->perm->action, s, report, "permission",
		      EVENT_PERMISSION))
	return FALSE;
  }
  
  if(check_uid(s, stat_buf.st_uid, report)) {
    s->uid->event_flag= TRUE;
    if(! eval_actions(s->uid->action, s, report, "uid", EVENT_UID))
	return FALSE;
  } 
  
  if(check_gid(s, stat_buf.st_gid, report)) {
    s->gid->event_flag= TRUE;
    if(! eval_actions(s->gid->action, s, report, "gid", EVENT_GID))
	return FALSE;
  } 

  if(!check_timestamps(s))
    return FALSE;

  return TRUE;

}
예제 #13
0
파일: validate.c 프로젝트: KISSMonX/monit
/**
 * Test process ppid for possible change since last cycle
 */
static void check_process_ppid(Service_T s) {

  ASSERT(s && s->inf);

  /* process ppid was not initialized yet */
  if (s->inf->priv.process._ppid == -1)
    return;

  if (s->inf->priv.process._ppid != s->inf->priv.process.ppid)
    Event_post(s, Event_PPid, STATE_CHANGED, s->action_PPID, "process PPID changed from %d to %d", s->inf->priv.process._ppid, s->inf->priv.process.ppid);
  else
    Event_post(s, Event_PPid, STATE_CHANGEDNOT, s->action_PPID, "process PPID has not changed since last cycle");
}
/*
 *  ======== Adaptor_sendPacket ========
 *  Function called by a service to send a packet.
 */
Bool Adaptor_sendPacket(UIAPacket_Hdr *packet)
{
    Bool status;
    Adaptor_Entry *entry;

    /* Set the src fields */
    UIAPacket_setSenderAdrs(packet, 0);

    /*
     *  If the call is being made in the context of the transferAgent,
     *  just call the Adaptor directly.
     */
    if ((Adaptor_module->transferAgentHandle == Task_self())) {
        status = Adaptor_sendToHost(packet);
    }
    else {

        /* Not in the transfer agent's context. Put it on the outgoing queue */
        entry = (Adaptor_Entry *)((UInt)packet - sizeof(Queue_Elem));

        Queue_put(Adaptor_module->outgoingQ, (Queue_Elem *)entry);
        Event_post(Adaptor_module->event, Event_Id_03);
        status = TRUE;
    }

    return (status);
}
예제 #15
0
// 获取一次数据以供发送
void GetData()
{
	Uint8 *data;
	while(TRUE)
	{
		/* Wait 10 sets of data from ADS1298_ISR(). */
		Semaphore_pend(semDRDY, BIOS_WAIT_FOREVER);

		// 获取缓冲区地址
		data = dataPool;

		// 切换数据池
		if(dataPool == *DataPool1)
		{
			dataPool = *DataPool2;
		}
		else
		{
			dataPool = *DataPool2;
		}

		retrieve_data(data);

		Data2Send = AllData[8-Channel_No];

		signal_process();

		//发送单通道数据,触发发送事件
		Event_post(eventServer, Event_Id_01);
	}
}
bool_t osSetEventFromIsr(OsEvent *event)
{
   //Set the specified event to the signaled state
   Event_post(event->handle, Event_Id_00);

   //The return value is not relevant
   return FALSE;
}
/*
 *  ======== Adaptor_clockFxn ========
 */
Void Adaptor_clockFxn(UArg arg0)
{
    /*
     *  Post the Event to allow the transfer agent to run
     *  and determine which services should send events.
     */
    Event_post(Adaptor_module->event, Event_Id_00);
}
예제 #18
0
파일: validate.c 프로젝트: KISSMonX/monit
/**
 * Validate a given filesystem service s. Events are posted according to 
 * its configuration. In case of a fatal event FALSE is returned.
 */
int check_filesystem(Service_T s) {
  char *p;
  char path_buf[PATH_MAX+1];
  Filesystem_T td;
  struct stat stat_buf;

  ASSERT(s);

  p = s->path;

  /* We need to resolve symbolic link so if it points to device, we'll be able to find it in mnttab */
  if (lstat(s->path, &stat_buf) != 0) {
    Event_post(s, Event_Nonexist, STATE_FAILED, s->action_NONEXIST, "filesystem doesn't exist");
    return FALSE;
  }
  if (S_ISLNK(stat_buf.st_mode)) {
    if (! realpath(s->path, path_buf)) {
      Event_post(s, Event_Nonexist, STATE_FAILED, s->action_NONEXIST, "filesystem symbolic link error -- %s", STRERROR);
      return FALSE;
    }
    p = path_buf;
    Event_post(s, Event_Nonexist, STATE_SUCCEEDED, s->action_NONEXIST, "filesystem symbolic link %s -> %s", s->path, p);
    if (stat(p, &stat_buf) != 0) {
      Event_post(s, Event_Nonexist, STATE_FAILED, s->action_NONEXIST, "filesystem doesn't exist");
      return FALSE;
    }
  }
  Event_post(s, Event_Nonexist, STATE_SUCCEEDED, s->action_NONEXIST, "filesystem exists");

  s->inf->st_mode = stat_buf.st_mode;
  s->inf->st_uid  = stat_buf.st_uid;
  s->inf->st_gid  = stat_buf.st_gid;

  if (!filesystem_usage(s->inf, p)) {
    Event_post(s, Event_Data, STATE_FAILED, s->action_DATA, "unable to read filesystem %s state", p);
    return FALSE;
  }
  s->inf->priv.filesystem.inode_percent = s->inf->priv.filesystem.f_files > 0 ? (int)((1000.0 * (s->inf->priv.filesystem.f_files - s->inf->priv.filesystem.f_filesfree)) / (float)s->inf->priv.filesystem.f_files) : 0;
  s->inf->priv.filesystem.space_percent = s->inf->priv.filesystem.f_blocks > 0 ? (int)((1000.0 * (s->inf->priv.filesystem.f_blocks - s->inf->priv.filesystem.f_blocksfree)) / (float)s->inf->priv.filesystem.f_blocks) : 0;
  s->inf->priv.filesystem.inode_total   = s->inf->priv.filesystem.f_files - s->inf->priv.filesystem.f_filesfree;
  s->inf->priv.filesystem.space_total   = s->inf->priv.filesystem.f_blocks - s->inf->priv.filesystem.f_blocksfreetotal;
  Event_post(s, Event_Data, STATE_SUCCEEDED, s->action_DATA, "succeeded getting filesystem statistic for %s", p);

  if (s->perm)
    check_perm(s);

  if (s->uid)
    check_uid(s);

  if (s->gid)
    check_gid(s);

  check_filesystem_flags(s);

  if (s->filesystemlist)
    for (td = s->filesystemlist; td; td = td->next)
      check_filesystem_resources(s, td);

  return TRUE;
}
예제 #19
0
파일: control.c 프로젝트: hafiz/yoke
/*
 * This function runs in its own thread and waits for the service to
 * start running. If the service did not start a failed event is
 * posted to notify the user.
 * @param service A Service to wait for
 */
static void wait_start(Service_T s) {
  time_t timeout = time(NULL) + s->start->timeout;
  
  ASSERT(s);

  while ((time(NULL) < timeout) && !Run.stopped) {
    if (Util_isProcessRunning(s))
      break;
    sleep(1);
  }
  
  if (!Util_isProcessRunning(s))
    Event_post(s, Event_Exec, STATE_FAILED, s->action_EXEC, "failed to start");
  else
    Event_post(s, Event_Exec, STATE_SUCCEEDED, s->action_EXEC, "started");

  return;
}
예제 #20
0
파일: control.c 프로젝트: hafiz/yoke
/*
 * This function waits for the service to stop running. If the service
 * did not stop a failed event is posted to notify the user. This
 * function does purposefully not run in its own thread because, if we
 * did a restart we need to know if we successfully managed to stop
 * the service first before we can do a start.
 * @param service A Service to wait for
 * @return TRUE if the service was stopped otherwise FALSE
 */
static int wait_stop(Service_T s) {
  time_t timeout = time(NULL) + s->stop->timeout;
  
  ASSERT(s);

  while ((time(NULL) < timeout) && !Run.stopped) {
    if (!Util_isProcessRunning(s))
      break;
    sleep(1);
  }

  if (Util_isProcessRunning(s)) {
    Event_post(s, Event_Exec, STATE_FAILED, s->action_EXEC, "failed to stop");
    return FALSE;
  } else {
    Event_post(s, Event_Exec, STATE_SUCCEEDED, s->action_EXEC, "stopped");
  }

  return TRUE;
}
예제 #21
0
파일: validate.c 프로젝트: KISSMonX/monit
/**
 * Validate a given fifo service s. Events are posted according to 
 * its configuration. In case of a fatal event FALSE is returned.
 */
int check_fifo(Service_T s) {

  struct stat stat_buf;

  ASSERT(s);

  if (stat(s->path, &stat_buf) != 0) {
    Event_post(s, Event_Nonexist, STATE_FAILED, s->action_NONEXIST, "fifo doesn't exist");
    return FALSE;
  } else {
    s->inf->st_mode   = stat_buf.st_mode;
    s->inf->st_uid    = stat_buf.st_uid;
    s->inf->st_gid    = stat_buf.st_gid;
    s->inf->timestamp = MAX(stat_buf.st_mtime, stat_buf.st_ctime);
    DEBUG("'%s' fifo exists check succeeded\n", s->name);
    Event_post(s, Event_Nonexist, STATE_SUCCEEDED, s->action_NONEXIST, "fifo exist");
  }

  if (!S_ISFIFO(s->inf->st_mode)) {
    Event_post(s, Event_Invalid, STATE_FAILED, s->action_INVALID, "is not fifo");
    return FALSE;
  } else {
    DEBUG("'%s' is fifo\n", s->name);
    Event_post(s, Event_Invalid, STATE_SUCCEEDED, s->action_INVALID, "is fifo");
  }

  if (s->perm)
    check_perm(s);

  if (s->uid)
    check_uid(s);

  if (s->gid)
    check_gid(s);

  if (s->timestamplist)
    check_timestamp(s);

  return TRUE;

}
/*
 *  ======== Adaptor_rxTaskFxn ========
 *  Task that receives incoming messages from the host.
 *  These messages are then sent to the transfer agent.
 */
Void Adaptor_rxTaskFxn(UArg arg, UArg unused)
{
    Int status;
    Adaptor_Entry *entry;
    UIAPacket_Hdr *packet;

    /* Make sure the transport is set to go */
    if (ServiceMgr_transportFxns.startFxn != NULL) {
        Adaptor_module->transportMsgHandle =
            ServiceMgr_transportFxns.startFxn(UIAPacket_HdrType_Msg);
    }

    /*
     *  Loop to receive msgs from the instrumentation host
     */
    while (TRUE) {

        /* Grab a free incomingMsg buffer */
        packet = Adaptor_getFreePacket(UIAPacket_HdrType_Msg,
                                       BIOS_WAIT_FOREVER);

        /* Receive the packet. */
        status = ServiceMgr_transportFxns.recvFxn(
                     Adaptor_module->transportMsgHandle, &packet,
                     ServiceMgr_maxCtrlPacketSize);

        /* Put onto router's message queue */
        if ((status > 0) &&
            (UIAPacket_getHdrType(packet) == UIAPacket_HdrType_Msg)) {

            /* The Queue elem is just above the packet */
            entry = (Adaptor_Entry *)((UInt)packet - sizeof(Queue_Elem));

            Queue_put(Adaptor_module->incomingQ, (Queue_Elem *)entry);
            Event_post(Adaptor_module->event, Event_Id_01);
        }
        else {
            /* Return the packet */
            Adaptor_freePacket(packet);

            /* Reset the transport with a stop/start */
            if (ServiceMgr_transportFxns.stopFxn != NULL) {
                ServiceMgr_transportFxns.stopFxn(
                    Adaptor_module->transportMsgHandle);
            }

            if (ServiceMgr_transportFxns.startFxn != NULL) {
                Adaptor_module->transportMsgHandle =
                    ServiceMgr_transportFxns.startFxn(UIAPacket_HdrType_Msg);
            }
        }
    }
}
예제 #23
0
파일: control.c 프로젝트: andreax79/monit
/*
 * This function runs in its own thread and waits for the service to
 * start running. If the service did not start a failed event is
 * posted to notify the user.
 * @param service A Service to wait for
 */
static void wait_start(Service_T s, SpawnResult *spawn_result) {
  time_t timeout = time(NULL) + s->start->timeout;
  
  ASSERT(s);

  while ((time(NULL) < timeout) && !Run.stopped) {
    if (Util_isProcessRunning(s))
      break;
    if (spawn_result != NULL && spawn_result->exit_code > 0) {
      LogError("%s start exit with code %d\n", s->name,  spawn_result->exit_code);
      break;
    }
    sleep(1);
  }
  
  if (!Util_isProcessRunning(s))
    Event_post(s, Event_Exec, STATE_FAILED, s->action_EXEC, "failed to start");
  else
    Event_post(s, Event_Exec, STATE_SUCCEEDED, s->action_EXEC, "started");

  return;
}
예제 #24
0
파일: validate.c 프로젝트: KISSMonX/monit
/**
 * Test for associated path checksum change
 */
static void check_checksum(Service_T s) {
  int         changed;
  Checksum_T  cs;

  ASSERT(s && s->path && s->checksum);

  cs = s->checksum;

  if (Util_getChecksum(s->path, cs->type, s->inf->priv.file.cs_sum, sizeof(s->inf->priv.file.cs_sum))) {

    Event_post(s, Event_Data, STATE_SUCCEEDED, s->action_DATA, "checksum computed for %s", s->path);

    switch(cs->type) {
      case HASH_MD5:
        changed = strncmp(cs->hash, s->inf->priv.file.cs_sum, 32);
        break;
      case HASH_SHA1:
        changed = strncmp(cs->hash, s->inf->priv.file.cs_sum, 40);
        break;
      default:
        LogError("'%s' unknown hash type\n", s->name);
        *s->inf->priv.file.cs_sum = 0;
        return;
    }

    if (changed) {

      /* if we are testing for changes only, the value is variable */
      if (cs->test_changes) {
        if (!cs->test_changes_ok)
          /* the checksum was not initialized during monit start, so set the checksum now and allow further checksum change testing */
          cs->test_changes_ok = TRUE;
        else
          Event_post(s, Event_Checksum, STATE_CHANGED, cs->action, "checksum was changed for %s", s->path);

        /* reset expected value for next cycle */
        snprintf(cs->hash, sizeof(cs->hash), "%s", s->inf->priv.file.cs_sum);

      } else
        /* we are testing constant value for failed or succeeded state */
        Event_post(s, Event_Checksum, STATE_FAILED, cs->action, "checksum test failed for %s", s->path);

    } else if (cs->test_changes) {

      DEBUG("'%s' checksum has not changed\n", s->name);
      Event_post(s, Event_Checksum, STATE_CHANGEDNOT, cs->action, "checksum has not changed");

    } else {

      DEBUG("'%s' has valid checksums\n", s->name);
      Event_post(s, Event_Checksum, STATE_SUCCEEDED, cs->action, "checksum succeeded");

    }
    return;
  }

  Event_post(s, Event_Data, STATE_FAILED, s->action_DATA, "cannot compute checksum for %s", s->path);

}
void common_wrapper(UArg arg0, UArg arg1)
{
	taskArgs* t = (taskArgs*)arg0 ;
	int tid = (int)arg1 ;
	int i ;
	for(i=0 ; i<NUM_ITER ; i++) {
		if(tid == 0) {
			callBarrier(0, /*lock_id=*/4) ;
			callLocalBarrier() ;
			multiply(t->buffer1, t->buffer2, t->buffer3, t->start_indx, t->end_indx) ;
		} else {
			callLocalBarrier() ;
			multiply(t->buffer1, t->buffer2, t->buffer3, t->start_indx, t->end_indx) ;
		}
		
	}

	if(tid == 0)
		Event_post(edgeDetectEvent, Event_Id_00) ;
	else
		Event_post(edgeDetectEvent, Event_Id_01) ;
}
예제 #26
0
파일: Race.c 프로젝트: lordnathan0/RTOS
void Race()
{
	Bike.Mode = MODE_RACE;
	Bike.Fault.all = 0;
	Bike.Warning.all = 0;
	W2000.BusVoltage = 0;
	if(Event_pend(EVT_Change_Mode,Event_Id_00, Event_Id_NONE,BIOS_NO_WAIT) != 0)
	{
		Event_post(EVT_Change_Mode,Event_Id_00);
		return;
	}
	GPIO_Race();
	if(Event_pend(EVT_Change_Mode,Event_Id_00, Event_Id_NONE,BIOS_NO_WAIT) != 0)
	{
		Event_post(EVT_Change_Mode,Event_Id_00);
		return;
	}
	if (Start_Race_Peripheral() == 1 || GpioDataRegs.GPBDAT.A_FUALT_OVERRIDE_SW == FAULT_OVERRIDE_ON)
	{
		Close_Contactors();
	}
	Event_Logger("MODE CHANGE TO RACE");
}
예제 #27
0
파일: validate.c 프로젝트: KISSMonX/monit
/**
 * Test size
 */
static void check_size(Service_T s) {
  Size_T sl;

  ASSERT(s && s->sizelist);

  for (sl = s->sizelist; sl; sl = sl->next) {

    /* if we are testing for changes only, the value is variable */
    if (sl->test_changes) {
      if (!sl->test_changes_ok) {
        /* the size was not initialized during monit start, so set the size now
         * and allow further size change testing */
        sl->test_changes_ok = TRUE;
        sl->size = s->inf->priv.file.st_size;
      } else {
        if (sl->size != s->inf->priv.file.st_size) {
          Event_post(s, Event_Size, STATE_CHANGED, sl->action, "size was changed for %s", s->path);
          /* reset expected value for next cycle */
          sl->size = s->inf->priv.file.st_size;
        } else {
          DEBUG("'%s' size has not changed [current size=%llu B]\n", s->name, s->inf->priv.file.st_size);
          Event_post(s, Event_Size, STATE_CHANGEDNOT, sl->action, "size was not changed", s->path);
        }
      }
      break;
    }

    /* we are testing constant value for failed or succeeded state */
    if (Util_evalQExpression(sl->operator, s->inf->priv.file.st_size, sl->size))
      Event_post(s, Event_Size, STATE_FAILED, sl->action, "size test failed for %s -- current size is %llu B", s->path, s->inf->priv.file.st_size);
    else {
      DEBUG("'%s' file size check succeeded [current size=%llu B]\n", s->name, s->inf->priv.file.st_size);
      Event_post(s, Event_Size, STATE_SUCCEEDED, sl->action, "size succeeded");
    }
  }
}
/*
 *  ======== Adaptor_requestEnergy ========
 */
Void Adaptor_requestEnergy(Int id)
{
    UInt key;

    /* Must protect against the Adaptor transferAgent */
    key = Hwi_disable();

    /* Give the service energy to run. */
    Adaptor_reqEnergy[id] = TRUE;

    /* Leave the gate */
    Hwi_restore(key);

    /* Wake up the transfer agent */
    Event_post(Adaptor_module->event, Event_Id_02);
}
예제 #29
0
/*********************************************************************
 * @fn      Util_enqueueMsg
 *
 * @brief   Creates a queue node and puts the node in RTOS queue.
 *
 * @param   msgQueue - queue handle.
 * @param   sem - thread's event processing semaphore that queue is
 *                associated with.
 * @param   pMsg - pointer to message to be queued
 *
 * @return  TRUE if message was queued, FALSE otherwise.
 */
uint8_t Util_enqueueMsg(Queue_Handle msgQueue, 
#ifdef ICALL_EVENTS
                        Event_Handle event,
#else //!ICALL_EVENTS
                        Semaphore_Handle sem,
#endif //ICALL_EVENTS
                        uint8_t *pMsg)
{
  queueRec_t *pRec;

  // Allocated space for queue node.
#ifdef USE_ICALL
  if ((pRec = ICall_malloc(sizeof(queueRec_t))))
#else
  if ((pRec = (queueRec_t *)malloc(sizeof(queueRec_t))))
#endif
  {
    pRec->pData = pMsg;

    // This is an atomic operation
    Queue_put(msgQueue, &pRec->_elem);

    // Wake up the application thread event handler.
#ifdef ICALL_EVENTS
    if (event)
    {
      Event_post(event, UTIL_QUEUE_EVENT_ID);
    }
#else //!ICALL_EVENTS
    if (sem)
    {
      Semaphore_post(sem);
    }
#endif //ICALL_EVENTS

    return TRUE;
  }

  // Free the message.
#ifdef USE_ICALL
  ICall_free(pMsg);
#else
  free(pMsg);
#endif

  return FALSE;
}
예제 #30
0
/**
 * usage: this method does the work, checkes the queue, writes to the UART and post's
 * 		  the Event
 * @method uart_method
 * @author: patrik.szabo
 * @param arg0 - not used param for the task
 * @return *none*
 */
void uart_method(UArg arg0) {

	// char input;
	UART_Handle uart;
	UART_Params uartParams;

	/* Create a UART with data processing off. */
	UART_Params_init(&uartParams);
	uartParams.writeDataMode = UART_DATA_BINARY;
	uartParams.readDataMode = UART_DATA_BINARY;
	uartParams.readReturnMode = UART_RETURN_FULL;
	uartParams.readEcho = UART_ECHO_OFF;
	uartParams.baudRate = 9600;
	uart = UART_open(Board_UART0, &uartParams);

	if (uart == NULL) {
		System_abort("Error opening the UART");
	}

	QueueObject* queueObjectPointer;

	char altData[22] = "";
	char pressData[16] = "";
	char tempData[18] = "";

	while (1) {
		while (!Queue_empty(uartQueue)) {
			queueObjectPointer = Queue_dequeue(uartQueue);
			sprintf(altData, "Altitude: %d | ",
					(int) queueObjectPointer->myInformationPointer->alt);
			System_printf("%s", altData);
			UART_write(uart, altData, sizeof(altData));
			sprintf(pressData, "Pressure: %d | ",
					queueObjectPointer->myInformationPointer->press);
			System_printf("%s", pressData);
			UART_write(uart, pressData, sizeof(pressData));
			sprintf(tempData, "Temparature: %d\n\r",
					queueObjectPointer->myInformationPointer->temp);
			System_printf("%s", tempData);
			UART_write(uart, tempData, sizeof(tempData));
			Event_post(uartReadyEvent, Event_Id_02);
		}
		Task_sleep(500);
	}
}