Attempt to fix broken /dev/null resulting from bug in updater script. (#21432)
* Attempt to fix broken /dev/null resulting from bug in updater script. This checks if `/dev/null` either doesn’t exist, or is a regular file, and attempts to recreate it correctly as a device file if either of those situations is the case. This is intended to automatically repair systems that were affected by the bug fixed by PR #21428. * Handle SELinux security context properly. * Remove FreeBSD case. * Update packaging/installer/netdata-updater.sh Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> * Use a secure temporary file. --------- Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
Austin S. Hemmelgarn committed
Dec 11, 2025 at 06:48 UTC
8c40d4cc9044a1b9fb4832fde15bb3445090f75f
1 file changed
+39
packaging/installer/netdata-updater.sh
+39
@@ -300,6 +300,43 @@ install_build_dependencies() {
300
fi
301
}
302
303
+# Certain versions of this script had a bug that could cause /dev/null
304
+# to be removed mistakenly under some circumstances.
305
+#
306
+# This function attempts to detect and fix the resulting situation.
307
+#
308
+# Fix limited to Linux for the moment because apparently trying to
309
+# proactively fix systems that we aren’t certain have been affected is
310
+# too invasive of a change for some people...
311
+dev_null_fix() {
312
+ if [ -f /dev/null ] || [ ! -e /dev/null ]; then
313
+ case "$(uname -s)" in
314
+ Linux)
315
+ rm -f /dev/.null
316
+ mknod -m 666 /dev/.null c 1 3
317
+ # Some distros use ownership other than root:root for /dev/null,
318
+ # but it almost always matches the ownership of /dev/full,
319
+ # so if possible copy the onwership from there.
320
+ if [ -c /dev/full ]; then
321
+ chown --reference=/dev/full /dev/.null
322
+ fi
323
+ mv -f /dev/.null /dev/null
324
+ # If the system seems to be using SELinux, apply the correct
325
+ # security context to the new /dev/null.
326
+ #
327
+ # This check doesn’t use /dev/null as trying to access it
328
+ # without the right security context being set may fail.
329
+ dummy_null="$(mktemp)"
330
+ if command -v restorecon >"${dummy_null}" 2>&1; then
331
+ restorecon /dev/null
332
+ fi
333
+ rm -f "${dummy_null}" || true # Cleanup from the above check
334
+ ;;
335
+ *) ;;
336
+ esac
337
+ fi
338
+}
339
+
340
enable_netdata_updater() {
341
updater_type="$(echo "${1}" | tr '[:upper:]' '[:lower:]')"
342
case "${updater_type}" in
@@ -1397,6 +1434,8 @@ fi
1434
1435
self_update
1436
1437
+dev_null_fix
1438
+
1439
# shellcheck disable=SC2153
1440
case "${INSTALL_TYPE}" in
1441
*-build)