Add .clang-format for automated style
Add a .clang-format style to enable automated style check to align code
format with rest of OpenBmc.
Change-Id: Ieace2b9135fa29a47be1aea21766a87b4e0b29b1
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/src/main.cpp b/src/main.cpp
index 7f58ef0..89b4f58 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -22,21 +22,19 @@
#include "dbus_server.hpp"
#include "dbus_watch.hpp"
#include "log_manager.hpp"
+
#include <getopt.h>
+
+#include <climits>
#include <cstdio>
#include <cstdlib>
-#include <climits>
-
// Global logger configuration instance
-Config loggerConfig = {
- .path = LOG_OUTPUT_PATH,
- .storageSizeLimit = LOG_STORAGE_SIZE_LIMIT,
- .storageTimeLimit = LOG_STORAGE_TIME_LIMIT,
- .flushPeriod = LOG_FLUSH_PERIOD,
- .rotationLimit = LOG_ROTATION_LIMIT
-};
-
+Config loggerConfig = {.path = LOG_OUTPUT_PATH,
+ .storageSizeLimit = LOG_STORAGE_SIZE_LIMIT,
+ .storageTimeLimit = LOG_STORAGE_TIME_LIMIT,
+ .flushPeriod = LOG_FLUSH_PERIOD,
+ .rotationLimit = LOG_ROTATION_LIMIT};
/** @brief Print title with version info. */
static void printTitle()
@@ -44,7 +42,6 @@
printf("Host logger service " PACKAGE_VERSION ".\n");
}
-
/** @brief Print help usage info.
*
* @param[in] app - application's file name
@@ -54,29 +51,29 @@
printTitle();
printf("Copyright (c) 2018 YADRO.\n");
printf("Usage: %s [options]\n", app);
- printf("Options (defaults are specified in brackets):\n"
- " -p, --path=PATH Path used to store logs [%s]\n"
- "Intermediate storage buffer capacity setup:\n"
- " -s, --szlimit=N Store up to N last messages [%i], 0=unlimited\n"
- " -t, --tmlimit=N Store messages for last N hours [%i], 0=unlimited\n"
- "Flush storage buffer policy:\n"
- " -f, --flush=N Flush logs every N hours [%i]\n"
- " If this option is set to 0 flush will be called at\n"
- " every host state change event from D-Bus.\n"
- "Log files rotation policy:\n"
- " -r, --rotate=N Store up to N files in the log directory [%i],\n"
- " 0=unlimited\n"
- "Common options:\n"
- " -v, --version Print version and exit\n"
- " -h, --help Print this help and exit\n",
- loggerConfig.path,
- loggerConfig.storageSizeLimit,
- loggerConfig.storageTimeLimit,
- loggerConfig.flushPeriod,
- loggerConfig.rotationLimit);
+ printf(
+ "Options (defaults are specified in brackets):\n"
+ " -p, --path=PATH Path used to store logs [%s]\n"
+ "Intermediate storage buffer capacity setup:\n"
+ " -s, --szlimit=N Store up to N last messages [%i], 0=unlimited\n"
+ " -t, --tmlimit=N Store messages for last N hours [%i], "
+ "0=unlimited\n"
+ "Flush storage buffer policy:\n"
+ " -f, --flush=N Flush logs every N hours [%i]\n"
+ " If this option is set to 0 flush will be called "
+ "at\n"
+ " every host state change event from D-Bus.\n"
+ "Log files rotation policy:\n"
+ " -r, --rotate=N Store up to N files in the log directory [%i],\n"
+ " 0=unlimited\n"
+ "Common options:\n"
+ " -v, --version Print version and exit\n"
+ " -h, --help Print this help and exit\n",
+ loggerConfig.path, loggerConfig.storageSizeLimit,
+ loggerConfig.storageTimeLimit, loggerConfig.flushPeriod,
+ loggerConfig.rotationLimit);
}
-
/** @brief Get numeric positive value from string argument.
*
* @param[in] param - parameter name
@@ -88,19 +85,20 @@
{
char* ep = nullptr;
const unsigned long val = strtoul(arg, &ep, 0);
- if (val > INT_MAX || !ep || ep == arg || *ep != 0) {
- fprintf(stderr, "Invalid %s param: %s, expected 0<=N<=%i\n",
- param, arg, INT_MAX);
+ if (val > INT_MAX || !ep || ep == arg || *ep != 0)
+ {
+ fprintf(stderr, "Invalid %s param: %s, expected 0<=N<=%i\n", param, arg,
+ INT_MAX);
return -1;
}
return static_cast<int>(val);
}
-
/** @brief Application entry point. */
-int main(int argc, char *argv[])
+int main(int argc, char* argv[])
{
int opt_val;
+ // clang-format off
const struct option opts[] = {
{ "path", required_argument, 0, 'p' },
{ "szlimit", required_argument, 0, 's' },
@@ -111,34 +109,45 @@
{ "help", no_argument, 0, 'h' },
{ 0, 0, 0, 0 }
};
+ // clang-format on
opterr = 0;
- while ((opt_val = getopt_long(argc, argv, "p:s:t:f:r:vh", opts, NULL)) != -1) {
- switch (opt_val) {
+ while ((opt_val = getopt_long(argc, argv, "p:s:t:f:r:vh", opts, NULL)) !=
+ -1)
+ {
+ switch (opt_val)
+ {
case 'p':
loggerConfig.path = optarg;
- if (*loggerConfig.path != '/') {
- fprintf(stderr, "Invalid directory: %s, expected absolute path\n", loggerConfig.path);
+ if (*loggerConfig.path != '/')
+ {
+ fprintf(stderr,
+ "Invalid directory: %s, expected absolute path\n",
+ loggerConfig.path);
return EXIT_FAILURE;
}
break;
case 's':
- loggerConfig.storageSizeLimit = getNumericArg(opts[optind - 1].name, optarg);
+ loggerConfig.storageSizeLimit =
+ getNumericArg(opts[optind - 1].name, optarg);
if (loggerConfig.storageSizeLimit < 0)
return EXIT_FAILURE;
break;
case 't':
- loggerConfig.storageTimeLimit = getNumericArg(opts[optind - 1].name, optarg);
+ loggerConfig.storageTimeLimit =
+ getNumericArg(opts[optind - 1].name, optarg);
if (loggerConfig.storageTimeLimit < 0)
return EXIT_FAILURE;
break;
case 'f':
- loggerConfig.flushPeriod = getNumericArg(opts[optind - 1].name, optarg);
+ loggerConfig.flushPeriod =
+ getNumericArg(opts[optind - 1].name, optarg);
if (loggerConfig.flushPeriod < 0)
return EXIT_FAILURE;
break;
case 'r':
- loggerConfig.rotationLimit = getNumericArg(opts[optind - 1].name, optarg);
+ loggerConfig.rotationLimit =
+ getNumericArg(opts[optind - 1].name, optarg);
if (loggerConfig.rotationLimit < 0)
return EXIT_FAILURE;
break;
@@ -166,7 +175,8 @@
sdbusplus::bus::bus bus = sdbusplus::bus::new_default();
sd_event* event = nullptr;
rc = sd_event_default(&event);
- if (rc < 0) {
+ if (rc < 0)
+ {
fprintf(stderr, "Error occurred during the sd_event_default: %i\n", rc);
return EXIT_FAILURE;
}