mirror of
https://github.com/FirebirdSQL/firebird.git
synced 2025-01-24 02:43:03 +01:00
1) Cleanup
2) Some changes for the embedded server
This commit is contained in:
parent
d214defda1
commit
ef9fb69fa9
@ -310,18 +310,15 @@ TempDirectoryList::TempDirectoryList() : items(0)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const Firebird::PathName TempDirectoryList::GetConfigString() const
|
const Firebird::PathName TempDirectoryList::GetConfigString() const
|
||||||
{
|
{
|
||||||
const char* value;
|
const char* value;
|
||||||
if (!(value = Config::getTempDirectories()) &&
|
char tmp_buf[MAXPATHLEN];
|
||||||
|
if (!(value = Config::getTempDirectories())) {
|
||||||
// Temporary directory configuration has not been defined.
|
// Temporary directory configuration has not been defined.
|
||||||
// Let's make default configuration.
|
// Let's make default configuration.
|
||||||
!(value = getenv("FIREBIRD_TMP")) &&
|
gds__temp_dir(tmp_buf);
|
||||||
!(value = getenv("TMP")) &&
|
value = tmp_buf;
|
||||||
!(value = getenv("TEMP")))
|
|
||||||
{
|
|
||||||
value = WORKDIR;
|
|
||||||
}
|
}
|
||||||
return Firebird::PathName(value);
|
return Firebird::PathName(value);
|
||||||
}
|
}
|
||||||
|
@ -73,6 +73,7 @@
|
|||||||
|
|
||||||
#if defined(WIN_NT)
|
#if defined(WIN_NT)
|
||||||
#include <io.h>
|
#include <io.h>
|
||||||
|
#include <process.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/timeb.h>
|
#include <sys/timeb.h>
|
||||||
#endif
|
#endif
|
||||||
@ -154,6 +155,8 @@ static const TEXT gdslogid[] = "";
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static const char * FB_PID_FILE = "fb_%d";
|
||||||
|
|
||||||
#include "gen/sql_code.h"
|
#include "gen/sql_code.h"
|
||||||
#include "../jrd/thd.h"
|
#include "../jrd/thd.h"
|
||||||
#include "../jrd/gdsold.h"
|
#include "../jrd/gdsold.h"
|
||||||
@ -508,6 +511,7 @@ static const struct
|
|||||||
#define FB_ENV "FIREBIRD"
|
#define FB_ENV "FIREBIRD"
|
||||||
#define FB_LOCK_ENV "FIREBIRD_LOCK"
|
#define FB_LOCK_ENV "FIREBIRD_LOCK"
|
||||||
#define FB_MSG_ENV "FIREBIRD_MSG"
|
#define FB_MSG_ENV "FIREBIRD_MSG"
|
||||||
|
#define FB_TMP_ENV "FIREBIRD_TMP"
|
||||||
|
|
||||||
#ifdef WIN_NT
|
#ifdef WIN_NT
|
||||||
#define EXPAND_PATH(relative, absolute) _fullpath(absolute, relative, MAXPATHLEN)
|
#define EXPAND_PATH(relative, absolute) _fullpath(absolute, relative, MAXPATHLEN)
|
||||||
@ -1650,8 +1654,18 @@ void API_ROUTINE gds__prefix_lock(TEXT * string, const TEXT * root)
|
|||||||
|
|
||||||
if (ib_prefix_lock == NULL) {
|
if (ib_prefix_lock == NULL) {
|
||||||
if (!(ib_prefix_lock = getenv(FB_LOCK_ENV))) {
|
if (!(ib_prefix_lock = getenv(FB_LOCK_ENV))) {
|
||||||
|
#ifdef EMBEDDED
|
||||||
|
ib_prefix_lock = ib_prefix_lock_val;
|
||||||
|
gds__temp_dir(ib_prefix_lock);
|
||||||
|
// Generate filename based on the current PID
|
||||||
|
TEXT tmp_buf[MAXPATHLEN];
|
||||||
|
sprintf(tmp_buf, FB_PID_FILE, getpid());
|
||||||
|
sprintf(tmp_buf, root, tmp_buf);
|
||||||
|
root = tmp_buf;
|
||||||
|
#else
|
||||||
ib_prefix_lock = ib_prefix_lock_val;
|
ib_prefix_lock = ib_prefix_lock_val;
|
||||||
gds__prefix(ib_prefix_lock, "");
|
gds__prefix(ib_prefix_lock, "");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
strcat(ib_prefix_lock_val, ib_prefix_lock);
|
strcat(ib_prefix_lock_val, ib_prefix_lock);
|
||||||
@ -1688,7 +1702,7 @@ void API_ROUTINE gds__prefix_lock(TEXT * string, const TEXT * root)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check for the existence of an InterBase logical name. If there is
|
/* Check for the existence of a Firebird logical name. If there is
|
||||||
one use it, otherwise use the system directories. */
|
one use it, otherwise use the system directories. */
|
||||||
|
|
||||||
if (ISC_expand_logical_once
|
if (ISC_expand_logical_once
|
||||||
@ -2225,6 +2239,37 @@ void API_ROUTINE gds__sqlcode_s(ISC_STATUS * status_vector, ULONG * sqlcode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void API_ROUTINE gds__temp_dir(TEXT * buffer)
|
||||||
|
{
|
||||||
|
/**************************************
|
||||||
|
*
|
||||||
|
* g d s _ _ t e m p _ d i r
|
||||||
|
*
|
||||||
|
**************************************
|
||||||
|
*
|
||||||
|
* Functional description
|
||||||
|
* Return temporary directory.
|
||||||
|
*
|
||||||
|
**************************************/
|
||||||
|
TEXT * directory = 0;
|
||||||
|
if (!(directory = getenv(FB_TMP_ENV))) {
|
||||||
|
#ifdef WIN_NT
|
||||||
|
TEXT temp_dir[MAXPATHLEN];
|
||||||
|
DWORD len;
|
||||||
|
// This checks "TEMP" and "TMP" environment variables
|
||||||
|
if ((len = GetTempPath(sizeof(temp_dir), temp_dir)) &&
|
||||||
|
len < sizeof(temp_dir))
|
||||||
|
directory = temp_dir;
|
||||||
|
#else
|
||||||
|
directory = getenv("TMP"));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
if (!directory || strlen(directory) >= MAXPATHLEN)
|
||||||
|
directory = WORKFILE;
|
||||||
|
strcpy(buffer, directory);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void * API_ROUTINE gds__temp_file(
|
void * API_ROUTINE gds__temp_file(
|
||||||
BOOLEAN stdio_flag, TEXT * string,
|
BOOLEAN stdio_flag, TEXT * string,
|
||||||
TEXT * expanded_string, TEXT * dir, BOOLEAN unlink_flag)
|
TEXT * expanded_string, TEXT * dir, BOOLEAN unlink_flag)
|
||||||
@ -2247,25 +2292,22 @@ void * API_ROUTINE gds__temp_file(
|
|||||||
* via introducing two functions with different return types.
|
* via introducing two functions with different return types.
|
||||||
*
|
*
|
||||||
**************************************/
|
**************************************/
|
||||||
#ifdef WIN_NT
|
|
||||||
/* These are the characters used in temporary filenames. */
|
|
||||||
static const char letters[] = "abcdefghijklmnopqrstuvwxyz0123456789";
|
|
||||||
|
|
||||||
TEXT temp_dir[MAXPATHLEN];
|
TEXT temp_dir[MAXPATHLEN];
|
||||||
|
|
||||||
TEXT *directory = dir;
|
TEXT *directory = dir;
|
||||||
if (!directory && !(directory = getenv("FIREBIRD_TMP"))) {
|
if (!directory) {
|
||||||
DWORD len;
|
gds__temp_dir(temp_dir);
|
||||||
// This checks "TEMP" and "TMP" environment variables
|
|
||||||
if ((len = GetTempPath(sizeof(temp_dir), temp_dir)) &&
|
|
||||||
len < sizeof(temp_dir))
|
|
||||||
directory = temp_dir;
|
directory = temp_dir;
|
||||||
else
|
|
||||||
directory = WORKFILE;
|
|
||||||
}
|
}
|
||||||
if (strlen(directory) >= MAXPATHLEN-strlen(string)-strlen(TEMP_PATTERN)-2)
|
if (strlen(directory) >= MAXPATHLEN-strlen(string)-strlen(TEMP_PATTERN)-2)
|
||||||
return (void *)-1;
|
return (void *)-1;
|
||||||
|
|
||||||
void *result;
|
void *result;
|
||||||
|
|
||||||
|
#ifdef WIN_NT
|
||||||
|
/* These are the characters used in temporary filenames. */
|
||||||
|
static const char letters[] = "abcdefghijklmnopqrstuvwxyz0123456789";
|
||||||
|
|
||||||
_timeb t;
|
_timeb t;
|
||||||
_ftime(&t);
|
_ftime(&t);
|
||||||
__int64 randomness = t.time;
|
__int64 randomness = t.time;
|
||||||
@ -2299,14 +2341,8 @@ void * API_ROUTINE gds__temp_file(
|
|||||||
if (!(result = ib_fdopen((int) result, "w+b")))
|
if (!(result = ib_fdopen((int) result, "w+b")))
|
||||||
return (void *)-1;
|
return (void *)-1;
|
||||||
}
|
}
|
||||||
return result;
|
|
||||||
#else
|
#else
|
||||||
TEXT *directory = dir;
|
|
||||||
if (!directory && !(directory = getenv("FIREBIRD_TMP")) && !(directory = getenv("TMP")))
|
|
||||||
directory = WORKFILE;
|
|
||||||
TEXT file_name[MAXPATHLEN];
|
TEXT file_name[MAXPATHLEN];
|
||||||
if (strlen(directory) >= MAXPATHLEN-strlen(string)-strlen(TEMP_PATTERN)-2)
|
|
||||||
return (void *)-1;
|
|
||||||
strcpy(file_name, directory);
|
strcpy(file_name, directory);
|
||||||
if (file_name[strlen(file_name)-1] != '/')
|
if (file_name[strlen(file_name)-1] != '/')
|
||||||
strcat(file_name, "/");
|
strcat(file_name, "/");
|
||||||
@ -2318,7 +2354,7 @@ void * API_ROUTINE gds__temp_file(
|
|||||||
#else
|
#else
|
||||||
if (mktemp(file_name) == (char *)0)
|
if (mktemp(file_name) == (char *)0)
|
||||||
return (void *)-1;
|
return (void *)-1;
|
||||||
void *result;
|
|
||||||
do {
|
do {
|
||||||
result = (void *)open(file_name, O_RDWR | O_EXCL| O_CREAT);
|
result = (void *)open(file_name, O_RDWR | O_EXCL| O_CREAT);
|
||||||
} while (result == (void *)-1 && errno == EINTR);
|
} while (result == (void *)-1 && errno == EINTR);
|
||||||
@ -2335,8 +2371,9 @@ void * API_ROUTINE gds__temp_file(
|
|||||||
|
|
||||||
if (!expanded_string || unlink_flag)
|
if (!expanded_string || unlink_flag)
|
||||||
unlink(file_name);
|
unlink(file_name);
|
||||||
return result;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -121,6 +121,7 @@ void API_ROUTINE gds__qtoq(void*, void*);
|
|||||||
void API_ROUTINE gds__register_cleanup(FPTR_VOID_PTR, void*);
|
void API_ROUTINE gds__register_cleanup(FPTR_VOID_PTR, void*);
|
||||||
SLONG API_ROUTINE gds__sqlcode(ISC_STATUS*);
|
SLONG API_ROUTINE gds__sqlcode(ISC_STATUS*);
|
||||||
void API_ROUTINE gds__sqlcode_s(ISC_STATUS*, ULONG*);
|
void API_ROUTINE gds__sqlcode_s(ISC_STATUS*, ULONG*);
|
||||||
|
void API_ROUTINE gds__temp_dir(TEXT*);
|
||||||
void* API_ROUTINE gds__temp_file(BOOLEAN, TEXT*, TEXT*, TEXT* = NULL, BOOLEAN = FALSE);
|
void* API_ROUTINE gds__temp_file(BOOLEAN, TEXT*, TEXT*, TEXT* = NULL, BOOLEAN = FALSE);
|
||||||
void API_ROUTINE gds__unregister_cleanup(FPTR_VOID_PTR, void*);
|
void API_ROUTINE gds__unregister_cleanup(FPTR_VOID_PTR, void*);
|
||||||
BOOLEAN API_ROUTINE gds__validate_lib_path(TEXT*, TEXT*, TEXT*,
|
BOOLEAN API_ROUTINE gds__validate_lib_path(TEXT*, TEXT*, TEXT*,
|
||||||
|
Loading…
Reference in New Issue
Block a user