convert atypical env_universal_common logging

This is a quick and dirty conversion of the atypical, and undocumented,
logging done by env_universal_common.cpp to the usual `debug()` pattern. I
didn't want to drop the messages because they could be useful when
debugging future issues. So I simply converted them to the lowest debug
level using the normal debug() function.

Fixes #2887
This commit is contained in:
Kurtis Rader 2016-04-03 20:23:43 -07:00
parent 9dd6873e58
commit 411d573ba9
2 changed files with 14 additions and 26 deletions

View file

@ -498,7 +498,7 @@ void env_universal_t::load_from_fd(int fd, callback_data_list_t *callbacks)
const file_id_t current_file = file_id_for_fd(fd); const file_id_t current_file = file_id_for_fd(fd);
if (current_file == last_read_file) if (current_file == last_read_file)
{ {
UNIVERSAL_LOG("Sync elided based on fstat()"); debug(5, L"universal log sync elided based on fstat()");
} }
else else
{ {
@ -525,7 +525,7 @@ bool env_universal_t::load_from_path(const wcstring &path, callback_data_list_t
/* Check to see if the file is unchanged. We do this again in load_from_fd, but this avoids opening the file unnecessarily. */ /* Check to see if the file is unchanged. We do this again in load_from_fd, but this avoids opening the file unnecessarily. */
if (last_read_file != kInvalidFileID && file_id_for_path(path) == last_read_file) if (last_read_file != kInvalidFileID && file_id_for_path(path) == last_read_file)
{ {
UNIVERSAL_LOG("Sync elided based on fast stat()"); debug(5, L"universal log sync elided based on fast stat()");
return true; return true;
} }
@ -533,7 +533,7 @@ bool env_universal_t::load_from_path(const wcstring &path, callback_data_list_t
int fd = wopen_cloexec(path, O_RDONLY); int fd = wopen_cloexec(path, O_RDONLY);
if (fd >= 0) if (fd >= 0)
{ {
UNIVERSAL_LOG("Reading from file"); debug(5, L"universal log reading from file");
this->load_from_fd(fd, callbacks); this->load_from_fd(fd, callbacks);
close(fd); close(fd);
result = true; result = true;
@ -788,7 +788,7 @@ bool env_universal_t::open_and_acquire_lock(const wcstring &path, int *out_fd)
/* Returns true if modified variables were written, false if not. (There may still be variable changes due to other processes on a false return). */ /* Returns true if modified variables were written, false if not. (There may still be variable changes due to other processes on a false return). */
bool env_universal_t::sync(callback_data_list_t *callbacks) bool env_universal_t::sync(callback_data_list_t *callbacks)
{ {
UNIVERSAL_LOG("sync"); debug(5, L"universal log sync");
scoped_lock locker(lock); scoped_lock locker(lock);
/* Our saving strategy: /* Our saving strategy:
@ -810,7 +810,7 @@ bool env_universal_t::sync(callback_data_list_t *callbacks)
const wcstring &vars_path = explicit_vars_path.empty() ? default_vars_path() : explicit_vars_path; const wcstring &vars_path = explicit_vars_path.empty() ? default_vars_path() : explicit_vars_path;
if (vars_path.empty()) { if (vars_path.empty()) {
debug(2, "No universal variable path available"); debug(2, L"No universal variable path available");
return false; return false;
} }
@ -818,7 +818,7 @@ bool env_universal_t::sync(callback_data_list_t *callbacks)
if (modified.empty()) if (modified.empty())
{ {
this->load_from_path(vars_path, callbacks); this->load_from_path(vars_path, callbacks);
UNIVERSAL_LOG("No modifications"); debug(5, L"universal log no modifications");
return false; return false;
} }
@ -828,13 +828,13 @@ bool env_universal_t::sync(callback_data_list_t *callbacks)
int private_fd = -1; int private_fd = -1;
wcstring private_file_path; wcstring private_file_path;
UNIVERSAL_LOG("Performing full sync"); debug(5, L"universal log performing full sync");
/* Open the file */ /* Open the file */
if (success) if (success)
{ {
success = this->open_and_acquire_lock(vars_path, &vars_fd); success = this->open_and_acquire_lock(vars_path, &vars_fd);
if (! success) UNIVERSAL_LOG("open_and_acquire_lock() failed"); if (! success) debug(5, L"universal log open_and_acquire_lock() failed");
} }
/* Read from it */ /* Read from it */
@ -849,7 +849,7 @@ bool env_universal_t::sync(callback_data_list_t *callbacks)
if (success) if (success)
{ {
success = this->open_temporary_file(directory, &private_file_path, &private_fd); success = this->open_temporary_file(directory, &private_file_path, &private_fd);
if (! success) UNIVERSAL_LOG("open_temporary_file() failed"); if (! success) debug(5, L"universal log open_temporary_file() failed");
} }
/* Write to it */ /* Write to it */
@ -857,7 +857,7 @@ bool env_universal_t::sync(callback_data_list_t *callbacks)
{ {
assert(private_fd >= 0); assert(private_fd >= 0);
success = this->write_to_fd(private_fd, private_file_path); success = this->write_to_fd(private_fd, private_file_path);
if (! success) UNIVERSAL_LOG("write_to_fd() failed"); if (! success) debug(5, L"universal log write_to_fd() failed");
} }
if (success) if (success)
@ -867,9 +867,9 @@ bool env_universal_t::sync(callback_data_list_t *callbacks)
if (wstat(vars_path, &sbuf) >= 0) if (wstat(vars_path, &sbuf) >= 0)
{ {
if (fchown(private_fd, sbuf.st_uid, sbuf.st_gid) == -1) if (fchown(private_fd, sbuf.st_uid, sbuf.st_gid) == -1)
UNIVERSAL_LOG("fchown() failed"); debug(5, L"universal log fchown() failed");
if (fchmod(private_fd, sbuf.st_mode) == -1) if (fchmod(private_fd, sbuf.st_mode) == -1)
UNIVERSAL_LOG("fchmod() failed"); debug(5, L"universal log fchmod() failed");
} }
/* Linux by default stores the mtime with low precision, low enough that updates that occur in quick succession may /* Linux by default stores the mtime with low precision, low enough that updates that occur in quick succession may
@ -890,7 +890,7 @@ bool env_universal_t::sync(callback_data_list_t *callbacks)
/* Apply new file */ /* Apply new file */
success = this->move_new_vars_file_into_place(private_file_path, vars_path); success = this->move_new_vars_file_into_place(private_file_path, vars_path);
if (! success) UNIVERSAL_LOG("move_new_vars_file_into_place() failed"); if (! success) debug(5, L"universal log move_new_vars_file_into_place() failed");
} }
if (success) if (success)
@ -1745,9 +1745,3 @@ static bool bool_from_env_var(const char *name, bool default_value)
const char *var = getenv(name); const char *var = getenv(name);
return var ? from_string<bool>(var) : default_value; return var ? from_string<bool>(var) : default_value;
} }
bool universal_log_enabled()
{
return bool_from_env_var(UNIVERSAL_LOGGING_ENV_NAME, false);
}

View file

@ -167,13 +167,7 @@ public:
virtual bool notification_fd_became_readable(int fd); virtual bool notification_fd_became_readable(int fd);
}; };
bool universal_log_enabled();
#define UNIVERSAL_LOG(x) do { if (universal_log_enabled()) fprintf(stderr, "UNIVERSAL LOG: %s\n", x); } while (0)
/* Environment variable for requesting a particular universal notifier. See fetch_default_strategy_from_environment for names. */ /* Environment variable for requesting a particular universal notifier. See fetch_default_strategy_from_environment for names. */
#define UNIVERSAL_NOTIFIER_ENV_NAME "fish_universal_notifier" #define UNIVERSAL_NOTIFIER_ENV_NAME "fish_universal_notifier"
/* Environment variable for enabling universal variable logging (to stderr) */
#define UNIVERSAL_LOGGING_ENV_NAME "fish_universal_log"
#endif #endif