Exemplo n.º 1
0
void GuiWidgetList::ScrollList(int /*n*/, const std::string & value)
{
	if (value == "fwd")
	{
		int delta = m_vertical ? m_rows : m_cols;
		if (m_list_offset < m_list_size - delta)
		{
			m_list_offset += delta;
			if (get_values.connected())
			{
				m_values.resize(m_rows * m_cols);
				get_values(m_list_offset, m_values);
			}
		}
	}
	else if (value == "rev")
	{
		int delta = m_vertical ? m_rows : m_cols;
		if (m_list_offset >= delta)
		{
			m_list_offset -= delta;
			if (get_values.connected())
			{
				m_values.resize(m_rows * m_cols);
				get_values(m_list_offset, m_values);
			}
		}
	}
}
Exemplo n.º 2
0
void
line_create(void)
{
    char               *s;
    float               x1 = 0, y1 = 0, x2 = 0, y2 = 0;
    int                 res;

    serv_set_hint(DUP(_("enter first point: ")));

    serv_set_state(ST_LINE1);

    do
      {
          s = serv_get_string();
          res = get_values(s, shell->context.fx, shell->context.fy, &x1, &y1);
          if (res == 1)
              serv_set_hint(DUP(_("error, please reenter: ")));
      }
    while (res == 1);

    serv_set_state(ST_LINE2);

    if (res == 0)
      {
          serv_set_state(ST_NORMAL);
          return;
      }

    do
      {
          pre_line_x1y1(x1, y1);
          shell->context.fx = x1;
          shell->context.fy = y1;

          serv_set_hint(DUP(_("enter next point: ")));
          do
            {
                s = serv_get_string();
                res = get_values(s, x1, y1, &x2, &y2);
                if (res == 1)
                    serv_set_hint(DUP(_("error, please reenter: ")));
            }
          while (res == 1);
          if (res == 0)
            {
                serv_set_state(ST_NORMAL);
                return;
            }

          lock_data();
          _line_create(x1, y1, x2, y2);
          shell->context.fx = x2;
          shell->context.fy = y2;
          unlock_data();
          x1 = x2;
          y1 = y2;
      }
    while (1);
}
Exemplo n.º 3
0
int read_hdrfile(char *infile)
{
  SEASAT_header_ext *hdr;
  FILE *fp = fopen(infile,"r");
  
  int val, i, end_line;
  double dtmp, t, t1;
  
  int clock_drift_hist[MAX_CLOCK_DRIFT];
  int clock_drift_median;
  double clock_shift;
  
  if (fp==NULL) {printf("ERROR: can't open %s header file\n",infile); return(1); }
  hdr = (SEASAT_header_ext *) malloc(sizeof(SEASAT_header_ext));

  for (i=0; i<start_line; i++) {
    val = get_values(fp, hdr);
    if (val!=20) {printf("ERROR: unable to read to specified start line in header file\n"); exit(1);}
  }

  station_code = hdr->station_code;

  start_year = 1970 + hdr->lsd_year;
  start_date = hdr->day_of_year;
  start_sec  = (double) hdr->msec / 1000.0;
  
  s_date.year = 1970 + hdr->lsd_year;
  s_date.jd   = hdr->day_of_year;
  dtmp = (double) hdr->msec / 1000.0;
  date_sec2hms(dtmp,&s_time);

  if (USE_CLOCK_DRIFT==1) {
    for (i=0; i<MAX_CLOCK_DRIFT; i++) clock_drift_hist[i] = 0;
    end_line = start_line + npatches*patch_size;
    for (i = start_line; i<end_line; i++) {
      val = get_values(fp, hdr);
      if (val!=20) {printf("ERROR: unable to read to specified end line in header file\n"); exit(1);}
      clock_drift_hist[hdr->clock_drift]++;
    }
    
    printf("APPLYING CLOCK DRIFT TO IMAGE TIMING.\n");
    clock_drift_median = get_median(clock_drift_hist,MAX_CLOCK_DRIFT);
    printf("\tclock_drift_median     = %li \n",clock_drift_median);
    
    clock_shift = (double) clock_drift_median / 1000.0;
    start_sec += clock_shift;
    if (start_sec > 86400.0) {start_sec -= 86400.0; start_date += 1;}

    dtmp = date_hms2sec(&s_time)+clock_shift;
    if (dtmp > 86400.0) { s_date.jd+=1; dtmp-=86400.0;}
    date_sec2hms(dtmp,&s_time);
  }

  printf("Found start time: %i %i %lf\n",start_year, start_date, start_sec);
  fclose(fp);

}
int between_days(struct node *date1head, struct node *date2head)
{
	struct date d1, d2;
	if (date1head == NULL || date2head == NULL)
		return -1;
	get_values(date1head, &d1);
	get_values(date2head, &d2);
	int diff = difference(&d1, &d2);
	if (diff < 0)
		return -diff;
	return diff;
}
Exemplo n.º 5
0
int main(int argc, char *argv[])
{
  int c, unit = 'B', t = 1;
  char *iface = NULL;
  int warningrx = 0, warningtx = 0, criticalrx = 0, criticaltx = 0;
  while (c = getopt(argc, argv, "bBht:i:w:c:"), c != -1) {
    switch (c) {
    case 'b':
    case 'B':
      unit = c;
      break;
    case 't':
      t = atoi(optarg);
      break;
    case 'i':
      iface = strcat(optarg, ":");
      break;
    case 'w':
      sscanf(optarg, "%d:%d", &warningrx, &warningtx);
      break;
    case 'c':
      sscanf(optarg, "%d:%d", &criticalrx, &criticaltx);
      break;
    case 'h':
      usage(argv);
      return STATE_UNKNOWN;
    }
  }

  time_t s, s_old;
  ulli received, sent, received_old, sent_old;
  double rx, tx;

  get_values(iface, &s_old, &received_old, &sent_old);

  while (1) {
    sleep(t);
    get_values(iface, &s, &received, &sent);

    rx = (received - received_old) / (float)(s - s_old);
    tx = (sent - sent_old) / (float)(s - s_old);
    display(unit, rx, warningrx, criticalrx);
    printf(" ");
    display(unit, tx, warningtx, criticaltx);
    fflush(stdout);
    s_old = s;
    received_old = received;
    sent_old = sent;
  }

  return STATE_OK;
}
Exemplo n.º 6
0
void	main_poller_loop(unsigned char poller_type)
{
	int	nextcheck, sleeptime, processed;
	double	sec;

	zabbix_log(LOG_LEVEL_DEBUG, "In main_poller_loop() process_type:'%s' process_num:%d",
			get_process_type_string(process_type), process_num);

	zbx_setproctitle("%s [connecting to the database]", get_process_type_string(process_type));

	DBconnect(ZBX_DB_CONNECT_NORMAL);

	for (;;)
	{
		zbx_setproctitle("%s [getting values]", get_process_type_string(process_type));

		sec = zbx_time();
		processed = get_values(poller_type);
		sec = zbx_time() - sec;

		zabbix_log(LOG_LEVEL_DEBUG, "%s #%d spent " ZBX_FS_DBL " seconds while updating %d values",
				get_process_type_string(process_type), process_num, sec, processed);

		nextcheck = DCconfig_get_poller_nextcheck(poller_type);
		sleeptime = calculate_sleeptime(nextcheck, POLLER_DELAY);

		zbx_sleep_loop(sleeptime);
	}
}
Exemplo n.º 7
0
static PyObject *
py_hivex_node_set_values (PyObject *self, PyObject *args)
{
  PyObject *py_r;
  int r;
  hive_h *h;
  PyObject *py_h;
  long node;
  py_set_values values;
  PyObject *py_values;

  if (!PyArg_ParseTuple (args, (char *) "OlO:hivex_node_set_values", &py_h, &node, &py_values))
    return NULL;
  h = get_handle (py_h);
  if (get_values (py_values, &values) == -1)
    return NULL;
  r = hivex_node_set_values (h, node, values.nr_values, values.values, 0);
  free (values.values);
  if (r == -1) {
    PyErr_SetString (PyExc_RuntimeError,
                     strerror (errno));
    return NULL;
  }

  Py_INCREF (Py_None);
  py_r = Py_None;
  return py_r;
}
Exemplo n.º 8
0
s_ctrl
read_ctrl_infos (oss_mixext ext, int id)
{
	s_ctrl ctrl;

	ctrl.id = id;
	ctrl.real_id = ext.ctrl;
	ctrl.dev = ext.dev;
	ctrl.timestamp = ext.timestamp;
	ctrl.type = ext.type;
	ctrl.name = strdup(ext.extname);
	ctrl.max_value = ext.maxvalue;
	ctrl.min_value = ext.minvalue;

	if (ext.flags & MIXF_DECIBEL)
		ctrl.units_type = DECIBEL;
	else if (ext.flags & MIXF_CENTIBEL)
		ctrl.units_type = CENTIBEL;
	else if (ext.flags & MIXF_HZ)
		ctrl.units_type = HZ;

	get_values(&ctrl);

	return ctrl;
}
Exemplo n.º 9
0
void weights::reconcile_values(Al::request& req) {
  auto& values = get_values();
  if (values.RedundantSize() > 1) {
    values *= DataType(1) / values.RedundantSize();
    m_comm->nb_allreduce(values, values.RedundantComm(), req);
  }
}
Exemplo n.º 10
0
static void process_downtime(json_t * payload) {
	char * host_name, * service_description = NULL;
	char * author_name = NULL, *comment_data = NULL;
	time_t start_time = 0, end_time = 0, entry_time = 0;
	int fixed;
	unsigned long duration = 0, triggered_by = 0, downtimeid;

	if(get_values(payload,
		"host_name", JSON_STRING, 1, &host_name,
		"service_description", JSON_STRING, 0, &service_description,
		"entry_time", JSON_INTEGER, 1, &entry_time,
		"author_name", JSON_STRING, 0, &author_name,
		"comment_data", JSON_STRING, 0, &comment_data,
		"start_time", JSON_INTEGER, 1, &start_time,
		"end_time", JSON_INTEGER, 1, &end_time,
		"fixed", JSON_TRUE, 1, &fixed,
		"duration", JSON_INTEGER, 1, &duration,
		"triggered_by", JSON_INTEGER, 0, &triggered_by,
		NULL) != 0) {
		json_decref(payload);
		return;
	}

	schedule_downtime(service_description != NULL ? SERVICE_DOWNTIME:
		HOST_DOWNTIME, host_name, service_description, entry_time,
		author_name, comment_data, start_time, end_time, fixed,
		triggered_by, duration, &downtimeid);
	json_decref(payload);
}
Exemplo n.º 11
0
/**
 * Function to initialize the user directories of a user.
 */
