Skip to content

logger: Log fread error only when it happened - #3463

Merged
lgirdwood merged 4 commits into
thesofproject:masterfrom
ktrzcinx:logger-ferror
Sep 25, 2020
Merged

lgirdwood merged 4 commits into
thesofproject:masterfrom
ktrzcinx:logger-ferror

Conversation

@ktrzcinx

@ktrzcinx ktrzcinx commented Sep 24, 2020 •

Copy link
Copy Markdown
Member
fread may return 0 when some error occurred or nothig has been reded.

Fixes: 337afc4f3809: ("logger: add error message when reading sof/etrace instead of sof/trace")

Signed-off-by: Karol Trzcinski <karolx.trzcinski@linux.intel.com>

@ktrzcinx
ktrzcinx requested a review from marc-hb September 24, 2020 12:03
@ktrzcinx
ktrzcinx force-pushed the logger-ferror branch 3 times, most recently from 5467b77 to 59b0054 Compare September 24, 2020 13:43
Comment thread tools/logger/convert.c Outdated

@marc-hb marc-hb left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The while (!ferror(global_config->in_fd)) { still doesn't make sense to me. Should it not be while(!feof)? What is the expected code path when no error ever occurs and feof is met?

Comment thread tools/logger/convert.c Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I removed ferror() here in commit 337afc4, my bad. After doing my homework (better late than never) I think it's better to add ferror() back here and use it instead of !feof() because the standard doesn't state that feof and ferror are mutually exclusive. In fact you could imagine both of them being true.

https://pubs.opengroup.org/onlinepubs/9699919799/functions/fread.html

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW the if(!ret) is really confusing, please change it to if(ret<1) to make it consistent with the fread() specification.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@marc-hb

marc-hb commented Sep 25, 2020

Copy link
Copy Markdown
Collaborator

337afc4: doesn't work in github, use 12 characters and no trailing colon: 337afc4f3809. When unquoted it shows up as: 337afc4

Please also run this command:

git config --global core.abbrev 12

Only once per user account and done! It's required for the Linux kernel and is better for everything else.

fread may return 0 when some error occurred or nothig has been reded.
Moreover errno may not be set on Windows plaform, use ferror
instead. See:
https://www.gnu.org/software/gnulib/manual/html_node/fread.html

Fixes: 337afc4: ("logger: add error message when reading sof/etrace instead of sof/trace")

Signed-off-by: Karol Trzcinski <karolx.trzcinski@linux.intel.com>
log format text comes from ldc file (may be invalid),
so error check is needed. Don't treat it as fatal error,
because this error may not impact following logs, when
formatting text is root cause of the issue.

Signed-off-by: Karol Trzcinski <karolx.trzcinski@linux.intel.com>
Windows platform needs "rb" mode to read binary file,
otherwise after read 0x1A EOF will be. See:
https://stackoverflow.com/questions/11717120/unexpected-return-value-from-fread

Signed-off-by: Karol Trzcinski <karolx.trzcinski@linux.intel.com>
fread() returns number of readed blocks, 0 when nothing read.
Comparison fread return value with "!ret" is quite misleading -
may suggests that negative value is returrned after fail.

Swapping if content makes flow easier, then first is error check,
and eventyally return statement, next try to reopen file.
It allows to check error condition only in one place, so there
won't be possibility to use different error checks in subsequent
stages (like ferror() and errno).

in_file alignment with trace entry size check has been added,
to warn about corrupted file.

Signed-off-by: Karol Trzcinski <karolx.trzcinski@linux.intel.com>
@lgirdwood

Copy link
Copy Markdown
Member

@ktrzcinx we will get this in v1.6 final.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants