Пример #1
0
BOOST_CONTEXT_DECL
std::size_t pagesize()
{
    static std::size_t pagesize(
        static_cast< std::size_t >( system_info().dwPageSize) );
    return pagesize;
}
Пример #2
0
BOOST_CONTEXT_DECL
std::size_t minimum_stacksize()
{
    static std::size_t stacksize(
        static_cast< std::size_t >( system_info().dwAllocationGranularity) );
    return stacksize;
}
Пример #3
0
void do_reboot(USER_DATA *usr, char *argument) {
	DESC_DATA *d, *d_next;
	FILE *fp;
	char p_buf[100];
	char c_buf[100];
	extern int port;
	extern int control;

	if (!(fp = fopen(COPYOVER_FILE, "w"))) {
		send_to_user("ERROR: Could not open to save copyover.data\n\r", usr);
		bbs_bug("Do_copyover: Could not open to save %s", COPYOVER_FILE);
		return;
	}

	system_info("Rebooting, please reamin seated");
	for (d = desc_list; d; d = d_next) {
		USER_DATA *usr = d->user;
		d_next = d->next;

		if (!USR(d) || d->login > CON_LOGIN) {
			write_to_desc(d->descr, "\n\r\007Sorry, we are rebooting. "
				"Come back in a few minutes.\n\r", 0);
			close_socket(d);
		} else if (EDIT_MODE(USR(d)) != EDITOR_NONE) {
			write_to_desc(d->descr, "\n\r\007Sorry, we are rebooting. "
				"Come back in a few minutes.\n\r", 0);
			close_socket(d);
		} else {
			fprintf(fp, "%d %s %s %s %s\n", d->descr, usr->pBoard->short_name,
					usr->name, d->ident, d->host);
			save_user(usr);
		}
	}

	fprintf(fp, "-1\n");
	fclose(fp);

	fclose(fpReserve);

	sprintf(p_buf, "%d", port);
	sprintf(c_buf, "%d", control);
	execl(EXE_FILE, "bbs", p_buf, "copyover", c_buf, (char *) NULL);
	perror("Do_copyover: execl");
	send_to_user("ERROR: Copyover failed!\n\r", usr);
	fpReserve = fopen(NULL_FILE, "r");
}
inline
std::size_t pagesize()
{ return static_cast< std::size_t >( system_info().dwPageSize); }
Пример #5
0
/*
 * This is the function called from the main polling loop.
 *
 * It calls command functions to get strings of data, and sends them to the server.
 *
*/
int collect_and_send_metrics(int cycle) {
	int retval;
	char* command;
	
	StringInfoData commands;
	
	pgstat_report_activity(STATE_RUNNING, "Collecting metrics");
	
	initStringInfo(&commands);
	/*
	 * Populate first cycle command data.	These are executed on the first cycle
	 *	 of a restart.	The bgworker restars every N cycles, as listed at the bottom
	 *	 of the main loop in pgsampler.c.	
	 */
	if (cycle == 0) {
	
		command = restart_gucs();
		appendStringInfoString(&commands, command);
		if (strcmp(output_mode, "csv") == 0) 
			write_to_csv("restart_gucs", command);			
		pfree(command);

		command = relation_info();
		appendStringInfoString(&commands, command);
		if (strcmp(output_mode, "csv") == 0) 
			write_to_csv("stat_class", command);
		pfree(command);

		command = database_list();
		appendStringInfoString(&commands, command);
		if (strcmp(output_mode, "csv") == 0) 
			write_to_csv("databases", command);
		pfree(command);
		
		command = column_info();
		appendStringInfoString(&commands, command);
		if (strcmp(output_mode, "csv") == 0) 
			write_to_csv("columns", command);
		pfree(command);

		command = index_info();
		appendStringInfoString(&commands, command);
		if (strcmp(output_mode, "csv") == 0) 
			write_to_csv("indexes", command);
		pfree(command);

		command = column_stats();
		appendStringInfoString(&commands, command);
		if (strcmp(output_mode, "csv") == 0) 
			write_to_csv("stat_column", command);
		pfree(command);

		command = db_stats();
		appendStringInfoString(&commands, command);
		if (strcmp(output_mode, "csv") == 0) 
			write_to_csv("stat_database", command);
		pfree(command);

	}

	/* HEARTBEAT */
	if (cycle % heartbeat_seconds == 0) {
		command = heartbeat();
		appendStringInfoString(&commands, command);
		if (strcmp(output_mode, "csv") == 0) 
			write_to_csv("heartbeats", command);
		pfree(command);
	}

	/* SYSTEM INFO */
	if (cycle % system_seconds == 0) {
		command = system_info();	
		appendStringInfoString(&commands, command);
		if (strcmp(output_mode, "csv") == 0) 
			write_to_csv("stat_system", command);
		pfree(command);

		command = fs_info();
		appendStringInfoString(&commands, command);
		if (strcmp(output_mode, "csv") == 0) 
			write_to_csv("stat_filesystem", command);
		pfree(command);
	}

	/* */
	if (cycle % activity_seconds == 0) {
		command = activity_stats(); 
		appendStringInfoString(&commands, command);
		if (strcmp(output_mode, "csv") == 0) 
			write_to_csv("stat_activity", command);
		pfree(command);
	}

	if (cycle % replication_seconds == 0) {
		command = replication_stats(); 
		appendStringInfoString(&commands, command);
		if (strcmp(output_mode, "csv") == 0) 
			write_to_csv("stat_replication", command);
		pfree(command);
	}

	/*	*/
	if (cycle % bgwriter_seconds == 0) {
		command = bgwriter_stats();
		appendStringInfoString(&commands, command);
		if (strcmp(output_mode, "csv") == 0) 
			write_to_csv("stat_bgwriter", command);
		pfree(command);
	}
	
	if (cycle % guc_seconds == 0) {
		command = transient_gucs();
		appendStringInfoString(&commands, command);
		if (strcmp(output_mode, "csv") == 0) 
			write_to_csv("transient_gucs", command);
		pfree(command);
	}
	
	if (cycle % statements_seconds == 0) {
		command = stat_statements();
		appendStringInfoString(&commands, command);
		if (strcmp(output_mode, "csv") == 0) 
			write_to_csv("stat_statements", command);
		pfree(command);
	}

	/* */	
	if (cycle % relation_seconds == 0) {
		command = table_stats();
		appendStringInfoString(&commands, command);
		if (strcmp(output_mode, "csv") == 0) 
			write_to_csv("stat_table", command);
		pfree(command);
		
		command = index_stats();
		appendStringInfoString(&commands, command);
		if (strcmp(output_mode, "csv") == 0) 
			write_to_csv("stat_index", command);
		pfree(command);
		
		command = table_io_stats();
		appendStringInfoString(&commands, command);
		if (strcmp(output_mode, "csv") == 0) 
			write_to_csv("statio_user_tables", command);
		pfree(command);

		command = index_io_stats();
		appendStringInfoString(&commands, command);
		if (strcmp(output_mode, "csv") == 0) 
			write_to_csv("statio_user_indexes", command);
		pfree(command);

		command = function_stats();
		appendStringInfoString(&commands, command);
		if (strcmp(output_mode, "csv") == 0) 
			write_to_csv("stat_function", command);
		pfree(command);
	}



	/* Send / Write metrics based on output_mode */
	if (strcmp(output_mode, "network") == 0) {
		pgstat_report_activity(STATE_RUNNING, "Sending metrics to antenna");
		retval = send_data(commands.data);
		if (retval == NO_DATA_SENT) { //close socket and retry establishing connection and sending data.
		 	// elog(LOG, "reseting..."); //just a note to say reseting socket
			if (sockfd != 0) 
				shutdown(sockfd, SHUT_RDWR);

			sockfd = 0;
			retval = send_data(commands.data); // we ignore success or failure here.	drops data if fails.
		}
	}

	return 0;
}
Пример #6
0
void copyover_recover(void) {
	DESC_DATA *d;
	FILE *fp;
	char name[100];
	char host[STRING];
	char board[100];
	char user[100];
	int desc;
	bool fOld;

	log_string("Copyover: Copyover recovery initiated.");
	if (!(fp = fopen(COPYOVER_FILE, "r"))) {
		bbs_bug("Copyover_recover: Could not open to read %s", COPYOVER_FILE);
		exit(1);
	}

	unlink(COPYOVER_FILE);

	for (;;) {
		fscanf(fp, "%d %s %s %s %s\n", &desc, board, name, user, host);
		if (desc == -1)
			break;

		if (!write_to_desc(desc, "", 0)) {
			close(desc);
			continue;
		}

		d = new_desc();
		d->descr = desc;
		if (d->host)
			free_string(d->host);
		d->host = str_dup(host);
		if (d->ident)
			free_string(d->ident);
		d->ident = str_dup(user);
		d->next = desc_list;
		desc_list = d;
		d->login = CON_REBOOT_RECOVER;

		fOld = load_user(d, name);

		if (!fOld) {
			write_to_desc(
					desc,
					"\n\rSomehow, your user was lost in the reboot, sorry.\n\r",
					0);
			close_socket(d);
		} else {
			if (!d->user->pBoard)
				d->user->pBoard = board_lookup("lobby", FALSE);

			d->user->next = user_list;
			user_list = d->user;
			d->login = CON_LOGIN;
			USR(d)->logon = current_time;
			USR(d)->pBoard = board_lookup(board, FALSE);
			save_user(USR(d));
		}
	}

	system_info("Reboot recover complete");
	log_string("Copyover: Done.");
	fclose(fp);
	return;
}