mirror of https://github.com/nocturn9x/nimd.git
50 lines
1.8 KiB
Nim
50 lines
1.8 KiB
Nim
# Copyright 2021 Mattia Giambirtone & All Contributors
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
import segfaults # Makes us catch segfaults as NilAccessDefect exceptions!
|
|
import strformat
|
|
import posix
|
|
import os
|
|
|
|
|
|
import ../util/[logging, disks, misc]
|
|
|
|
|
|
proc mainLoop*(logger: Logger, mountDisks: bool = true) =
|
|
## NimD's main execution loop
|
|
try:
|
|
if mountDisks:
|
|
logger.info("Mounting virtual disks")
|
|
mountVirtualDisks(logger)
|
|
logger.info("Mounting real disks")
|
|
mountRealDisks(logger)
|
|
else:
|
|
logger.info("Skipping disk mounting, did we restart after a critical error?")
|
|
except IndexDefect: # Check parseFileSystemTable for more info on this catch block
|
|
logger.fatal("Improperly formatted /etc/fstab, exiting")
|
|
nimDExit(logger, 131)
|
|
logger.info("Disks mounted")
|
|
logger.info("Processing boot runlevel")
|
|
# TODO
|
|
logger.info("Processing default runlevel")
|
|
# TODO
|
|
logger.info("System initialization complete, going idle")
|
|
while true:
|
|
try:
|
|
# TODO
|
|
sleepSeconds(5)
|
|
except:
|
|
logger.critical(&"A critical error has occurred while running, restarting the mainloop! Error -> {getCurrentExceptionMsg()}")
|
|
# We *absolutely* cannot die
|
|
mainLoop(logger, mountDisks=false)
|