コード例 #1
0
ファイル: file_op.c プロジェクト: HLi91/ECE391OS
/*
 * stdin_read
 * Description: standard read 
 * INPUTS:	
		 int32_t fd -- file descriptor
		 void* buf -- buffer address
		 int32_t nbytes -- number of bytes
		 pcb_t* mypcb -- Process control block
 * OUTPUTS:	None
 * RETURN: None
 * SIDE EFFECTS: None
 */
extern int32_t stdin_read(int32_t fd, void* buf, int32_t nbytes, pcb_t* mypcb)			
{

	if (fd == 0)
	{

		int i;
		while(1)
		{
		if (check_signal((uint32_t)mypcb)){
			return EPENDSIG;
		}
			if (cur_terminal == kernel_pid[get_cur_pid()].terminal_num)
			{
				for (i=0; i<nbytes; i++)
				{
					((int8_t*)buf)[i] = c_buffer[terminal_index].data[i];
					if (c_buffer[terminal_index].data[i] == '\0')
						break;
					else if (c_buffer[terminal_index].data[i] == '\n')
					{
						clear_c_buffer();
						return i;
					}
		
				}
			}
		
		}
	
	}
	return -1;

}
コード例 #2
0
ファイル: object.c プロジェクト: MDomagala/bluez
gboolean g_dbus_send_message(DBusConnection *connection, DBusMessage *message)
{
	dbus_bool_t result = FALSE;

	if (dbus_message_get_type(message) == DBUS_MESSAGE_TYPE_METHOD_CALL)
		dbus_message_set_no_reply(message, TRUE);
	else if (dbus_message_get_type(message) == DBUS_MESSAGE_TYPE_SIGNAL) {
		const char *path = dbus_message_get_path(message);
		const char *interface = dbus_message_get_interface(message);
		const char *name = dbus_message_get_member(message);
		const GDBusArgInfo *args;

		if (!check_signal(connection, path, interface, name, &args))
			goto out;
	}

	/* Flush pending signal to guarantee message order */
	g_dbus_flush(connection);

	result = dbus_connection_send(connection, message, NULL);

out:
	dbus_message_unref(message);

	return result;
}
コード例 #3
0
ファイル: object.c プロジェクト: MDomagala/bluez
gboolean g_dbus_emit_signal_valist(DBusConnection *connection,
				const char *path, const char *interface,
				const char *name, int type, va_list args)
{
	DBusMessage *signal;
	dbus_bool_t ret;
	const GDBusArgInfo *args_info;

	if (!check_signal(connection, path, interface, name, &args_info))
		return FALSE;

	signal = dbus_message_new_signal(path, interface, name);
	if (signal == NULL) {
		error("Unable to allocate new %s.%s signal", interface,  name);
		return FALSE;
	}

	ret = dbus_message_append_args_valist(signal, type, args);
	if (!ret)
		goto fail;

	if (g_dbus_args_have_signature(args_info, signal) == FALSE) {
		error("%s.%s: got unexpected signature '%s'", interface, name,
					dbus_message_get_signature(signal));
		ret = FALSE;
		goto fail;
	}

	return g_dbus_send_message(connection, signal);

fail:
	dbus_message_unref(signal);

	return ret;
}
コード例 #4
0
ファイル: msh_father_n_son.c プロジェクト: Jaahd/Minishell
int				father_n_son(char **cmd, char **env, t_duo **env_cpy)
{
	pid_t		father;
	int			stat_loc;

	father = fork();
	if (father > 0)
	{
		check_signal(3);
		wait(&stat_loc);
	}
	if (father == 0)
	{
		check_signal(2);
		check_fct(cmd, env, env_cpy);
		ft_putstr("minishell: ");
		ft_putstr(cmd[0]);
		ft_putendl(": command not found");
		exit(EXIT_FAILURE);
	}
	return (0);
}
コード例 #5
0
ファイル: my_signal.c プロジェクト: ahonorat/usersThreads
int get_signal(unsigned int listsig){
  if(check_signal(listsig,THREAD_SIGKILL))
    return THREAD_SIGKILL;
  if(check_signal(listsig,THREAD_SIGKILL))
    return THREAD_SIGSTOP;
  int i,k = 0;

  for(i = 1; i < 23; i++){
    if(check_signal(listsig,i)){
      k = i;
      if ((k == THREAD_SIGUSR1) || (k == THREAD_SIGUSR2)) // traitement des sig user après les autres
        k = 0;
      if (k != 0)
        return k;
    }
  }
  if(check_signal(listsig,THREAD_SIGUSR1))
    return THREAD_SIGUSR1;
  if(check_signal(listsig,THREAD_SIGUSR2))
    return THREAD_SIGUSR2;

  return 0;
}
コード例 #6
0
ファイル: server_main.cpp プロジェクト: Sishio/cyberpvnk
int main(int argc, char **argv){
	misc_init();
	argc_ = argc;
	argv_ = argv;
	init(menu());
	for(uint_ i = 0;i < server_loop_code->code.size();i++){
		try{
			loop_entry_t *tmp = (loop_entry_t*)find_pointer(server_loop_code->code[i]);
			throw_if_nullptr(tmp);
			tmp->settings = 0;
		}catch(const std::logic_error &e){}
	}
	printf("Starting the main loop\n");
	while(likely(check_signal(SIGINT) == false && check_signal(SIGKILL) == false && check_signal(SIGTERM) == false)){
		loop_run(server_loop_code);
		once_per_second_update();
		if(once_per_second){
			server_time->update_timestamp(); // Should I make a new thread for this or is it good enough here w/ hangs?
		}
	}
	close();
	last_thing_to_execute();
	return 0;
}
コード例 #7
0
ファイル: main.c プロジェクト: hazirguo/AVR
int main(void)
{
	//系统初始化
	//1.GPIO口初始化
	port_init();
	
	//2.计时器初始化
	timer_init();
	
	//3.串口初始化
	ustra_init();
	
	//4.中断初始化,关中断
	cli();
	
	//开机显示
	cur_state = SYS_START;
	show_start_image();
	
	//读取工作模式
	work_mode = read_work_mode();
	
	//读取时间设置
	time_set = read_time_set(work_mode);

	//开中断,进入过渡状态
	cur_state = SYS_INTERIM;
	time_count = FIVE_MININUTES;
	stop_work_mode(work_mode);

	sei();
	
    while(1)
    {	
		//检查是否有信号来
		//	有信号,进入工作模式
        if ((uchar)((uchar)(cur_state != SYS_WORK) && ((uchar)check_signal(work_mode)))) {		//?不强制类型转化会出错!!!why?!!!
			cur_state = SYS_WORK;			//设置系统当前状态为工作状态
			time_count = time_set;			//重置时间
			start_work_mode(work_mode);		//设置系统开始工作
		} 
		
		//无信号,继续检查
    }
}
コード例 #8
0
ファイル: execution_next.c プロジェクト: girards/42sh
int	start_execution(t_cmd *cmd, t_42sh *shell, int i)
{
  cmd[i].close_fd = which_one_to_close(cmd, i);
  if (cmd[i].type == 0)
    {
      if (check_and_close_father(cmd, shell, i) == -42)
	return (-42);
    }
  else
    exec_redir(cmd, i);
  if (cmd[i].token != NULL && (strcmp(cmd[i].token, "||") == 0
			       || strcmp(cmd[i].token, "&&") == 0))
    waitpid(cmd[i].pid, &cmd[i].status, 0);
  else if (i > 0 && (strcmp(cmd[i - 1].token, "|") != 0))
    waitpid(cmd[i].pid, &cmd[i].status, 0);
  check_signal(cmd[i].status);
  return (0);
}
コード例 #9
0
ファイル: file_op.c プロジェクト: HLi91/ECE391OS
/*
 * stdout_write
 * Description: write standard output
 * INPUTS:	
		 int32_t fd -- file descriptor
		 void* buf -- buffer address
		 int32_t nbytes -- number of bytes
		 pcb_t* mypcb -- Process control block
 * OUTPUTS:	None
 * RETURN: None
 * SIDE EFFECTS: None
 */
