8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-30 20:03:03 +01:00
firebird-mirror/src/utilities/cache.cpp

157 lines
3.6 KiB
C++
Raw Normal View History

2001-05-23 15:26:42 +02:00
/*
* PROGRAM: JRD Shared Cache Manager
* MODULE: cache.cpp
2001-05-23 15:26:42 +02:00
* DESCRIPTION: Manage shared database cache
*
* 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 <stdlib.h>
#include <string.h>
#include <signal.h>
#include "../jrd/common.h"
2003-11-08 17:40:17 +01:00
#include "../jrd/ibase.h"
2001-05-23 15:26:42 +02:00
#include "../jrd/license.h"
#include "../jrd/gds_proto.h"
#include "../jrd/why_proto.h"
#ifdef HAVE_IO_H
2001-05-23 15:26:42 +02:00
#include <io.h>
#endif
2004-11-08 04:09:27 +01:00
// CVC: Obsolete functionality?
static const UCHAR cache_dpb[] = { isc_dpb_version1, isc_dpb_cache_manager };
2001-05-23 15:26:42 +02:00
int CLIB_ROUTINE main( int argc, char **argv)
{
/**************************************
*
* m a i n
*
**************************************
*
* Functional description
* Run the shared cache manager.
*
**************************************/
2009-05-17 13:20:43 +02:00
// Perform some special handling when run as a Firebird service. The
// first switch can be "-svc" (lower case!) or it can be "-svc_re" followed
// by 3 file descriptors to use in re-directing stdin, stdout, and stderr.
2001-05-23 15:26:42 +02:00
2009-01-14 12:10:48 +01:00
if (argc > 1 && !strcmp(argv[1], "-svc"))
{
2001-05-23 15:26:42 +02:00
argv++;
argc--;
}
2009-01-14 12:10:48 +01:00
else if (argc > 4 && !strcmp(argv[1], "-svc_re"))
{
long redir_in = atol(argv[2]);
long redir_out = atol(argv[3]);
long redir_err = atol(argv[4]);
2001-05-23 15:26:42 +02:00
#ifdef WIN_NT
redir_in = _open_osfhandle(redir_in, 0);
redir_out = _open_osfhandle(redir_out, 0);
redir_err = _open_osfhandle(redir_err, 0);
#endif
if (redir_in != 0)
if (dup2((int) redir_in, 0))
close((int) redir_in);
if (redir_out != 1)
if (dup2((int) redir_out, 1))
close((int) redir_out);
if (redir_err != 2)
if (dup2((int) redir_err, 2))
close((int) redir_err);
argv += 4;
argc -= 4;
}
#ifdef UNIX
if (setreuid(0, 0) < 0)
2004-04-29 00:36:29 +02:00
printf("Shared cache manager: couldn't set uid to superuser\n");
2001-05-23 15:26:42 +02:00
#ifdef HAVE_SETPGRP
#ifdef SETPGRP_VOID
2009-01-14 12:10:48 +01:00
setpgrp();
#else
2009-01-14 12:10:48 +01:00
setpgrp(0, 0);
2009-05-17 13:20:43 +02:00
#endif // SETPGRP_VOID
#else
#ifdef HAVE_SETPGID
2009-01-14 12:10:48 +01:00
setpgid(0, 0);
2009-05-17 13:20:43 +02:00
#endif // HAVE_SETPGID
#endif // HAVE_SETPGRP
2001-05-23 15:26:42 +02:00
signal(SIGINT, SIG_IGN);
signal(SIGQUIT, SIG_IGN);
#endif
const TEXT* sw_database = "";
2001-05-23 15:26:42 +02:00
2009-01-14 12:10:48 +01:00
for (TEXT** end = argv++ + argc; argv < end;)
{
2009-01-14 13:37:23 +01:00
const TEXT* p = *argv++;
2001-05-23 15:26:42 +02:00
if (*p != '-')
sw_database = p;
2009-01-14 12:10:48 +01:00
else
{
TEXT c;
2001-05-23 15:26:42 +02:00
while (c = *++p)
2009-01-15 04:46:48 +01:00
{
2009-01-14 12:10:48 +01:00
switch (UPPER(c))
{
2001-05-23 15:26:42 +02:00
case 'D':
sw_database = *argv++;
break;
case 'Z':
2009-01-14 12:10:48 +01:00
printf("Shared cache manager version %s\n", GDS_VERSION);
2001-05-23 15:26:42 +02:00
exit(FINI_OK);
}
2009-01-15 04:46:48 +01:00
}
2001-05-23 15:26:42 +02:00
}
}
gds__disable_subsystem("REMINT");
ISC_STATUS status;
2001-05-23 15:26:42 +02:00
do {
isc_db_handle db_handle = NULL;
ISC_STATUS_ARRAY status_vector;
2003-11-08 17:40:17 +01:00
status = isc_attach_database(status_vector, 0, sw_database, &db_handle,
2003-08-30 03:35:29 +02:00
sizeof(cache_dpb), cache_dpb);
2001-05-23 15:26:42 +02:00
2003-11-08 17:40:17 +01:00
if (status && status != isc_cache_restart) {
isc_print_status(status_vector);
2001-05-23 15:26:42 +02:00
gds__log_status(sw_database, status_vector);
}
if (db_handle)
2003-11-08 17:40:17 +01:00
isc_detach_database(status_vector, &db_handle);
2001-05-23 15:26:42 +02:00
2003-11-08 17:40:17 +01:00
} while (status == isc_cache_restart);
2001-05-23 15:26:42 +02:00
exit(status ? FINI_ERROR : FINI_OK);
}