-
Notifications
You must be signed in to change notification settings - Fork 54
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
Remove flockfile for tedge_agent before running --init in postint script #1557
Remove flockfile for tedge_agent before running --init in postint script #1557
Conversation
tedge_agent is supposed to run by the 'tedge' user, therefore, the flockfile is owned by the 'tedge' user. However, due to the directory creation of '/var/tedge', 'tedge_agent --init' must be run as root in the postinst script. If the flockfile owned by 'tedge' user exists, the 'tedge_agent --init' will fail. To fix this issue, the postinst script should remove the flock file if it exists before the initialization. Signed-off-by: Rina Fujino <18257209+rina23q@users.noreply.github.com>
rm /run/lock/tedge_agent.lock | ||
fi | ||
# It must be run as root to create the directory `/var/tedge`. | ||
tedge_agent --init |
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.
But then, we will have a lock own by root, preventing the agent to run as tedge. Am I missing something?
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.
My experiment on my laptop, tedge_agent.lock
is gone after tedge_agent --init
. However, to keep it safe, I can add the lines to remove /run/lock/tedge_agent.lock
after tedge_agent --init
.
if [ -f "/run/lock/tedge_agent.lock" ]; then
rm /run/lock/tedge_agent.lock
fi
This was the output when I ran sudo tedge_agent --init
.
rina@SAG-CFPPNV2-U:/etc/tedge$ inotifywait -m /run/lock/
Setting up watches.
Watches established.
/run/lock/ CREATE tedge_agent.lock
/run/lock/ OPEN tedge_agent.lock
/run/lock/ CLOSE_WRITE,CLOSE tedge_agent.lock
/run/lock/ DELETE tedge_agent.lock
rina@SAG-CFPPNV2-U:~$ sudo tedge_agent --init
[sudo] password for rina:
2022-11-04T13:18:47.710656337Z INFO flockfile::unix: Lockfile created "/run/lock/tedge_agent.lock"
2022-11-04T13:18:47.710699697Z INFO tedge_agent::agent: tedge_agent starting
2022-11-04T13:18:47.712704417Z INFO sm-agent{config_dir="/etc/tedge"}: tedge_agent::agent: Initializing the tedge agent session
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.
Okay. It makes sense and it's useless to remove the lock after --init.
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.
Approved
Proposed changes
tedge_agent is supposed to run by the
tedge
user, therefore, the flockfile is owned by thetedge
user. However, due to the directory creation of/var/tedge
,tedge_agent --init
must be run as root in the postinst script. If the flockfile owned bytedge
user exists, thetedge_agent --init
will fail.To fix this issue, the postinst script should remove the flock file if it exists before the initialization.
Types of changes
Paste Link to the issue
#1551
Checklist
cargo fmt
as mentioned in CODING_GUIDELINEScargo clippy
as mentioned in CODING_GUIDELINESFurther comments