int initialize_user(const char *user) {
  char **local_dir = get_values(TT_SYS_DIR_KEY);
  if (local_dir == NULL) {
    fprintf(LOGFILE, "%s is not configured.\n", TT_SYS_DIR_KEY);
    return INVALID_TT_ROOT;
  }

  char *user_dir;
  char **local_dir_ptr = local_dir;
  int failed = 0;
  for(local_dir_ptr = local_dir; *local_dir_ptr != 0; ++local_dir_ptr) {
    user_dir = get_user_directory(*local_dir_ptr, user);
    if (user_dir == NULL) {
      fprintf(LOGFILE, "Couldn't get userdir directory for %s.\n", user);
      failed = 1;
      break;
    }
    if (create_directory_for_user(user_dir) != 0) {
      failed = 1;
    }
    free(user_dir);
  }
  free_values(local_dir);
  return failed ? INITIALIZE_USER_FAILED : 0;
}
Exemplo n.º 12
0
void process_pull_msg(zmq_msg_t * payload_msg) {
	char * type = NULL;

	json_t * payload = json_loadb(zmq_msg_data(payload_msg),
		zmq_msg_size(payload_msg), 0, NULL);
	if(payload == NULL)
		return;

	if(get_values(payload,
		"type", JSON_STRING, 1, &type,
		NULL) != 0) {
		json_decref(payload);
		return;
	}

	if(strcmp(type, "command") == 0)
		process_cmd(payload);
	else if(strcmp(type, "host_check_processed") == 0 ||
		strcmp(type, "service_check_processed") == 0)
		process_status(payload);
	else if(strcmp(type, "acknowledgement") == 0)
		process_acknowledgement(payload);
	else if(strcmp(type, "comment_add") == 0)
		process_comment(payload);
	else if(strcmp(type, "downtime_add") == 0)
		process_downtime(payload);
	else if(strcmp(type, "state_data") == 0)
		process_bulkstate(payload);
	return;
}
Exemplo n.º 13
0
Arquivo: lcCharSet.c Projeto: aosm/X11
/* Retrieves a number of attributes of an XlcCharSet.
   Return NULL if successful, otherwise the name of the first argument
   specifiying a nonexistent attribute. */
