Skip to content

Fix mountinfo parsing #153 #154

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

Merged
merged 9 commits into from
Feb 7, 2022
Merged

Fix mountinfo parsing #153 #154

merged 9 commits into from
Feb 7, 2022

Conversation

IGLOU-EU
Copy link
Contributor

@IGLOU-EU IGLOU-EU commented Jan 9, 2022

Quick patch to fix
#153 mount -t tmpfs - /tmp -> "found invalid line"

Split directly with strings.Fields instead of "(8) separator: marks the end of the optional fields"

Todo:

Signed-off-by: Adrien Kara adrien@iglou.eu

@muesli
Copy link
Owner

muesli commented Jan 9, 2022

We should probably add a test for various valid and/or problematic entries.

@IGLOU-EU
Copy link
Contributor Author

IGLOU-EU commented Jan 9, 2022

Do you have any test cases in mind ?

By reading the source code of glib:

I tested the encoded part

$ sudo mount -t tmpfs a-b /mnt/a\ b
$ cat /proc/self/mountinfo
...
94 27 0:38 / /mnt/a\040b rw,relatime shared:263 - tmpfs a-b rw,inode64

There was no need to go so far ... https://man7.org/linux/man-pages/man5/fstab.5.html

The second field (fs_file) => If the name of the mount point contains spaces or tabs these can be escaped as `\040' and '\011' respectively.

EDIT:
Because of the apparent "complexity", I think a dedicated function is needed. Don't you?
If it is good for you, I will add a mounts_linux_internal_test.go file

scr_100122_152913

@muesli ?

@muesli
Copy link
Owner

muesli commented Feb 1, 2022

Do you have any test cases in mind ?

The second field (fs_file) => If the name of the mount point contains spaces or tabs these can be escaped as `\040' and '\011' respectively.

That should we test for as well.

EDIT: Because of the apparent "complexity", I think a dedicated function is needed. Don't you? If it is good for you, I will add a mounts_linux_internal_test.go file

I agree.

Nice work so far, will give this a proper review asap.

@IGLOU-EU IGLOU-EU changed the title [WIP] Fix mountinfo parsing #153 Fix mountinfo parsing #153 Feb 6, 2022
@IGLOU-EU
Copy link
Contributor Author

IGLOU-EU commented Feb 6, 2022

@muesli , can you review ? 🙂

scr_060222_044535

IGLOU-EU and others added 9 commits February 6, 2022 09:09
Signed-off-by: Adrien Kara <adrien@iglou.eu>
Added a getFields function to parse fields as defined in
    "proc(5)" section "/proc/[pid]/mountinfo".
It is possible to use forbidden characters in the mountinfo file, for this
    Linux kernel encodes them
    https://github.com/torvalds/linux/blob/master/fs/proc_namespace.c#L87.
Skip empty or commented lines.

Signed-off-by: Adrien Kara <adrien@iglou.eu>
Signed-off-by: Adrien Kara <adrien@iglou.eu>
Signed-off-by: Adrien Kara <adrien@iglou.eu>
Signed-off-by: Adrien Kara <adrien@iglou.eu>
Signed-off-by: Adrien Kara <adrien@iglou.eu>
Signed-off-by: Adrien Kara <adrien@iglou.eu>
@muesli
Copy link
Owner

muesli commented Feb 7, 2022

Ok, I've simplified the mountinfo parsing a bit. Everything seems to be working and testing fine, but maybe you wanna give it one more review as well. unescapeFstab seems to decode the strings just fine, so I've removed the newly added decodeName function again.

@muesli muesli added the bug Something isn't working label Feb 7, 2022
@IGLOU-EU
Copy link
Contributor Author

IGLOU-EU commented Feb 7, 2022

Cool, I hadn't seen it.
I'm not sure if it's a good idea to not respect the official mountinfo index, like defined by proc man pages.

Otherwise, it's good to me

@muesli muesli merged commit e98632a into muesli:master Feb 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants