8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-31 12:43:02 +01:00
firebird-mirror/src/utilities/run_service.cpp

132 lines
3.3 KiB
C++
Raw Normal View History

2001-05-23 15:26:42 +02:00
/*
* PROGRAM: Service manager
* MODULE: run_service.cpp
* DESCRIPTION: Run a utility as a Firebird service
2001-05-23 15:26:42 +02:00
*
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
#include "firebird.h"
2004-04-29 00:36:29 +02:00
#include <stdio.h>
2001-05-23 15:26:42 +02:00
#include <string.h>
2003-11-08 17:40:17 +01:00
#include "../jrd/ibase.h"
2010-10-12 10:02:57 +02:00
#include "../yvalve/gds_proto.h"
2001-05-23 15:26:42 +02:00
2003-11-08 17:40:17 +01:00
static const SCHAR recv_items[] = { isc_info_svc_to_eof };
static const SCHAR send_timeout[] = { isc_info_svc_timeout, 1, 0, 30 };
2001-05-23 15:26:42 +02:00
int CLIB_ROUTINE main( int argc, char *argv[])
{
/**************************************
*
* m a i n
*
**************************************
*
* Functional description
* Initialize lock manager for process.
*
**************************************/
2009-07-03 12:44:55 +02:00
if (argc < 2)
{
2004-04-29 00:36:29 +02:00
printf("usage: run_service service_path [args]\n");
2001-05-23 15:26:42 +02:00
exit(FINI_ERROR);
}
2003-12-03 09:19:24 +01:00
const char* service_path = argv[1];
2001-05-23 15:26:42 +02:00
2003-12-03 09:19:24 +01:00
char spb_buffer[2048];
char* spb = spb_buffer;
2009-05-17 13:20:43 +02:00
const char* const spb_end = spb_buffer + sizeof(spb_buffer) - 1;
2009-01-18 12:29:24 +01:00
if (argc > 2)
{
2003-11-08 17:40:17 +01:00
*spb++ = isc_spb_version1;
*spb++ = isc_spb_command_line;
2001-05-23 15:26:42 +02:00
spb++;
2009-07-03 12:44:55 +02:00
for (argv += 2, argc -= 2; argc && spb < spb_end; --argc)
{
2009-05-20 02:45:45 +02:00
for (const char* p = *argv++; spb < spb_end && (*spb = *p++); spb++)
;
2001-05-23 15:26:42 +02:00
*spb++ = ' ';
}
*--spb = 0;
2009-05-17 13:20:43 +02:00
fb_assert(spb < spb_end);
2001-05-23 15:26:42 +02:00
spb_buffer[2] = strlen(spb_buffer + 3);
}
2003-12-03 09:19:24 +01:00
SLONG* handle = NULL;
2009-01-18 12:29:24 +01:00
isc_service_attach(NULL, 0, service_path, &handle, (SSHORT) (spb - spb_buffer), spb_buffer);
2001-05-23 15:26:42 +02:00
2004-11-17 06:20:55 +01:00
SCHAR send_buffer[2048];
const char* send_items;
SSHORT send_item_length;
2009-07-03 12:44:55 +02:00
if (strstr(service_path, "start_cache"))
{
2001-05-23 15:26:42 +02:00
send_items = send_timeout;
send_item_length = sizeof(send_timeout);
}
2009-07-03 12:44:55 +02:00
else
{
2001-05-23 15:26:42 +02:00
send_items = send_buffer;
send_item_length = 0;
}
2009-07-03 12:44:55 +02:00
if (send_item_length)
{
2004-04-29 00:36:29 +02:00
printf
2001-05-23 15:26:42 +02:00
("It will take about 30 seconds to confirm that the cache manager\nis running. Please wait...\n");
2003-12-03 09:19:24 +01:00
}
2001-05-23 15:26:42 +02:00
2003-12-03 09:19:24 +01:00
char buffer[2048];
char item = isc_info_end;
2001-05-23 15:26:42 +02:00
do {
isc_service_query(NULL, &handle, send_item_length, send_items,
2009-01-18 12:29:24 +01:00
sizeof(recv_items), recv_items, sizeof(buffer), buffer);
2001-05-23 15:26:42 +02:00
if (send_items == send_buffer)
send_item_length = 0;
2003-12-03 09:19:24 +01:00
const char* p = buffer;
2009-01-18 12:29:24 +01:00
while (p < buffer + sizeof(buffer) && (item = *p) != isc_info_end &&
item != isc_info_truncated && item != isc_info_svc_timeout)
2003-12-03 09:19:24 +01:00
{
SSHORT len = gds__vax_integer(p + 1, 2);
2001-05-23 15:26:42 +02:00
p += 2;
2009-05-17 13:20:43 +02:00
while (len--)
{
2001-05-23 15:26:42 +02:00
p++;
if (*p != '\001')
putchar(*p);
2001-05-23 15:26:42 +02:00
}
2009-05-17 13:20:43 +02:00
if (*p++ == '\001')
{
2003-11-08 17:40:17 +01:00
send_buffer[0] = isc_info_svc_line;
2004-04-29 00:36:29 +02:00
fgets(send_buffer + 3, sizeof(send_buffer) - 3, stdin);
2001-05-23 15:26:42 +02:00
len = strlen(send_buffer + 3);
send_buffer[1] = len;
send_buffer[2] = len >> 8;
send_item_length = len + 3;
}
}
2008-12-31 06:06:08 +01:00
} while (item == isc_info_truncated || (send_items == send_buffer && send_item_length));
2001-05-23 15:26:42 +02:00
isc_service_detach(NULL, &handle);
2001-05-23 15:26:42 +02:00
exit(FINI_OK);
}