char *
_XlcGetCSValues(XlcCharSet charset, ...)
{
    va_list var;
    XlcArgList args;
    char *ret;
    int num_args;

    va_start(var, charset);
    _XlcCountVaList(var, &num_args);
    va_end(var);

    va_start(var, charset);
    _XlcVaToArgList(var, num_args, &args);
    va_end(var);

    if (args == (XlcArgList) NULL)
	return (char *) NULL;
    
    ret = get_values(charset, args, num_args);

    Xfree(args);

    return ret;
}
Exemplo n.º 14
0
static gboolean
deserialize_cache (MuContacts *self)
{
	gchar **groups;
	gsize i, len;

	groups = g_key_file_get_groups (self->_ccache, &len);
	for (i = 0; i != len; ++i) {
		ContactInfo *cinfo;
		char *name, *email;
		size_t tstamp;
		if (!get_values (self->_ccache, groups[i],
				 &email, &name, &tstamp))
			continue; /* ignore this one... */

		cinfo = contact_info_new (email, name, tstamp);

		/* note, we're using the groups[i], so don't free with g_strfreev */
		g_hash_table_insert (self->_hash, groups[i],
				     cinfo);
	}

	g_free (groups);
	return TRUE;
}
Exemplo n.º 15
0
/**
 * Delete the given directory as the user from each of the tt_root directories
 * user: the user doing the delete
 * subdir: the subdir to delete
 */
