Add options to kernelinfo(2).

This commit is contained in:
Jonas 'Sortie' Termansen 2023-09-03 17:23:12 +02:00
parent 4aadc182a6
commit dc98bcf0ca
4 changed files with 45 additions and 2 deletions

View File

@ -80,6 +80,7 @@
#include "kb/default-kblayout.h"
#include "kb/kblayout.h"
#include "kb/ps2.h"
#include "kernelinfo.h"
#include "logterminal.h"
#include "mouse/ps2.h"
#include "multiboot.h"
@ -228,6 +229,9 @@ extern "C" void KernelInit(unsigned long magic, multiboot_info_t* bootinfo_p)
FreeKernelAddress(&alloc);
}
if ( !(kernel_options = strdup(cmdline ? cmdline : "")) )
Panic("Failed to allocate kernel command line");
int argmax = 1;
argv = new char*[argmax + 1];
if ( !argv )

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2015, 2022 Jonas 'Sortie' Termansen.
* Copyright (c) 2012, 2015, 2022, 2023 Jonas 'Sortie' Termansen.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@ -24,17 +24,22 @@
#include <sortix/kernel/kernel.h>
#include <sortix/kernel/syscall.h>
#include "kernelinfo.h"
#ifndef VERSIONSTR
#define VERSIONSTR "unknown"
#endif
namespace Sortix {
char* kernel_options;
static const char* KernelInfo(const char* req)
{
if ( strcmp(req, "name") == 0 ) { return BRAND_KERNEL_NAME; }
if ( strcmp(req, "version") == 0 ) { return VERSIONSTR; }
if ( strcmp(req, "tagline") == 0 ) { return BRAND_RELEASE_TAGLINE; }
if ( strcmp(req, "options") == 0 ) { return kernel_options; }
if ( strcmp(req, "builddate") == 0 ) { return __DATE__; }
if ( strcmp(req, "buildtime") == 0 ) { return __TIME__; }
#if defined(__i386__) || defined(__x86_64__)

29
kernel/kernelinfo.h Normal file
View File

@ -0,0 +1,29 @@
/*
* Copyright (c) 2023 Jonas 'Sortie' Termansen.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* kernelinfo.h
* Lets user-space query information about the kernel.
*/
#ifndef KERNELINFO_H
#define KERNELINFO_H
namespace Sortix {
extern char* kernel_options;
} // namespace Sortix
#endif

View File

@ -21,6 +21,10 @@ The name of the current kernel.
The version of the current kernel.
.It Sy tagline
The tagline (slogan) of the release.
.It Sy options
The
.Xr kernel 7
options.
.It Sy builddate
The date on which the current kernel was built.
.It Sy buildtime
@ -33,4 +37,5 @@ The firmware of the system (e.g. "bios" or "uefi")
will exit 0 on success and non-zero otherwise.
.Sh SEE ALSO
.Xr uname 1 ,
.Xr kernelinfo 2
.Xr kernelinfo 2 ,
.Xr kernel 7