-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unify logging in sesman #1708
Unify logging in sesman #1708
Conversation
Hi @aquesnel Thanks very much for this. I was half expecting it it show up soon! I've just run a few textual modifications, and I'm pretty sure that the vast majority of this PR, with the exception of Assuming it is, we can focus the discussion on
|
Yes you are correct, this commit was created by running a find and replace over the code. I created a shell script to handle the weirdness of the double parenthesis of some of the old macros. I can post this script or add it to the pull request if you think it's worth it. For this change I assumed that the previous log levels were correct, and I'm happy to fix them up. For the hex dump, I've already written a log hex dump function and macro, but I didn't include it in pull request since I hadn't seen a hex dump used in any of the files. I'll just include the function in this pull request. |
I don't think we need the script - this particular file is easy enough to review manually in any case. The hex dump was a surprise to me too - I've not seen it before but I can see where it would be useful. |
Hi @matt335672 , I've updated the code to include the |
Hi @aquesnel, That's great - thanks. A couple of general points:-
Also, with reference to
The wildcard looks a bit odd, but is necessary with a single file. One hint I'll give is around line 729 where you've got I'll get on with a review of the code now. I might be a bit pressed for time over the next couple of days with family duties. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good. I'll run some tests when changes are done. Thanks again.
common/log.c
Outdated
if(logger->log_level < log_level) | ||
{ | ||
return 0; | ||
} | ||
else | ||
{ | ||
return 1; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't return (log_level <= logger->log_level)
be a simpler way to express this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed, fixed
common/log.c
Outdated
} | ||
|
||
dump_line_length = 4 + 3 /* = 4 offset + 3 space */ | ||
+ ((2 + 1) * 16) /* + (2 hex + 1 space) per byte for 16 bytes */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest making the 16
a macro as it's used a lot.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed, fixed
sesman/chansrv/smartcard_pcsc.c
Outdated
if (uds_client_id == 0) | ||
{ | ||
LLOGLN(10, ("get_uds_client_by_id: uds_client_id zero")); | ||
LOG_DEVEL(LOG_LEVEL_ERROR, "get_uds_client_by_id: uds_client_id zero"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace LOG_DEVEL
with LOG
in all places where LOG_LEVEL_ERROR
is used in this file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what a sysadmin will do with the log messages like "ERROR: uds_client_id is zero", since this seems more like a bug than a misconfiguration.
I'm deferring to you that having these messages in the release version's log makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair point! It's a poor message, but probably better than nothing at all.
common/log.c
Outdated
aligned to the first column instead of to after the log message | ||
preamble (eg. time, log level, ...) | ||
*/ | ||
g_sprintf(dump_buffer, "%%s Hex Dump:"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra comment which I managed to lose in the review:-
Suggest making "%s Hex Dump:\n"
a macro like this:-
#ifdef _WIN32
#define HEX_DUMP_HEADER "%s Hex Dump:\r\n"
#else
#ifdef _MACOS
#define HEX_DUMP_HEADER "%s Hex Dump:\r"
#else
#define HEX_DUMP_HEADER "%s Hex Dump:\n"
#endif
#endif
#define HEX_DUMP_HEADER_SIZE (sizeof(HEX_DUMP_HEADER) - 1)
I'm sure you get the idea. You can them remove the magic number 12.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed, fixed
Hi @matt335672 , I've been trying to get Diff pre- vs post- astyle formatting:
My problem is similar to this stack overflow question but the links to the astyle bug report is broken. I've done my own debugging and been able to trace this down to having the word "enum" in the return type of the function that is being formatted. When I replace the enum with a typedef or macro for that enum, then astyle formats the split line with the expected indentation. This looks like a bug in astyle mis-identifying the function as an enum or something. The only thing I have found in the is a reference in the astyle release notes for 2.05.1 for "Fix error in identifying an enum return type as an enumeration" I've tried running with astyle version 2.06 and with 3.1. The 3.1 version does a better formatting job overall, but it still lines up the split dump_line_length line to the left. My plan is to make a typedef for Do you have a different suggestion for how to workaround this astyle issue? |
Hi @aquesnel Yes I do. I'd mentioned it above but re-reading my comment I could have been clearer. If you add parentheses around the whole expression astyle will behave differently. Try this (adjust to taste):- dump_line_length = (4 + 3 + /* = 4 offset + 3 space */
((2 + 1) * 16) + /* + (2 hex + 1 space) per byte for 16 bytes */
2 + 16 + 1); /* + 2 space + 16 bytes as chars + 1 newline */ I'm using astyle 3.1. Try that and let me know how you get on. |
Hi @matt335672 , I had originally tried adding braces as you suggested around the dump_line_length line, but apparently astyle 2.06 has a bug that causes it to not indent the braced split line when a function returns an enum. This bug is fixed in astyle 3.1 so I'll add a note to the Coding-Style wiki page to say that astyle 3.1 or above should be used. I've also run astyle on all of the .c files in sesman/* since most of the formatting errors are caused by the logging changes. I skipped the following files because:
Please let me know if you have any concerns with the additional code formatting. |
Hi @aquesnel Thanks for that. I've approved the changes I've requested, and I've run your hexdump code through a test rig. It all looks fine to me. One small change you might like to consider is adding a call for the As it stands, an attacker managing to get a large value into the Personally I'm happy that you've run the rest of the sesman code through astyle. It's a good time to do it as all the logging macros are changing too, so I can't see it causing any more upheaval than this PR would anyway. It makes checking code before commit a lot easier in the future, @metalefty - are you happy with asyle being run on sesman in this way? |
Hi @metalefty , Do you have any concerns or feedback for this pull request that you think should be addressed before this can be merged? |
42923b0
to
0c61a15
Compare
Let's merge. |
Follow-on pull request to #1633 which migrates all logging in sesman to use the
LOG()
andLOG_DEVEL()
macros.