Beispiel #1
0
/*
 * Gets a reply from the MongoDB server and
 * creates a cursor for it
 */
int mongo_link_hear(SV *cursor_sv) {
  int sock;
  int num_returned = 0;
  mongo_cursor *cursor = (mongo_cursor*)perl_mongo_get_ptr_from_instance(cursor_sv);
  SV *link_sv = perl_mongo_call_reader(cursor_sv, "_connection");
  mongo_link *link = (mongo_link*)perl_mongo_get_ptr_from_instance(link_sv);

  if (!check_connection(link)) {
    croak("can't get db response, not connected");
    return 0;
  }

  sock = perl_mongo_link_master(link_sv);

  // if this fails, we might be disconnected... but we're probably
  // just out of results
  if (recv(sock, (char*)&cursor->header.length, INT_32, 0) == -1) {
    return 0;
  }

  // make sure we're not getting crazy data
  if (cursor->header.length > MAX_RESPONSE_LEN ||
      cursor->header.length < REPLY_HEADER_SIZE) {

    set_disconnected(link);

    if (!check_connection(link)) {
      croak("bad response length: %d, max: %d, did the db assert?\n", cursor->header.length, MAX_RESPONSE_LEN);
      return 0;
    }
  }

  if (recv(sock, (char*)&cursor->header.request_id, INT_32, 0) == -1 ||
      recv(sock, (char*)&cursor->header.response_to, INT_32, 0) == -1 ||
      recv(sock, (char*)&cursor->header.op, INT_32, 0) == -1 ||
      recv(sock, (char*)&cursor->flag, INT_32, 0) == -1 ||
      recv(sock, (char*)&cursor->cursor_id, INT_64, 0) == -1 ||
      recv(sock, (char*)&cursor->start, INT_32, 0) == -1 ||
      recv(sock, (char*)&num_returned, INT_32, 0) == -1) {
    return 0;
  }

  // create buf
  cursor->header.length -= INT_32*9;

  // point buf.start at buf's first char
  if (!cursor->buf.start) {
    Newx(cursor->buf.start, cursor->header.length, char);
    cursor->buf.end = cursor->buf.start + cursor->header.length;
  }
Beispiel #2
0
static VALUE method_to_s(VALUE self) {
    if (check_connection(self)) {
        VALUE array = method_all_inputs(self);
        rb_define_variable("arry", &array);
        return rb_eval_string("$arry.join(';')");
    }
}
Beispiel #3
0
extern int as_mysql_node_up(mysql_conn_t *mysql_conn,
			    struct node_record *node_ptr,
			    time_t event_time)
{
	char* query;
	int rc = SLURM_SUCCESS;

	if (check_connection(mysql_conn) != SLURM_SUCCESS)
		return ESLURM_DB_CONNECTION;

	if (!mysql_conn->cluster_name) {
		error("%s:%d no cluster name", THIS_FILE, __LINE__);
		return SLURM_ERROR;
	}

	query = xstrdup_printf(
		"update \"%s_%s\" set time_end=%ld where "
		"time_end=0 and node_name='%s';",
		mysql_conn->cluster_name, event_table,
		event_time, node_ptr->name);
	debug4("%d(%s:%d) query\n%s",
	       mysql_conn->conn, THIS_FILE, __LINE__, query);
	rc = mysql_db_query(mysql_conn, query);
	xfree(query);
	return rc;
}
Beispiel #4
0
int FastSerial::available(void)
{
	struct tcp_state *s = &tcp_state[_u2x];

	check_connection(s);

	if (!s->connected) {
		return 0;
	}

	if (select_check(s->fd)) {
#ifdef FIONREAD
		// use FIONREAD to get exact value if possible
		int num_ready;
		if (ioctl(s->fd, FIONREAD, &num_ready) == 0) {
			if (num_ready > BUFFER_SIZE) {
				return BUFFER_SIZE;
			}
			if (num_ready == 0) {
				// EOF is reached
				fprintf(stdout, "Closed connection on serial port %u\n", s->serial_port);
				close(s->fd);
				s->connected = false;
				return 0;
			}
			return num_ready;
		}
#endif
		return 1; // best we can do is say 1 byte available
	}
	return 0;
}
Beispiel #5
0
/**
 * 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;
  
}
Beispiel #6
0
extern List as_mysql_remove_wckeys(mysql_conn_t *mysql_conn,
                                   uint32_t uid,
                                   slurmdb_wckey_cond_t *wckey_cond)
{
    List ret_list = NULL;
    int rc = SLURM_SUCCESS;
    char *extra = NULL, *object = NULL;
    char *user_name = NULL;
    List use_cluster_list = as_mysql_cluster_list;
    ListIterator itr;

    if (!wckey_cond) {
        xstrcat(extra, " where deleted=0");
        goto empty;
    }

    if (check_connection(mysql_conn) != SLURM_SUCCESS)
        return NULL;

    if (!is_user_min_admin_level(mysql_conn, uid, SLURMDB_ADMIN_OPERATOR)) {
        errno = ESLURM_ACCESS_DENIED;
        return NULL;
    }

    (void) _setup_wckey_cond_limits(wckey_cond, &extra);

    if (wckey_cond->cluster_list && list_count(wckey_cond->cluster_list))
        use_cluster_list = wckey_cond->cluster_list;
empty:
    if (!extra) {
        error("Nothing to remove");
        return NULL;
    }

    user_name = uid_to_string((uid_t) uid);

    if (use_cluster_list == as_mysql_cluster_list)
        slurm_mutex_lock(&as_mysql_cluster_list_lock);
    ret_list = list_create(slurm_destroy_char);
    itr = list_iterator_create(use_cluster_list);
    while ((object = list_next(itr))) {
        if ((rc = _cluster_remove_wckeys(
                      mysql_conn, extra, object, user_name, ret_list))
                != SLURM_SUCCESS)
            break;
    }
    list_iterator_destroy(itr);
    xfree(extra);
    xfree(user_name);

    if (use_cluster_list == as_mysql_cluster_list)
        slurm_mutex_unlock(&as_mysql_cluster_list_lock);

    if (rc == SLURM_ERROR) {
        list_destroy(ret_list);
        return NULL;
    }

    return ret_list;
}
Beispiel #7
0
static int lconn_command(lua_State * L)
{
  redisContext * pContext = check_connection(L, 1);

  const char * argv[LUAHIREDIS_MAXARGS];
  size_t argvlen[LUAHIREDIS_MAXARGS];
  int nargs = load_args(L, pContext, 2, argv, argvlen);

  int nret = 0;

  redisReply * pReply = (redisReply *)redisCommandArgv(
      pContext, nargs, argv, argvlen
    );
  if (pReply == NULL)
  {
    /* TODO: Shouldn't we clear the context error state somehow after this? */
    return push_error(L, pContext);
  }

  nret = push_reply(L, pReply);

  /*
  * TODO: Not entirely safe: if above code throws error, reply object is leaked.
  */
  freeReplyObject(pReply);
  pReply = NULL;

  return nret;
}
Beispiel #8
0
extern int as_mysql_node_down(mysql_conn_t *mysql_conn,
			      struct node_record *node_ptr,
			      time_t event_time, char *reason,
			      uint32_t reason_uid)
{
	uint16_t cpus;
	int rc = SLURM_SUCCESS;
	char *query = NULL;
	char *my_reason;

	if (check_connection(mysql_conn) != SLURM_SUCCESS)
		return ESLURM_DB_CONNECTION;

	if (!node_ptr) {
		error("No node_ptr given!");
		return SLURM_ERROR;
	}

	if (slurmctld_conf.fast_schedule && !slurmdbd_conf)
		cpus = node_ptr->config_ptr->cpus;
	else
		cpus = node_ptr->cpus;

	if (reason)
		my_reason = slurm_add_slash_to_quotes(reason);
	else
		my_reason = slurm_add_slash_to_quotes(node_ptr->reason);

	debug2("inserting %s(%s) with %u cpus",
	       node_ptr->name, mysql_conn->cluster_name, cpus);

	query = xstrdup_printf(
		"update \"%s_%s\" set time_end=%ld where "
		"time_end=0 and node_name='%s';",
		mysql_conn->cluster_name, event_table,
		event_time, node_ptr->name);
	/* If you are clean-restarting the controller over and over again you
	 * could get records that are duplicates in the database.  If
	 * this is the case we will zero out the time_end we are
	 * just filled in.  This will cause the last time to be erased
	 * from the last restart, but if you are restarting things
	 * this often the pervious one didn't mean anything anyway.
	 * This way we only get one for the last time we let it run.
	 */
	xstrfmtcat(query,
		   "insert into \"%s_%s\" "
		   "(node_name, state, cpu_count, time_start, "
		   "reason, reason_uid) "
		   "values ('%s', %u, %u, %ld, '%s', %u) "
		   "on duplicate key update time_end=0;",
		   mysql_conn->cluster_name, event_table,
		   node_ptr->name, node_ptr->node_state,
		   cpus, event_time, my_reason, reason_uid);
	debug4("%d(%s:%d) query\n%s",
	       mysql_conn->conn, THIS_FILE, __LINE__, query);
	rc = mysql_db_query(mysql_conn, query);
	xfree(query);
	xfree(my_reason);
	return rc;
}
Beispiel #9
0
static int lconn_get_reply(lua_State * L)
{
  redisContext * pContext = check_connection(L, 1);

  int nret = 0;

  redisReply * pReply = NULL;

  int ok = redisGetReply(pContext, (void **)&pReply);
  if (ok != REDIS_OK || pReply == NULL)
  {
    /* TODO: Shouldn't we clear the context error state somehow after this? */
    return push_error(L, pContext);
  }

  nret = push_reply(L, pReply);

  /*
  * TODO: Not entirely safe: if above code throws error, reply object is leaked.
  */
  freeReplyObject(pReply);
  pReply = NULL;

  return nret;
}
Beispiel #10
0
/* Defines the used database. */
void command_use(cli_t *cli, char *pt) {
	int rc;

	// check connection if needed
	if (!check_connection(cli))
		return;
	// request
	if (!strlen(pt) || !strcasecmp(pt, "default")) {
		// use default database
		if ((rc = finedb_setdb(cli->finedb, NULL)) != 0) {
			printf_color("red", "Unable to use the default database (%d).", rc);
			printf("\n");
		} else {
			YFREE(cli->dbname);
			printf_decorated("faint", "Use the default database");
			printf("\n");
		}
	} else {
		// set a new database
		if ((rc = finedb_setdb(cli->finedb, pt)) != 0) {
			printf_color("red", "Unable to use the '%s' database (%d).", rc);
			printf("\n");
		} else {
			YFREE(cli->dbname);
			cli->dbname = strdup(pt);
			printf_decorated("faint", "Use the '%s' database", pt);
			printf("\n");
		}
	}
}
Beispiel #11
0
extern int as_mysql_register_ctld(mysql_conn_t *mysql_conn,
				  char *cluster, uint16_t port)
{
	char *query = NULL;
	char *address = NULL;
	char hostname[255];
	time_t now = time(NULL);
	uint32_t flags = slurmdb_setup_cluster_flags();
	int rc = SLURM_SUCCESS;

	if (slurmdbd_conf)
		fatal("clusteracct_storage_g_register_ctld "
		      "should never be called from the slurmdbd.");

	if (check_connection(mysql_conn) != SLURM_SUCCESS)
		return ESLURM_DB_CONNECTION;

	if (!mysql_conn->cluster_name) {
		error("%s:%d no cluster name", THIS_FILE, __LINE__);
		return SLURM_ERROR;
	}

	if (!mysql_conn->cluster_name)
		mysql_conn->cluster_name = xstrdup(cluster);

	info("Registering slurmctld for cluster %s at port %u in database.",
	     cluster, port);
	gethostname(hostname, sizeof(hostname));

	/* check if we are running on the backup controller */
	if (slurmctld_conf.backup_controller
	    && !strcmp(slurmctld_conf.backup_controller, hostname)) {
		address = slurmctld_conf.backup_addr;
	} else
		address = slurmctld_conf.control_addr;

	query = xstrdup_printf(
		"update %s set deleted=0, mod_time=%ld, "
		"control_host='%s', control_port=%u, last_port=%u, "
		"rpc_version=%d, dimensions=%d, flags=%u, "
		"plugin_id_select=%d where name='%s';",
		cluster_table, now, address, port, port, SLURM_PROTOCOL_VERSION,
		SYSTEM_DIMENSIONS, flags, select_get_plugin_id(), cluster);
	xstrfmtcat(query,
		   "insert into %s "
		   "(timestamp, action, name, actor, info) "
		   "values (%ld, %d, '%s', '%s', '%s %u %u %u %u');",
		   txn_table,
		   now, DBD_MODIFY_CLUSTERS, cluster,
		   slurmctld_conf.slurm_user_name, address, port,
		   SYSTEM_DIMENSIONS, flags, select_get_plugin_id());

	if (debug_flags & DEBUG_FLAG_DB_ASSOC)
		DB_DEBUG(mysql_conn->conn, "query\n%s", query);

	rc = mysql_db_query(mysql_conn, query);
	xfree(query);
	return rc;
}
Beispiel #12
0
static VALUE method_set_all_digital(VALUE self) {
    if (check_connection(self)) {
        if (SetAllDigital() != -1)
            return Qtrue;
        printf("K8055 returned an error.\n");
        return Qfalse;
    }
}
Beispiel #13
0
void Canddisp::show()
{
    if (!candwin_w)
	return;
    fprintf(candwin_w, "show\f\f");
    fflush(candwin_w);
    check_connection();
}
Beispiel #14
0
void Canddisp::deactivate()
{
    if (!candwin_w)
	return;
    fprintf(candwin_w, "deactivate\f\f");
    fflush(candwin_w);
    check_connection();
}
Beispiel #15
0
void Canddisp::hide_caret_state()
{
    if (!candwin_w)
	return;
    fprintf(candwin_w, "hide_caret_state\f\f");
    fflush(candwin_w);
    check_connection();
}
Beispiel #16
0
static VALUE method_clear_all_analog(VALUE self) {
    if (check_connection(self)) {
        if (ClearAllAnalog() != -1)
            return Qtrue;
        printf("K8055 returned an error.\n");
        return Qfalse;
    }
}
Beispiel #17
0
static int lconn_tostring(lua_State * L)
{
  /* redisContext * pContext = */check_connection(L, 1);

  /* TODO: Provide more information? */
  lua_pushliteral(L, "lua-hiredis.connection");

  return 1;
}
Beispiel #18
0
static VALUE method_write_all_digital(VALUE self, int value) {
    if (check_connection(self)) {
        value = NUM2INT(value);
        if (WriteAllDigital(value) != -1)
            return Qtrue;
        printf("K8055 returned an error.\n");
        return Qfalse;
    }
}
Beispiel #19
0
void Canddisp::select(int index, bool need_hilite)
{
    if (!candwin_w)
	return;
    fprintf(candwin_w, "select\f");
    fprintf(candwin_w, "%d\f", index);
    fprintf(candwin_w, "%d\f\f", need_hilite? 1 : 0);
    fflush(candwin_w);
    check_connection();
}
Beispiel #20
0
static int lconn_tostring(lua_State * L)
{
  check_connection(L, 1);

  /* TODO: Provide more information? */
  luaL_checkstack(L, 1, "not enough stack to push reply");
  lua_pushliteral(L, "lua-hiredis.connection");

  return 1;
}
static void
check_account (EmpathyConnectionAggregator *self,
    TpAccount *account)
{
  TpConnection *conn;

  conn = tp_account_get_connection (account);
  if (conn != NULL)
    check_connection (self, conn);
}
extern int as_mysql_fix_runaway_jobs(mysql_conn_t *mysql_conn, uint32_t uid,
				     List runaway_jobs)
{
	char *query = NULL, *job_ids = NULL;
	slurmdb_job_rec_t *job = NULL;
	ListIterator iter = NULL;
	int rc = SLURM_SUCCESS;
	slurmdb_job_rec_t *first_job;

	list_sort(runaway_jobs, _job_sort_by_start_time);
	first_job = list_peek(runaway_jobs);

	if (check_connection(mysql_conn) != SLURM_SUCCESS)
		return ESLURM_DB_CONNECTION;

	if (!is_user_min_admin_level(mysql_conn, uid, SLURMDB_ADMIN_OPERATOR)) {
		slurmdb_user_rec_t user;

		memset(&user, 0, sizeof(slurmdb_user_rec_t));
		user.uid = uid;

		if (!is_user_any_coord(mysql_conn, &user)) {
			error("Only admins/operators/coordinators "
			      "can fix runaway jobs");
			return ESLURM_ACCESS_DENIED;
		}
	}

	iter = list_iterator_create(runaway_jobs);
	while ((job = list_next(iter))) {
		xstrfmtcat(job_ids, "%s%d", ((job_ids) ? "," : ""), job->jobid);
	}

	query = xstrdup_printf("UPDATE \"%s_%s\" SET time_end="
			       "GREATEST(time_start, time_eligible, time_submit), "
			       "state=%d WHERE id_job IN (%s);",
			       mysql_conn->cluster_name, job_table,
			       JOB_COMPLETE, job_ids);

	if (debug_flags & DEBUG_FLAG_DB_QUERY)
		DB_DEBUG(mysql_conn->conn, "query\n%s", query);
	mysql_db_query(mysql_conn, query);
	xfree(query);
	xfree(job_ids);

	/* Set rollup to the the last day of the previous month of the first
	 * runaway job */
	rc = _first_job_roll_up(mysql_conn, first_job->start);
	if (rc != SLURM_SUCCESS) {
		error("Failed to fix runaway jobs");
		return SLURM_ERROR;
	}

	return rc;
}
Beispiel #23
0
void Canddisp::move(int x, int y)
{
    if (!candwin_w)
	return;
    fprintf(candwin_w, "move\f");
    fprintf(candwin_w, "%d\f", x);
    fprintf(candwin_w, "%d\f", y);
    fprintf(candwin_w, "\f");
    fflush(candwin_w);
    check_connection();
}
Beispiel #24
0
static VALUE method_reset_counter(VALUE self, long counter) {
    if (check_connection(self)) {
        counter = NUM2INT(counter);
        if (valid_counter(counter)) {
            if (ResetCounter(counter) != -1)
                return Qtrue;
        }
        printf("K8055 returned an error.\n");
        return Qfalse;
    }
}
Beispiel #25
0
/**
 * 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;
  
}
Beispiel #26
0
void Canddisp::show_page(int page)
{
    if (!candwin_w)
	return;

    fprintf(candwin_w, "show_page\f");
    fprintf(candwin_w, "%d\f", page);
    fprintf(candwin_w, "\f");
    fflush(candwin_w);
    check_connection();
}
Beispiel #27
0
void Canddisp::show_caret_state(const char *str, int timeout)
{
    if (!candwin_w)
	return;
    fprintf(candwin_w, "show_caret_state\f");
    fprintf(candwin_w, "%d\f", timeout);
    fprintf(candwin_w, "%s\f", str);
    fprintf(candwin_w, "\f");
    fflush(candwin_w);
    check_connection();
}
Beispiel #28
0
void Canddisp::set_nr_candidates(int nr, int display_limit)
{
    if (!candwin_w)
	return;

    fprintf(candwin_w, "set_nr_candidates\f");
    fprintf(candwin_w, "%d\f", nr);
    fprintf(candwin_w, "%d\f", display_limit);
    fprintf(candwin_w, "\f");
    fflush(candwin_w);
    check_connection();
}
Beispiel #29
0
static int lconn_append_command(lua_State * L)
{
  redisContext * pContext = check_connection(L, 1);

  const char * argv[LUAHIREDIS_MAXARGS];
  size_t argvlen[LUAHIREDIS_MAXARGS];
  int nargs = load_args(L, pContext, 2, argv, argvlen);

  redisAppendCommandArgv(pContext, nargs, argv, argvlen);

  return 0;
}
Beispiel #30
0
void dt_circle_note_on::update(){
	data.fire_rate*=0.8;

	if(dt_config::DT_PLAY_GEN_RHYTHM){
		data.position += data.move_speed;
	
		float deg = 360.0 * seq->indicator/seq->total_steps * DEG_TO_RAD;
		data.world_position = data.position + ofVec2f(cos(deg), sin(deg)) * data.rev_radius;
	
		check_connection();
	}
}