extern int32_t stdout_write(int32_t fd, const void* buf, int32_t nbytes, pcb_t* mypcb)	//this function do nothing
{
	if (fd == 1)
	{
		int i;
		uint32_t flag;
		//int8_t local[2000];
		int8_t * local = (int8_t *)r_kmalloc(nbytes+1);
		//strcpy(local, (int8_t *)buf);
		memcpy(local, buf, nbytes);
		local[nbytes] = '\0';
		//((int8_t *)buf)[nbytes-1] = '\0';

		cli_and_save(flag);

		//printf("%s", local);
		if (modeX_enabled == 0)
		{
		if (check_signal((uint32_t)mypcb)){
			return EPENDSIG;
		}
			for (i=0;i<nbytes;i++){
				//if (local[i]!='\0')
					putc(local[i]);
			}
		}else
		{
		
			puts(local);
		
		}

		restore_flags(flag);
		mypcb->file_array[fd].file_position = nbytes;
		r_kfree((uint32_t)local);
		
		return nbytes;
	
	}
	return -1;

}
コード例 #10
0
ファイル: global_exec.c プロジェクト: heitzls/42sh
int	global_exec(t_cmd *cmd, t_42sh *shell, int tok)
{
  int	i;

  i = 0;
  shell->tok = tok;
  while (shell->tok > 0)
    {
      global_prepa(cmd, i);
      prepa_pipes(cmd, i);
      prepa_semi_col(cmd, i);
      if (execution(cmd, shell, tok, i) == -42)
	return (-42);
      while (cmd[i].token != NULL && cmd[i].token[0] != ';')
	i++;
      i++;
    }
  check_signal(cmd->status);
  return (0);
}
コード例 #11
0
ファイル: rtc.c プロジェクト: HLi91/ECE391OS
/*
 * rtc_read
 * DESCRITPION: waits for an interrupt to occur
 * INPUT: none
 * OUTPUT: none
 * RETURN: 0 on success
 * SIDE EFFECT: wait until an interrupt
 */
