Uncrustify maxscale
See script directory for method. The script to run in the top level MaxScale directory is called maxscale-uncrustify.sh, which uses another script, list-src, from the same directory (so you need to set your PATH). The uncrustify version was 0.66.
This commit is contained in:
@ -30,7 +30,7 @@
|
||||
*
|
||||
* For obvious reasons, it cannot use its own functions for reporting errors.
|
||||
*/
|
||||
#define LOG_ERROR(format, ...) do { fprintf(stderr, format, ##__VA_ARGS__); } while (false)
|
||||
#define LOG_ERROR(format, ...) do {fprintf(stderr, format, ##__VA_ARGS__);} while (false)
|
||||
|
||||
//
|
||||
// Helper functions
|
||||
@ -40,7 +40,8 @@ namespace
|
||||
|
||||
int open_fd(const std::string& filename)
|
||||
{
|
||||
int fd = open(filename.c_str(), O_WRONLY | O_APPEND | O_CREAT,
|
||||
int fd = open(filename.c_str(),
|
||||
O_WRONLY | O_APPEND | O_CREAT,
|
||||
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
|
||||
|
||||
if (fd == -1)
|
||||
@ -85,7 +86,6 @@ std::string get_ident()
|
||||
|
||||
return this_unit.ident;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace maxbase
|
||||
@ -108,7 +108,7 @@ std::unique_ptr<Logger> FileLogger::create(const std::string& filename)
|
||||
|
||||
if (fd != -1)
|
||||
{
|
||||
logger.reset(new (std::nothrow) FileLogger(fd, filename));
|
||||
logger.reset(new( std::nothrow) FileLogger(fd, filename));
|
||||
|
||||
if (logger)
|
||||
{
|
||||
@ -151,7 +151,7 @@ bool FileLogger::write(const char* msg, int len)
|
||||
|
||||
if (rc == -1)
|
||||
{
|
||||
if (should_log_error()) // Coarse error suppression
|
||||
if (should_log_error()) // Coarse error suppression
|
||||
{
|
||||
LOG_ERROR("Failed to write to log: %d, %s\n", errno, mxb_strerror(errno));
|
||||
}
|
||||
@ -186,9 +186,9 @@ bool FileLogger::rotate()
|
||||
// Private methods
|
||||
//
|
||||
|
||||
FileLogger::FileLogger(int fd, const std::string& filename):
|
||||
Logger(filename),
|
||||
m_fd(fd)
|
||||
FileLogger::FileLogger(int fd, const std::string& filename)
|
||||
: Logger(filename)
|
||||
, m_fd(fd)
|
||||
{
|
||||
}
|
||||
|
||||
@ -207,25 +207,27 @@ bool FileLogger::write_header()
|
||||
localtime_r(&t, &tm);
|
||||
|
||||
std::string ident = get_ident();
|
||||
char time_string[32]; // 26 would be enough, according to "man asctime".
|
||||
char time_string[32]; // 26 would be enough, according to "man asctime".
|
||||
asctime_r(&tm, time_string);
|
||||
|
||||
size_t size = ident.length() + 2 * sizeof(' ') + m_filename.length() + 2 * sizeof(' ') + strlen(time_string);
|
||||
size_t size = ident.length() + 2 * sizeof(' ') + m_filename.length() + 2 * sizeof(' ') + strlen(
|
||||
time_string);
|
||||
|
||||
char header[size + 2 + 1]; // For the 2 newlines and the trailing NULL.
|
||||
char header[size + 2 + 1]; // For the 2 newlines and the trailing NULL.
|
||||
sprintf(header, "\n\n%s %s %s", ident.c_str(), m_filename.c_str(), time_string);
|
||||
|
||||
char line[sizeof(header) - 1];
|
||||
memset(line, '-', sizeof(line) - 1);
|
||||
line[sizeof(line) - 1] = '\n';
|
||||
|
||||
bool ok = ::write(m_fd, header, sizeof(header) - 1) != -1 &&
|
||||
::write(m_fd, line, sizeof(line)) != -1;
|
||||
bool ok = ::write(m_fd, header, sizeof(header) - 1) != -1
|
||||
&& ::write(m_fd, line, sizeof(line)) != -1;
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
LOG_ERROR("Error: Writing log header failed due to %d, %s\n",
|
||||
errno, mxb_strerror(errno));
|
||||
errno,
|
||||
mxb_strerror(errno));
|
||||
}
|
||||
|
||||
return ok;
|
||||
@ -239,10 +241,16 @@ bool FileLogger::write_footer(const char* suffix)
|
||||
localtime_r(&t, &tm);
|
||||
|
||||
const char FORMAT[] = "%04d-%02d-%02d %02d:%02d:%02d";
|
||||
char time_string[20]; // 19 chars + NULL.
|
||||
char time_string[20]; // 19 chars + NULL.
|
||||
|
||||
sprintf(time_string, FORMAT,
|
||||
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
|
||||
sprintf(time_string,
|
||||
FORMAT,
|
||||
tm.tm_year + 1900,
|
||||
tm.tm_mon + 1,
|
||||
tm.tm_mday,
|
||||
tm.tm_hour,
|
||||
tm.tm_min,
|
||||
tm.tm_sec);
|
||||
|
||||
size_t size = sizeof(time_string) + 3 * sizeof(' ') + strlen(suffix) + sizeof('\n');
|
||||
|
||||
@ -253,16 +261,16 @@ bool FileLogger::write_footer(const char* suffix)
|
||||
memset(line, '-', sizeof(line) - 1);
|
||||
line[sizeof(line) - 1] = '\n';
|
||||
|
||||
bool ok = ::write(m_fd, header, sizeof(header) - 1) != -1 &&
|
||||
::write(m_fd, line, sizeof(line)) != -1;
|
||||
bool ok = ::write(m_fd, header, sizeof(header) - 1) != -1
|
||||
&& ::write(m_fd, line, sizeof(line)) != -1;
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
LOG_ERROR("Error: Writing log footer failed due to %d, %s\n",
|
||||
errno, mxb_strerror(errno));
|
||||
errno,
|
||||
mxb_strerror(errno));
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user