-
Notifications
You must be signed in to change notification settings - Fork 881
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
fix(runpath): On *BSD, create /run is not ephemeral #4677
Conversation
6482cc4
to
3035854
Compare
On *BSD, `/run` is not ephemeral, but the way cloud-init behaves, it expects it to be. This is hack is partial fix for canonicalGH-4180 / canonicalGH-4231. But to be good Unix citizens, we should still make /run relocatable in the code and in the installer. Sponsored by: The FreeBSD Foundation Fixes canonicalGH-4180 Fixes canonicalGH-4231
let's just use an `if`! Sponsored by: The FreeBSD Foundation
3035854
to
6ab2f83
Compare
let's just use an `if`! Sponsored by: The FreeBSD Foundation
6ab2f83
to
12bcdfd
Compare
let's just use an `if`! Sponsored by: The FreeBSD Foundation
12bcdfd
to
10e6d4c
Compare
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 is some of the best (harmless) shell code I've written yet
0a274a1
to
e2c4cdb
Compare
let's just use an `if`! Sponsored by: The FreeBSD Foundation
shuffle code-paths around such that we initialize RUN_PATH, and all the things that depend on it after figuring out which OS we're on, while still alowing these global variables to be overwritten from the outside. On BSD /run is not ephemeral, so here we set RUN_PATH to /var/run. Ensure everything is initialized for 'print_info', not just for 'main'. For the tests, we equally ensure that for not-Linux systems the data is written into `rootd + var/run` instead of `rootd + run`. Sponsored by: The FreeBSD Foundation
on BSD, /run is not ephemeral. relocate BSDs config to /var/run Sponsored by: The FreeBSD Foundation Fixes canonicalGH-4180 Fixes canonicalGH-4231 Co-authored-by: Brett Holman <brett.holman@canonical.com>
tools/ds-identify
Outdated
@@ -1579,6 +1581,10 @@ collect_info() { | |||
} | |||
|
|||
print_info() { | |||
DI_LOG=stderr |
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 understanding is that this is correct
although it didn't seem to be necessary before
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.
Why do we need the DI_LOG=stderr
and ensure_sane_path
calls? I don't think that those ones are required.
I think that I see why read_uname_info
and set_run_path
might be required - this function is the other "main" entry point of this function, thus will require the PATH_RUN*
variables to be properly set, as they were before this function.
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.
here's what happens without DI_LOG=stderr
:
tools/ds-identify: 185: 3: Bad file descriptor
tools/ds-identify: 185: 3: Bad file descriptor
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 set_run_path
is not, so i removed that.
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 meant the other way around:
diff --git a/tools/ds-identify b/tools/ds-identify
index 6e923a550..154668a00 100755
--- a/tools/ds-identify
+++ b/tools/ds-identify
@@ -1584,8 +1584,7 @@ collect_info() {
}
print_info() {
- DI_LOG=stderr
- ensure_sane_path
+ set_run_path
read_uname_info
collect_info
_print_info
set_run_path
sets DI_LOG
, so I don't think hardcoding it here is necessary. We shouldn't unconditionally log to stderr, in case of DI_MAIN=print_info DI_LOG=/some/file tools/ds-identify
or similar.
The above didn't have the bad descriptor issue you mentioned.
Also ensure_sane_path
wasn't called in print_info
before - I see no reason to add it.
let's just use an `if`! Sponsored by: The FreeBSD Foundation
shuffle code-paths around such that we initialize RUN_PATH, and all the things that depend on it after figuring out which OS we're on, while still alowing these global variables to be overwritten from the outside. On BSD /run is not ephemeral, so here we set RUN_PATH to /var/run. Ensure everything is initialized for 'print_info', not just for 'main'. For the tests, we equally ensure that for not-Linux systems the data is written into `rootd + var/run` instead of `rootd + run`. Sponsored by: The FreeBSD Foundation
on BSD, /run is not ephemeral. relocate BSDs config to /var/run Sponsored by: The FreeBSD Foundation Fixes canonicalGH-4180 Fixes canonicalGH-4231 Co-authored-by: Brett Holman <brett.holman@canonical.com>
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.
Great work here @igalic, I like the way this one is coming together. I have a couple smallish requests / questions, once resolved I'll merge.
tools/ds-identify
Outdated
@@ -1579,6 +1581,10 @@ collect_info() { | |||
} | |||
|
|||
print_info() { | |||
DI_LOG=stderr |
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.
Why do we need the DI_LOG=stderr
and ensure_sane_path
calls? I don't think that those ones are required.
I think that I see why read_uname_info
and set_run_path
might be required - this function is the other "main" entry point of this function, thus will require the PATH_RUN*
variables to be properly set, as they were before this function.
tools/ds-identify
Outdated
|
||
DI_LOG="${DI_LOG:-${PATH_RUN_CI}/ds-identify.log}" | ||
# Declare global here, we'll set it properly in main() |
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.
Lets add a comment explaining that the default values for these variables are system-specific, therefore must be assigned after collecting some information from the system.
e2c4cdb
to
c8098d0
Compare
let's just use an `if`! Sponsored by: The FreeBSD Foundation
shuffle code-paths around such that we initialize RUN_PATH, and all the things that depend on it after figuring out which OS we're on, while still alowing these global variables to be overwritten from the outside. On BSD /run is not ephemeral, so here we set RUN_PATH to /var/run. Ensure everything is initialized for 'print_info', not just for 'main'. For the tests, we equally ensure that for not-Linux systems the data is written into `rootd + var/run` instead of `rootd + run`. Sponsored by: The FreeBSD Foundation
on BSD, /run is not ephemeral. relocate BSDs config to /var/run Sponsored by: The FreeBSD Foundation Fixes canonicalGH-4180 Fixes canonicalGH-4231
let's just use an `if`! Sponsored by: The FreeBSD Foundation
shuffle code-paths around such that we initialize RUN_PATH, and all the things that depend on it after figuring out which OS we're on, while still alowing these global variables to be overwritten from the outside. On BSD /run is not ephemeral, so here we set RUN_PATH to /var/run. Ensure everything is initialized for 'print_info', not just for 'main'. For the tests, we equally ensure that for not-Linux systems the data is written into `rootd + var/run` instead of `rootd + run`. Sponsored by: The FreeBSD Foundation
on BSD, /run is not ephemeral. relocate BSDs config to /var/run Sponsored by: The FreeBSD Foundation Fixes canonicalGH-4180 Fixes canonicalGH-4231
2bbde27
to
13281ca
Compare
shuffle code-paths around such that we initialize RUN_PATH, and all the things that depend on it after figuring out which OS we're on, while still alowing these global variables to be overwritten from the outside. On BSD /run is not ephemeral, so here we set RUN_PATH to /var/run. Ensure everything is initialized for 'print_info', not just for 'main'. For the tests, we equally ensure that for not-Linux systems the data is written into `rootd + var/run` instead of `rootd + run`. Sponsored by: The FreeBSD Foundation
on BSD, /run is not ephemeral. relocate BSDs config to /var/run Sponsored by: The FreeBSD Foundation Fixes canonicalGH-4180 Fixes canonicalGH-4231
shuffle code-paths around such that we initialize RUN_PATH, and all the things that depend on it after figuring out which OS we're on, while still alowing these global variables to be overwritten from the outside. On BSD /run is not ephemeral, so here we set RUN_PATH to /var/run. Ensure everything is initialized for 'print_info', not just for 'main'. For the tests, we equally ensure that for not-Linux systems the data is written into `rootd + var/run` instead of `rootd + run`. Sponsored by: The FreeBSD Foundation
on BSD, /run is not ephemeral. relocate BSDs config to /var/run Sponsored by: The FreeBSD Foundation Fixes canonicalGH-4180 Fixes canonicalGH-4231
13281ca
to
8852126
Compare
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 this is done now…
@@ -1835,12 +1843,25 @@ read_uptime() { | |||
return | |||
} | |||
|
|||
set_run_path() { | |||
if [ "$DI_UNAME_KERNEL_NAME" != "Linux" ]; then |
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.
make sure this function works on Linux… even if someone forgot to call read_uname_info()
…
@@ -154,6 +159,8 @@ debug() { | |||
shift | |||
[ "$lvl" -gt "${DI_DEBUG_LEVEL}" ] && return | |||
|
|||
[ "$DI_LOG" = "" ] && DI_LOG="stderr" |
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.
make sure the debug()
function works, even if someone forgot to set_run_path()
, or DI_LOG
.
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.
Mentally walking through this:
- call to
debug
beforeset_run_path
causesDI_LOG
set tostderr
,_DI_LOGGED
set tostderr
, file descriptor 3 redirects to file descriptor 2 set_run_path
redefinesDI_LOG
towhatever/cloud-init.log
- subsequent call to
debug
sees that"$_DI_LOGGED" != "$DI_LOG"
, re-opens fd 3 pointing towhatever/cloud-init.log
, reassigns_DI_LOGGED
to$DI_LOG
- subsequent calls to
debug
use fd 3 which points to the right file
Looks good to me!
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.
Great work @igalic. This looks good to me.
@@ -154,6 +159,8 @@ debug() { | |||
shift | |||
[ "$lvl" -gt "${DI_DEBUG_LEVEL}" ] && return | |||
|
|||
[ "$DI_LOG" = "" ] && DI_LOG="stderr" |
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.
Mentally walking through this:
- call to
debug
beforeset_run_path
causesDI_LOG
set tostderr
,_DI_LOGGED
set tostderr
, file descriptor 3 redirects to file descriptor 2 set_run_path
redefinesDI_LOG
towhatever/cloud-init.log
- subsequent call to
debug
sees that"$_DI_LOGGED" != "$DI_LOG"
, re-opens fd 3 pointing towhatever/cloud-init.log
, reassigns_DI_LOGGED
to$DI_LOG
- subsequent calls to
debug
use fd 3 which points to the right file
Looks good to me!
let's just use an `if`! Sponsored by: The FreeBSD Foundation
shuffle code-paths around such that we initialize RUN_PATH, and all the things that depend on it after figuring out which OS we're on, while still alowing these global variables to be overwritten from the outside. On BSD /run is not ephemeral, so here we set RUN_PATH to /var/run. Ensure everything is initialized for 'print_info', not just for 'main'. For the tests, we equally ensure that for not-Linux systems the data is written into `rootd + var/run` instead of `rootd + run`. Sponsored by: The FreeBSD Foundation
Changelog(s): - https://github.com/canonical/cloud-init/releases/tag/23.4.1 - https://github.com/canonical/cloud-init/releases/tag/23.4 Note that net/cloud-init-devel finally relocates /run to /var/run See: canonical/cloud-init#4677 PR: 275896
Proposed Commit Message
Additional Context
Test Steps
Checklist
Merge type