示例#1
0
static void		s_get_argument(int column, t_line *line)
{
	int		i;

	i = 0;
	while (line->data[column] != '\0')
	{
		s_jump_whitespace(&column, line->data);
		s_set_arg(line, i, &column);
		s_jump_whitespace(&column, line->data);
		if (line->data[column] == '\0' || line->data[column] == COMMENT_CHAR
			|| line->data[column] == COMMENT_CHAR_BASIC)
			break ;
		else if (line->data[column] == SEPARATOR_CHAR && (++column))
			++i;
		else
		{
			line->args[i].column = line->args[i].column +
				ft_strlen(line->args[i].data);
			line->args[i].data = NULL;
			line->nb_args = i + 1;
			return (error_print_sug(line->args[i], ERR_OP_SEP, ","));
		}
	}
	line->nb_args = i + 1;
}
示例#2
0
static inline bool
s_log_init(lagopus_log_destination_t dst,
           const char *arg,
           bool multi_process,
           bool emit_date,
           uint16_t debug_level) {
  bool ret = false;

  if (s_is_fork_initialized == false) {
    (void)pthread_atfork(NULL, NULL, s_child_at_fork);
    s_is_fork_initialized = true;
  }

  if (dst == LAGOPUS_LOG_EMIT_TO_FILE ||
      dst == LAGOPUS_LOG_EMIT_TO_UNKNOWN) {
    int ofd = -INT_MAX;

    s_log_final();

    if (IS_VALID_STRING(arg) == true &&
        dst == LAGOPUS_LOG_EMIT_TO_FILE &&
        s_is_file(arg) == true) {
      s_set_arg(arg);
      ofd = open(s_log_arg, O_RDWR | O_CREAT | O_APPEND, 0600);
      if (ofd >= 0) {
        s_log_fd = fdopen(ofd, "a+");
        if (s_log_fd != NULL) {
          ret = true;
        }
      }
    } else {
      s_log_fd = NULL;	/* use stderr. */
      ret = true;
    }
  } else if (dst == LAGOPUS_LOG_EMIT_TO_SYSLOG) {
    if (IS_VALID_STRING(arg) == true) {

      s_log_final();

      /*
       * Note that the syslog(3) uses the first argument of openlog(3)
       * STATICALLY. So DON'T pass any heap addresses to openlog(3). I
       * never knew that until this moment, BTW.
       */
      s_set_arg(arg);
      openlog(s_log_arg, 0, LOG_USER);

      ret = true;
    }
  }

  if (ret == true) {
    s_log_dst = dst;
    s_do_multi_process = multi_process;
    s_do_date = emit_date;
    s_dbg_level = debug_level;
  } else {
    s_reset_arg();
  }

  return ret;
}