int delete_as_user(const char *user,
                   const char *subdir) {
  int ret = 0;

  char** tt_roots = get_values(TT_SYS_DIR_KEY);
  char** ptr;
  if (tt_roots == NULL || *tt_roots == NULL) {
    fprintf(LOGFILE, "No %s defined in the configuration\n", TT_SYS_DIR_KEY);
    return INVALID_CONFIG_FILE;
  }

  // do the delete
  for(ptr = tt_roots; *ptr != NULL; ++ptr) {
    char* full_path = get_user_subdirectory(*ptr, user, subdir);
    if (full_path == NULL) {
      return -1;
    }
    int this_ret = delete_path(full_path, strlen(subdir) == 0);
    free(full_path);
    // delete as much as we can, but remember the error
    if (this_ret != 0) {
      ret = this_ret;
    }
  }
  free_values(tt_roots);
  return ret;
}
Exemplo n.º 16
0
static void process_comment(json_t * payload) {
	char * host_name, *service_description = NULL, *comment_data, *author_name;
	time_t expire_time = 0;
	int persistent = 0, expires = 0;
	struct timeval entry_time;
	if(get_values(payload,
		"host_name", JSON_STRING, 1, &host_name,
		"service_description", JSON_STRING, 0, &service_description,
		"comment_data", JSON_STRING, 1, &comment_data,
		"author_name", JSON_STRING, 1, &author_name,
		"timestamp", JSON_TIMEVAL, 1, &entry_time,
		"persistent", JSON_TRUE, 1, &persistent,
		"expires", JSON_TRUE, 1, &expires,
		"expire_time", JSON_INTEGER, 0, &expire_time,
		NULL) != 0) {
		json_decref(payload);
		return;
	}

	add_new_comment((service_description==NULL) ? HOST_COMMENT:SERVICE_COMMENT,
		USER_COMMENT, host_name, service_description, entry_time.tv_sec, author_name,
		comment_data, persistent, COMMENTSOURCE_EXTERNAL, expires, expire_time,
		NULL);
	json_decref(payload);
}
Exemplo n.º 17
0
void handle_get_response(
        sai_object_type_t object_type,
        uint32_t get_attr_count,
        sai_attribute_t* get_attr_list,
        const std::string& response)
{
    SWSS_LOG_ENTER();

    //std::cout << "processing " << response << std::endl;

    // timestamp|action|objecttype:objectid|attrid=value,...
    auto v = swss::tokenize(response, '|');

    auto values = get_values(v);

    SaiAttributeList list(object_type, values, false);

    sai_attribute_t *attr_list = list.get_attr_list();
    uint32_t attr_count = list.get_attr_count();

    match_list_lengths(object_type, get_attr_count, get_attr_list, attr_count, attr_list);

    SWSS_LOG_DEBUG("list match");

    match_redis_with_rec(object_type, get_attr_count, get_attr_list, attr_count, attr_list);

    // NOTE: Primitive values are not matched (recording vs switch/vs), we can add that check
}
Exemplo n.º 18
0
void GUIWIDGETLIST::UpdateList(const std::string &)
{
	if (get_values.connected())
	{
		m_values.resize(m_rows * m_cols);
		get_values(m_list_offset, m_values);
	}
}
Exemplo n.º 19
0
void GridmapLocations::updateObstacleTime(const CostMapList &cm_list){
  double obs_ts = cm_list.obs_timestamp / 1.0e6; //kept as seconds 
  double *topic_utime = get_values(cm_list.topic);

  for(int j=0; j < cm_list.indices.size(); j++){
    topic_utime[cm_list.indices[j].index] = obs_ts;         
  }
}
Exemplo n.º 20
0
/**
 * Is the user a real user account?
 * Checks:
 *   1. Not root
 *   2. UID is above the minimum configured.
 *   3. Not in banned user list
 * Returns NULL on failure
 */
