obmc-console: Add clang-format configuration
And apply the formatting.
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Change-Id: I75251051affa5129c8698185baf8d151302b19d6
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..38daa66
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,111 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Originally from Linux v5.6
+---
+AccessModifierOffset: -4
+AlignAfterOpenBracket: Align
+AlignConsecutiveMacros: true
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+#AlignEscapedNewlines: Left # Unknown to clang-format-4.0
+AlignOperands: true
+AlignTrailingComments: false
+AllowAllParametersOfDeclarationOnNextLine: false
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: None
+AllowShortIfStatementsOnASingleLine: false
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: false
+BinPackArguments: true
+BinPackParameters: true
+BraceWrapping:
+ AfterClass: false
+ AfterControlStatement: false
+ AfterEnum: false
+ AfterFunction: true
+ AfterNamespace: true
+ AfterObjCDeclaration: false
+ AfterStruct: false
+ AfterUnion: false
+ #AfterExternBlock: false # Unknown to clang-format-5.0
+ BeforeCatch: false
+ BeforeElse: false
+ IndentBraces: false
+ #SplitEmptyFunction: true # Unknown to clang-format-4.0
+ #SplitEmptyRecord: true # Unknown to clang-format-4.0
+ #SplitEmptyNamespace: true # Unknown to clang-format-4.0
+BreakBeforeBinaryOperators: None
+BreakBeforeBraces: Custom
+#BreakBeforeInheritanceComma: false # Unknown to clang-format-4.0
+BreakBeforeTernaryOperators: false
+BreakConstructorInitializersBeforeComma: false
+#BreakConstructorInitializers: BeforeComma # Unknown to clang-format-4.0
+BreakAfterJavaFieldAnnotations: false
+BreakStringLiterals: false
+ColumnLimit: 80
+CommentPragmas: '^ IWYU pragma:'
+#CompactNamespaces: false # Unknown to clang-format-4.0
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+ConstructorInitializerIndentWidth: 8
+ContinuationIndentWidth: 8
+Cpp11BracedListStyle: false
+DerivePointerAlignment: false
+DisableFormat: false
+ExperimentalAutoDetectBinPacking: false
+#FixNamespaceComments: false # Unknown to clang-format-4.0
+#IncludeBlocks: Preserve # Unknown to clang-format-5.0
+IncludeCategories:
+ - Regex: '.*'
+ Priority: 1
+IncludeIsMainRegex: '(Test)?$'
+IndentCaseLabels: false
+#IndentPPDirectives: None # Unknown to clang-format-5.0
+IndentWidth: 8
+IndentWrappedFunctionNames: false
+JavaScriptQuotes: Leave
+JavaScriptWrapImports: true
+KeepEmptyLinesAtTheStartOfBlocks: false
+MacroBlockBegin: ''
+MacroBlockEnd: ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: Inner
+#ObjCBinPackProtocolList: Auto # Unknown to clang-format-5.0
+ObjCBlockIndentWidth: 8
+ObjCSpaceAfterProperty: true
+ObjCSpaceBeforeProtocolList: true
+
+# Taken from git's rules
+#PenaltyBreakAssignment: 10 # Unknown to clang-format-4.0
+PenaltyBreakBeforeFirstCallParameter: 30
+PenaltyBreakComment: 10
+PenaltyBreakFirstLessLess: 0
+PenaltyBreakString: 10
+PenaltyExcessCharacter: 100
+PenaltyReturnTypeOnItsOwnLine: 60
+
+PointerAlignment: Right
+ReflowComments: false
+SortIncludes: false
+#SortUsingDeclarations: false # Unknown to clang-format-4.0
+SpaceAfterCStyleCast: false
+SpaceAfterTemplateKeyword: true
+SpaceBeforeAssignmentOperators: true
+#SpaceBeforeCtorInitializerColon: true # Unknown to clang-format-5.0
+#SpaceBeforeInheritanceColon: true # Unknown to clang-format-5.0
+SpaceBeforeParens: ControlStatements
+#SpaceBeforeRangeBasedForLoopColon: true # Unknown to clang-format-5.0
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles: false
+SpacesInContainerLiterals: false
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+Standard: Cpp03
+TabWidth: 8
+UseTab: Always
+...
diff --git a/config.c b/config.c
index 5cdd76b..1174eaa 100644
--- a/config.c
+++ b/config.c
@@ -34,13 +34,13 @@
static const char *config_default_filename = SYSCONFDIR "/obmc-console.conf";
struct config_item {
- char *name;
- char *value;
- struct config_item *next;
+ char *name;
+ char *value;
+ struct config_item *next;
};
struct config {
- struct config_item *items;
+ struct config_item *items;
};
const char *config_get_value(struct config *config, const char *name)
@@ -61,11 +61,11 @@
char *p, *line;
for (p = NULL, line = strtok_r(buf, "\n", &p); line;
- line = strtok_r(NULL, "\n", &p)) {
+ line = strtok_r(NULL, "\n", &p)) {
int rc;
/* trim leading space */
- for (;*line == ' ' || *line == '\t'; line++)
+ for (; *line == ' ' || *line == '\t'; line++)
;
/* skip comments */
@@ -121,7 +121,6 @@
size <<= 1;
buf = realloc(buf, size + 1);
}
-
}
buf[len] = '\0';
@@ -171,13 +170,17 @@
}
struct terminal_speed_name {
- speed_t speed;
- uint32_t baud;
- const char *name;
+ speed_t speed;
+ uint32_t baud;
+ const char *name;
};
-#define TERM_SPEED(x) { B##x, x, #x}
+#define TERM_SPEED(x) \
+ { \
+ B##x, x, #x \
+ }
+// clang-format off
static const struct terminal_speed_name terminal_speeds[] = {
TERM_SPEED(50),
TERM_SPEED(75),
@@ -210,6 +213,7 @@
TERM_SPEED(3500000),
TERM_SPEED(4000000),
};
+// clang-format on
int config_parse_baud(speed_t *speed, const char *baud_string)
{
@@ -252,8 +256,8 @@
{
struct size_suffix_shift {
/* Left shiftwidth corresponding to the suffix. */
- size_t shiftwidth;
- int unit;
+ size_t shiftwidth;
+ int unit;
};
const struct size_suffix_shift suffixes[] = {
@@ -261,8 +265,8 @@
{ 20, 'M' },
{ 30, 'G' },
};
- const size_t num_suffixes = sizeof(suffixes) /
- sizeof(struct size_suffix_shift);
+ const size_t num_suffixes =
+ sizeof(suffixes) / sizeof(struct size_suffix_shift);
size_t logsize;
char *suffix;
size_t i;
@@ -322,6 +326,5 @@
config_fini(config);
return EXIT_SUCCESS;
-
}
#endif
diff --git a/console-client.c b/console-client.c
index 1f85176..13bd20d 100644
--- a/console-client.c
+++ b/console-client.c
@@ -54,28 +54,27 @@
};
struct console_client {
- int console_sd;
- int fd_in;
- int fd_out;
- bool is_tty;
- struct termios orig_termios;
- enum esc_type esc_type;
+ int console_sd;
+ int fd_in;
+ int fd_out;
+ bool is_tty;
+ struct termios orig_termios;
+ enum esc_type esc_type;
union {
struct ssh_esc_state ssh;
struct str_esc_state str;
} esc_state;
};
-static enum process_rc process_ssh_tty(
- struct console_client *client, const uint8_t *buf, size_t len)
+static enum process_rc process_ssh_tty(struct console_client *client,
+ const uint8_t *buf, size_t len)
{
struct ssh_esc_state *esc_state = &client->esc_state.ssh;
const uint8_t *out_buf = buf;
int rc;
for (size_t i = 0; i < len; ++i) {
- switch (buf[i])
- {
+ switch (buf[i]) {
case '.':
if (esc_state->state != '~') {
esc_state->state = '\0';
@@ -89,11 +88,11 @@
}
esc_state->state = '~';
/* We need to print everything to skip the tilde */
- rc = write_buf_to_fd(
- client->console_sd, out_buf, i-(out_buf-buf));
+ rc = write_buf_to_fd(client->console_sd, out_buf,
+ i - (out_buf - buf));
if (rc < 0)
return PROCESS_ERR;
- out_buf = &buf[i+1];
+ out_buf = &buf[i + 1];
break;
case '\r':
esc_state->state = '\r';
@@ -103,12 +102,13 @@
}
}
- rc = write_buf_to_fd(client->console_sd, out_buf, len-(out_buf-buf));
+ rc = write_buf_to_fd(client->console_sd, out_buf,
+ len - (out_buf - buf));
return rc < 0 ? PROCESS_ERR : PROCESS_OK;
}
-static enum process_rc process_str_tty(
- struct console_client *client, const uint8_t *buf, size_t len)
+static enum process_rc process_str_tty(struct console_client *client,
+ const uint8_t *buf, size_t len)
{
struct str_esc_state *esc_state = &client->esc_state.str;
enum process_rc prc = PROCESS_OK;
@@ -143,8 +143,7 @@
if (len == 0)
return PROCESS_EXIT;
- switch (client->esc_type)
- {
+ switch (client->esc_type) {
case ESC_TYPE_SSH:
return process_ssh_tty(client, buf, len);
case ESC_TYPE_STR:
@@ -154,7 +153,6 @@
}
}
-
static int process_console(struct console_client *client)
{
uint8_t buf[4096];
@@ -232,7 +230,7 @@
}
rc = connect(client->console_sd, (struct sockaddr *)&addr,
- sizeof(addr) - sizeof(addr.sun_path) + len);
+ sizeof(addr) - sizeof(addr.sun_path) + len);
if (!rc)
return 0;
@@ -283,11 +281,12 @@
fprintf(stderr, "Escape str cannot be empty\n");
return EXIT_FAILURE;
}
- esc = (const uint8_t*)optarg;
+ esc = (const uint8_t *)optarg;
break;
case 'i':
if (optarg[0] == '\0') {
- fprintf(stderr, "Socket ID str cannot be empty\n");
+ fprintf(stderr,
+ "Socket ID str cannot be empty\n");
return EXIT_FAILURE;
}
socket_id = optarg;
@@ -311,7 +310,8 @@
}
if (!esc)
- esc = (const uint8_t *)config_get_value(config, "escape-sequence");
+ esc = (const uint8_t *)config_get_value(
+ config, "escape-sequence");
if (!socket_id)
socket_id = config_get_value(config, "socket-id");
@@ -364,4 +364,3 @@
return EXIT_ESCAPE;
return rc ? EXIT_FAILURE : EXIT_SUCCESS;
}
-
diff --git a/console-server.c b/console-server.c
index 3c71904..803262b 100644
--- a/console-server.c
+++ b/console-server.c
@@ -40,38 +40,38 @@
#include "console-server.h"
-#define DBUS_ERR "org.openbmc.error"
+#define DBUS_ERR "org.openbmc.error"
#define DBUS_NAME "xyz.openbmc_project.console"
-#define OBJ_NAME "/xyz/openbmc_project/console"
+#define OBJ_NAME "/xyz/openbmc_project/console"
struct console {
- const char *tty_kname;
- char *tty_sysfs_devnode;
- char *tty_dev;
- int tty_sirq;
- int tty_lpc_addr;
- speed_t tty_baud;
- int tty_fd;
+ const char *tty_kname;
+ char *tty_sysfs_devnode;
+ char *tty_dev;
+ int tty_sirq;
+ int tty_lpc_addr;
+ speed_t tty_baud;
+ int tty_fd;
- struct ringbuffer *rb;
+ struct ringbuffer *rb;
- struct handler **handlers;
- int n_handlers;
+ struct handler **handlers;
+ int n_handlers;
- struct poller **pollers;
- int n_pollers;
+ struct poller **pollers;
+ int n_pollers;
- struct pollfd *pollfds;
- struct sd_bus *bus;
+ struct pollfd *pollfds;
+ struct sd_bus *bus;
};
struct poller {
- struct handler *handler;
- void *data;
- poller_event_fn_t event_fn;
- poller_timeout_fn_t timeout_fn;
- struct timeval timeout;
- bool remove;
+ struct handler *handler;
+ void *data;
+ poller_event_fn_t event_fn;
+ poller_timeout_fn_t timeout_fn;
+ struct timeval timeout;
+ bool remove;
};
/* we have two extra entry in the pollfds array for the VUART tty */
@@ -90,11 +90,11 @@
static void usage(const char *progname)
{
fprintf(stderr,
-"usage: %s [options] <DEVICE>\n"
-"\n"
-"Options:\n"
-" --config <FILE> Use FILE for configuration\n"
-"",
+ "usage: %s [options] <DEVICE>\n"
+ "\n"
+ "Options:\n"
+ " --config <FILE> Use FILE for configuration\n"
+ "",
progname);
}
@@ -135,8 +135,8 @@
goto out_free;
}
- rc = asprintf(&tty_class_device_link,
- "/sys/class/tty/%s", tty_kname_real);
+ rc = asprintf(&tty_class_device_link, "/sys/class/tty/%s",
+ tty_kname_real);
if (rc < 0)
goto out_free;
@@ -171,7 +171,7 @@
}
static int tty_set_sysfs_attr(struct console *console, const char *name,
- int value)
+ int value)
{
char *path;
FILE *fp;
@@ -183,8 +183,8 @@
fp = fopen(path, "w");
if (!fp) {
- warn("Can't access attribute %s on device %s",
- name, console->tty_kname);
+ warn("Can't access attribute %s on device %s", name,
+ console->tty_kname);
rc = -1;
goto out_free;
}
@@ -192,12 +192,10 @@
rc = fprintf(fp, "0x%x", value);
if (rc < 0)
- warn("Error writing to %s attribute of device %s",
- name, console->tty_kname);
+ warn("Error writing to %s attribute of device %s", name,
+ console->tty_kname);
fclose(fp);
-
-
out_free:
free(path);
return rc;
@@ -232,7 +230,6 @@
warn("Can't set terminal options for %s", console->tty_kname);
}
-
static void tty_change_baudrate(struct console *console)
{
struct handler *handler;
@@ -248,7 +245,7 @@
rc = handler->baudrate(handler, console->tty_baud);
if (rc)
warnx("Can't set terminal baudrate for handler %s",
- handler->name);
+ handler->name);
}
}
@@ -261,7 +258,7 @@
tty_set_sysfs_attr(console, "sirq", console->tty_sirq);
if (console->tty_lpc_addr)
tty_set_sysfs_attr(console, "lpc_address",
- console->tty_lpc_addr);
+ console->tty_lpc_addr);
console->tty_fd = open(console->tty_dev, O_RDWR);
if (console->tty_fd <= 0) {
@@ -323,14 +320,13 @@
return rc;
}
-
int console_data_out(struct console *console, const uint8_t *data, size_t len)
{
return write_buf_to_fd(console->tty_fd, data, len);
}
static int method_set_baud_rate(sd_bus_message *msg, void *userdata,
- sd_bus_error *err)
+ sd_bus_error *err)
{
struct console *console = userdata;
uint32_t baudrate;
@@ -365,7 +361,8 @@
const char *interface __attribute__((unused)),
const char *property __attribute__((unused)),
sd_bus_message *reply, void *userdata,
- sd_bus_error *error __attribute__((unused))) {
+ sd_bus_error *error __attribute__((unused)))
+{
struct console *console = userdata;
uint32_t baudrate;
int r;
@@ -384,9 +381,11 @@
SD_BUS_METHOD("setBaudRate", "u", "x", method_set_baud_rate,
SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_PROPERTY("baudrate", "u", get_handler, 0, 0),
- SD_BUS_VTABLE_END,};
+ SD_BUS_VTABLE_END,
+};
-static void dbus_init(struct console *console, struct config *config __attribute__((unused)))
+static void dbus_init(struct console *console,
+ struct config *config __attribute__((unused)))
{
int dbus_poller = 0;
int fd, r;
@@ -409,8 +408,9 @@
return;
}
- r = sd_bus_request_name(console->bus, DBUS_NAME, SD_BUS_NAME_ALLOW_REPLACEMENT
- |SD_BUS_NAME_REPLACE_EXISTING);
+ r = sd_bus_request_name(console->bus, DBUS_NAME,
+ SD_BUS_NAME_ALLOW_REPLACEMENT |
+ SD_BUS_NAME_REPLACE_EXISTING);
if (r < 0) {
warnx("Failed to acquire service name: %s", strerror(-r));
return;
@@ -438,7 +438,7 @@
console->handlers = &__start_handlers;
printf("%d handler%s\n", console->n_handlers,
- console->n_handlers == 1 ? "" : "s");
+ console->n_handlers == 1 ? "" : "s");
for (i = 0; i < console->n_handlers; i++) {
handler = console->handlers[i];
@@ -450,7 +450,7 @@
handler->active = rc == 0;
printf(" %s [%sactive]\n", handler->name,
- handler->active ? "" : "in");
+ handler->active ? "" : "in");
}
}
@@ -486,17 +486,18 @@
return 0;
}
-struct ringbuffer_consumer *console_ringbuffer_consumer_register(
- struct console *console,
- ringbuffer_poll_fn_t poll_fn, void *data)
+struct ringbuffer_consumer *
+console_ringbuffer_consumer_register(struct console *console,
+ ringbuffer_poll_fn_t poll_fn, void *data)
{
return ringbuffer_consumer_register(console->rb, poll_fn, data);
}
struct poller *console_poller_register(struct console *console,
- struct handler *handler, poller_event_fn_t poller_fn,
- poller_timeout_fn_t timeout_fn, int fd,
- int events, void *data)
+ struct handler *handler,
+ poller_event_fn_t poller_fn,
+ poller_timeout_fn_t timeout_fn, int fd,
+ int events, void *data)
{
struct poller *poller;
int n;
@@ -510,20 +511,21 @@
/* add one to our pollers array */
n = console->n_pollers++;
- console->pollers = realloc(console->pollers,
+ console->pollers =
+ realloc(console->pollers,
sizeof(*console->pollers) * console->n_pollers);
console->pollers[n] = poller;
/* increase pollfds array too */
- console->pollfds = realloc(console->pollfds,
+ console->pollfds =
+ realloc(console->pollfds,
sizeof(*console->pollfds) *
(MAX_INTERNAL_POLLFD + console->n_pollers));
/* shift the end pollfds up by one */
- memcpy(&console->pollfds[n+1],
- &console->pollfds[n],
- sizeof(*console->pollfds) * MAX_INTERNAL_POLLFD);
+ memcpy(&console->pollfds[n + 1], &console->pollfds[n],
+ sizeof(*console->pollfds) * MAX_INTERNAL_POLLFD);
console->pollfds[n].fd = fd;
console->pollfds[n].events = events;
@@ -531,8 +533,7 @@
return poller;
}
-void console_poller_unregister(struct console *console,
- struct poller *poller)
+void console_poller_unregister(struct console *console, struct poller *poller)
{
int i;
@@ -546,28 +547,28 @@
console->n_pollers--;
/* remove the item from the pollers array... */
- memmove(&console->pollers[i], &console->pollers[i+1],
- sizeof(*console->pollers)
- * (console->n_pollers - i));
+ memmove(&console->pollers[i], &console->pollers[i + 1],
+ sizeof(*console->pollers) * (console->n_pollers - i));
- console->pollers = realloc(console->pollers,
+ console->pollers =
+ realloc(console->pollers,
sizeof(*console->pollers) * console->n_pollers);
/* ... and the pollfds array */
- memmove(&console->pollfds[i], &console->pollfds[i+1],
- sizeof(*console->pollfds) *
- (MAX_INTERNAL_POLLFD + console->n_pollers - i));
+ memmove(&console->pollfds[i], &console->pollfds[i + 1],
+ sizeof(*console->pollfds) *
+ (MAX_INTERNAL_POLLFD + console->n_pollers - i));
- console->pollfds = realloc(console->pollfds,
+ console->pollfds =
+ realloc(console->pollfds,
sizeof(*console->pollfds) *
(MAX_INTERNAL_POLLFD + console->n_pollers));
-
free(poller);
}
void console_poller_set_events(struct console *console, struct poller *poller,
- int events)
+ int events)
{
int i;
@@ -580,7 +581,7 @@
}
void console_poller_set_timeout(struct console *console __attribute__((unused)),
- struct poller *poller, const struct timeval *tv)
+ struct poller *poller, const struct timeval *tv)
{
struct timeval now;
int rc;
@@ -605,7 +606,7 @@
if (poller->timeout_fn && timerisset(&poller->timeout) &&
(!earliest ||
- (earliest && timercmp(&poller->timeout, earliest, <)))){
+ (earliest && timercmp(&poller->timeout, earliest, <)))) {
// poller is buffering data and needs the poll
// function to timeout.
earliest = &poller->timeout;
@@ -650,7 +651,7 @@
/* process pending events... */
if (pollfd->revents) {
prc = poller->event_fn(poller->handler, pollfd->revents,
- poller->data);
+ poller->data);
if (prc == POLLER_EXIT)
rc = -1;
else if (prc == POLLER_REMOVE)
@@ -731,8 +732,7 @@
timeout = get_poll_timeout(console, &tv);
rc = poll(console->pollfds,
- console->n_pollers + MAX_INTERNAL_POLLFD,
- timeout);
+ console->n_pollers + MAX_INTERNAL_POLLFD, timeout);
if (rc < 0) {
if (errno == EINTR) {
@@ -772,8 +772,8 @@
return rc ? -1 : 0;
}
static const struct option options[] = {
- { "config", required_argument, 0, 'c'},
- { 0, 0, 0, 0},
+ { "config", required_argument, 0, 'c' },
+ { 0, 0, 0, 0 },
};
int main(int argc, char **argv)
@@ -809,8 +809,8 @@
console = malloc(sizeof(struct console));
memset(console, 0, sizeof(*console));
- console->pollfds = calloc(MAX_INTERNAL_POLLFD,
- sizeof(*console->pollfds));
+ console->pollfds =
+ calloc(MAX_INTERNAL_POLLFD, sizeof(*console->pollfds));
console->rb = ringbuffer_init(buffer_size);
config = config_init(config_filename);
diff --git a/console-server.h b/console-server.h
index b433a79..a98f477 100644
--- a/console-server.h
+++ b/console-server.h
@@ -45,24 +45,21 @@
* poller API, through console_poller_register().
*/
struct handler {
- const char *name;
- int (*init)(struct handler *handler,
- struct console *console,
- struct config *config);
- void (*fini)(struct handler *handler);
- int (*baudrate)(struct handler *handler,
- speed_t baudrate);
- bool active;
+ const char *name;
+ int (*init)(struct handler *handler, struct console *console,
+ struct config *config);
+ void (*fini)(struct handler *handler);
+ int (*baudrate)(struct handler *handler, speed_t baudrate);
+ bool active;
};
-#define __handler_name(n) __handler_ ## n
-#define _handler_name(n) __handler_name(n)
+#define __handler_name(n) __handler_##n
+#define _handler_name(n) __handler_name(n)
-#define console_handler_register(h) \
- static const \
- __attribute__((section("handlers"))) \
- __attribute__((used)) \
- struct handler * _handler_name(__COUNTER__) = h
+#define console_handler_register(h) \
+ static const __attribute__((section("handlers"))) \
+ __attribute__((used)) struct handler * \
+ _handler_name(__COUNTER__) = h
int console_data_out(struct console *console, const uint8_t *data, size_t len);
@@ -76,19 +73,20 @@
};
typedef enum poller_ret (*poller_event_fn_t)(struct handler *handler,
- int revents, void *data);
+ int revents, void *data);
typedef enum poller_ret (*poller_timeout_fn_t)(struct handler *handler,
- void *data);
+ void *data);
struct poller *console_poller_register(struct console *console,
- struct handler *handler, poller_event_fn_t event_fn,
- poller_timeout_fn_t timeout_fn, int fd, int events,
- void *data);
+ struct handler *handler,
+ poller_event_fn_t event_fn,
+ poller_timeout_fn_t timeout_fn, int fd,
+ int events, void *data);
void console_poller_unregister(struct console *console, struct poller *poller);
void console_poller_set_events(struct console *console, struct poller *poller,
- int events);
+ int events);
void console_poller_set_timeout(struct console *console, struct poller *poller,
const struct timeval *interval);
@@ -100,7 +98,7 @@
};
typedef enum ringbuffer_poll_ret (*ringbuffer_poll_fn_t)(void *data,
- size_t force_len);
+ size_t force_len);
struct ringbuffer;
struct ringbuffer_consumer;
@@ -108,24 +106,25 @@
struct ringbuffer *ringbuffer_init(size_t size);
void ringbuffer_fini(struct ringbuffer *rb);
-struct ringbuffer_consumer *ringbuffer_consumer_register(struct ringbuffer *rb,
- ringbuffer_poll_fn_t poll_fn, void *data);
+struct ringbuffer_consumer *
+ringbuffer_consumer_register(struct ringbuffer *rb,
+ ringbuffer_poll_fn_t poll_fn, void *data);
void ringbuffer_consumer_unregister(struct ringbuffer_consumer *rbc);
int ringbuffer_queue(struct ringbuffer *rb, uint8_t *data, size_t len);
size_t ringbuffer_dequeue_peek(struct ringbuffer_consumer *rbc, size_t offset,
- uint8_t **data);
+ uint8_t **data);
int ringbuffer_dequeue_commit(struct ringbuffer_consumer *rbc, size_t len);
size_t ringbuffer_len(struct ringbuffer_consumer *rbc);
/* console wrapper around ringbuffer consumer registration */
-struct ringbuffer_consumer *console_ringbuffer_consumer_register(
- struct console *console,
- ringbuffer_poll_fn_t poll_fn, void *data);
+struct ringbuffer_consumer *
+console_ringbuffer_consumer_register(struct console *console,
+ ringbuffer_poll_fn_t poll_fn, void *data);
/* config API */
struct config;
@@ -141,7 +140,7 @@
/* socket paths */
ssize_t console_socket_path(struct sockaddr_un *addr, const char *id);
-typedef char (socket_path_t)[sizeof(((struct sockaddr_un *)NULL)->sun_path)];
+typedef char(socket_path_t)[sizeof(((struct sockaddr_un *)NULL)->sun_path)];
ssize_t console_socket_path_readable(const struct sockaddr_un *addr,
size_t addrlen, socket_path_t path);
@@ -151,14 +150,13 @@
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
#ifndef offsetof
-#define offsetof(type, member) \
- ((unsigned long)&((type *)NULL)->member)
+#define offsetof(type, member) ((unsigned long)&((type *)NULL)->member)
#endif
-#define container_of(ptr, type, member) \
- ((type *)((void *)((ptr) - offsetof(type, member))))
+#define container_of(ptr, type, member) \
+ ((type *)((void *)((ptr)-offsetof(type, member))))
-#define BUILD_ASSERT(c) \
- do { \
- char __c[(c)?1:-1] __attribute__((unused)); \
+#define BUILD_ASSERT(c) \
+ do { \
+ char __c[(c) ? 1 : -1] __attribute__((unused)); \
} while (0)
diff --git a/log-handler.c b/log-handler.c
index b1128cd..4e2425f 100644
--- a/log-handler.c
+++ b/log-handler.c
@@ -31,18 +31,17 @@
#include "console-server.h"
struct log_handler {
- struct handler handler;
- struct console *console;
- struct ringbuffer_consumer *rbc;
- int fd;
- size_t size;
- size_t maxsize;
- size_t pagesize;
- char *log_filename;
- char *rotate_filename;
+ struct handler handler;
+ struct console *console;
+ struct ringbuffer_consumer *rbc;
+ int fd;
+ size_t size;
+ size_t maxsize;
+ size_t pagesize;
+ char *log_filename;
+ char *rotate_filename;
};
-
static const char *default_filename = LOCALSTATEDIR "/log/obmc-console.log";
static const size_t default_logsize = 16 * 1024;
@@ -59,7 +58,8 @@
close(lh->fd);
rc = rename(lh->log_filename, lh->rotate_filename);
if (rc) {
- warn("Failed to rename %s to %s", lh->log_filename, lh->rotate_filename);
+ warn("Failed to rename %s to %s", lh->log_filename,
+ lh->rotate_filename);
/* don't return, as we need to re-open the logfile */
}
@@ -98,8 +98,8 @@
return 0;
}
-static enum ringbuffer_poll_ret log_ringbuffer_poll(void *arg,
- size_t force_len __attribute__((unused)))
+static enum ringbuffer_poll_ret log_ringbuffer_poll(void *arg, size_t force_len
+ __attribute__((unused)))
{
struct log_handler *lh = arg;
uint8_t *buf;
@@ -124,7 +124,7 @@
}
static int log_init(struct handler *handler, struct console *console,
- struct config *config)
+ struct config *config)
{
struct log_handler *lh = to_log_handler(handler);
const char *filename, *logsize_str;
@@ -142,7 +142,7 @@
if (logsize_str != NULL && rc) {
logsize = default_logsize;
warn("Invalid logsize. Default to %ukB",
- (unsigned int)(logsize >> 10));
+ (unsigned int)(logsize >> 10));
}
lh->maxsize = logsize <= lh->pagesize ? lh->pagesize + 1 : logsize;
@@ -165,7 +165,7 @@
}
lh->rbc = console_ringbuffer_consumer_register(console,
- log_ringbuffer_poll, lh);
+ log_ringbuffer_poll, lh);
return 0;
}
@@ -188,4 +188,3 @@
};
console_handler_register(&log_handler.handler);
-
diff --git a/ringbuffer.c b/ringbuffer.c
index 14cb63d..996dc49 100644
--- a/ringbuffer.c
+++ b/ringbuffer.c
@@ -29,18 +29,18 @@
}
struct ringbuffer {
- uint8_t *buf;
- size_t size;
- size_t tail;
- struct ringbuffer_consumer **consumers;
- int n_consumers;
+ uint8_t *buf;
+ size_t size;
+ size_t tail;
+ struct ringbuffer_consumer **consumers;
+ int n_consumers;
};
struct ringbuffer_consumer {
- struct ringbuffer *rb;
- ringbuffer_poll_fn_t poll_fn;
- void *poll_data;
- size_t pos;
+ struct ringbuffer *rb;
+ ringbuffer_poll_fn_t poll_fn;
+ void *poll_data;
+ size_t pos;
};
struct ringbuffer *ringbuffer_init(size_t size)
@@ -65,8 +65,9 @@
free(rb);
}
-struct ringbuffer_consumer *ringbuffer_consumer_register(struct ringbuffer *rb,
- ringbuffer_poll_fn_t fn, void *data)
+struct ringbuffer_consumer *
+ringbuffer_consumer_register(struct ringbuffer *rb, ringbuffer_poll_fn_t fn,
+ void *data)
{
struct ringbuffer_consumer *rbc;
int n;
@@ -79,7 +80,7 @@
n = rb->n_consumers++;
rb->consumers = realloc(rb->consumers,
- sizeof(*rb->consumers) * rb->n_consumers);
+ sizeof(*rb->consumers) * rb->n_consumers);
rb->consumers[n] = rbc;
return rbc;
@@ -98,11 +99,11 @@
rb->n_consumers--;
- memmove(&rb->consumers[i], &rb->consumers[i+1],
- sizeof(*rb->consumers) * (rb->n_consumers - i));
+ memmove(&rb->consumers[i], &rb->consumers[i + 1],
+ sizeof(*rb->consumers) * (rb->n_consumers - i));
rb->consumers = realloc(rb->consumers,
- sizeof(*rb->consumers) * rb->n_consumers);
+ sizeof(*rb->consumers) * rb->n_consumers);
free(rbc);
}
@@ -120,8 +121,8 @@
return rbc->rb->size - ringbuffer_len(rbc) - 1;
}
-static int ringbuffer_consumer_ensure_space(
- struct ringbuffer_consumer *rbc, size_t len)
+static int ringbuffer_consumer_ensure_space(struct ringbuffer_consumer *rbc,
+ size_t len)
{
enum ringbuffer_poll_ret prc;
int force_len;
@@ -178,7 +179,6 @@
memcpy(rb->buf, data, len);
rb->tail += len;
-
/* Inform consumers of new data in non-blocking mode, by calling
* ->poll_fn with 0 force_len */
for (i = 0; i < rb->n_consumers; i++) {
@@ -196,7 +196,7 @@
}
size_t ringbuffer_dequeue_peek(struct ringbuffer_consumer *rbc, size_t offset,
- uint8_t **data)
+ uint8_t **data)
{
struct ringbuffer *rb = rbc->rb;
size_t pos;
diff --git a/socket-handler.c b/socket-handler.c
index a4f835d..b10615b 100644
--- a/socket-handler.c
+++ b/socket-handler.c
@@ -38,21 +38,21 @@
#define SOCKET_HANDLER_PKT_US_TIMEOUT 4000
struct client {
- struct socket_handler *sh;
- struct poller *poller;
- struct ringbuffer_consumer *rbc;
- int fd;
- bool blocked;
+ struct socket_handler *sh;
+ struct poller *poller;
+ struct ringbuffer_consumer *rbc;
+ int fd;
+ bool blocked;
};
struct socket_handler {
- struct handler handler;
- struct console *console;
- struct poller *poller;
- int sd;
+ struct handler handler;
+ struct console *console;
+ struct poller *poller;
+ int sd;
- struct client **clients;
- int n_clients;
+ struct client **clients;
+ int n_clients;
};
static struct timeval const socket_handler_timeout = {
@@ -87,10 +87,10 @@
client = NULL;
sh->n_clients--;
- memmove(&sh->clients[idx], &sh->clients[idx+1],
- sizeof(*sh->clients) * (sh->n_clients - idx));
- sh->clients = realloc(sh->clients,
- sizeof(*sh->clients) * sh->n_clients);
+ memmove(&sh->clients[idx], &sh->clients[idx + 1],
+ sizeof(*sh->clients) * (sh->n_clients - idx));
+ sh->clients =
+ realloc(sh->clients, sizeof(*sh->clients) * sh->n_clients);
}
static void client_set_blocked(struct client *client, bool blocked)
@@ -109,8 +109,8 @@
console_poller_set_events(client->sh->console, client->poller, events);
}
-static ssize_t send_all(struct client *client, void *buf,
- size_t len, bool block)
+static ssize_t send_all(struct client *client, void *buf, size_t len,
+ bool block)
{
int fd, rc, flags;
size_t pos;
@@ -124,8 +124,8 @@
for (pos = 0; pos < len; pos += rc) {
rc = send(fd, (char *)buf + pos, len - pos, flags);
if (rc < 0) {
- if (!block && (errno == EAGAIN ||
- errno == EWOULDBLOCK)) {
+ if (!block &&
+ (errno == EAGAIN || errno == EWOULDBLOCK)) {
client_set_blocked(client, true);
break;
}
@@ -186,7 +186,7 @@
}
static enum ringbuffer_poll_ret client_ringbuffer_poll(void *arg,
- size_t force_len)
+ size_t force_len)
{
struct client *client = arg;
int rc, len;
@@ -211,7 +211,8 @@
return RINGBUFFER_POLL_OK;
}
-static enum poller_ret client_timeout(struct handler *handler __attribute__((unused)), void *data)
+static enum poller_ret
+client_timeout(struct handler *handler __attribute__((unused)), void *data)
{
struct client *client = data;
int rc = 0;
@@ -231,8 +232,8 @@
return POLLER_OK;
}
-static enum poller_ret client_poll(struct handler *handler,
- int events, void *data)
+static enum poller_ret client_poll(struct handler *handler, int events,
+ void *data)
{
struct socket_handler *sh = to_socket_handler(handler);
struct client *client = data;
@@ -268,8 +269,8 @@
return POLLER_REMOVE;
}
-static enum poller_ret socket_poll(struct handler *handler,
- int events, void __attribute__((unused)) *data)
+static enum poller_ret socket_poll(struct handler *handler, int events,
+ void __attribute__((unused)) * data)
{
struct socket_handler *sh = to_socket_handler(handler);
struct client *client;
@@ -288,22 +289,21 @@
client->sh = sh;
client->fd = fd;
client->poller = console_poller_register(sh->console, handler,
- client_poll, client_timeout, client->fd, POLLIN,
- client);
- client->rbc = console_ringbuffer_consumer_register(sh->console,
- client_ringbuffer_poll, client);
+ client_poll, client_timeout,
+ client->fd, POLLIN, client);
+ client->rbc = console_ringbuffer_consumer_register(
+ sh->console, client_ringbuffer_poll, client);
n = sh->n_clients++;
- sh->clients = realloc(sh->clients,
- sizeof(*sh->clients) * sh->n_clients);
+ sh->clients =
+ realloc(sh->clients, sizeof(*sh->clients) * sh->n_clients);
sh->clients[n] = client;
return POLLER_OK;
-
}
static int socket_init(struct handler *handler, struct console *console,
- struct config *config)
+ struct config *config)
{
struct socket_handler *sh = to_socket_handler(handler);
struct sockaddr_un addr;
@@ -328,11 +328,12 @@
/* Try to take a socket from systemd first */
if (sd_listen_fds(0) == 1 &&
- sd_is_socket_unix(SD_LISTEN_FDS_START, SOCK_STREAM, 1, addr.sun_path, len) > 0) {
+ sd_is_socket_unix(SD_LISTEN_FDS_START, SOCK_STREAM, 1,
+ addr.sun_path, len) > 0) {
sh->sd = SD_LISTEN_FDS_START;
} else {
sh->sd = socket(AF_UNIX, SOCK_STREAM, 0);
- if(sh->sd < 0) {
+ if (sh->sd < 0) {
warn("Can't create socket");
return -1;
}
@@ -344,7 +345,7 @@
socket_path_t name;
console_socket_path_readable(&addr, addrlen, name);
warn("Can't bind to socket path %s (terminated at first null)",
- name);
+ name);
goto cleanup;
}
@@ -356,7 +357,7 @@
}
sh->poller = console_poller_register(console, handler, socket_poll,
- NULL, sh->sd, POLLIN, NULL);
+ NULL, sh->sd, POLLIN, NULL);
return 0;
cleanup:
@@ -386,4 +387,3 @@
};
console_handler_register(&socket_handler.handler);
-
diff --git a/test/ringbuffer-test-utils.c b/test/ringbuffer-test-utils.c
index bbe688a..9172648 100644
--- a/test/ringbuffer-test-utils.c
+++ b/test/ringbuffer-test-utils.c
@@ -1,11 +1,11 @@
struct rb_test_ctx {
- struct ringbuffer_consumer *rbc;
- bool ignore_poll;
- bool force_only;
- int count;
- uint8_t *data;
- int len;
+ struct ringbuffer_consumer *rbc;
+ bool ignore_poll;
+ bool force_only;
+ int count;
+ uint8_t *data;
+ int len;
};
void ringbuffer_test_context_init(struct rb_test_ctx *ctx)
@@ -22,15 +22,15 @@
free(ctx->data);
}
-enum ringbuffer_poll_ret ringbuffer_poll_nop(
- void *data __attribute__((unused)),
- size_t force_len __attribute__((unused)))
+enum ringbuffer_poll_ret ringbuffer_poll_nop(void *data __attribute__((unused)),
+ size_t force_len
+ __attribute__((unused)))
{
return RINGBUFFER_POLL_OK;
}
enum ringbuffer_poll_ret ringbuffer_poll_append_all(void *data,
- size_t force_len)
+ size_t force_len)
{
struct rb_test_ctx *ctx = data;
size_t len, total_len;
@@ -73,7 +73,7 @@
int j;
printf("---- ringbuffer (%d consumer%s)\n", rb->n_consumers,
- rb->n_consumers == 1 ? "" : "s");
+ rb->n_consumers == 1 ? "" : "s");
for (i = 0; i < rb->size; i++) {
bool has_consumer = false;
@@ -95,4 +95,3 @@
printf("\n");
}
}
-
diff --git a/test/test-client-escape.c b/test/test-client-escape.c
index 6567024..43998fc 100644
--- a/test/test-client-escape.c
+++ b/test/test-client-escape.c
@@ -27,127 +27,126 @@
#undef main
struct test {
- enum esc_type esc_type;
+ enum esc_type esc_type;
union {
struct ssh_esc_state ssh;
struct str_esc_state str;
} esc_state;
- const char *in[4];
- size_t n_in;
- const char *exp_out;
- int exp_rc;
+ const char *in[4];
+ size_t n_in;
+ const char *exp_out;
+ int exp_rc;
};
struct test_ctx {
- struct console_client client;
- struct test *test;
- uint8_t out[4096];
- size_t cur_in;
- size_t cur_out;
+ struct console_client client;
+ struct test *test;
+ uint8_t out[4096];
+ size_t cur_in;
+ size_t cur_out;
};
-
struct test tests[] = {
{
/* no escape code */
- .esc_type = ESC_TYPE_SSH,
- .in = {"a"},
- .n_in = 1,
- .exp_out = "a",
- .exp_rc = PROCESS_EXIT,
+ .esc_type = ESC_TYPE_SSH,
+ .in = { "a" },
+ .n_in = 1,
+ .exp_out = "a",
+ .exp_rc = PROCESS_EXIT,
},
{
/* no escape code, multiple reads */
- .esc_type = ESC_TYPE_SSH,
- .in = {"a", "b"},
- .n_in = 2,
- .exp_out = "ab",
- .exp_rc = PROCESS_EXIT,
+ .esc_type = ESC_TYPE_SSH,
+ .in = { "a", "b" },
+ .n_in = 2,
+ .exp_out = "ab",
+ .exp_rc = PROCESS_EXIT,
},
{
/* ssh escape in one read */
- .esc_type = ESC_TYPE_SSH,
- .in = {"a\r~."},
- .n_in = 1,
- .exp_out = "a\r",
- .exp_rc = PROCESS_ESC,
+ .esc_type = ESC_TYPE_SSH,
+ .in = { "a\r~." },
+ .n_in = 1,
+ .exp_out = "a\r",
+ .exp_rc = PROCESS_ESC,
},
{
/* ssh escape, partial ~ is not output. */
- .esc_type = ESC_TYPE_SSH,
- .in = {"a\r~"},
- .n_in = 1,
- .exp_out = "a\r",
- .exp_rc = PROCESS_EXIT,
+ .esc_type = ESC_TYPE_SSH,
+ .in = { "a\r~" },
+ .n_in = 1,
+ .exp_out = "a\r",
+ .exp_rc = PROCESS_EXIT,
},
{
/* ssh escape split into individual reads */
- .esc_type = ESC_TYPE_SSH,
- .in = {"a", "\r", "~", "."},
- .n_in = 4,
- .exp_out = "a\r",
- .exp_rc = PROCESS_ESC,
+ .esc_type = ESC_TYPE_SSH,
+ .in = { "a", "\r", "~", "." },
+ .n_in = 4,
+ .exp_out = "a\r",
+ .exp_rc = PROCESS_ESC,
},
{
/* ssh escape, escaped. */
- .esc_type = ESC_TYPE_SSH,
- .in = {"a\r~~."},
- .n_in = 1,
- .exp_out = "a\r~.",
- .exp_rc = PROCESS_EXIT,
+ .esc_type = ESC_TYPE_SSH,
+ .in = { "a\r~~." },
+ .n_in = 1,
+ .exp_out = "a\r~.",
+ .exp_rc = PROCESS_EXIT,
},
{
/* ssh escape, escaped ~, and not completed. */
- .esc_type = ESC_TYPE_SSH,
- .in = {"a\r~~"},
- .n_in = 1,
- .exp_out = "a\r~",
- .exp_rc = PROCESS_EXIT,
+ .esc_type = ESC_TYPE_SSH,
+ .in = { "a\r~~" },
+ .n_in = 1,
+ .exp_out = "a\r~",
+ .exp_rc = PROCESS_EXIT,
},
{
/* str escape, no match */
- .esc_type = ESC_TYPE_STR,
- .esc_state = { .str = { .str = (const uint8_t *)"c" } },
- .in = {"ab"},
- .n_in = 1,
- .exp_out = "ab",
- .exp_rc = PROCESS_EXIT,
+ .esc_type = ESC_TYPE_STR,
+ .esc_state = { .str = { .str = (const uint8_t *)"c" } },
+ .in = { "ab" },
+ .n_in = 1,
+ .exp_out = "ab",
+ .exp_rc = PROCESS_EXIT,
},
{
/* str escape, one byte, as one read */
- .esc_type = ESC_TYPE_STR,
- .esc_state = { .str = { .str = (const uint8_t *)"b" } },
- .in = {"abc"},
- .n_in = 1,
- .exp_out = "ab",
- .exp_rc = PROCESS_ESC,
+ .esc_type = ESC_TYPE_STR,
+ .esc_state = { .str = { .str = (const uint8_t *)"b" } },
+ .in = { "abc" },
+ .n_in = 1,
+ .exp_out = "ab",
+ .exp_rc = PROCESS_ESC,
},
{
/* str escape, multiple bytes, as one read */
- .esc_type = ESC_TYPE_STR,
- .esc_state = { .str = { .str = (const uint8_t *)"bc" } },
- .in = {"abcd"},
- .n_in = 1,
- .exp_out = "abc",
- .exp_rc = PROCESS_ESC,
+ .esc_type = ESC_TYPE_STR,
+ .esc_state = { .str = { .str = (const uint8_t *)"bc" } },
+ .in = { "abcd" },
+ .n_in = 1,
+ .exp_out = "abc",
+ .exp_rc = PROCESS_ESC,
},
{
/* str escape, multiple bytes, split over reads */
- .esc_type = ESC_TYPE_STR,
- .esc_state = { .str = { .str = (const uint8_t *)"bc" } },
- .in = {"ab", "cd"},
- .n_in = 2,
- .exp_out = "abc",
- .exp_rc = PROCESS_ESC,
+ .esc_type = ESC_TYPE_STR,
+ .esc_state = { .str = { .str = (const uint8_t *)"bc" } },
+ .in = { "ab", "cd" },
+ .n_in = 2,
+ .exp_out = "abc",
+ .exp_rc = PROCESS_ESC,
},
{
/* str escape, not matched due to intermediate data */
- .esc_type = ESC_TYPE_STR,
- .esc_state = { .str = { .str = (const uint8_t *)"ab" } },
- .in = {"acb"},
- .n_in = 1,
- .exp_out = "acb",
- .exp_rc = PROCESS_EXIT,
+ .esc_type = ESC_TYPE_STR,
+ .esc_state = { .str = { .str = (const uint8_t *)"ab" } },
+ .in = { "acb" },
+ .n_in = 1,
+ .exp_out = "acb",
+ .exp_rc = PROCESS_EXIT,
},
};
@@ -195,7 +194,7 @@
ctx->client.fd_in = idx;
ctx->client.esc_type = test->esc_type;
memcpy(&ctx->client.esc_state, &test->esc_state,
- sizeof(test->esc_state));
+ sizeof(test->esc_state));
ctx->test = test;
for (;;) {
@@ -207,9 +206,8 @@
exp_out_len = strlen(test->exp_out);
#ifdef DEBUG
- printf("got: rc %d %s(%d), exp: rc %d %s(%ld)\n",
- rc, ctx->out, ctx->cur_out,
- test->exp_rc, test->exp_out, exp_out_len);
+ printf("got: rc %d %s(%d), exp: rc %d %s(%ld)\n", rc, ctx->out,
+ ctx->cur_out, test->exp_rc, test->exp_out, exp_out_len);
fflush(stdout);
#endif
assert(rc == test->exp_rc);
diff --git a/test/test-config-parse-logsize.c b/test/test-config-parse-logsize.c
index d6b4873..482932e 100644
--- a/test/test-config-parse-logsize.c
+++ b/test/test-config-parse-logsize.c
@@ -11,36 +11,36 @@
#include "config.c"
struct test_parse_size_unit {
- const char *test_str;
- size_t expected_size;
- int expected_rc;
+ const char *test_str;
+ size_t expected_size;
+ int expected_rc;
};
void test_config_parse_logsize(void)
{
const struct test_parse_size_unit test_data[] = {
- {"0", 0, -1},
- {"1", 1, 0},
- {"4k", 4*1024, 0},
- {"6M", (6ul << 20), 0},
- {"4095M", (4095ul << 20), 0},
- {"2G", (2ul << 30), 0},
- {"8M\n", (8ul << 20), 0}, /* Suffix ignored */
- {" 10k", 10*1024, 0}, /* Leading spaces trimmed */
- {"10k ", 10*1024, 0}, /* Trailing spaces trimmed */
- {"\r\t10k \r\t",10*1024, 0}, /* Spaces trimmed */
- {" 10 kB ", 10*1024, 0}, /* Spaces trimmed */
- {"11G", 0, -1}, /* Overflow */
- {"4294967296", 0, -1}, /* Overflow */
- {"4096M", 0, -1}, /* Overflow */
- {"65535G", 0, -1}, /* Overflow */
- {"xyz", 0, -1}, /* Invalid */
- {"000", 0, -1}, /* Invalid */
- {"0.1", 0, -1}, /* Invalid */
- {"9T", 0, -1}, /* Invalid suffix */
+ { "0", 0, -1 },
+ { "1", 1, 0 },
+ { "4k", 4 * 1024, 0 },
+ { "6M", (6ul << 20), 0 },
+ { "4095M", (4095ul << 20), 0 },
+ { "2G", (2ul << 30), 0 },
+ { "8M\n", (8ul << 20), 0 }, /* Suffix ignored */
+ { " 10k", 10 * 1024, 0 }, /* Leading spaces trimmed */
+ { "10k ", 10 * 1024, 0 }, /* Trailing spaces trimmed */
+ { "\r\t10k \r\t", 10 * 1024, 0 }, /* Spaces trimmed */
+ { " 10 kB ", 10 * 1024, 0 }, /* Spaces trimmed */
+ { "11G", 0, -1 }, /* Overflow */
+ { "4294967296", 0, -1 }, /* Overflow */
+ { "4096M", 0, -1 }, /* Overflow */
+ { "65535G", 0, -1 }, /* Overflow */
+ { "xyz", 0, -1 }, /* Invalid */
+ { "000", 0, -1 }, /* Invalid */
+ { "0.1", 0, -1 }, /* Invalid */
+ { "9T", 0, -1 }, /* Invalid suffix */
};
- const size_t num_tests = sizeof(test_data) /
- sizeof(struct test_parse_size_unit);
+ const size_t num_tests =
+ sizeof(test_data) / sizeof(struct test_parse_size_unit);
size_t size;
size_t i;
int rc;
@@ -49,17 +49,13 @@
rc = config_parse_logsize(test_data[i].test_str, &size);
if (rc == -1 && rc != test_data[i].expected_rc) {
- warn("[%zu] Str %s expected rc %d, got rc %d\n",
- i,
- test_data[i].test_str,
- test_data[i].expected_rc,
+ warn("[%zu] Str %s expected rc %d, got rc %d\n", i,
+ test_data[i].test_str, test_data[i].expected_rc,
rc);
} else if (rc == 0 && test_data[i].expected_size != size) {
warn("[%zu] Str %s expected size %lu, got size %lu\n",
- i,
- test_data[i].test_str,
- test_data[i].expected_size,
- size);
+ i, test_data[i].test_str,
+ test_data[i].expected_size, size);
}
assert(rc == test_data[i].expected_rc);
if (rc == 0)
diff --git a/test/test-config-parse.c b/test/test-config-parse.c
index 6392bd9..7d2d687 100644
--- a/test/test-config-parse.c
+++ b/test/test-config-parse.c
@@ -11,7 +11,8 @@
#include "config.c"
-static void execute_test(const char *input, const char *key, const char *expected)
+static void execute_test(const char *input, const char *key,
+ const char *expected)
{
struct config *ctx;
const char *found;
diff --git a/test/test-ringbuffer-boundary-poll.c b/test/test-ringbuffer-boundary-poll.c
index 6f6ddc7..aa8a350 100644
--- a/test/test-ringbuffer-boundary-poll.c
+++ b/test/test-ringbuffer-boundary-poll.c
@@ -17,8 +17,8 @@
rb = ringbuffer_init(10);
- ctx->rbc = ringbuffer_consumer_register(rb,
- ringbuffer_poll_append_all, ctx);
+ ctx->rbc = ringbuffer_consumer_register(rb, ringbuffer_poll_append_all,
+ ctx);
/* don't consume initial data in the poll callback */
ctx->ignore_poll = true;
diff --git a/test/test-ringbuffer-boundary-read.c b/test/test-ringbuffer-boundary-read.c
index 2b982e1..5a8fb8f 100644
--- a/test/test-ringbuffer-boundary-read.c
+++ b/test/test-ringbuffer-boundary-read.c
@@ -36,7 +36,7 @@
len = ringbuffer_dequeue_peek(rbc, pos, &out_buf);
if (len == 0)
break;
- assert(!memcmp(in_buf+pos, out_buf, len));
+ assert(!memcmp(in_buf + pos, out_buf, len));
pos += len;
}
assert(pos == sizeof(in_buf));
diff --git a/test/test-ringbuffer-poll-force.c b/test/test-ringbuffer-poll-force.c
index 0993de5..e1e4245 100644
--- a/test/test-ringbuffer-poll-force.c
+++ b/test/test-ringbuffer-poll-force.c
@@ -8,7 +8,9 @@
void test_poll_force(void)
{
- uint8_t in_buf[] = { 'a', 'b', 'c', 'd', 'e', 'f', };
+ uint8_t in_buf[] = {
+ 'a', 'b', 'c', 'd', 'e', 'f',
+ };
struct rb_test_ctx _ctx, *ctx = &_ctx;
struct ringbuffer *rb;
int rc;
@@ -17,8 +19,8 @@
rb = ringbuffer_init(5);
- ctx->rbc = ringbuffer_consumer_register(rb,
- ringbuffer_poll_append_all, ctx);
+ ctx->rbc = ringbuffer_consumer_register(rb, ringbuffer_poll_append_all,
+ ctx);
ctx->force_only = true;
diff --git a/test/test-ringbuffer-read-commit.c b/test/test-ringbuffer-read-commit.c
index a4be624..0dba0d7 100644
--- a/test/test-ringbuffer-read-commit.c
+++ b/test/test-ringbuffer-read-commit.c
@@ -8,7 +8,11 @@
void test_read_commit(void)
{
- uint8_t *out_buf, in_buf[] = { 'a', 'b', 'c', };
+ uint8_t *out_buf, in_buf[] = {
+ 'a',
+ 'b',
+ 'c',
+ };
struct ringbuffer_consumer *rbc;
struct ringbuffer *rb;
size_t len;
diff --git a/test/test-ringbuffer-simple-poll.c b/test/test-ringbuffer-simple-poll.c
index 116fe8c..89a9477 100644
--- a/test/test-ringbuffer-simple-poll.c
+++ b/test/test-ringbuffer-simple-poll.c
@@ -17,8 +17,8 @@
ringbuffer_test_context_init(ctx);
rb = ringbuffer_init(10);
- ctx->rbc = ringbuffer_consumer_register(rb,
- ringbuffer_poll_append_all, ctx);
+ ctx->rbc = ringbuffer_consumer_register(rb, ringbuffer_poll_append_all,
+ ctx);
rc = ringbuffer_queue(rb, in_buf, sizeof(in_buf));
assert(!rc);
diff --git a/tty-handler.c b/tty-handler.c
index 3546aca..bdc0870 100644
--- a/tty-handler.c
+++ b/tty-handler.c
@@ -29,13 +29,13 @@
#include "console-server.h"
struct tty_handler {
- struct handler handler;
- struct console *console;
- struct ringbuffer_consumer *rbc;
- struct poller *poller;
- int fd;
- int fd_flags;
- bool blocked;
+ struct handler handler;
+ struct console *console;
+ struct ringbuffer_consumer *rbc;
+ struct poller *poller;
+ int fd;
+ int fd_flags;
+ bool blocked;
};
static struct tty_handler *to_tty_handler(struct handler *handler)
@@ -111,8 +111,8 @@
if (wlen < 0) {
if (errno == EINTR)
continue;
- if ((errno == EAGAIN || errno == EWOULDBLOCK)
- && !force_len) {
+ if ((errno == EAGAIN || errno == EWOULDBLOCK) &&
+ !force_len) {
tty_set_blocked(th, true);
break;
}
@@ -148,8 +148,8 @@
return RINGBUFFER_POLL_OK;
}
-static enum poller_ret tty_poll(struct handler *handler,
- int events, void __attribute__((unused)) *data)
+static enum poller_ret tty_poll(struct handler *handler, int events,
+ void __attribute__((unused)) * data)
{
struct tty_handler *th = to_tty_handler(handler);
uint8_t buf[4096];
@@ -181,7 +181,8 @@
}
static int set_terminal_baud(struct tty_handler *th, const char *tty_name,
- speed_t speed) {
+ speed_t speed)
+{
struct termios term_options;
if (tcgetattr(th->fd, &term_options) < 0) {
@@ -202,7 +203,8 @@
return 0;
}
-static int make_terminal_raw(struct tty_handler *th, const char *tty_name) {
+static int make_terminal_raw(struct tty_handler *th, const char *tty_name)
+{
struct termios term_options;
if (tcgetattr(th->fd, &term_options) < 0) {
@@ -225,7 +227,7 @@
}
static int tty_init(struct handler *handler, struct console *console,
- struct config *config __attribute__((unused)))
+ struct config *config __attribute__((unused)))
{
struct tty_handler *th = to_tty_handler(handler);
speed_t desired_speed;
@@ -261,7 +263,8 @@
} else {
rc = set_terminal_baud(th, tty_name, desired_speed);
if (rc)
- fprintf(stderr, "Couldn't set baud rate for %s to %s\n",
+ fprintf(stderr,
+ "Couldn't set baud rate for %s to %s\n",
tty_name, tty_baud);
}
}
@@ -270,10 +273,10 @@
fprintf(stderr, "Couldn't make %s a raw terminal\n", tty_name);
th->poller = console_poller_register(console, handler, tty_poll, NULL,
- th->fd, POLLIN, NULL);
+ th->fd, POLLIN, NULL);
th->console = console;
th->rbc = console_ringbuffer_consumer_register(console,
- tty_ringbuffer_poll, th);
+ tty_ringbuffer_poll, th);
return 0;
}
@@ -313,4 +316,3 @@
};
console_handler_register(&tty_handler.handler);
-
diff --git a/util.c b/util.c
index d6e037a..8a3cfbf 100644
--- a/util.c
+++ b/util.c
@@ -34,4 +34,3 @@
return 0;
}
-