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
Augeas add lenspath to errormessage #3286
Conversation
references #203
New message:
|
jenkins build libelektra please |
Thank you, looks good to me. |
The commands: kdb mount /etc/security/limits.conf system/tests augeas lens=NonExistingLens
kdb ls system/tests do not print an error message on my machine. Is this expected behavior? |
Thank you for the fast response. Maybe I still use an old version of Elektra. Guess I need to try again with a clean build directory. |
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 think I found a small off-by-one error. Other than that everything looks good as far as I can tell.
@@ -111,12 +111,17 @@ int elektraAugeasGenConf (KeySet * ks, Key * errorKey ELEKTRA_UNUSED) | |||
return retval; | |||
} | |||
|
|||
static const char * getAugeasError (augeas * augeasHandle) | |||
static const char * getAugeasError (augeas * augeasHandle, const char * lensPath) |
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 think you can also make the pointer const
, if you want to.
static const char * getAugeasError (augeas * augeasHandle, const char * lensPath) | |
static const char * getAugeasError (augeas * augeasHandle, const char * const lensPath) |
reason = aug_error_message (augeasHandle); | ||
size_t messageSize = strlen (reason) + strlen (lensPath) + strlen (format); |
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.
As far as I know strlen
only returns the number of characters of a string.
The strlen() function returns the number of characters that precede the terminating NUL character.
I think you need an additional byte for the terminating \0
character, otherwise buffer
will not be able to hold the entire error message.
size_t messageSize = strlen (reason) + strlen (lensPath) + strlen (format); | |
size_t messageSize = strlen (reason) + strlen (lensPath) + strlen (format) + 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.
I have copied this from here:
libelektra/src/plugins/augeas/augeas.c
Lines 143 to 150 in e747336
const char * format = "%s\n\tposition: %s:%s\n\tmessage: %s\n\tlens: %s"; | |
size_t messageSize = (augeasError ? strlen (augeasError) : 0) + (line ? strlen (line) : 0) + | |
(character ? strlen (character) : 0) + (message ? strlen (message) : 0) + | |
(lens ? strlen (lens) : 0) + strlen (format); | |
char * buffer = elektraMalloc (messageSize); | |
snprintf (buffer, messageSize, format, augeasError ? augeasError : "", line ? line : "", character ? character : "", | |
message ? message : "", lens ? lens : ""); | |
reason = buffer; |
This bug should then also appear there
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.
This bug should then also appear there
I think you are right. The off-by-one error is also one of the reasons why elektraStrLen
also counts the terminating NULL
character.
libelektra/src/libs/elektra/internal.c
Lines 369 to 371 in f3460ca
* This function differs from strlen() because it is Unicode and multibyte | |
* chars safe. While strlen() counts characters and ignores the final NULL, | |
* elektraStrLen() count bytes including the ending NULL. |
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.
@kodebach can you take a look here?
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.
What exactly should I look at?
@sanssecours is right in general, but actually the + 1
is not needed here. The string format
is a printf
-string in the resulting buffer the %s
will not be present, but they are counted by strlen
. So actually the allocated buffer is 3 bytes bigger than it needs to be.
I didn't check the second one. It might be more problematic, because in the NULL
cases, strlen
is replaced by 0, but the NULL string is replaced by " "
. I think it still works, but adding 1 to the buffer size certainly doesn't hurt.
PS If someone is working on augeas
, there are code paths where it sets an error, but continues to execute and in the end returns SUCCESS
.
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.
The string
format
is aprintf
-string in the resulting buffer the%s
will not be present, but they are counted bystrlen
.
I did not think about that 😊. Thank you for the detailed explanation.
I still can not reproduce the error message. Neither on macOS nor on Ubuntu Bionic the commands:
print an error message. I also tried to reproduce the error message unsuccessfully on Cirrus using FreeBSD. Of course there is still the possibility that I did something wrong. As far as I can tell the branch I used for testing should include the updates of this PR though. |
I just pulled from origin/master, cleared the build directory, freshly installed and tried it with success. does the behavior change when you add sudo to the commands? |
@sanssecours I think you have a different problem than this PR tries to solve. This PR is about adding additional information about an (in this PR unchanged) error from Augeas. Of course it would be nice to have shell recorder tests for the augeas plugin but I think other tasks have higher priority. For me it works:
I agree with @sanssecours though that these arbitrary whitespaces everywhere only create problems. It is also inconsistent to other errors. |
That might be the case. As I write below I was finally able to reproduce the error using Docker. For my usual build configuration on macOS, the commands still do not produce an error message though. Anyway, from my point of view, this PR does what it is supposed to do 👍.
Nope. The commands:
do not print an error message. There might be some differences between my system and your system that influence the behavior. For example:
Anyway, after some time I was finally able to reproduce the error message using the steps below.
|
Basics
These points need to be fulfilled for every PR:
(added as entry in
doc/news/_preparation_next_release.md
whichcontains
_(my name)_
)Please always add something to the release notes.
(first line should have
module: short statement
syntax)close #X
, are in the commit messages.If you have any troubles fulfilling these criteria, please write
about the trouble as comment in the PR. We will help you.
But we cannot accept PRs that do not fulfill the basics.
Checklist
Check relevant points but please do not remove entries.
For docu fixes, spell checking, and similar none of these points below
need to be checked.
(not in the PR description)
Review
Reviewers will usually check the following:
Labels
If you are already Elektra developer:
say that everything is ready to be merged.