struct passwd* check_user(const char *user) {
  if (strcmp(user, "root") == 0) {
    fprintf(LOGFILE, "Running as root is not allowed\n");
    fflush(LOGFILE);
    return NULL;
  }
  char *min_uid_str = get_value(MIN_USERID_KEY);
  int min_uid = DEFAULT_MIN_USERID;
  if (min_uid_str != NULL) {
    char *end_ptr = NULL;
    min_uid = strtol(min_uid_str, &end_ptr, 10);
    if (min_uid_str == end_ptr || *end_ptr != '\0') {
      fprintf(LOGFILE, "Illegal value of %s for %s in configuration\n", 
	      min_uid_str, MIN_USERID_KEY);
      fflush(LOGFILE);
      free(min_uid_str);
      min_uid_str = NULL;
      return NULL;
    }
    free(min_uid_str);
    min_uid_str = NULL;
  }
  struct passwd *user_info = get_user_info(user);
  if (NULL == user_info) {
    fprintf(LOGFILE, "User %s not found\n", user);
    fflush(LOGFILE);
    return NULL;
  }
  if (user_info->pw_uid < min_uid) {
    fprintf(LOGFILE, "Requested user %s has id %d, which is below the "
	    "minimum allowed %d\n", user, user_info->pw_uid, min_uid);
    fflush(LOGFILE);
    free(user_info);
    user_info = NULL;
    return NULL;
  }
  char **banned_users = get_values(BANNED_USERS_KEY);
  char **banned_user = (banned_users == NULL) ? 
    (char**) DEFAULT_BANNED_USERS : banned_users;
  for(; *banned_user; ++banned_user) {
    if (strcmp(*banned_user, user) == 0) {
      free(user_info);
      user_info = NULL;
      if (banned_users != (char**)DEFAULT_BANNED_USERS) {
        free_values(banned_users);
        banned_users = NULL;
      }
      fprintf(LOGFILE, "Requested user %s is banned\n", user);
      return NULL;
    }
  }
  if (banned_users != NULL && banned_users != (char**)DEFAULT_BANNED_USERS) {
    free_values(banned_users);
    banned_users = NULL;
  }
  return user_info;
}
Exemplo n.º 21
0
void main_poller_loop(zbx_process_t p, int type, int num)
{
	struct	sigaction phan;
	int	now;
	int	nextcheck, sleeptime;
	int	items;
	double	sec;

	zabbix_log( LOG_LEVEL_DEBUG, "In main_poller_loop(type:%d,num:%d)",
			type,
			num);

/*	phan.sa_handler = child_signal_handler;*/
	phan.sa_sigaction = child_signal_handler;
	sigemptyset(&phan.sa_mask);
	phan.sa_flags = SA_SIGINFO;
	sigaction(SIGALRM, &phan, NULL);

	zbx_process	= p;
	poller_type	= type;
	poller_num	= num;

	DBconnect(ZBX_DB_CONNECT_NORMAL);

	for (;;) {
		zbx_setproctitle("poller [getting values]");

		now = time(NULL);
		sec = zbx_time();
		items = get_values(now, &nextcheck);
		sec = zbx_time() - sec;

		if (FAIL == nextcheck)
			sleeptime = POLLER_DELAY;
		else
		{
			sleeptime = nextcheck - time(NULL);
			if (sleeptime < 0)
				sleeptime = 0;
			if (sleeptime > POLLER_DELAY)
				sleeptime = POLLER_DELAY;
		}

		zabbix_log(LOG_LEVEL_DEBUG, "Poller spent " ZBX_FS_DBL " seconds while updating %3d values."
				" Sleeping for %d seconds",
				sec,
				items,
				sleeptime);

		if (sleeptime > 0)
		{
			zbx_setproctitle("poller [sleeping for %d seconds]", sleeptime);
			sleep(sleeptime);
		}
	}
}
Exemplo n.º 22
0
static void process_status(json_t * payload) {
	char * host_name, *service_description = NULL, *output = NULL;
	check_result * newcr = NULL, t;

	init_check_result(&t);
	t.output_file = NULL;
	t.output_file_fp = NULL;
	if(get_values(payload,
		"host_name", JSON_STRING, 1, &host_name,
		"service_description", JSON_STRING, 0, &service_description,
		"output", JSON_STRING, 1, &output,
		"return_code", JSON_INTEGER, 1, &t.return_code,
		"start_time", JSON_TIMEVAL, 0, &t.start_time,
		"finish_time", JSON_TIMEVAL, 1, &t.finish_time,
		"check_type", JSON_INTEGER, 1, &t.check_type,
		"check_options", JSON_INTEGER, 0, &t.check_options,
		"scheduled_check", JSON_INTEGER, 0, &t.scheduled_check,
		"reschedule_check", JSON_INTEGER, 0, &t.reschedule_check,
		"latency", JSON_REAL, 0, &t.latency,
		"early_timeout", JSON_INTEGER, 0, &t.early_timeout,
		"exited_ok", JSON_INTEGER, 0, &t.exited_ok,
		NULL) != 0) {
		json_decref(payload);
		return;
	}

	service * service_target = NULL;
	if(service_description)
		service_target = find_service(host_name, service_description);
	host * host_target = find_host(host_name);
	if(host_target == NULL || (service_description && !service_target)) {
		json_decref(payload);
		return;
	}

	newcr = malloc(sizeof(check_result));
	memcpy(newcr, &t, sizeof(check_result));
	newcr->host_name = strdup(host_name);
	if(service_target) {
		newcr->service_description = strdup(service_description);
		newcr->object_check_type = SERVICE_CHECK;
	}
	newcr->output = strdup(output);
	json_decref(payload);
#ifdef HAVE_NAGIOS4
	newcr->engine = &nagmq_check_engine;
	process_check_result(newcr);
#else
#ifdef HAVE_ADD_CHECK_RESULT_ONE
	add_check_result_to_list(newcr);
#elif defined(HAVE_ADD_CHECK_RESULT_TWO)
	add_check_result_to_list(&check_result_list, newcr);
#endif
#endif
}
Exemplo n.º 23
0
static void init() {
    get_values();

    // Create main Window element and assign to pointer
    s_main_window = window_create();
    //window_set_background_color(s_main_window, PBL_IF_BW_ELSE(GColorBlack, GColorBabyBlueEyes));
    // Set handlers to manage the elements inside the Window
    window_set_window_handlers(s_main_window, (WindowHandlers) {
            .load = main_window_load,
            .unload = main_window_unload
            });
Exemplo n.º 24
0
 observable<T> get_observable() const {
     auto keepAlive = s;
     auto observable = make_observable_dynamic<T>([=](subscriber<T> o){
         if (keepAlive.get_subscription().is_subscribed()) {
             for (auto&& value: get_values())
                 o.on_next(value);
         }
         keepAlive.add(keepAlive.get_subscriber(), std::move(o));
     });
     return s.get_coordinator().in(observable);
 }
Exemplo n.º 25
0
//-------------------------------------------------------------------
// Process short form entry on single line
//      '#VAR=VAL "TITLE" [MIN MAX]'
// or   '#VAR=VAL "TITLE" {A B C D ...}'
//-------------------------------------------------------------------
static int process_single(const char *ptr)
{
    sc_param *p;
    ptr = get_name(ptr, MAX_PARAM_NAME_LEN, &p, 1);
    if (p)
    {
        ptr = get_default(p, ptr, 1);
        ptr = skip_whitespace(ptr);
        if ((*ptr == '"') || (*ptr == '\''))
        {
            const char *s = skip_tochar(ptr+1, *ptr);
            p->desc = malloc(s-ptr);
            strncpy(p->desc, ptr+1, s-ptr-1);
            p->desc[s-ptr-1] = 0;
            if (*s == *ptr) s++;
            ptr = skip_whitespace(s);
        }
        else
        {
            // Error - log to console and abort
            return 0;
        }
        if (*ptr == '[')
        {
            ptr = get_range(p, ptr+1, ']');
        }
        else if (*ptr == '{')
        {
            ptr = get_values(p, ptr+1, '}');
            ptr = skip_whitespace(ptr);
            if (strncmp(ptr,"table",5) == 0)
            {
                p->data_type = DTYPE_TABLE;
                p->val--;   // Initial value is 1 based for Lua table, convert to 0 based for C code
                p->def_val--;   // also adjust default
            }
        }
        ptr = skip_whitespace(ptr);
        if (strncmp(ptr,"bool",4) == 0)
        {
            p->range = MENU_MINMAX(1,0);   // Force boolean data type in Lua (ToDo: this is clunky, needs fixing)
            p->range_type = MENUITEM_BOOL|MENUITEM_SCRIPT_PARAM;
            ptr = skip_token(ptr);
        }
        ptr = skip_whitespace(ptr);
        if (strncmp(ptr,"long",4) == 0)
        {
            p->range = 9999999;
            p->range_type = MENUITEM_INT|MENUITEM_SD_INT;
            ptr = skip_token(ptr);
        }
    }
    return 1;
}
Exemplo n.º 26
0
/**
 * Function to prepare the attempt directories for the task JVM.
 * It creates the task work and log directories.
 */
static int create_attempt_directories(const char* user, const char *job_id, 
					const char *task_id) {
  // create dirs as 0750
  const mode_t perms = S_IRWXU | S_IRGRP | S_IXGRP;
  if (job_id == NULL || task_id == NULL || user == NULL) {
    fprintf(LOGFILE, 
            "Either task_id is null or the user passed is null.\n");
    return -1;
  }
  int result = 0;

  char **local_dir = get_values(TT_SYS_DIR_KEY);

  if (local_dir == NULL) {
    fprintf(LOGFILE, "%s is not configured.\n", TT_SYS_DIR_KEY);
    return -1;
  }

  char **local_dir_ptr;
  for(local_dir_ptr = local_dir; *local_dir_ptr != NULL; ++local_dir_ptr) {
    char *task_dir = get_attempt_work_directory(*local_dir_ptr, user, job_id, 
                                                task_id);
    if (task_dir == NULL) {
      free_values(local_dir);
      return -1;
    }
    if (mkdirs(task_dir, perms) != 0) {
      // continue on to create other task directories
      free(task_dir);
    } else {
      free(task_dir);
    }
  }
  free_values(local_dir);

  // also make the directory for the task logs
  char *job_task_name = malloc(strlen(job_id) + strlen(task_id) + 2);
  if (job_task_name == NULL) {
    fprintf(LOGFILE, "Malloc of job task name failed\n");
    result = -1;
  } else {
    sprintf(job_task_name, "%s/%s", job_id, task_id);
    char *log_dir = get_job_log_directory(job_task_name);
    free(job_task_name);
    if (log_dir == NULL) {
      result = -1;
    } else if (mkdirs(log_dir, perms) != 0) {
      result = -1;
    }
    free(log_dir);
  }
  return result;
}
Exemplo n.º 27
0
int is_whitelisted(const char *user) {
  char **whitelist = get_values(ALLOWED_SYSTEM_USERS_KEY);
  char **users = whitelist;
  if (whitelist != NULL) {
    for(; *users; ++users) {
      if (strncmp(*users, user, LOGIN_NAME_MAX) == 0) {
        free_values(whitelist);
        return 1;
      }
    }
    free_values(whitelist);
  }
  return 0;
}
Exemplo n.º 28
0
void GuiWidgetList::UpdateList(const std::string & vnum)
{
	if (!get_values.connected())
		return;

	std::istringstream s(vnum);
	s >> m_list_size;

	if (m_list_size <= m_list_offset)
		m_list_offset = m_list_size - m_list_size % (m_rows * m_cols);

	m_values.resize(m_rows * m_cols);
	get_values(m_list_offset, m_values);
}
Exemplo n.º 29
0
void create_userlogs_dir() {
    char** tt_roots = get_values("mapred.local.dir");
    char** tt_root;
    for(tt_root=tt_roots; *tt_root != NULL; ++tt_root) {
        char buffer[100000];
        sprintf(buffer, "%s/userlogs", *tt_root);
        if (mkdir(buffer, 0755) != 0) {
            printf("FAIL: Can't create directory %s - %s\n", buffer,
                   strerror(errno));
            exit(1);
        }
    }
    free_values(tt_roots);
}
Exemplo n.º 30
0
bgfx_suppressor* suppressor_reader::read_from_value(const Value& value, std::string prefix, std::map<std::string, bgfx_slider*>& sliders)
{
	if (!validate_parameters(value, prefix))
	{
		return nullptr;
	}

	std::string name = value["name"].GetString();
	uint32_t condition = uint32_t(get_enum_from_value(value, "condition", bgfx_suppressor::condition_type::CONDITION_EQUAL, CONDITION_NAMES, CONDITION_COUNT));
	bgfx_suppressor::combine_mode mode = bgfx_suppressor::combine_mode(get_enum_from_value(value, "combine", bgfx_suppressor::combine_mode::COMBINE_OR, COMBINE_NAMES, COMBINE_COUNT));

	std::vector<bgfx_slider*> check_sliders;
	check_sliders.push_back(sliders[name + "0"]);

	int slider_count;
	switch (check_sliders[0]->type())
	{
		case bgfx_slider::slider_type::SLIDER_FLOAT:
		case bgfx_slider::slider_type::SLIDER_INT:
		case bgfx_slider::slider_type::SLIDER_INT_ENUM:
			slider_count = 1;
			break;
		case bgfx_slider::slider_type::SLIDER_VEC2:
			slider_count = 2;
			break;
		case bgfx_slider::slider_type::SLIDER_COLOR:
			slider_count = 3;
			break;
		default:
			slider_count = 0;
			break;
	}

	int values[4];
	if (slider_count > 1)
	{
		get_values(value, prefix, "value", values, slider_count);
		if (!READER_CHECK(slider_count == value["value"].GetArray().Size(), (prefix + "Expected " + std::to_string(slider_count) + " values, got " + std::to_string(value["value"].GetArray().Size()) + "\n").c_str())) return nullptr;
		for (int index = 1; index < slider_count; index++)
		{
			check_sliders.push_back(sliders[name + std::to_string(index)]);
		}
	}
	else
	{
		values[0] = get_int(value, "value", 0);
	}

	return new bgfx_suppressor(check_sliders, condition, mode, values);
}