mirror of
https://github.com/Telecominfraproject/wlan-ucentral-client.git
synced 2026-01-27 02:23:32 +00:00
ucentral-client: add chrashlog handling
Signed-off-by: John Crispin <john@phrozen.org>
This commit is contained in:
@@ -5,7 +5,7 @@ ADD_DEFINITIONS(-Os -ggdb -Wextra -Wall -Werror --std=gnu99 -Wmissing-declaratio
|
||||
|
||||
SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
|
||||
|
||||
SET(SOURCES main.c config.c proto.c ubus.c task.c cmd.c blink.c health.c apply.c verify.c failsafe.c upload.c)
|
||||
SET(SOURCES main.c config.c proto.c ubus.c task.c cmd.c blink.c health.c apply.c verify.c failsafe.c upload.c crashlog.c)
|
||||
|
||||
FIND_LIBRARY(ubus NAMES ubus)
|
||||
FIND_LIBRARY(blobmsg_json NAMES blobmsg_json)
|
||||
|
||||
40
crashlog.c
Normal file
40
crashlog.c
Normal file
@@ -0,0 +1,40 @@
|
||||
/* SPDX-License-Identifier: BSD-3-Clause */
|
||||
|
||||
#include "ucentral.h"
|
||||
|
||||
#define CRASHLOG "/tmp/crashlog"
|
||||
|
||||
static struct blob_buf crashlog;
|
||||
|
||||
void
|
||||
crashlog_init(void)
|
||||
{
|
||||
enum {
|
||||
CRASH_LOG,
|
||||
__CRASH_MAX,
|
||||
};
|
||||
|
||||
static const struct blobmsg_policy crash_policy[__CRASH_MAX] = {
|
||||
[CRASH_LOG] = { .name = "crashlog", .type = BLOBMSG_TYPE_ARRAY },
|
||||
};
|
||||
|
||||
struct blob_attr *tb[__CRASH_MAX] = {};
|
||||
struct stat s = {};
|
||||
|
||||
if (stat(CRASHLOG, &s))
|
||||
return;
|
||||
|
||||
blob_buf_init(&crashlog, 0);
|
||||
if (blobmsg_add_json_from_file(&crashlog, CRASHLOG)) {
|
||||
blobmsg_parse(crash_policy, __CRASH_MAX, tb, blob_data(crashlog.head),
|
||||
blob_len(crashlog.head));
|
||||
if (tb[CRASH_LOG])
|
||||
crashlog_send(tb[CRASH_LOG]);
|
||||
else
|
||||
log_send("failed to parse the crashlog");
|
||||
} else {
|
||||
log_send("found a crashlog that is not valid json");
|
||||
}
|
||||
blob_buf_free(&crashlog);
|
||||
unlink(CRASHLOG);
|
||||
}
|
||||
1
main.c
1
main.c
@@ -161,6 +161,7 @@ callback_broker(struct lws *wsi, enum lws_callback_reasons reason,
|
||||
conn_time = time(NULL);
|
||||
websocket = wsi;
|
||||
connect_send();
|
||||
crashlog_init();
|
||||
break;
|
||||
|
||||
case LWS_CALLBACK_CLIENT_RECEIVE:
|
||||
|
||||
19
proto.c
19
proto.c
@@ -291,7 +291,24 @@ health_send(uint32_t sanity, struct blob_attr *a)
|
||||
blobmsg_add_blob(&proto, b);
|
||||
blobmsg_close_table(&proto, c);
|
||||
blobmsg_close_table(&proto, m);
|
||||
ULOG_DBG("xmit message\n");
|
||||
proto_send_blob();
|
||||
}
|
||||
|
||||
void
|
||||
crashlog_send(struct blob_attr *a)
|
||||
{
|
||||
void *m = proto_new_blob("crashlog");
|
||||
struct blob_attr *b;
|
||||
void *c;
|
||||
int rem;
|
||||
|
||||
blobmsg_add_string(&proto, "serial", client.serial);
|
||||
blobmsg_add_u64(&proto, "uuid", uuid_active);
|
||||
c = blobmsg_open_array(&proto, "loglines");
|
||||
blobmsg_for_each_attr(b, a, rem)
|
||||
blobmsg_add_blob(&proto, b);
|
||||
blobmsg_close_array(&proto, c);
|
||||
blobmsg_close_table(&proto, m);
|
||||
proto_send_blob();
|
||||
}
|
||||
|
||||
|
||||
@@ -103,6 +103,10 @@ void failsafe_init(void);
|
||||
void task_run(struct task *task, time_t uuid, uint32_t id);
|
||||
void task_stop(struct task *task);
|
||||
|
||||
void crashlog_init(void);
|
||||
void crashlog_send(struct blob_attr *b);
|
||||
|
||||
|
||||
static inline void safe_free(char **mem)
|
||||
{
|
||||
if (!*mem)
|
||||
|
||||
3
upload.c
3
upload.c
@@ -18,7 +18,8 @@ upload_run_cb(time_t uuid)
|
||||
ULOG_INFO("failed to start upload task\n");
|
||||
exit(1);
|
||||
}
|
||||
ULOG_INFO("running upload task\n");
|
||||
ULOG_INFO("Calling /usr/bin/curl -F %s -f %s %s %s", name, file, upload_uri,
|
||||
client.selfsigned ? "--insecure" : "");
|
||||
|
||||
execlp("/usr/bin/curl", "/usr/bin/curl",
|
||||
"-F", name, "-f", file, upload_uri,
|
||||
|
||||
Reference in New Issue
Block a user