2 * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation
3 * Copyright 2017 Philippe Proulx <jeremie.galarneau@efficios.com>
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 #define BT_LOG_TAG "PLUGIN-TEXT-DMESG-SRC"
32 #include <babeltrace/babeltrace.h>
33 #include <babeltrace/values-internal.h>
34 #include <babeltrace/compat/utc-internal.h>
35 #include <babeltrace/compat/stdio-internal.h>
38 #define NSEC_PER_USEC 1000UL
39 #define NSEC_PER_MSEC 1000000UL
40 #define NSEC_PER_SEC 1000000000ULL
41 #define USEC_PER_SEC 1000000UL
43 struct dmesg_component
;
45 struct dmesg_notif_iter
{
46 struct dmesg_component
*dmesg_comp
;
52 struct dmesg_component
{
55 bt_bool read_from_stdin
;
58 struct bt_ctf_trace
*trace
;
59 struct bt_ctf_stream_class
*stream_class
;
60 struct bt_ctf_event_class
*event_class
;
61 struct bt_ctf_stream
*stream
;
62 struct bt_ctf_packet
*packet
;
63 struct bt_ctf_clock_class
*clock_class
;
64 struct bt_clock_class_priority_map
*cc_prio_map
;
68 struct bt_ctf_field_type
*create_packet_header_ft(void)
70 struct bt_ctf_field_type
*root_ft
= NULL
;
71 struct bt_ctf_field_type
*ft
= NULL
;
74 root_ft
= bt_ctf_field_type_structure_create();
76 BT_LOGE_STR("Cannot create an empty structure field type object.");
80 ft
= bt_ctf_field_type_integer_create(32);
82 BT_LOGE_STR("Cannot create an integer field type object.");
86 ret
= bt_ctf_field_type_structure_add_field(root_ft
, ft
, "magic");
88 BT_LOGE("Cannot add `magic` field type to structure field type: "
94 ft
= bt_ctf_field_type_integer_create(8);
96 BT_LOGE_STR("Cannot create an integer field type object.");
111 struct bt_ctf_field_type
*create_packet_context_ft(void)
113 struct bt_ctf_field_type
*root_ft
= NULL
;
114 struct bt_ctf_field_type
*ft
= NULL
;
117 root_ft
= bt_ctf_field_type_structure_create();
119 BT_LOGE_STR("Cannot create an empty structure field type object.");
123 ft
= bt_ctf_field_type_integer_create(64);
125 BT_LOGE_STR("Cannot create an integer field type object.");
129 ret
= bt_ctf_field_type_structure_add_field(root_ft
,
132 BT_LOGE("Cannot add `content_size` field type to structure field type: "
138 ft
= bt_ctf_field_type_integer_create(64);
140 BT_LOGE_STR("Cannot create an integer field type object.");
144 ret
= bt_ctf_field_type_structure_add_field(root_ft
,
147 BT_LOGE("Cannot add `packet_size` field type to structure field type: "
163 struct bt_ctf_field_type
*create_event_header_ft(
164 struct bt_ctf_clock_class
*clock_class
)
166 struct bt_ctf_field_type
*root_ft
= NULL
;
167 struct bt_ctf_field_type
*ft
= NULL
;
170 root_ft
= bt_ctf_field_type_structure_create();
172 BT_LOGE_STR("Cannot create an empty structure field type object.");
176 ft
= bt_ctf_field_type_integer_create(64);
178 BT_LOGE_STR("Cannot create an integer field type object.");
182 ret
= bt_ctf_field_type_integer_set_mapped_clock_class(ft
, clock_class
);
184 BT_LOGE("Cannot map integer field type to clock class: "
189 ret
= bt_ctf_field_type_structure_add_field(root_ft
,
192 BT_LOGE("Cannot add `timestamp` field type to structure field type: "
208 struct bt_ctf_field_type
*create_event_payload_ft(void)
210 struct bt_ctf_field_type
*root_ft
= NULL
;
211 struct bt_ctf_field_type
*ft
= NULL
;
214 root_ft
= bt_ctf_field_type_structure_create();
216 BT_LOGE_STR("Cannot create an empty structure field type object.");
220 ft
= bt_ctf_field_type_string_create();
222 BT_LOGE_STR("Cannot create a string field type object.");
226 ret
= bt_ctf_field_type_structure_add_field(root_ft
,
229 BT_LOGE("Cannot add `str` field type to structure field type: "
245 struct bt_ctf_clock_class
*create_clock_class(void)
247 return bt_ctf_clock_class_create("the_clock", 1000000000);
251 int create_meta(struct dmesg_component
*dmesg_comp
, bool has_ts
)
253 struct bt_ctf_field_type
*ft
= NULL
;
254 const char *trace_name
= NULL
;
255 gchar
*basename
= NULL
;
258 dmesg_comp
->trace
= bt_ctf_trace_create();
259 if (!dmesg_comp
->trace
) {
260 BT_LOGE_STR("Cannot create an empty trace object.");
264 ft
= create_packet_header_ft();
266 BT_LOGE_STR("Cannot create packet header field type.");
270 ret
= bt_ctf_trace_set_packet_header_type(dmesg_comp
->trace
, ft
);
272 BT_LOGE_STR("Cannot set trace's packet header field type.");
276 if (dmesg_comp
->params
.read_from_stdin
) {
277 trace_name
= "STDIN";
279 basename
= g_path_get_basename(dmesg_comp
->params
.path
->str
);
282 if (strcmp(basename
, G_DIR_SEPARATOR_S
) != 0 &&
283 strcmp(basename
, ".") != 0) {
284 trace_name
= basename
;
289 ret
= bt_ctf_trace_set_name(dmesg_comp
->trace
, trace_name
);
291 BT_LOGE("Cannot set trace's name: name=\"%s\"", trace_name
);
296 dmesg_comp
->stream_class
= bt_ctf_stream_class_create_empty(NULL
);
297 if (!dmesg_comp
->stream_class
) {
298 BT_LOGE_STR("Cannot create an empty stream class object.");
303 ft
= create_packet_context_ft();
305 BT_LOGE_STR("Cannot create packet context field type.");
309 ret
= bt_ctf_stream_class_set_packet_context_type(
310 dmesg_comp
->stream_class
, ft
);
312 BT_LOGE_STR("Cannot set stream class's packet context field type.");
316 dmesg_comp
->cc_prio_map
= bt_clock_class_priority_map_create();
317 if (!dmesg_comp
->cc_prio_map
) {
318 BT_LOGE_STR("Cannot create empty clock class priority map.");
323 dmesg_comp
->clock_class
= create_clock_class();
324 if (!dmesg_comp
->clock_class
) {
325 BT_LOGE_STR("Cannot create clock class.");
329 ret
= bt_ctf_trace_add_clock_class(dmesg_comp
->trace
,
330 dmesg_comp
->clock_class
);
332 BT_LOGE_STR("Cannot add clock class to trace.");
336 ret
= bt_clock_class_priority_map_add_clock_class(
337 dmesg_comp
->cc_prio_map
, dmesg_comp
->clock_class
, 0);
339 BT_LOGE_STR("Cannot add clock class to clock class priority map.");
344 ft
= create_event_header_ft(dmesg_comp
->clock_class
);
346 BT_LOGE_STR("Cannot create event header field type.");
350 ret
= bt_ctf_stream_class_set_event_header_type(
351 dmesg_comp
->stream_class
, ft
);
353 BT_LOGE_STR("Cannot set stream class's event header field type.");
358 dmesg_comp
->event_class
= bt_ctf_event_class_create("string");
359 if (!dmesg_comp
->event_class
) {
360 BT_LOGE_STR("Cannot create an empty event class object.");
365 ft
= create_event_payload_ft();
367 BT_LOGE_STR("Cannot create event payload field type.");
371 ret
= bt_ctf_event_class_set_payload_type(dmesg_comp
->event_class
, ft
);
373 BT_LOGE_STR("Cannot set event class's event payload field type.");
377 ret
= bt_ctf_stream_class_add_event_class(dmesg_comp
->stream_class
,
378 dmesg_comp
->event_class
);
380 BT_LOGE("Cannot add event class to stream class: ret=%d", ret
);
384 ret
= bt_ctf_trace_add_stream_class(dmesg_comp
->trace
,
385 dmesg_comp
->stream_class
);
387 BT_LOGE("Cannot add event class to stream class: ret=%d", ret
);
407 int handle_params(struct dmesg_component
*dmesg_comp
, struct bt_value
*params
)
409 struct bt_value
*read_from_stdin
= NULL
;
410 struct bt_value
*path
= NULL
;
411 const char *path_str
;
414 read_from_stdin
= bt_value_map_get(params
, "read-from-stdin");
415 if (read_from_stdin
) {
416 if (!bt_value_is_bool(read_from_stdin
)) {
417 BT_LOGE("Expecting a boolean value for the `read-from-stdin` parameter: "
419 bt_value_type_string(
420 bt_value_get_type(read_from_stdin
)));
424 ret
= bt_value_bool_get(read_from_stdin
,
425 &dmesg_comp
->params
.read_from_stdin
);
429 path
= bt_value_map_get(params
, "path");
431 if (dmesg_comp
->params
.read_from_stdin
) {
432 BT_LOGE_STR("Cannot specify both `read-from-stdin` and `path` parameters.");
436 if (!bt_value_is_string(path
)) {
437 BT_LOGE("Expecting a string value for the `path` parameter: "
439 bt_value_type_string(
440 bt_value_get_type(path
)));
444 ret
= bt_value_string_get(path
, &path_str
);
446 g_string_assign(dmesg_comp
->params
.path
, path_str
);
448 if (!dmesg_comp
->params
.read_from_stdin
) {
449 BT_LOGE_STR("Expecting `path` parameter or true `read-from-stdin` parameter.");
460 bt_put(read_from_stdin
);
466 struct bt_ctf_field
*create_packet_header_field(struct bt_ctf_field_type
*ft
)
468 struct bt_ctf_field
*ph
= NULL
;
469 struct bt_ctf_field
*magic
= NULL
;
472 ph
= bt_ctf_field_create(ft
);
474 BT_LOGE_STR("Cannot create field object.");
478 magic
= bt_ctf_field_structure_get_field_by_name(ph
, "magic");
480 BT_LOGE_STR("Cannot get `magic` field from structure field.");
484 ret
= bt_ctf_field_unsigned_integer_set_value(magic
, 0xc1fc1fc1);
486 BT_LOGE_STR("Cannot set integer field's value.");
501 struct bt_ctf_field
*create_packet_context_field(struct bt_ctf_field_type
*ft
)
503 struct bt_ctf_field
*pc
= NULL
;
504 struct bt_ctf_field
*field
= NULL
;
507 pc
= bt_ctf_field_create(ft
);
509 BT_LOGE_STR("Cannot create field object.");
513 field
= bt_ctf_field_structure_get_field_by_name(pc
, "content_size");
515 BT_LOGE_STR("Cannot get `content_size` field from structure field.");
519 ret
= bt_ctf_field_unsigned_integer_set_value(field
, 0);
521 BT_LOGE_STR("Cannot set integer field's value.");
526 field
= bt_ctf_field_structure_get_field_by_name(pc
, "packet_size");
528 BT_LOGE_STR("Cannot get `packet_size` field from structure field.");
532 ret
= bt_ctf_field_unsigned_integer_set_value(field
, 0);
534 BT_LOGE_STR("Cannot set integer field's value.");
549 int create_packet_and_stream(struct dmesg_component
*dmesg_comp
)
552 struct bt_ctf_field_type
*ft
= NULL
;
553 struct bt_ctf_field
*field
= NULL
;
555 dmesg_comp
->stream
= bt_ctf_stream_create(dmesg_comp
->stream_class
,
557 if (!dmesg_comp
->stream
) {
558 BT_LOGE_STR("Cannot create stream object.");
562 dmesg_comp
->packet
= bt_ctf_packet_create(dmesg_comp
->stream
);
563 if (!dmesg_comp
->packet
) {
564 BT_LOGE_STR("Cannot create packet object.");
568 ft
= bt_ctf_trace_get_packet_header_type(dmesg_comp
->trace
);
570 field
= create_packet_header_field(ft
);
572 BT_LOGE_STR("Cannot create packet header field.");
576 ret
= bt_ctf_packet_set_header(dmesg_comp
->packet
, field
);
578 BT_LOGE_STR("Cannot set packet's header field.");
584 ft
= bt_ctf_stream_class_get_packet_context_type(
585 dmesg_comp
->stream_class
);
587 field
= create_packet_context_field(ft
);
589 BT_LOGE_STR("Cannot create packet context field.");
593 ret
= bt_ctf_packet_set_context(dmesg_comp
->packet
, field
);
595 BT_LOGE_STR("Cannot set packet's context field.");
599 ret
= bt_ctf_trace_set_is_static(dmesg_comp
->trace
);
601 BT_LOGE_STR("Cannot make trace static.");
617 int try_create_meta_stream_packet(struct dmesg_component
*dmesg_comp
,
622 if (dmesg_comp
->trace
) {
623 /* Already created */
627 ret
= create_meta(dmesg_comp
, has_ts
);
629 BT_LOGE("Cannot create metadata objects: dmesg-comp-addr=%p",
634 ret
= create_packet_and_stream(dmesg_comp
);
636 BT_LOGE("Cannot create packet and stream objects: "
637 "dmesg-comp-addr=%p", dmesg_comp
);
651 void destroy_dmesg_component(struct dmesg_component
*dmesg_comp
)
657 if (dmesg_comp
->params
.path
) {
658 g_string_free(dmesg_comp
->params
.path
, TRUE
);
661 bt_put(dmesg_comp
->packet
);
662 bt_put(dmesg_comp
->trace
);
663 bt_put(dmesg_comp
->stream_class
);
664 bt_put(dmesg_comp
->event_class
);
665 bt_put(dmesg_comp
->stream
);
666 bt_put(dmesg_comp
->clock_class
);
667 bt_put(dmesg_comp
->cc_prio_map
);
672 enum bt_component_status
create_port(struct bt_private_component
*priv_comp
)
674 return bt_private_component_source_add_output_private_port(priv_comp
,
679 enum bt_component_status
dmesg_init(struct bt_private_component
*priv_comp
,
680 struct bt_value
*params
, void *init_method_data
)
683 struct dmesg_component
*dmesg_comp
= g_new0(struct dmesg_component
, 1);
684 enum bt_component_status status
= BT_COMPONENT_STATUS_OK
;
687 BT_LOGE_STR("Failed to allocate one dmesg component structure.");
691 dmesg_comp
->params
.path
= g_string_new(NULL
);
692 if (!dmesg_comp
->params
.path
) {
693 BT_LOGE_STR("Failed to allocate a GString.");
697 ret
= handle_params(dmesg_comp
, params
);
699 BT_LOGE("Invalid parameters: comp-addr=%p", priv_comp
);
703 if (!dmesg_comp
->params
.read_from_stdin
&&
704 !g_file_test(dmesg_comp
->params
.path
->str
,
705 G_FILE_TEST_IS_REGULAR
)) {
706 BT_LOGE("Input path is not a regular file: "
707 "comp-addr=%p, path=\"%s\"", priv_comp
,
708 dmesg_comp
->params
.path
->str
);
712 status
= create_port(priv_comp
);
713 if (status
!= BT_COMPONENT_STATUS_OK
) {
717 (void) bt_private_component_set_user_data(priv_comp
, dmesg_comp
);
721 destroy_dmesg_component(dmesg_comp
);
722 (void) bt_private_component_set_user_data(priv_comp
, NULL
);
725 status
= BT_COMPONENT_STATUS_ERROR
;
733 void dmesg_finalize(struct bt_private_component
*priv_comp
)
735 void *data
= bt_private_component_get_user_data(priv_comp
);
737 destroy_dmesg_component(data
);
741 int create_event_header_from_line(
742 struct dmesg_component
*dmesg_comp
,
743 const char *line
, const char **new_start
,
744 struct bt_ctf_field
**user_field
,
745 struct bt_ctf_clock_value
**user_clock_value
)
747 bool has_timestamp
= false;
748 unsigned long sec
, usec
, msec
;
749 unsigned int year
, mon
, mday
, hour
, min
;
751 struct bt_ctf_clock_value
*clock_value
= NULL
;
752 struct bt_ctf_field_type
*ft
= NULL
;
753 struct bt_ctf_field
*eh_field
= NULL
;
754 struct bt_ctf_field
*ts_field
= NULL
;
757 assert(user_clock_value
);
761 /* Extract time from input line */
762 if (sscanf(line
, "[%lu.%lu] ", &sec
, &usec
) == 2) {
763 ts
= (uint64_t) sec
* USEC_PER_SEC
+ (uint64_t) usec
;
766 * The clock class we use has a 1 GHz frequency: convert
770 has_timestamp
= true;
771 } else if (sscanf(line
, "[%u-%u-%u %u:%u:%lu.%lu] ",
772 &year
, &mon
, &mday
, &hour
, &min
,
777 memset(&ti
, 0, sizeof(ti
));
778 ti
.tm_year
= year
- 1900; /* From 1900 */
779 ti
.tm_mon
= mon
- 1; /* 0 to 11 */
785 ep_sec
= bt_timegm(&ti
);
786 if (ep_sec
!= (time_t) -1) {
787 ts
= (uint64_t) ep_sec
* NSEC_PER_SEC
788 + (uint64_t) msec
* NSEC_PER_MSEC
;
791 has_timestamp
= true;
795 /* Set new start for the message portion of the line */
796 *new_start
= strchr(line
, ']');
800 if ((*new_start
)[0] == ' ') {
806 * At this point, we know if the stream class's event header
807 * field type should have a timestamp or not, so we can lazily
808 * create the metadata, stream, and packet objects.
810 ret
= try_create_meta_stream_packet(dmesg_comp
, has_timestamp
);
812 /* try_create_meta_stream_packet() logs errors */
816 if (dmesg_comp
->clock_class
) {
817 clock_value
= bt_ctf_clock_value_create(dmesg_comp
->clock_class
,
820 BT_LOGE_STR("Cannot create clock value object.");
824 ft
= bt_ctf_stream_class_get_event_header_type(
825 dmesg_comp
->stream_class
);
827 eh_field
= bt_ctf_field_create(ft
);
829 BT_LOGE_STR("Cannot create event header field object.");
833 ts_field
= bt_ctf_field_structure_get_field_by_name(eh_field
,
836 BT_LOGE_STR("Cannot get `timestamp` field from structure field.");
840 ret
= bt_ctf_field_unsigned_integer_set_value(ts_field
, ts
);
842 BT_LOGE_STR("Cannot set integer field's value.");
846 *user_clock_value
= clock_value
;
848 *user_field
= eh_field
;
866 int create_event_payload_from_line(
867 struct dmesg_component
*dmesg_comp
,
868 const char *line
, struct bt_ctf_field
**user_field
)
870 struct bt_ctf_field_type
*ft
= NULL
;
871 struct bt_ctf_field
*ep_field
= NULL
;
872 struct bt_ctf_field
*str_field
= NULL
;
877 ft
= bt_ctf_event_class_get_payload_type(dmesg_comp
->event_class
);
879 ep_field
= bt_ctf_field_create(ft
);
881 BT_LOGE_STR("Cannot create event payload field object.");
885 str_field
= bt_ctf_field_structure_get_field_by_name(ep_field
, "str");
887 BT_LOGE_STR("Cannot get `timestamp` field from structure field.");
892 if (line
[len
- 1] == '\n') {
893 /* Do not include the newline character in the payload */
897 ret
= bt_ctf_field_string_append_len(str_field
, line
, len
);
899 BT_LOGE("Cannot append value to string field object: "
904 *user_field
= ep_field
;
919 struct bt_notification
*create_notif_from_line(
920 struct dmesg_component
*dmesg_comp
, const char *line
)
922 struct bt_ctf_field
*eh_field
= NULL
;
923 struct bt_ctf_field
*ep_field
= NULL
;
924 struct bt_ctf_clock_value
*clock_value
= NULL
;
925 struct bt_ctf_event
*event
= NULL
;
926 struct bt_notification
*notif
= NULL
;
927 const char *new_start
;
930 ret
= create_event_header_from_line(dmesg_comp
, line
, &new_start
,
931 &eh_field
, &clock_value
);
933 BT_LOGE("Cannot create event header field from line: "
938 ret
= create_event_payload_from_line(dmesg_comp
, new_start
,
941 BT_LOGE("Cannot create event payload field from line: "
947 event
= bt_ctf_event_create(dmesg_comp
->event_class
);
949 BT_LOGE_STR("Cannot create event object.");
953 ret
= bt_ctf_event_set_packet(event
, dmesg_comp
->packet
);
955 BT_LOGE_STR("Cannot set event's packet.");
960 ret
= bt_ctf_event_set_header(event
, eh_field
);
962 BT_LOGE_STR("Cannot set event's header field.");
967 ret
= bt_ctf_event_set_event_payload(event
, ep_field
);
969 BT_LOGE_STR("Cannot set event's payload field.");
974 ret
= bt_ctf_event_set_clock_value(event
, clock_value
);
976 BT_LOGE_STR("Cannot set event's clock value.");
981 notif
= bt_notification_event_create(event
, dmesg_comp
->cc_prio_map
);
983 BT_LOGE_STR("Cannot create event notification.");
1001 void destroy_dmesg_notif_iter(struct dmesg_notif_iter
*dmesg_notif_iter
)
1003 if (!dmesg_notif_iter
) {
1007 if (dmesg_notif_iter
->fp
&& dmesg_notif_iter
->fp
!= stdin
) {
1008 if (fclose(dmesg_notif_iter
->fp
)) {
1009 BT_LOGE_ERRNO("Cannot close input file", ".");
1013 free(dmesg_notif_iter
->linebuf
);
1014 g_free(dmesg_notif_iter
);
1018 enum bt_notification_iterator_status
dmesg_notif_iter_init(
1019 struct bt_private_notification_iterator
*priv_notif_iter
,
1020 struct bt_private_port
*priv_port
)
1022 struct bt_private_component
*priv_comp
= NULL
;
1023 struct dmesg_component
*dmesg_comp
;
1024 struct dmesg_notif_iter
*dmesg_notif_iter
=
1025 g_new0(struct dmesg_notif_iter
, 1);
1026 enum bt_notification_iterator_status status
=
1027 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
1029 if (!dmesg_notif_iter
) {
1030 BT_LOGE_STR("Failed to allocate on dmesg notification iterator structure.");
1034 priv_comp
= bt_private_notification_iterator_get_private_component(
1037 dmesg_comp
= bt_private_component_get_user_data(priv_comp
);
1039 dmesg_notif_iter
->dmesg_comp
= dmesg_comp
;
1041 if (dmesg_comp
->params
.read_from_stdin
) {
1042 dmesg_notif_iter
->fp
= stdin
;
1044 dmesg_notif_iter
->fp
= fopen(dmesg_comp
->params
.path
->str
, "r");
1045 if (!dmesg_notif_iter
->fp
) {
1046 BT_LOGE_ERRNO("Cannot open input file in read mode", ": path=\"%s\"",
1047 dmesg_comp
->params
.path
->str
);
1052 (void) bt_private_notification_iterator_set_user_data(priv_notif_iter
,
1057 destroy_dmesg_notif_iter(dmesg_notif_iter
);
1058 (void) bt_private_notification_iterator_set_user_data(priv_notif_iter
,
1061 status
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
1070 void dmesg_notif_iter_finalize(
1071 struct bt_private_notification_iterator
*priv_notif_iter
)
1073 destroy_dmesg_notif_iter(bt_private_notification_iterator_get_user_data(
1078 struct bt_notification_iterator_next_return
dmesg_notif_iter_next(
1079 struct bt_private_notification_iterator
*priv_notif_iter
)
1082 struct dmesg_notif_iter
*dmesg_notif_iter
=
1083 bt_private_notification_iterator_get_user_data(
1085 struct dmesg_component
*dmesg_comp
;
1086 struct bt_notification_iterator_next_return next_ret
= {
1087 .status
= BT_NOTIFICATION_ITERATOR_STATUS_OK
,
1088 .notification
= NULL
1091 assert(dmesg_notif_iter
);
1092 dmesg_comp
= dmesg_notif_iter
->dmesg_comp
;
1097 bool only_spaces
= true;
1099 len
= bt_getline(&dmesg_notif_iter
->linebuf
,
1100 &dmesg_notif_iter
->linebuf_len
, dmesg_notif_iter
->fp
);
1102 if (errno
== EINVAL
) {
1104 BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
1105 } else if (errno
== ENOMEM
) {
1107 BT_NOTIFICATION_ITERATOR_STATUS_NOMEM
;
1110 BT_NOTIFICATION_ITERATOR_STATUS_END
;
1116 assert(dmesg_notif_iter
->linebuf
);
1118 /* Ignore empty lines, once trimmed */
1119 for (ch
= dmesg_notif_iter
->linebuf
; *ch
!= '\0'; ch
++) {
1120 if (!isspace(*ch
)) {
1121 only_spaces
= false;
1131 next_ret
.notification
= create_notif_from_line(dmesg_comp
,
1132 dmesg_notif_iter
->linebuf
);
1133 if (!next_ret
.notification
) {
1134 BT_LOGE("Cannot create event notification from line: "
1135 "dmesg-comp-addr=%p, line=\"%s\"", dmesg_comp
,
1136 dmesg_notif_iter
->linebuf
);