Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit158bc71

Browse files
author
Daniel Shelepanov
committed
[PBCKP-216] Setting C locale globally, env locale is only set while doing pg_probackup show
...in order to impose dot-based floating point representation for the results (including JSON-packed ones) of other commands
1 parent8bb0a61 commit158bc71

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

‎src/pg_probackup.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,9 @@ main(int argc, char *argv[])
311311
set_pglocale_pgservice(argv[0],PG_TEXTDOMAIN("pg_probackup"));
312312
PROGRAM_FULL_PATH=palloc0(MAXPGPATH);
313313

314+
// Setting C locale for numeric values in order to impose dot-based floating-point representation
315+
setlocale(LC_NUMERIC,"C");
316+
314317
/* Get current time */
315318
current_time=time(NULL);
316319

‎src/show.c

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* show.c: show backup information.
44
*
55
* Portions Copyright (c) 2009-2011, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
6-
* Portions Copyright (c) 2015-2019, Postgres Professional
6+
* Portions Copyright (c) 2015-2022, Postgres Professional
77
*
88
*-------------------------------------------------------------------------
99
*/
@@ -12,6 +12,7 @@
1212

1313
#include<time.h>
1414
#include<dirent.h>
15+
#include<locale.h>
1516
#include<sys/stat.h>
1617

1718
#include"utils/json.h"
@@ -71,6 +72,24 @@ static PQExpBufferData show_buf;
7172
staticboolfirst_instance= true;
7273
staticint32json_level=0;
7374

75+
typedefenum {
76+
LOCALE_PROBACKUP,
77+
LOCALE_ENV
78+
}output_numeric_locale;
79+
80+
staticvoidset_output_numeric_locale(output_numeric_localeloc) {
81+
constchar*l=loc==LOCALE_PROBACKUP ?"C" : (constchar*)getenv("LC_NUMERIC");
82+
// Setting environment-specified locale
83+
#ifdefHAVE_USELOCALE
84+
uselocale(newlocale(LC_NUMERIC_MASK,l, (locale_t)0));
85+
#else
86+
#ifdefHAVE__CONFIGTHREADLOCALE
87+
_configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
88+
#endif
89+
setlocale(LC_NUMERIC,l);
90+
#endif
91+
}
92+
7493
/*
7594
* Entry point of pg_probackup SHOW subcommand.
7695
*/
@@ -88,6 +107,7 @@ do_show(CatalogState *catalogState, InstanceState *instanceState,
88107
requested_backup_id!=INVALID_BACKUP_ID)
89108
elog(ERROR,"You cannot specify --archive and (-i, --backup-id) options together");
90109

110+
set_output_numeric_locale(LOCALE_ENV);
91111
/*
92112
* if instance is not specified,
93113
* show information about all instances in this backup catalog
@@ -110,6 +130,7 @@ do_show(CatalogState *catalogState, InstanceState *instanceState,
110130
show_instance(instanceState,INVALID_BACKUP_ID, true);
111131
}
112132
show_instance_end();
133+
set_output_numeric_locale(LOCALE_PROBACKUP);
113134

114135
return0;
115136
}
@@ -128,6 +149,7 @@ do_show(CatalogState *catalogState, InstanceState *instanceState,
128149
show_instance(instanceState,requested_backup_id, false);
129150

130151
show_instance_end();
152+
set_output_numeric_locale(LOCALE_PROBACKUP);
131153

132154
return0;
133155
}
@@ -141,6 +163,7 @@ do_show(CatalogState *catalogState, InstanceState *instanceState,
141163
else
142164
show_backup(instanceState,requested_backup_id);
143165

166+
set_output_numeric_locale(LOCALE_PROBACKUP);
144167
return0;
145168
}
146169
}
@@ -1045,8 +1068,9 @@ show_archive_json(const char *instance_name, uint32 xlog_seg_size,
10451068
appendPQExpBuffer(buf,"%lu",tlinfo->size);
10461069

10471070
json_add_key(buf,"zratio",json_level);
1071+
10481072
if (tlinfo->size!=0)
1049-
zratio= ((float)xlog_seg_size*tlinfo->n_xlog_files) /tlinfo->size;
1073+
zratio= ((float)xlog_seg_size*tlinfo->n_xlog_files) /tlinfo->size;
10501074
appendPQExpBuffer(buf,"%.2f",zratio);
10511075

10521076
if (tlinfo->closest_backup!=NULL)

‎src/utils/configuration.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818

1919
#include"getopt_long.h"
2020

21+
#ifndefWIN32
22+
#include<pwd.h>
23+
#endif
2124
#include<time.h>
2225

2326
#defineMAXPG_LSNCOMPONENT8

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp