Skip to content

Commit 4d63ca1

Browse files
committed
fixes: atomic inc for logger; consist. wide subst
- use an atomic increment for log file stamping, instead of a mutex; - correct the mixing of narrow and wide chars when escaping URL chars to be used in logging file name.
1 parent 92c3e41 commit 4d63ca1

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

driver/connect.c

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,10 @@ typedef struct {
9696
* HTTP headers used for all requests (Content-Type, Accept).
9797
*/
9898
static struct curl_slist *http_headers = NULL;
99-
/* this mutex protects a counter used to number DBC log files:
99+
/* counter used to number DBC log files:
100100
* the files are stamped with time (@ second resolution) and PID, which is not
101101
* enough to avoid name clashes. */
102-
esodbc_mutex_lt filelog_cnt_mux = SRWLOCK_INIT;
102+
volatile unsigned filelog_cnt = 0;
103103

104104
BOOL connect_init()
105105
{
@@ -645,17 +645,6 @@ static SQLRETURN test_connect(esodbc_dbc_st *dbc)
645645
RET_STATE(dbc->hdr.diag.state);
646646
}
647647

648-
static unsigned filelog_inc_counter()
649-
{
650-
static unsigned counter = 0;
651-
unsigned val;
652-
653-
ESODBC_MUX_LOCK(&filelog_cnt_mux);
654-
val = counter ++;
655-
ESODBC_MUX_UNLOCK(&filelog_cnt_mux);
656-
return val;
657-
}
658-
659648
static BOOL config_dbc_logging(esodbc_dbc_st *dbc, esodbc_dsn_attrs_st *attrs)
660649
{
661650
int cnt, level;
@@ -671,7 +660,7 @@ static BOOL config_dbc_logging(esodbc_dbc_st *dbc, esodbc_dsn_attrs_st *attrs)
671660
cnt = swprintf(ident.str, ident.cnt,
672661
WPFWP_LDESC "_" WPFWP_LDESC "_" "%d-%u",
673662
LWSTR(&attrs->server), LWSTR(&attrs->port),
674-
GetCurrentProcessId(), filelog_inc_counter());
663+
GetCurrentProcessId(), InterlockedIncrement(&filelog_cnt));
675664
if (cnt <= 0 || ident.cnt <= cnt) {
676665
ERRH(dbc, "failed to print log file identifier.");
677666
SET_HDIAG(dbc, SQL_STATE_HY000, "failed to print log file ID", 0);
@@ -689,11 +678,11 @@ static BOOL config_dbc_logging(esodbc_dbc_st *dbc, esodbc_dsn_attrs_st *attrs)
689678
case L'<':
690679
case L'>':
691680
case L'|':
692-
case '/':
693-
case '\\':
681+
case L'/':
682+
case L'\\':
694683
case L'?':
695-
case '*':
696-
case ':':
684+
case L'*':
685+
case L':':
697686
ident.str[cnt] = L'_';
698687
}
699688
}

0 commit comments

Comments
 (0)