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
;
59 struct bt_ctf_trace
*trace
;
60 struct bt_ctf_stream_class
*stream_class
;
61 struct bt_ctf_event_class
*event_class
;
62 struct bt_ctf_stream
*stream
;
63 struct bt_ctf_packet
*packet
;
64 struct bt_ctf_clock_class
*clock_class
;
65 struct bt_clock_class_priority_map
*cc_prio_map
;
69 struct bt_ctf_field_type
*create_packet_header_ft(void)
71 struct bt_ctf_field_type
*root_ft
= NULL
;
72 struct bt_ctf_field_type
*ft
= NULL
;
75 root_ft
= bt_ctf_field_type_structure_create();
77 BT_LOGE_STR("Cannot create an empty structure field type object.");
81 ft
= bt_ctf_field_type_integer_create(32);
83 BT_LOGE_STR("Cannot create an integer field type object.");
87 ret
= bt_ctf_field_type_structure_add_field(root_ft
, ft
, "magic");
89 BT_LOGE("Cannot add `magic` field type to structure field type: "
95 ft
= bt_ctf_field_type_integer_create(8);
97 BT_LOGE_STR("Cannot create an integer field type object.");
112 struct bt_ctf_field_type
*create_packet_context_ft(void)
114 struct bt_ctf_field_type
*root_ft
= NULL
;
115 struct bt_ctf_field_type
*ft
= NULL
;
118 root_ft
= bt_ctf_field_type_structure_create();
120 BT_LOGE_STR("Cannot create an empty structure field type object.");
124 ft
= bt_ctf_field_type_integer_create(64);
126 BT_LOGE_STR("Cannot create an integer field type object.");
130 ret
= bt_ctf_field_type_structure_add_field(root_ft
,
133 BT_LOGE("Cannot add `content_size` field type to structure field type: "
139 ft
= bt_ctf_field_type_integer_create(64);
141 BT_LOGE_STR("Cannot create an integer field type object.");
145 ret
= bt_ctf_field_type_structure_add_field(root_ft
,
148 BT_LOGE("Cannot add `packet_size` field type to structure field type: "
164 struct bt_ctf_field_type
*create_event_header_ft(
165 struct bt_ctf_clock_class
*clock_class
)
167 struct bt_ctf_field_type
*root_ft
= NULL
;
168 struct bt_ctf_field_type
*ft
= NULL
;
171 root_ft
= bt_ctf_field_type_structure_create();
173 BT_LOGE_STR("Cannot create an empty structure field type object.");
177 ft
= bt_ctf_field_type_integer_create(64);
179 BT_LOGE_STR("Cannot create an integer field type object.");
183 ret
= bt_ctf_field_type_integer_set_mapped_clock_class(ft
, clock_class
);
185 BT_LOGE("Cannot map integer field type to clock class: "
190 ret
= bt_ctf_field_type_structure_add_field(root_ft
,
193 BT_LOGE("Cannot add `timestamp` field type to structure field type: "
209 struct bt_ctf_field_type
*create_event_payload_ft(void)
211 struct bt_ctf_field_type
*root_ft
= NULL
;
212 struct bt_ctf_field_type
*ft
= NULL
;
215 root_ft
= bt_ctf_field_type_structure_create();
217 BT_LOGE_STR("Cannot create an empty structure field type object.");
221 ft
= bt_ctf_field_type_string_create();
223 BT_LOGE_STR("Cannot create a string field type object.");
227 ret
= bt_ctf_field_type_structure_add_field(root_ft
,
230 BT_LOGE("Cannot add `str` field type to structure field type: "
246 struct bt_ctf_clock_class
*create_clock_class(void)
248 return bt_ctf_clock_class_create("the_clock", 1000000000);
252 int create_meta(struct dmesg_component
*dmesg_comp
, bool has_ts
)
254 struct bt_ctf_field_type
*ft
= NULL
;
255 const char *trace_name
= NULL
;
256 gchar
*basename
= NULL
;
259 dmesg_comp
->trace
= bt_ctf_trace_create();
260 if (!dmesg_comp
->trace
) {
261 BT_LOGE_STR("Cannot create an empty trace object.");
265 ft
= create_packet_header_ft();
267 BT_LOGE_STR("Cannot create packet header field type.");
271 ret
= bt_ctf_trace_set_packet_header_type(dmesg_comp
->trace
, ft
);
273 BT_LOGE_STR("Cannot set trace's packet header field type.");
277 if (dmesg_comp
->params
.read_from_stdin
) {
278 trace_name
= "STDIN";
280 basename
= g_path_get_basename(dmesg_comp
->params
.path
->str
);
283 if (strcmp(basename
, G_DIR_SEPARATOR_S
) != 0 &&
284 strcmp(basename
, ".") != 0) {
285 trace_name
= basename
;
290 ret
= bt_ctf_trace_set_name(dmesg_comp
->trace
, trace_name
);
292 BT_LOGE("Cannot set trace's name: name=\"%s\"", trace_name
);
297 dmesg_comp
->stream_class
= bt_ctf_stream_class_create_empty(NULL
);
298 if (!dmesg_comp
->stream_class
) {
299 BT_LOGE_STR("Cannot create an empty stream class object.");
304 ft
= create_packet_context_ft();
306 BT_LOGE_STR("Cannot create packet context field type.");
310 ret
= bt_ctf_stream_class_set_packet_context_type(
311 dmesg_comp
->stream_class
, ft
);
313 BT_LOGE_STR("Cannot set stream class's packet context field type.");
317 dmesg_comp
->cc_prio_map
= bt_clock_class_priority_map_create();
318 if (!dmesg_comp
->cc_prio_map
) {
319 BT_LOGE_STR("Cannot create empty clock class priority map.");
324 dmesg_comp
->clock_class
= create_clock_class();
325 if (!dmesg_comp
->clock_class
) {
326 BT_LOGE_STR("Cannot create clock class.");
330 ret
= bt_ctf_trace_add_clock_class(dmesg_comp
->trace
,
331 dmesg_comp
->clock_class
);
333 BT_LOGE_STR("Cannot add clock class to trace.");
337 ret
= bt_clock_class_priority_map_add_clock_class(
338 dmesg_comp
->cc_prio_map
, dmesg_comp
->clock_class
, 0);
340 BT_LOGE_STR("Cannot add clock class to clock class priority map.");
345 ft
= create_event_header_ft(dmesg_comp
->clock_class
);
347 BT_LOGE_STR("Cannot create event header field type.");
351 ret
= bt_ctf_stream_class_set_event_header_type(
352 dmesg_comp
->stream_class
, ft
);
354 BT_LOGE_STR("Cannot set stream class's event header field type.");
359 dmesg_comp
->event_class
= bt_ctf_event_class_create("string");
360 if (!dmesg_comp
->event_class
) {
361 BT_LOGE_STR("Cannot create an empty event class object.");
366 ft
= create_event_payload_ft();
368 BT_LOGE_STR("Cannot create event payload field type.");
372 ret
= bt_ctf_event_class_set_payload_type(dmesg_comp
->event_class
, ft
);
374 BT_LOGE_STR("Cannot set event class's event payload field type.");
378 ret
= bt_ctf_stream_class_add_event_class(dmesg_comp
->stream_class
,
379 dmesg_comp
->event_class
);
381 BT_LOGE("Cannot add event class to stream class: ret=%d", ret
);
385 ret
= bt_ctf_trace_add_stream_class(dmesg_comp
->trace
,
386 dmesg_comp
->stream_class
);
388 BT_LOGE("Cannot add event class to stream class: ret=%d", ret
);
408 int handle_params(struct dmesg_component
*dmesg_comp
, struct bt_value
*params
)
410 struct bt_value
*read_from_stdin
= NULL
;
411 struct bt_value
*no_timestamp
= NULL
;
412 struct bt_value
*path
= NULL
;
413 const char *path_str
;
416 read_from_stdin
= bt_value_map_get(params
, "read-from-stdin");
417 if (read_from_stdin
) {
418 if (!bt_value_is_bool(read_from_stdin
)) {
419 BT_LOGE("Expecting a boolean value for the `read-from-stdin` parameter: "
421 bt_value_type_string(
422 bt_value_get_type(read_from_stdin
)));
426 ret
= bt_value_bool_get(read_from_stdin
,
427 &dmesg_comp
->params
.read_from_stdin
);
431 no_timestamp
= bt_value_map_get(params
, "no-extract-timestamp");
433 if (!bt_value_is_bool(no_timestamp
)) {
434 BT_LOGE("Expecting a boolean value for the `no-extract-timestamp` parameter: "
436 bt_value_type_string(
437 bt_value_get_type(no_timestamp
)));
441 ret
= bt_value_bool_get(no_timestamp
,
442 &dmesg_comp
->params
.no_timestamp
);
446 path
= bt_value_map_get(params
, "path");
448 if (dmesg_comp
->params
.read_from_stdin
) {
449 BT_LOGE_STR("Cannot specify both `read-from-stdin` and `path` parameters.");
453 if (!bt_value_is_string(path
)) {
454 BT_LOGE("Expecting a string value for the `path` parameter: "
456 bt_value_type_string(
457 bt_value_get_type(path
)));
461 ret
= bt_value_string_get(path
, &path_str
);
463 g_string_assign(dmesg_comp
->params
.path
, path_str
);
465 if (!dmesg_comp
->params
.read_from_stdin
) {
466 BT_LOGE_STR("Expecting `path` parameter or true `read-from-stdin` parameter.");
477 bt_put(read_from_stdin
);
479 bt_put(no_timestamp
);
484 struct bt_ctf_field
*create_packet_header_field(struct bt_ctf_field_type
*ft
)
486 struct bt_ctf_field
*ph
= NULL
;
487 struct bt_ctf_field
*magic
= NULL
;
490 ph
= bt_ctf_field_create(ft
);
492 BT_LOGE_STR("Cannot create field object.");
496 magic
= bt_ctf_field_structure_get_field_by_name(ph
, "magic");
498 BT_LOGE_STR("Cannot get `magic` field from structure field.");
502 ret
= bt_ctf_field_unsigned_integer_set_value(magic
, 0xc1fc1fc1);
504 BT_LOGE_STR("Cannot set integer field's value.");
519 struct bt_ctf_field
*create_packet_context_field(struct bt_ctf_field_type
*ft
)
521 struct bt_ctf_field
*pc
= NULL
;
522 struct bt_ctf_field
*field
= NULL
;
525 pc
= bt_ctf_field_create(ft
);
527 BT_LOGE_STR("Cannot create field object.");
531 field
= bt_ctf_field_structure_get_field_by_name(pc
, "content_size");
533 BT_LOGE_STR("Cannot get `content_size` field from structure field.");
537 ret
= bt_ctf_field_unsigned_integer_set_value(field
, 0);
539 BT_LOGE_STR("Cannot set integer field's value.");
544 field
= bt_ctf_field_structure_get_field_by_name(pc
, "packet_size");
546 BT_LOGE_STR("Cannot get `packet_size` field from structure field.");
550 ret
= bt_ctf_field_unsigned_integer_set_value(field
, 0);
552 BT_LOGE_STR("Cannot set integer field's value.");
567 int create_packet_and_stream(struct dmesg_component
*dmesg_comp
)
570 struct bt_ctf_field_type
*ft
= NULL
;
571 struct bt_ctf_field
*field
= NULL
;
573 dmesg_comp
->stream
= bt_ctf_stream_create(dmesg_comp
->stream_class
,
575 if (!dmesg_comp
->stream
) {
576 BT_LOGE_STR("Cannot create stream object.");
580 dmesg_comp
->packet
= bt_ctf_packet_create(dmesg_comp
->stream
);
581 if (!dmesg_comp
->packet
) {
582 BT_LOGE_STR("Cannot create packet object.");
586 ft
= bt_ctf_trace_get_packet_header_type(dmesg_comp
->trace
);
588 field
= create_packet_header_field(ft
);
590 BT_LOGE_STR("Cannot create packet header field.");
594 ret
= bt_ctf_packet_set_header(dmesg_comp
->packet
, field
);
596 BT_LOGE_STR("Cannot set packet's header field.");
602 ft
= bt_ctf_stream_class_get_packet_context_type(
603 dmesg_comp
->stream_class
);
605 field
= create_packet_context_field(ft
);
607 BT_LOGE_STR("Cannot create packet context field.");
611 ret
= bt_ctf_packet_set_context(dmesg_comp
->packet
, field
);
613 BT_LOGE_STR("Cannot set packet's context field.");
617 ret
= bt_ctf_trace_set_is_static(dmesg_comp
->trace
);
619 BT_LOGE_STR("Cannot make trace static.");
635 int try_create_meta_stream_packet(struct dmesg_component
*dmesg_comp
,
640 if (dmesg_comp
->trace
) {
641 /* Already created */
645 ret
= create_meta(dmesg_comp
, has_ts
);
647 BT_LOGE("Cannot create metadata objects: dmesg-comp-addr=%p",
652 ret
= create_packet_and_stream(dmesg_comp
);
654 BT_LOGE("Cannot create packet and stream objects: "
655 "dmesg-comp-addr=%p", dmesg_comp
);
669 void destroy_dmesg_component(struct dmesg_component
*dmesg_comp
)
675 if (dmesg_comp
->params
.path
) {
676 g_string_free(dmesg_comp
->params
.path
, TRUE
);
679 bt_put(dmesg_comp
->packet
);
680 bt_put(dmesg_comp
->trace
);
681 bt_put(dmesg_comp
->stream_class
);
682 bt_put(dmesg_comp
->event_class
);
683 bt_put(dmesg_comp
->stream
);
684 bt_put(dmesg_comp
->clock_class
);
685 bt_put(dmesg_comp
->cc_prio_map
);
690 enum bt_component_status
create_port(struct bt_private_component
*priv_comp
)
692 return bt_private_component_source_add_output_private_port(priv_comp
,
697 enum bt_component_status
dmesg_init(struct bt_private_component
*priv_comp
,
698 struct bt_value
*params
, void *init_method_data
)
701 struct dmesg_component
*dmesg_comp
= g_new0(struct dmesg_component
, 1);
702 enum bt_component_status status
= BT_COMPONENT_STATUS_OK
;
705 BT_LOGE_STR("Failed to allocate one dmesg component structure.");
709 dmesg_comp
->params
.path
= g_string_new(NULL
);
710 if (!dmesg_comp
->params
.path
) {
711 BT_LOGE_STR("Failed to allocate a GString.");
715 ret
= handle_params(dmesg_comp
, params
);
717 BT_LOGE("Invalid parameters: comp-addr=%p", priv_comp
);
721 if (!dmesg_comp
->params
.read_from_stdin
&&
722 !g_file_test(dmesg_comp
->params
.path
->str
,
723 G_FILE_TEST_IS_REGULAR
)) {
724 BT_LOGE("Input path is not a regular file: "
725 "comp-addr=%p, path=\"%s\"", priv_comp
,
726 dmesg_comp
->params
.path
->str
);
730 status
= create_port(priv_comp
);
731 if (status
!= BT_COMPONENT_STATUS_OK
) {
735 (void) bt_private_component_set_user_data(priv_comp
, dmesg_comp
);
739 destroy_dmesg_component(dmesg_comp
);
740 (void) bt_private_component_set_user_data(priv_comp
, NULL
);
743 status
= BT_COMPONENT_STATUS_ERROR
;
751 void dmesg_finalize(struct bt_private_component
*priv_comp
)
753 void *data
= bt_private_component_get_user_data(priv_comp
);
755 destroy_dmesg_component(data
);
759 int create_event_header_from_line(
760 struct dmesg_component
*dmesg_comp
,
761 const char *line
, const char **new_start
,
762 struct bt_ctf_field
**user_field
,
763 struct bt_ctf_clock_value
**user_clock_value
)
765 bool has_timestamp
= false;
766 unsigned long sec
, usec
, msec
;
767 unsigned int year
, mon
, mday
, hour
, min
;
769 struct bt_ctf_clock_value
*clock_value
= NULL
;
770 struct bt_ctf_field_type
*ft
= NULL
;
771 struct bt_ctf_field
*eh_field
= NULL
;
772 struct bt_ctf_field
*ts_field
= NULL
;
775 assert(user_clock_value
);
779 if (dmesg_comp
->params
.no_timestamp
) {
783 /* Extract time from input line */
784 if (sscanf(line
, "[%lu.%lu] ", &sec
, &usec
) == 2) {
785 ts
= (uint64_t) sec
* USEC_PER_SEC
+ (uint64_t) usec
;
788 * The clock class we use has a 1 GHz frequency: convert
792 has_timestamp
= true;
793 } else if (sscanf(line
, "[%u-%u-%u %u:%u:%lu.%lu] ",
794 &year
, &mon
, &mday
, &hour
, &min
,
799 memset(&ti
, 0, sizeof(ti
));
800 ti
.tm_year
= year
- 1900; /* From 1900 */
801 ti
.tm_mon
= mon
- 1; /* 0 to 11 */
807 ep_sec
= bt_timegm(&ti
);
808 if (ep_sec
!= (time_t) -1) {
809 ts
= (uint64_t) ep_sec
* NSEC_PER_SEC
810 + (uint64_t) msec
* NSEC_PER_MSEC
;
813 has_timestamp
= true;
817 /* Set new start for the message portion of the line */
818 *new_start
= strchr(line
, ']');
822 if ((*new_start
)[0] == ' ') {
829 * At this point, we know if the stream class's event header
830 * field type should have a timestamp or not, so we can lazily
831 * create the metadata, stream, and packet objects.
833 ret
= try_create_meta_stream_packet(dmesg_comp
, has_timestamp
);
835 /* try_create_meta_stream_packet() logs errors */
839 if (dmesg_comp
->clock_class
) {
840 clock_value
= bt_ctf_clock_value_create(dmesg_comp
->clock_class
,
843 BT_LOGE_STR("Cannot create clock value object.");
847 ft
= bt_ctf_stream_class_get_event_header_type(
848 dmesg_comp
->stream_class
);
850 eh_field
= bt_ctf_field_create(ft
);
852 BT_LOGE_STR("Cannot create event header field object.");
856 ts_field
= bt_ctf_field_structure_get_field_by_name(eh_field
,
859 BT_LOGE_STR("Cannot get `timestamp` field from structure field.");
863 ret
= bt_ctf_field_unsigned_integer_set_value(ts_field
, ts
);
865 BT_LOGE_STR("Cannot set integer field's value.");
869 *user_clock_value
= clock_value
;
871 *user_field
= eh_field
;
889 int create_event_payload_from_line(
890 struct dmesg_component
*dmesg_comp
,
891 const char *line
, struct bt_ctf_field
**user_field
)
893 struct bt_ctf_field_type
*ft
= NULL
;
894 struct bt_ctf_field
*ep_field
= NULL
;
895 struct bt_ctf_field
*str_field
= NULL
;
900 ft
= bt_ctf_event_class_get_payload_type(dmesg_comp
->event_class
);
902 ep_field
= bt_ctf_field_create(ft
);
904 BT_LOGE_STR("Cannot create event payload field object.");
908 str_field
= bt_ctf_field_structure_get_field_by_name(ep_field
, "str");
910 BT_LOGE_STR("Cannot get `timestamp` field from structure field.");
915 if (line
[len
- 1] == '\n') {
916 /* Do not include the newline character in the payload */
920 ret
= bt_ctf_field_string_append_len(str_field
, line
, len
);
922 BT_LOGE("Cannot append value to string field object: "
927 *user_field
= ep_field
;
942 struct bt_notification
*create_notif_from_line(
943 struct dmesg_component
*dmesg_comp
, const char *line
)
945 struct bt_ctf_field
*eh_field
= NULL
;
946 struct bt_ctf_field
*ep_field
= NULL
;
947 struct bt_ctf_clock_value
*clock_value
= NULL
;
948 struct bt_ctf_event
*event
= NULL
;
949 struct bt_notification
*notif
= NULL
;
950 const char *new_start
;
953 ret
= create_event_header_from_line(dmesg_comp
, line
, &new_start
,
954 &eh_field
, &clock_value
);
956 BT_LOGE("Cannot create event header field from line: "
961 ret
= create_event_payload_from_line(dmesg_comp
, new_start
,
964 BT_LOGE("Cannot create event payload field from line: "
970 event
= bt_ctf_event_create(dmesg_comp
->event_class
);
972 BT_LOGE_STR("Cannot create event object.");
976 ret
= bt_ctf_event_set_packet(event
, dmesg_comp
->packet
);
978 BT_LOGE_STR("Cannot set event's packet.");
983 ret
= bt_ctf_event_set_header(event
, eh_field
);
985 BT_LOGE_STR("Cannot set event's header field.");
990 ret
= bt_ctf_event_set_event_payload(event
, ep_field
);
992 BT_LOGE_STR("Cannot set event's payload field.");
997 ret
= bt_ctf_event_set_clock_value(event
, clock_value
);
999 BT_LOGE_STR("Cannot set event's clock value.");
1004 notif
= bt_notification_event_create(event
, dmesg_comp
->cc_prio_map
);
1006 BT_LOGE_STR("Cannot create event notification.");
1018 bt_put(clock_value
);
1024 void destroy_dmesg_notif_iter(struct dmesg_notif_iter
*dmesg_notif_iter
)
1026 if (!dmesg_notif_iter
) {
1030 if (dmesg_notif_iter
->fp
&& dmesg_notif_iter
->fp
!= stdin
) {
1031 if (fclose(dmesg_notif_iter
->fp
)) {
1032 BT_LOGE_ERRNO("Cannot close input file", ".");
1036 free(dmesg_notif_iter
->linebuf
);
1037 g_free(dmesg_notif_iter
);
1041 enum bt_notification_iterator_status
dmesg_notif_iter_init(
1042 struct bt_private_notification_iterator
*priv_notif_iter
,
1043 struct bt_private_port
*priv_port
)
1045 struct bt_private_component
*priv_comp
= NULL
;
1046 struct dmesg_component
*dmesg_comp
;
1047 struct dmesg_notif_iter
*dmesg_notif_iter
=
1048 g_new0(struct dmesg_notif_iter
, 1);
1049 enum bt_notification_iterator_status status
=
1050 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
1052 if (!dmesg_notif_iter
) {
1053 BT_LOGE_STR("Failed to allocate on dmesg notification iterator structure.");
1057 priv_comp
= bt_private_notification_iterator_get_private_component(
1060 dmesg_comp
= bt_private_component_get_user_data(priv_comp
);
1062 dmesg_notif_iter
->dmesg_comp
= dmesg_comp
;
1064 if (dmesg_comp
->params
.read_from_stdin
) {
1065 dmesg_notif_iter
->fp
= stdin
;
1067 dmesg_notif_iter
->fp
= fopen(dmesg_comp
->params
.path
->str
, "r");
1068 if (!dmesg_notif_iter
->fp
) {
1069 BT_LOGE_ERRNO("Cannot open input file in read mode", ": path=\"%s\"",
1070 dmesg_comp
->params
.path
->str
);
1075 (void) bt_private_notification_iterator_set_user_data(priv_notif_iter
,
1080 destroy_dmesg_notif_iter(dmesg_notif_iter
);
1081 (void) bt_private_notification_iterator_set_user_data(priv_notif_iter
,
1084 status
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
1093 void dmesg_notif_iter_finalize(
1094 struct bt_private_notification_iterator
*priv_notif_iter
)
1096 destroy_dmesg_notif_iter(bt_private_notification_iterator_get_user_data(
1101 struct bt_notification_iterator_next_return
dmesg_notif_iter_next(
1102 struct bt_private_notification_iterator
*priv_notif_iter
)
1105 struct dmesg_notif_iter
*dmesg_notif_iter
=
1106 bt_private_notification_iterator_get_user_data(
1108 struct dmesg_component
*dmesg_comp
;
1109 struct bt_notification_iterator_next_return next_ret
= {
1110 .status
= BT_NOTIFICATION_ITERATOR_STATUS_OK
,
1111 .notification
= NULL
1114 assert(dmesg_notif_iter
);
1115 dmesg_comp
= dmesg_notif_iter
->dmesg_comp
;
1120 bool only_spaces
= true;
1122 len
= bt_getline(&dmesg_notif_iter
->linebuf
,
1123 &dmesg_notif_iter
->linebuf_len
, dmesg_notif_iter
->fp
);
1125 if (errno
== EINVAL
) {
1127 BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
1128 } else if (errno
== ENOMEM
) {
1130 BT_NOTIFICATION_ITERATOR_STATUS_NOMEM
;
1133 BT_NOTIFICATION_ITERATOR_STATUS_END
;
1139 assert(dmesg_notif_iter
->linebuf
);
1141 /* Ignore empty lines, once trimmed */
1142 for (ch
= dmesg_notif_iter
->linebuf
; *ch
!= '\0'; ch
++) {
1143 if (!isspace(*ch
)) {
1144 only_spaces
= false;
1154 next_ret
.notification
= create_notif_from_line(dmesg_comp
,
1155 dmesg_notif_iter
->linebuf
);
1156 if (!next_ret
.notification
) {
1157 BT_LOGE("Cannot create event notification from line: "
1158 "dmesg-comp-addr=%p, line=\"%s\"", dmesg_comp
,
1159 dmesg_notif_iter
->linebuf
);