#include "postgres_fe.h"#include "pg_upgrade.h"#include <signal.h>
Go to the source code of this file.
Functions | |
| void | report_status (eLogType type, const char *fmt,...) |
| void | end_progress_output (void) |
| void | prep_status (const char *fmt,...) |
| void | pg_log (eLogType type, char *fmt,...) |
| void | check_ok (void) |
| char * | quote_identifier (const char *s) |
| int | get_user_info (char **user_name) |
| const char * | getErrorText (int errNum) |
| unsigned int | str2uint (const char *str) |
| void | pg_putenv (const char *var, const char *val) |
Variables | |
| LogOpts | log_opts |
| void check_ok | ( | void | ) |
Definition at line 147 of file util.c.
References PG_REPORT, and report_status().
Referenced by adjust_data_dir(), bootstrap_template1(), check_cluster_versions(), check_for_isn_and_int8_passing_mismatch(), check_for_prepared_transactions(), check_for_reg_data_type_usage(), check_is_super_user(), check_loadable_libraries(), copy_clog_xlog_xid(), copy_subdir_files(), create_data_directory(), create_new_objects(), create_script_for_cluster_analyze(), create_script_for_old_cluster_deletion(), create_xlog_symlink(), disable_old_cluster(), generate_old_dump(), get_set_pwd(), initialize_data_directory(), issue_warnings(), load_plpgsql(), main(), make_postgres(), make_template0(), new_9_0_populate_pg_largeobject_metadata(), old_8_3_check_for_name_data_type_usage(), old_8_3_check_for_tsquery_usage(), old_8_3_check_ltree_usage(), old_8_3_create_sequence_script(), old_8_3_invalidate_bpchar_pattern_ops_indexes(), old_8_3_invalidate_hash_gin_indexes(), old_8_3_rebuild_tsvector_tables(), perform_fsync(), prepare_new_cluster(), prepare_new_databases(), set_frozenxids(), setup_auth(), setup_collation(), setup_config(), setup_conversion(), setup_depend(), setup_description(), setup_dictionary(), setup_privileges(), setup_schema(), setup_sysviews(), transfer_all_new_tablespaces(), uninstall_support_functions_from_new_cluster(), and vacuum_db().
{
/* all seems well */
report_status(PG_REPORT, "ok");
fflush(stdout);
}
| void end_progress_output | ( | void | ) |
Definition at line 40 of file util.c.
References prep_status().
Referenced by create_new_objects(), generate_old_dump(), and transfer_all_new_tablespaces().
{
/*
* In case nothing printed; pass a space so gcc doesn't complain about
* empty format string.
*/
prep_status(" ");
}
| int get_user_info | ( | char ** | user_name | ) |
Definition at line 188 of file util.c.
References pg_strdup().
Referenced by parseCommandLine().
{
int user_id;
#ifndef WIN32
struct passwd *pw = getpwuid(geteuid());
user_id = geteuid();
#else /* the windows code */
struct passwd_win32
{
int pw_uid;
char pw_name[128];
} pass_win32;
struct passwd_win32 *pw = &pass_win32;
DWORD pwname_size = sizeof(pass_win32.pw_name) - 1;
GetUserName(pw->pw_name, &pwname_size);
user_id = 1;
#endif
*user_name = pg_strdup(pw->pw_name);
return user_id;
}
| const char* getErrorText | ( | int | errNum | ) |
Definition at line 225 of file util.c.
References _dosmaperr(), pg_strdup(), and strerror().
Referenced by adjust_data_dir(), check_bin_dir(), check_data_dir(), check_for_isn_and_int8_passing_mismatch(), check_for_reg_data_type_usage(), check_hard_link(), check_loadable_libraries(), copyAndUpdateFile(), create_script_for_cluster_analyze(), create_script_for_old_cluster_deletion(), get_bin_version(), get_control_data(), linkAndUpdateFile(), new_9_0_populate_pg_largeobject_metadata(), old_8_3_check_for_name_data_type_usage(), old_8_3_check_for_tsquery_usage(), old_8_3_check_ltree_usage(), old_8_3_create_sequence_script(), old_8_3_invalidate_bpchar_pattern_ops_indexes(), old_8_3_invalidate_hash_gin_indexes(), old_8_3_rebuild_tsvector_tables(), pid_lock_file_exists(), setup(), transfer_relfile(), and validate_exec().
{
#ifdef WIN32
_dosmaperr(GetLastError());
#endif
return pg_strdup(strerror(errNum));
}
| void pg_log | ( | eLogType | type, | |
| char * | fmt, | |||
| ... | ||||
| ) |
Definition at line 84 of file util.c.
References _, LogOpts::internal, MESSAGE_WIDTH, NULL, PG_FATAL, PG_REPORT, PG_STATUS, PG_VERBOSE, PG_WARNING, LogOpts::verbose, and vsnprintf().
{
va_list args;
char message[MAX_STRING];
va_start(args, fmt);
vsnprintf(message, sizeof(message), fmt, args);
va_end(args);
/* PG_VERBOSE and PG_STATUS are only output in verbose mode */
/* fopen() on log_opts.internal might have failed, so check it */
if (((type != PG_VERBOSE && type != PG_STATUS) || log_opts.verbose) &&
log_opts.internal != NULL)
{
if (type == PG_STATUS)
/* status messages need two leading spaces and a newline */
fprintf(log_opts.internal, " %s\n", message);
else
fprintf(log_opts.internal, "%s", message);
fflush(log_opts.internal);
}
switch (type)
{
case PG_VERBOSE:
if (log_opts.verbose)
printf("%s", _(message));
break;
case PG_STATUS:
/* for output to a display, do leading truncation and append \r */
if (isatty(fileno(stdout)))
/* -2 because we use a 2-space indent */
printf(" %s%-*.*s\r",
/* prefix with "..." if we do leading truncation */
strlen(message) <= MESSAGE_WIDTH - 2 ? "" : "...",
MESSAGE_WIDTH - 2, MESSAGE_WIDTH - 2,
/* optional leading truncation */
strlen(message) <= MESSAGE_WIDTH - 2 ? message :
message + strlen(message) - MESSAGE_WIDTH + 3 + 2);
else
printf(" %s\n", _(message));
break;
case PG_REPORT:
case PG_WARNING:
printf("%s", _(message));
break;
case PG_FATAL:
printf("\n%s", _(message));
printf("Failure, exiting\n");
exit(1);
break;
default:
break;
}
fflush(stdout);
}
| void pg_putenv | ( | const char * | var, | |
| const char * | val | |||
| ) |
Definition at line 253 of file util.c.
References pg_malloc(), putenv, and unsetenv.
Referenced by get_control_data(), and parseCommandLine().
{
if (val)
{
#ifndef WIN32
char *envstr = (char *) pg_malloc(strlen(var) +
strlen(val) + 2);
sprintf(envstr, "%s=%s", var, val);
putenv(envstr);
/*
* Do not free envstr because it becomes part of the environment on
* some operating systems. See port/unsetenv.c::unsetenv.
*/
#else
SetEnvironmentVariableA(var, val);
#endif
}
else
{
#ifndef WIN32
unsetenv(var);
#else
SetEnvironmentVariableA(var, "");
#endif
}
}
| void prep_status | ( | const char * | fmt, | |
| ... | ||||
| ) |
Definition at line 66 of file util.c.
References MESSAGE_WIDTH, pg_log(), PG_REPORT, and vsnprintf().
{
va_list args;
char message[MAX_STRING];
va_start(args, fmt);
vsnprintf(message, sizeof(message), fmt, args);
va_end(args);
if (strlen(message) > 0 && message[strlen(message) - 1] == '\n')
pg_log(PG_REPORT, "%s", message);
else
/* trim strings that don't end in a newline */
pg_log(PG_REPORT, "%-*s", MESSAGE_WIDTH, message);
}
| char* quote_identifier | ( | const char * | s | ) |
| void report_status | ( | eLogType | type, | |
| const char * | fmt, | |||
| ... | ||||
| ) |
| unsigned int str2uint | ( | const char * | str | ) |
Definition at line 240 of file util.c.
References NULL.
Referenced by get_control_data().
{
return strtoul(str, NULL, 10);
}
Definition at line 17 of file util.c.
Referenced by cleanup(), generate_old_dump(), get_db_and_rel_infos(), parseCommandLine(), prepare_new_cluster(), and print_maps().
1.7.1