projects
/
project
/
ubox.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
log: make valgrind less complain by freeing allocated memory
[project/ubox.git]
/
log
/
logd.c
diff --git
a/log/logd.c
b/log/logd.c
index
5dd9932
..
a4335ea
100644
(file)
--- a/
log/logd.c
+++ b/
log/logd.c
@@
-14,6
+14,7
@@
#include <stdio.h>
#include <unistd.h>
#include <syslog.h>
#include <stdio.h>
#include <unistd.h>
#include <syslog.h>
+#include <unistd.h>
#include <linux/types.h>
#include <linux/types.h>
@@
-54,15
+55,9
@@
client_close(struct ustream *s)
free(cl);
}
free(cl);
}
-static void
-client_notify_write(struct ustream *s, int bytes)
-{
- client_close(s);
-}
-
static void client_notify_state(struct ustream *s)
{
static void client_notify_state(struct ustream *s)
{
-
return
client_close(s);
+ client_close(s);
}
static int
}
static int
@@
-75,6
+70,7
@@
read_log(struct ubus_context *ctx, struct ubus_object *obj,
struct log_head *l;
int count = 0;
int fds[2];
struct log_head *l;
int count = 0;
int fds[2];
+ int ret;
if (msg) {
blobmsg_parse(&read_policy, 1, &tb, blob_data(msg), blob_len(msg));
if (msg) {
blobmsg_parse(&read_policy, 1, &tb, blob_data(msg), blob_len(msg));
@@
-82,10
+78,12
@@
read_log(struct ubus_context *ctx, struct ubus_object *obj,
count = blobmsg_get_u32(tb);
}
count = blobmsg_get_u32(tb);
}
- pipe(fds);
+ if (pipe(fds) == -1) {
+ fprintf(stderr, "logd: failed to create pipe: %s\n", strerror(errno));
+ return -1;
+ }
ubus_request_set_fd(ctx, req, fds[0]);
cl = calloc(1, sizeof(*cl));
ubus_request_set_fd(ctx, req, fds[0]);
cl = calloc(1, sizeof(*cl));
- cl->s.stream.notify_write = client_notify_write;
cl->s.stream.notify_state = client_notify_state;
cl->fd = fds[1];
ustream_fd_init(&cl->s, cl->fd);
cl->s.stream.notify_state = client_notify_state;
cl->fd = fds[1];
ustream_fd_init(&cl->s, cl->fd);
@@
-97,9
+95,11
@@
read_log(struct ubus_context *ctx, struct ubus_object *obj,
blobmsg_add_u32(&b, "id", l->id);
blobmsg_add_u32(&b, "priority", l->priority);
blobmsg_add_u32(&b, "source", l->source);
blobmsg_add_u32(&b, "id", l->id);
blobmsg_add_u32(&b, "priority", l->priority);
blobmsg_add_u32(&b, "source", l->source);
- blobmsg_add_u64(&b, "time", l->ts.tv_sec);
+ blobmsg_add_u64(&b, "time", l->ts.tv_sec
* 1000LL
);
l = log_list(count, l);
l = log_list(count, l);
- if (ustream_write(&cl->s.stream, (void *) b.head, blob_len(b.head) + sizeof(struct blob_attr), false) <= 0)
+ ret = ustream_write(&cl->s.stream, (void *) b.head, blob_len(b.head) + sizeof(struct blob_attr), false);
+ blob_buf_free(&b);
+ if (ret < 0)
break;
}
return 0;
break;
}
return 0;
@@
-164,18
+164,32
@@
ubus_connect_handler(struct ubus_context *ctx)
int ret;
ret = ubus_add_object(ctx, &log_object);
int ret;
ret = ubus_add_object(ctx, &log_object);
- if (ret)
+ if (ret)
{
fprintf(stderr, "Failed to add object: %s\n", ubus_strerror(ret));
fprintf(stderr, "Failed to add object: %s\n", ubus_strerror(ret));
+ exit(1);
+ }
fprintf(stderr, "log: connected to ubus\n");
}
int
main(int argc, char **argv)
{
fprintf(stderr, "log: connected to ubus\n");
}
int
main(int argc, char **argv)
{
+ int ch, log_size = 16;
+
signal(SIGPIPE, SIG_IGN);
signal(SIGPIPE, SIG_IGN);
+ while ((ch = getopt(argc, argv, "S:")) != -1) {
+ switch (ch) {
+ case 'S':
+ log_size = atoi(optarg);
+ if (log_size < 1)
+ log_size = 16;
+ break;
+ }
+ }
+ log_size *= 1024;
uloop_init();
uloop_init();
- log_init();
+ log_init(
log_size
);
conn.cb = ubus_connect_handler;
ubus_auto_connect(&conn);
uloop_run();
conn.cb = ubus_connect_handler;
ubus_auto_connect(&conn);
uloop_run();