int32_t rtc_read(pcb_t* mypcb, uint32_t fd, const uint32_t* buf, uint32_t nbytes){
	
	
	// reset RTC flag
	RTC_INT_FLAG = RESET;
	
	// printf("RTC Interrupt!                             \n");
	
	// wait for next interrupt
	while (RTC_INT_FLAG != SET){
		if (check_signal((uint32_t)mypcb)){
			return EPENDSIG;
		}
	}
	
	// printf("----------------RTC Interrupt---------------\n");
	
	// return on success
	return RET_SUCCESS;
}
コード例 #12
0
ファイル: object.c プロジェクト: 593141477/bluez-rda
static dbus_bool_t emit_signal_valist(DBusConnection *conn,
						const char *path,
						const char *interface,
						const char *name,
						int first,
						va_list var_args)
{
	DBusMessage *signal;
	dbus_bool_t ret;
	const char *signature, *args;

	if (!check_signal(conn, path, interface, name, &args))
		return FALSE;

	signal = dbus_message_new_signal(path, interface, name);
	if (signal == NULL) {
		error("Unable to allocate new %s.%s signal", interface,  name);
		return FALSE;
	}

	ret = dbus_message_append_args_valist(signal, first, var_args);
	if (!ret)
		goto fail;

	signature = dbus_message_get_signature(signal);
	if (strcmp(args, signature) != 0) {
		error("%s.%s: expected signature'%s' but got '%s'",
				interface, name, args, signature);
		ret = FALSE;
		goto fail;
	}

	ret = dbus_connection_send(conn, signal, NULL);

fail:
	dbus_message_unref(signal);

	return ret;
}
コード例 #13
0
ファイル: main.c プロジェクト: Ankirama/Epitech
int			main(int argc, char **argv)
{
  struct protoent	*pe;
  int			s;

  usage(argc);
  if (!(pe = getprotobyname("TCP")))
    return (EXIT_FAILURE);
  if ((s = _set_from_hostname(argv[1], argv[2], pe)) == -1)
    {
      perror("./client");
      return (EXIT_FAILURE);
    }
  check_signal(s);
  _handle_server(s);
  if (user(s, NULL, NULL, NULL))
    {
      my_close(s);
      return (EXIT_FAILURE);
    }
  (void)_loop(s);
  my_close(s);
  return (EXIT_SUCCESS);
}
コード例 #14
0
ファイル: fcron.c プロジェクト: colmsjo/batches
void
main_loop()
  /* main loop - get the time to sleep until next job execution,
   *             sleep, and then test all jobs and execute if needed. */
{
    time_t save;                /* time remaining until next save */
    time_t stime;               /* time to sleep until next job
                                 * execution */
#ifdef HAVE_GETTIMEOFDAY
    struct timeval tv;          /* we use usec field to get more precision */
#endif
#ifdef FCRONDYN
    int retcode = 0;
#endif

    debug("Entering main loop");

    now = time(NULL);

    synchronize_dir(".", is_system_startup());

    /* synchronize save with jobs execution */
    save = now + save_time;

    if (serial_num > 0 || once)
        stime = first_sleep;
    else if ((stime = time_to_sleep(save)) < first_sleep)
        /* force first execution after first_sleep sec : execution of jobs
         * during system boot time is not what we want */
        stime = first_sleep;
    debug("initial sleep time : %ld", stime);

    for (;;) {

#ifdef HAVE_GETTIMEOFDAY
#ifdef FCRONDYN
        gettimeofday(&tv, NULL);
        tv.tv_sec = (stime > 1) ? stime - 1 : 0;
        /* we set tv_usec to slightly more than necessary so as
         * we don't wake up too early, in which case we would
         * have to sleep again for some time */
        tv.tv_usec = 1001000 - tv.tv_usec;
        /* On some systems (BSD, etc), tv_usec cannot be greater than 999999 */
        if (tv.tv_usec > 999999)
            tv.tv_usec = 999999;
        /* note: read_set is set in socket.c */
        if ((retcode = select(set_max_fd + 1, &read_set, NULL, NULL, &tv)) < 0
            && errno != EINTR)
            die_e("select returned %d", errno);
#else
        if (stime > 1)
            sleep(stime - 1);
        gettimeofday(&tv, NULL);
        /* we set tv_usec to slightly more than necessary to avoid
         * infinite loop */
        usleep(1001000 - tv.tv_usec);
#endif                          /* FCRONDYN */
#else
        sleep(stime);
#endif                          /* HAVE_GETTIMEOFDAY */

        now = time(NULL);

        check_signal();

        debug("\n");

        test_jobs();

        while (serial_num > 0 && serial_running < serial_max_running)
            run_serial_job();

        if (once) {
            explain("Running with option once : exiting ... ");
            xexit(EXIT_OK);
        }

        if (save <= now) {
            save = now + save_time;
            /* save all files */
            save_file(NULL);
        }

#ifdef FCRONDYN
        /* check if there's a new connection, a new command to answer, etc ... */
        /* we do that *after* other checks, to avoid Denial Of Service attacks */
        check_socket(retcode);
#endif

        stime = check_lavg(save);
        debug("next sleep time : %ld", stime);

        check_signal();

    }

}
コード例 #15
0
ファイル: loop_main.cpp プロジェクト: truNEET/cyberpvnk
bool infinite_loop(){
	return unlikely(check_signal(SIGNAL_QUIT_LOOP) == false);
}
コード例 #16
0
ファイル: langmon.c プロジェクト: Magister/bjcups-2.50
static int connect_socket(int *sv, int *sk)
{
	int v,k;
	int i;

	/* create socket */
	for(i = 5; i > 0; i--){
		v = lm_create_server_socket();
		if(v >= 0)
			break; /* SUCCESS */
		else{
			if(check_signal() == -1){
#ifdef DEBUG
				write_log("socket create error(signal detected)\n");
#endif
				break;
			}
		}
#ifdef DEBUG
		write_log("socket create error(no signal and retry)\n");
#endif
	}
	if(v < 0){
		/* create error */
		*sv = -1;
		*sk = -1;
		return -1;
	}

	*sv = v;

	/* connect wait */
	for(i = 5; i > 0; i--){
#ifdef DEBUG
		write_log("start accept (LM main)\n");
#endif
		k = lm_wait_client_connect(v);
		if(k >= 0)
			break; /* SUCCESS */
		else{
			if(check_signal() == -1){
#ifdef DEBUG
				write_log("socket connect error(signal detected)\n");
#endif
				break;
			}
		}
#ifdef DEBUG
		write_log("socket connect error(no signal and retry)\n");
#endif
	}
	if(k < 0){
		/* connect error */
		*sk = -1;
		return -1;
	}

	*sk = k;

	return 0;
}
コード例 #17
0
ファイル: wait_evt.c プロジェクト: kjseefried/ada-1
extern int evt_wait (int *p_fd, boolean *p_read, timeout_t *timeout) {
  fd_set select_read_mask, select_write_mask;
  timeout_t exp_time, *timeout_ptr;
  boolean timeout_is_active;
  int start_fd;
  int n;
  ssize_t size;
  char c;

  /* Activate signal handling if necessary*/
  activate_signal_handling ();

  /* Compute exp_time = cur_time + timeout_ms */
  timeout_is_active = (timeout->tv_sec >= 0) && (timeout->tv_usec >= 0);
  if (timeout_is_active) {
    get_time (&exp_time);
    add_time (&exp_time, timeout);
    timeout_ptr = timeout;
  } else {
    timeout_ptr = NULL;
  }

  /* Init wake-up pipe */
  init_sig_and_wake_up ();

  for (;;) {

    /* Check for signal */
    if (check_signal() ) {
      *p_fd = SIG_EVENT;
      evt_time_remaining (timeout, &exp_time);
      return (WAIT_OK);
    }

    /* Copy select mask */
    memcpy (&select_read_mask,  &global_read_mask,  sizeof(fd_set));
    memcpy (&select_write_mask, &global_write_mask, sizeof(fd_set));

    /* Default result */
    *p_fd = NO_EVENT;
    *p_read = TRUE;

    /* Compute select timeout */
    if (timeout_is_active) {
      evt_time_remaining (timeout, &exp_time);
    }

    /* The select */
    n = select (last_fd + 1, &select_read_mask,
                             &select_write_mask, NULL, timeout_ptr);

    if (n > 0) {
      /* Start from 0 or from prev fd + 1 (round robin) */
      if (n == 1) {
        start_fd = 0;
      } else {
        start_fd = (prev_fd + 1) % (last_fd + 1);
      }

      /* Check read events first */
      *p_fd = check_fd (start_fd, &select_read_mask);
      if (*p_fd != NO_EVENT) {
         *p_read = TRUE;
      } else {
        /* Check write events second */
        *p_read = FALSE;
        *p_fd = check_fd (start_fd, &select_write_mask);
      }

      /* Check if p_fd is wake-up fd) */
      if (*p_fd == wake_up_fds[0] ) {
        for (;;) {
          size = read (wake_up_fds[0], &c, sizeof(c));
          if ( (size == -1) && (errno != EINTR) ) {
#ifdef DEBUG
            perror ("read");
#endif
            break;
          }
          if (size == 1) {
            break;
          }
        }
        *p_fd = WAKE_EVENT;
      } else if (*p_fd == NO_EVENT) {
#ifdef DEBUG
        fprintf (stderr, "No fd found\n");
#endif
        return (WAIT_ERR);
      }

      prev_fd = *p_fd;
      if (prev_fd < -1) {
        /* Not a fd => end of round robin */
        prev_fd = -1;
      }
      evt_time_remaining (timeout, &exp_time);
      return (WAIT_OK);

    } else if (n < 0) {
      if (errno != EINTR) {
        /* Real error */
#ifdef DEBUG
          perror ("select");
#endif
        return (WAIT_ERR);
      }
    }

    /* Check for timeout reached */
    if ( (!check_signal())
        && timeout_is_active
        && time_is_reached (&exp_time) ) {
      /* Done on timeout */
      *p_fd = NO_EVENT;
      timeout->tv_sec = 0;
      timeout->tv_usec = 0;
      return (WAIT_OK);
    }

  } /* for (;;) */
}
コード例 #18
0
ファイル: replika.c プロジェクト: buytenh/replika
static void *copy_thread_no_hashmap(void *_me)
{
	struct worker_thread *me = _me;

	while (1) {
		uint8_t buf[block_size];
		uint8_t hash[hash_size];
		off_t off;
		int ret;

		xsem_wait(&me->sem0);

		off = fd_off;
		if (off == sizeblocks) {
			xsem_post(&me->next->sem0);
			break;
		}

		if (check_signal()) {
			fd_off = sizeblocks;
			xsem_post(&me->next->sem0);
			break;
		}

		fd_off++;

		posix_fadvise(fd_src, off * block_size, 4 * block_size,
				POSIX_FADV_WILLNEED);

		ret = xpread(fd_src, buf, block_size, off * block_size);

		xsem_post(&me->next->sem0);

		if (ret < block_size && off != sizeblocks - 1) {
			fprintf(stderr, "short read\n");
			break;
		}

		gcry_md_hash_buffer(hash_algo, hash, buf, ret);

		xsem_wait(&me->sem1);

		if (memcmp(dsthashmap + off * hash_size, hash, hash_size)) {
			xpwrite(fd_dst, buf, ret, off * block_size);
			xpwrite(fd_dsthashmap, hash,
				hash_size, off * hash_size);
			memcpy(dsthashmap + off * hash_size, hash, hash_size);

			fprintf(stderr, "%Ld ", (long long)off);
			progress_reported();

			again = 1;
		} else if (should_report_progress()) {
			char str[256];

			ret = sprintf(str, "%Ld/%Ld", (long long)off,
				      (long long)sizeblocks);
			memset(str + ret, '\b', ret);
			str[2 * ret] = 0;

			fputs(str, stderr);
		}

		xsem_post(&me->next->sem1);
	}

	return NULL;
}
コード例 #19
0
ファイル: replika.c プロジェクト: buytenh/replika
static void *copy_thread_hashmap(void *_me)
{
	struct worker_thread *me = _me;

	while (1) {
		uint8_t buf[block_size];
		uint8_t hash[hash_size];
		off_t off;
		int ret;

		xsem_wait(&me->sem0);

		for (off = fd_off; off < sizeblocks; off++) {
			if (memcmp(srchashmap + off * hash_size,
				   dsthashmap + off * hash_size, hash_size)) {
				break;
			}
		}

		if (off == sizeblocks || check_signal()) {
			fd_off = sizeblocks;
			xsem_post(&me->next->sem0);
			break;
		}

		if (should_report_progress()) {
			char str[256];
			int ret;

			ret = sprintf(str, "%Ld/%Ld (%Ld/%Ld mismatches)",
				      (long long)off,
				      (long long)sizeblocks,
				      (long long)mismatch_idx,
				      (long long)mismatch_cnt);
			memset(str + ret, '\b', ret);
			str[2 * ret] = 0;

			fputs(str, stderr);
		}

		ret = xpread(fd_src, buf, block_size, off * block_size);

		fd_off = off + 1;
		mismatch_idx++;

		xsem_post(&me->next->sem0);

		if (ret < block_size && off != sizeblocks - 1) {
			fprintf(stderr, "short read\n");
			break;
		}

		gcry_md_hash_buffer(hash_algo, hash, buf, ret);

		if (memcmp(hash, srchashmap + off * hash_size, hash_size)) {
			fprintf(stderr, "warning: source image inconsistent "
					"with its hashmap at block %Ld\n",
				(long long)off);
		}

		xsem_wait(&me->sem1);

		xpwrite(fd_dst, buf, ret, off * block_size);

		memcpy(dsthashmap + off * hash_size, hash, hash_size);
		xpwrite(fd_dsthashmap, hash, hash_size, off * hash_size);

		xsem_post(&me->next->sem1);
	}

	return NULL;
}