Exemple #1
0
void TraceSvcUtil::runService(size_t spbSize, const UCHAR* spb)
{
	os_utils::CtrlCHandler ctrlCHandler;

	ISC_STATUS_ARRAY status;

	if (isc_service_start(status, &m_svcHandle, 0,
			static_cast<USHORT>(spbSize),
			reinterpret_cast<const char*>(spb)))
	{
		status_exception::raise(status);
	}

	const char query[] = {isc_info_svc_to_eof, isc_info_end};

	// use one second timeout to poll service
	char send[16];
	char* p = send;
	*p++ = isc_info_svc_timeout;
	ADD_SPB_LENGTH(p, 4);
	ADD_SPB_NUMERIC(p, 1);
	*p++ = isc_info_end;

	const USHORT sendSize = (p - send);

	char results[MAXBUF];
	bool noData;
	do
	{
		if (isc_service_query(status, &m_svcHandle, 0,
				sendSize, send,
				sizeof(query), query,
				sizeof(results) - 1, results))
		{
			status_exception::raise(status);
		}

		p = results;
		bool ignoreTruncation = false;
		bool dirty = false;
		noData = true;

		while (*p != isc_info_end)
		{
			const UCHAR item = *p++;
			switch (item)
			{
			case isc_info_svc_to_eof:
				ignoreTruncation = true;

			case isc_info_svc_line:
				{
					const unsigned short l = isc_vax_integer(p, sizeof(l));
					p += sizeof(l);
					if (l)
					{
						const char ch = p[l];
						p[l] = 0;
						fprintf(stdout, "%s", p);
						p[l] = ch;
						p += l;
						dirty = true;
					}
					noData = (l == 0);
				}
				break;

			case isc_info_truncated:
				if (!ignoreTruncation)
					return;
				break;

			case isc_info_svc_timeout:
			case isc_info_data_not_ready:
				noData = false;
				if (dirty)
				{
					fflush(stdout);
					dirty = false;
				}
				break;

			default:
				status_exception::raise(Arg::Gds(isc_fbsvcmgr_query_err) <<
										Arg::Num(static_cast<unsigned char>(p[-1])));
			}
		}
	} while (!(ctrlCHandler.getTerminated() || noData));
}
Exemple #2
0
int CLIB_ROUTINE main( int argc, char **argv)
{
/**************************************
*
*      m a i n
*
**************************************
*
*Functional Description
*  This utility uses the Firebird service api to inform the server
*  to print out the memory pool information into a specified file.
*  This utilitiy is for WIN_NT only, In case of UNIX ibmgr utility will
*  should be used.
*
*************************************************************************/
	char fname[512];

	if (argc != 2 && argc != 1)
	{
		printf("Usage %s \n      %s filename\n");
		exit(1);
	}
	if (argc == 1)
	{
		printf(" Filename : ");
		if (!fgets(fname, sizeof(fname), stdin))
			return 1;
		const size_t len = strlen(fname);
		if (!len)
			return 1;
		if (fname[len - 1] == '\n')
		{
			fname[len - 1] = 0;
			if (len == 1)
				return 1;
		}
	}
	else
	{
		fb_utils::copy_terminate(fname, argv[1], sizeof(fname));
		if (!fname[0])
			return 1;
	}

	printf("Filename to dump pool info = %s \n", fname);

	ISC_STATUS_ARRAY status;

	const char svc_name[] = "localhost:anonymous";
	isc_svc_handle svc_handle = NULL;
	if (isc_service_attach(status, 0, svc_name, &svc_handle, 0, NULL))
	{
		printf("Failed to attach service\n");
		return 1;
	}

	const unsigned short path_length = strlen(fname);

	char sendbuf[520]; // 512 + tag + length_word
	char* sptr = sendbuf;
	*sptr = isc_info_svc_dump_pool_info;
	++sptr;
	add_word(sptr, path_length);
	strcpy(sptr, fname);
	sptr += path_length;

	char respbuf[256];
	if (isc_service_query(status, &svc_handle, NULL, 0, NULL,
		sptr - sendbuf, sendbuf, sizeof(respbuf), respbuf))
	{
		printf("Failed to query service\n");
		isc_service_detach(status, &svc_handle);
		return 1;
	}

	isc_service_detach(status, &svc_handle);
	return 0;
}