diff --git a/.gitignore b/.gitignore index c619bbdd..a929e827 100644 --- a/.gitignore +++ b/.gitignore @@ -16,18 +16,12 @@ kernel-src/io/printf.c kernel-src/flanterm sysroot minimalsysroot -tools/init/init -tools/init/main.o tools/mount/mount tools/mount/main.o tools/netd/main.o tools/netd/netd -tools/init/poweroff -tools/init/poweroff.o -tools/init/reboot -tools/init/reboot.o -tools/init/acpid -tools/init/acpid.o +tools/netd/hostname +tools/netd/hostname.o tools/prof/astral-prof tools/prof/main.o tools/systrace/systrace diff --git a/Makefile b/Makefile index 953df1d8..2041c6fd 100644 --- a/Makefile +++ b/Makefile @@ -11,20 +11,19 @@ QEMUFLAGS=\ -M q35 \ -m 2g \ -smp cpus=4 \ - -no-shutdown \ - -no-reboot \ -debugcon file:/dev/stdout \ - -serial stdio \ -netdev user,id=net0 -device virtio-net,netdev=net0 \ -object filter-dump,id=f1,netdev=net0,file=netdump.dat QEMUISOFLAGS=-cdrom $(ISO) -QEMUDISKFLAGS=-drive file=$(DISKNAME),if=none,id=nvme -device nvme,serial=deadc0ff,drive=nvme -boot order=dc +QEMUDISKFLAGS=-drive file=$(DISKNAME),if=none,id=disk \ + -device nvme,drive=disk,serial=0xdeadbeef \ + -boot dc QEMUIMGFLAGS=-drive file=$(IMG),if=none,id=usb -device nec-usb-xhci,id=xhci -device usb-storage,bus=xhci.0,drive=usb,removable=on INITRD=$(JINX_DIR)/initrds/initrd DISTROTYPE=full INITRDTYPE=minimal -MINIMALPACKAGES=mlibc bash coreutils init distro-files vim nano mount shadow sudo xbps net-base fastfetch +MINIMALPACKAGES=mlibc bash coreutils openrc distro-files vim nano mount shadow sudo xbps net-base fastfetch limine dosfstools e2fsprogs parted netinfo systrace findutils sed .PHONY: all kernel clean clean-kernel iso img initrd full minimal disk distro-minimal distro-full @@ -110,12 +109,12 @@ disk: disk-$(DISTROTYPE) disk-full: distro-full cd $(JINX_DIR) && \ ../jinx install sysroot \* && \ - ../gendisk.sh 8g sysroot $(DISKNAME) + ../gendisk.sh 7g sysroot $(DISKNAME) disk-minimal: distro-minimal cd $(JINX_DIR) && \ ../jinx install minimalsysroot $(MINIMALPACKAGES) && \ - ../gendisk.sh 1g minimalsysroot $(DISKNAME) + ../gendisk.sh 1900m minimalsysroot $(DISKNAME) # ------ clean targets ------ @@ -132,32 +131,34 @@ clean: # ------ run targets ------ run: - qemu-system-x86_64 $(QEMUFLAGS) $(QEMUISOFLAGS) + qemu-system-x86_64 $(QEMUFLAGS) $(QEMUISOFLAGS) -serial stdio run-gdb: - qemu-system-x86_64 $(QEMUFLAGS) $(QEMUISOFLAGS) -S -s + qemu-system-x86_64 $(QEMUFLAGS) $(QEMUISOFLAGS) -S -s -serial stdio run-kvm: - qemu-system-x86_64 $(QEMUFLAGS) $(QEMUISOFLAGS) -enable-kvm -cpu host,migratable=off + qemu-system-x86_64 $(QEMUFLAGS) $(QEMUISOFLAGS) -enable-kvm -cpu host,migratable=off -serial stdio run-disk: - qemu-system-x86_64 $(QEMUFLAGS) $(QEMUISOFLAGS) $(QEMUDISKFLAGS) + qemu-system-x86_64 $(QEMUFLAGS) $(QEMUISOFLAGS) $(QEMUDISKFLAGS) -serial stdio run-disk-gdb: - qemu-system-x86_64 $(QEMUFLAGS) $(QEMUISOFLAGS) $(QEMUDISKFLAGS) -S -s + qemu-system-x86_64 $(QEMUFLAGS) $(QEMUISOFLAGS) $(QEMUDISKFLAGS) -S -s -serial stdio run-disk-kvm: - qemu-system-x86_64 $(QEMUFLAGS) $(QEMUISOFLAGS) $(QEMUDISKFLAGS) -enable-kvm -cpu host,migratable=off -s + qemu-system-x86_64 $(QEMUFLAGS) $(QEMUISOFLAGS) $(QEMUDISKFLAGS) -enable-kvm -cpu host,migratable=off -s -serial stdio + +run-disk-kvm-prof: + qemu-system-x86_64 $(QEMUFLAGS) $(QEMUISOFLAGS) $(QEMUDISKFLAGS) -enable-kvm -cpu host,migratable=off -s -serial file:profiler.out run-disk-kvm-gdb: - qemu-system-x86_64 $(QEMUFLAGS) $(QEMUISOFLAGS) $(QEMUDISKFLAGS) -enable-kvm -cpu host,migratable=off -S -s + qemu-system-x86_64 $(QEMUFLAGS) $(QEMUISOFLAGS) $(QEMUDISKFLAGS) -enable-kvm -cpu host,migratable=off -S -s -serial stdio - run-img: - qemu-system-x86_64 $(QEMUFLAGS) $(QEMUIMGFLAGS) + qemu-system-x86_64 $(QEMUFLAGS) $(QEMUIMGFLAGS) -serial stdio run-img-gdb: - qemu-system-x86_64 $(QEMUFLAGS) $(QEMUIMGFLAGS) -S -s + qemu-system-x86_64 $(QEMUFLAGS) $(QEMUIMGFLAGS) -S -s -serial stdio run-img-kvm: - qemu-system-x86_64 $(QEMUFLAGS) $(QEMUIMGFLAGS) -enable-kvm -cpu host,migratable=off + qemu-system-x86_64 $(QEMUFLAGS) $(QEMUIMGFLAGS) -enable-kvm -cpu host,migratable=off -serial stdio diff --git a/distro-files/etc/fstab b/distro-files/etc/fstab new file mode 100644 index 00000000..4d29ceea --- /dev/null +++ b/distro-files/etc/fstab @@ -0,0 +1,2 @@ +# there is no need to set up a root filesystem here. +none /tmp tmpfs defaults 0 0 diff --git a/distro-files/etc/local.d/firstboot.start b/distro-files/etc/local.d/firstboot.start new file mode 100755 index 00000000..fa8adc4b --- /dev/null +++ b/distro-files/etc/local.d/firstboot.start @@ -0,0 +1,9 @@ +if [ ! -f "/var/lib/.first_boot_done" ] ; then + mkdir -p /var/log + xbps-reconfigure -a > /var/log/first_install_reconfigure.log + + # all done + touch /var/lib/.first_boot_done +fi + +exit 0 diff --git a/distro-files/etc/rc b/distro-files/etc/rc deleted file mode 100644 index 06a54b85..00000000 --- a/distro-files/etc/rc +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/bash -mkdir -p /dev -mount /dev devfs -chmod 0755 /dev - -mkdir -p /dev/shm -mount /dev/shm tmpfs -chmod 1777 /dev/shm - -mkdir -p /tmp -mount /tmp tmpfs -chmod 1777 /tmp - -chmod 0755 /dev/pts - -# required to be owned by root and sticky for rootless Xorg. -mkdir -p /tmp/.X11-unix -chmod 1777 /tmp/.X11-unix - -/usr/sbin/acpid - -# do first time boot configuration if needed -if [ ! -f "/var/lib/.first_boot_done" ]; then - echo rc: running first boot script - /usr/libexec/astral/first-boot -fi diff --git a/distro-files/usr/libexec/astral/first-boot b/distro-files/usr/libexec/astral/first-boot deleted file mode 100755 index 9c5171e3..00000000 --- a/distro-files/usr/libexec/astral/first-boot +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/bash -# this file will be executed on the first boot of the system -# run post install hooks -echo first-boot: running post install hooks -mkdir -p /var/log -xbps-reconfigure -a > /var/log/first_install_reconfigure.log - -# all done -touch /var/lib/.first_boot_done - -echo first-boot: syncing disks -sync diff --git a/install-hooks/distro-files b/install-hooks/distro-files deleted file mode 100644 index 19e8898a..00000000 --- a/install-hooks/distro-files +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/bash - -case "$1" in -pre) - ;; -post) - mkdir -p /var/log - mkdir -p /var/run - mkdir -p /var/lib - ;; -esac - -exit 0 diff --git a/limine.conf b/limine.conf index b5776f15..7ec55c49 100644 --- a/limine.conf +++ b/limine.conf @@ -5,27 +5,15 @@ WALLPAPER_STYLE: stretched TIMEOUT: 5 SERIAL: yes -/Astral (X.org, nvme0n1, ext2) +/Astral (nvme0n1, ext2) PROTOCOL: limine KERNEL_PATH: boot():/astral -KERNEL_CMDLINE: rootfs=ext2 root=nvme0n1 initarg=withx +KERNEL_CMDLINE: rootfs=ext2 root=nvme0n1 init=/sbin/openrc-init COMMENT: "The Astral operating system" -/Astral (login prompt, nvme0n1, ext2) -PROTOCOL: limine -KERNEL_PATH: boot():/astral -KERNEL_CMDLINE: rootfs=ext2 root=nvme0n1 initarg=withlogin -COMMENT: "The Astral operating system" - -/Astral (root shell, nvme0n1, ext2) -PROTOCOL: limine -KERNEL_PATH: boot():/astral -KERNEL_CMDLINE: rootfs=ext2 root=nvme0n1 -COMMENT: "The Astral operating system" - -/Astral (root shell, initrd) +/Astral (initrd) PROTOCOL: limine KERNEL_PATH: boot():/astral MODULE_PATH: boot():/initrd -KERNEL_CMDLINE: initrd rootfs=tmpfs +KERNEL_CMDLINE: initrd rootfs=tmpfs init=/sbin/openrc-init COMMENT: "The Astral operating system" diff --git a/patches/openrc/jinx-working-patch.patch b/patches/openrc/jinx-working-patch.patch new file mode 100644 index 00000000..174432e5 --- /dev/null +++ b/patches/openrc/jinx-working-patch.patch @@ -0,0 +1,787 @@ +diff --git openrc-clean/conf.d/meson.build openrc-workdir/conf.d/meson.build +index 7c2c99a..bba4a69 100644 +--- openrc-clean/conf.d/meson.build ++++ openrc-workdir/conf.d/meson.build +@@ -40,6 +40,10 @@ conf_Linux = [ + 'seedrng', + ] + ++conf_Astral = [ ++ 'agetty', ++] ++ + conf_NetBSD = [ + 'moused', + 'rarpd', +@@ -57,6 +61,8 @@ elif os == 'linux' + conf_data = conf_data + conf_Linux + elif os == 'netbsd' + conf_data = conf_data + conf_NetBSD ++elif os == 'astral' ++ conf_data = conf_data + conf_Astral + endif + + install_data(conf_data, install_dir : conf_d_dir) +diff --git openrc-clean/init.d/bootmisc.in openrc-workdir/init.d/bootmisc.in +index 33f676a..d544710 100644 +--- openrc-clean/init.d/bootmisc.in ++++ openrc-workdir/init.d/bootmisc.in +@@ -220,19 +220,21 @@ start() + fi + fi + +- if yesno $log_dmesg; then +- if $logw || checkpath -W /var/log; then +- # Create an 'after-boot' dmesg log +- case "$RC_SYS" in +- VSERVER|OPENVZ|LXC|SYSTEMD-NSPAWN) ;; +- *) +- if yesno ${previous_dmesg:-no} && [ -e /var/log/dmesg ]; then +- mv /var/log/dmesg /var/log/dmesg.old +- fi +- dmesg > /var/log/dmesg +- chmod 640 /var/log/dmesg +- ;; +- esac ++ if [ "$RC_UNAME" != Astral ] ; then ++ if yesno $log_dmesg; then ++ if $logw || checkpath -W /var/log; then ++ # Create an 'after-boot' dmesg log ++ case "$RC_SYS" in ++ VSERVER|OPENVZ|LXC|SYSTEMD-NSPAWN) ;; ++ *) ++ if yesno ${previous_dmesg:-no} && [ -e /var/log/dmesg ]; then ++ mv /var/log/dmesg /var/log/dmesg.old ++ fi ++ dmesg > /var/log/dmesg ++ chmod 640 /var/log/dmesg ++ ;; ++ esac ++ fi + fi + fi + +diff --git openrc-clean/init.d/devfs.in openrc-workdir/init.d/devfs.in +index 6d67230..3584353 100644 +--- openrc-clean/init.d/devfs.in ++++ openrc-workdir/init.d/devfs.in +@@ -127,8 +127,18 @@ restorecon_dev() + + start() + { +- mount_dev +- seed_dev +- restorecon_dev ++ if [ "$RC_UNAME" = Linux ]; then ++ mount_dev ++ seed_dev ++ restorecon_dev ++ elif [ "$RC_UNAME" = Astral ]; then ++ mkdir -p /dev ++ mount /dev -t devfs ++ chmod 0755 /dev ++ ++ mkdir -p /dev/shm ++ mount /dev/shm -t tmpfs ++ chmod 1777 /dev/shm ++ fi + return 0 + } +diff --git openrc-clean/init.d/localmount.in openrc-workdir/init.d/localmount.in +index 9535b59..d86e39d 100644 +--- openrc-clean/init.d/localmount.in ++++ openrc-workdir/init.d/localmount.in +@@ -35,7 +35,13 @@ start() + fi + fi + ebegin "Mounting local filesystems" +- mount -at "$types" $no_netdev ++ ++ if [ "$RC_UNAME" = Astral ]; then ++ mount -a ++ else ++ mount -at "$types" $no_netdev ++ fi ++ + eend $? "Some local filesystem failed to mount" + rc=$? + if [ -z "$critical_mounts" ]; then +@@ -78,7 +84,9 @@ stop() + no_umounts_r="^($no_umounts_r)$" + + # Flush all pending disk writes now ++ ebegin Syncing disks + sync ++ eend + + . "$RC_LIBEXECDIR"/sh/rc-mount.sh + +@@ -109,6 +117,11 @@ stop() + done + fi + ++ # no unmount support for Astral yet ++ if [ "$RC_UNAME" = Astral ] ; then ++ return 0 ++ fi ++ + # Umount loop devices + einfo "Unmounting loop devices" + eindent +diff --git openrc-clean/init.d/meson.build openrc-workdir/init.d/meson.build +index d0699dc..79c3383 100644 +--- openrc-clean/init.d/meson.build ++++ openrc-workdir/init.d/meson.build +@@ -1,19 +1,15 @@ + init_d_dir = get_option('sysconfdir') / 'init.d' + + init_common = [ +- 'bootmisc.in', + 'fsck.in', ++ 'bootmisc.in', + 'hostname.in', + 'local.in', + 'localmount.in', +- 'loopback.in', +- 'netmount.in', + 'osclock.in', + 'root.in', + 'savecache.in', +- 'swap.in', + 'swclock.in', +- 'sysctl.in', + 'runsvdir.in', + 's6-svscan.in', + 'user.in', +@@ -27,6 +23,8 @@ if get_option('newnet') + endif + + init_Linux = [ ++ 'swap.in', ++ 'netmount.in', + 'agetty.in', + 'binfmt.in', + 'cgroups.in', +@@ -47,9 +45,13 @@ init_Linux = [ + 'seedrng.in', + 'sysfs.in', + 'termencoding.in', ++ 'sysctl.in', ++ 'loopback.in', + ] + + init_BSD = [ ++ 'swap.in', ++ 'netmount.in', + 'hostid.in', + 'moused.in', + 'newsyslog.in', +@@ -60,9 +62,13 @@ init_BSD = [ + 'savecore.in', + 'syslogd.in', + 'urandom.in', ++ 'sysctl.in', ++ 'loopback.in', + ] + + init_FreeBSD = [ ++ 'swap.in', ++ 'netmount.in', + 'adjkerntz.in', + 'devd.in', + 'dumpon.in', +@@ -73,15 +79,26 @@ init_FreeBSD = [ + 'nscd.in', + 'powerd.in', + 'syscons.in', ++ 'sysctl.in', ++ 'loopback.in', + ] + + init_NetBSD = [ ++ 'swap.in', ++ 'netmount.in', + 'devdb.in', + 'swap-blk.in', + 'ttys.in', + 'wscons.in', ++ 'sysctl.in', ++ 'loopback.in', + ] + ++init_Astral = [ ++ 'agetty.in', ++ 'devfs.in', ++ 'netd.in', ++ ] + init_data = init_common + if os == 'dragonfly' + init_data = init_data + init_BSD +@@ -91,7 +108,9 @@ elif os == 'linux' + init_data = init_data + init_Linux + elif os == 'netbsd' + init_data = init_data + init_BSD + init_NetBSD +- endif ++elif os == 'astral' ++ init_data = init_data + init_Astral ++endif + + foreach init_d_file : init_data + configure_file(input : init_d_file, +@@ -104,7 +123,7 @@ install_symlink('functions.sh', + pointing_to: rc_shdir / 'functions.sh', + install_dir: init_d_dir) + +-if get_option('sysvinit') == true and os == 'linux' ++if (get_option('sysvinit') == true and os == 'linux') or os == 'astral' + foreach x : get_option('agetty') + link_name = 'agetty.' + x + install_symlink(link_name, +diff --git openrc-workdir/init.d/netd.in openrc-workdir/init.d/netd.in +new file mode 100644 +index 0000000..df17882 +--- /dev/null ++++ openrc-workdir/init.d/netd.in +@@ -0,0 +1,22 @@ ++#!@SBINDIR@/openrc-run ++ ++description="start the network daemon" ++supervisor=supervise-daemon ++respawn_period="${respawn_period:-60}" ++command=/usr/sbin/netd ++command_args_foreground="${netd_options} ${netd_device}" ++pidfile="/run/${RC_SVCNAME}.pid" ++ ++depend() { ++ after dev hostname ++ provide net ++} ++ ++start_pre() { ++ export EINFO_QUIET="${quiet:-yes}" ++} ++ ++stop_pre() ++{ ++ export EINFO_QUIET="${quiet:-yes}" ++} +diff --git openrc-clean/init.d/root.in openrc-workdir/init.d/root.in +index 28be936..0807794 100644 +--- openrc-clean/init.d/root.in ++++ openrc-workdir/init.d/root.in +@@ -20,6 +20,20 @@ depend() + + start() + { ++ if [ "$RC_UNAME" = Astral ]; then ++ ebegin Updating /etc/mtab with root ++ # astral does not support remounting yet, nor ro mounts. ++ # add the root to /etc/mtab for accounting ++ local root_dev dev ++ root_dev=$(stat -c '%d' /) ++ for dev in /dev/*; do ++ [ -b "$dev" ] && [ "$(stat -c '%r' "$dev")" = "$root_dev" ] && break ++ done ++ echo -e "$dev\t/\tunknown\tdefaults\t0\t0" >> /etc/mtab ++ eend ++ return 0 ++ fi ++ + local root_opts=",$(fstabinfo -o /)," + case "$root_opts" in + *,ro,*) +diff --git openrc-clean/runlevels/meson.build openrc-workdir/runlevels/meson.build +index cb41560..28cc483 100644 +--- openrc-clean/runlevels/meson.build ++++ openrc-workdir/runlevels/meson.build +@@ -6,30 +6,39 @@ sysinit_linux = [ + 'devfs', + 'dmesg', + 'sysfs'] ++sysinit_astral = [ ++ 'devfs' ++] ++ + if os == 'linux' + sysinit += sysinit_linux ++elif os == 'astral' ++ sysinit += sysinit_astral + endif + + boot = [ + 'bootmisc', +- 'fsck', + 'hostname', + 'localmount', +- 'loopback', +- 'root', +- 'swap', +- 'sysctl'] ++ 'fsck', ++ 'root'] + boot_bsd = [ + 'hostid', + 'newsyslog', + 'savecore', + 'syslogd', +- 'urandom'] ++ 'loopback', ++ 'swap', ++ 'urandom', ++ 'sysctl'] + boot_freebsd = [ + 'adjkerntz', + 'dumpon', + 'modules', +- 'syscons'] ++ 'loopback', ++ 'swap', ++ 'syscons', ++ 'sysctl'] + boot_linux = [ + 'binfmt', + 'hwclock', +@@ -40,12 +49,21 @@ boot_linux = [ + 'save-keymaps', + 'save-termencoding', + 'seedrng', +- 'termencoding'] ++ 'loopback', ++ 'swap', ++ 'termencoding', ++ 'sysctl'] + boot_netbsd = [ + 'devdb', + 'swap-blk', + 'tys', +- 'wscons'] ++ 'loopback', ++ 'swap', ++ 'wscons', ++ 'sysctl'] ++boot_astral = [ ++ 'netd' ++] + if get_option('newnet') + boot += [ + 'network', +@@ -59,11 +77,12 @@ elif os == 'linux' + boot += boot_linux + elif os == 'netbsd' + boot += boot_bsd + boot_netbsd ++elif os == 'astral' ++ boot += boot_astral + endif + + default = [ +- 'local', +- 'netmount'] ++ 'local'] + + nonetwork=['local'] + +@@ -71,8 +90,12 @@ shutdown = ['savecache'] + shutdown_linux = [ + 'killprocs', + 'mount-ro'] ++shutdown_astral = [ ++] + if os == 'linux' + shutdown += shutdown_linux ++elif os == 'astral' ++ shutdown += shutdown_astral + endif + + runlevels = { +@@ -89,7 +112,7 @@ foreach runlevel: runlevels.keys() + install_dir: runlevel_dir / runlevel, + pointing_to: init_d_dir / service) + endforeach +- if get_option('sysvinit') == true and os == 'linux' and runlevel == 'default' ++ if ((get_option('sysvinit') == true and os == 'linux') or os == 'astral') and runlevel == 'default' + foreach tty : get_option('agetty') + install_symlink('agetty.' + tty, + install_dir: runlevel_dir / runlevel, +diff --git openrc-workdir/sh/init.sh.Astral.in openrc-workdir/sh/init.sh.Astral.in +new file mode 100644 +index 0000000..c180f37 +--- /dev/null ++++ openrc-workdir/sh/init.sh.Astral.in +@@ -0,0 +1,39 @@ ++#!/bin/sh ++ ++ebegin "Creating /tmp" ++mkdir -p /tmp ++eend $? ++ ++ebegin "Cleaning up /etc/mtab" ++echo "" > /etc/mtab ++eend $? ++ ++if [ ! -d /run ]; then ++ ebegin "Creating /run" ++ mkdir -p /run ++ eend $? ++fi ++ ++ebegin "Mounting /run" ++mount /run -t tmpfs ++if [ $? != 0 ]; then ++ eerror "Unable to mount tmpfs on /run." ++ eerror "Can't continue." ++ exit 1 ++fi ++eend ++ ++ebegin "Creating $RC_SVCDIR" ++mkdir -p $RC_SVCDIR ++eend $? ++ ++ebegin "Mounting tmpfs at $RC_SVCDIR" ++mount $RC_SVCDIR -t tmpfs ++eend $? ++ ++if [ -d "$RC_CACHEDIR" ]; then ++ cp -pr "$RC_CACHEDIR"/* "$RC_SVCDIR" 2>/dev/null ++fi ++ ++echo sysinit >"$RC_SVCDIR"/softlevel ++exit 0 +diff --git openrc-clean/sh/meson.build openrc-workdir/sh/meson.build +index a567380..2e04567 100644 +--- openrc-clean/sh/meson.build ++++ openrc-workdir/sh/meson.build +@@ -43,6 +43,10 @@ elif os == 'gnu' + scripts_config_os = [ + ['init.sh.GNU.in', 'init.sh'], + ] ++elif os == 'astral' ++ scripts_config_os = [ ++ ['init.sh.Astral.in', 'init.sh'], ++ ] + else + scripts_config_os = [ + ['init.sh.BSD.in', 'init.sh'], +diff --git openrc-clean/src/fstabinfo/fstabinfo.c openrc-workdir/src/fstabinfo/fstabinfo.c +index 7ae56ae..e9845a8 100644 +--- openrc-clean/src/fstabinfo/fstabinfo.c ++++ openrc-workdir/src/fstabinfo/fstabinfo.c +@@ -28,7 +28,7 @@ + /* Yay for linux and its non liking of POSIX functions. + Okay, we could use getfsent but the man page says use getmntent instead + AND we don't have getfsent on uclibc or dietlibc for some odd reason. */ +-#ifdef __linux__ ++#if defined(__linux__) || defined(__astral__) + # define HAVE_GETMNTENT + # include + +diff --git openrc-clean/src/halt/meson.build openrc-workdir/src/halt/meson.build +index 059c53b..9e44df1 100644 +--- openrc-clean/src/halt/meson.build ++++ openrc-workdir/src/halt/meson.build +@@ -1,4 +1,4 @@ +-if os == 'linux' and get_option('sysvinit') ++if (os == 'linux' and get_option('sysvinit')) or os == 'astral' + configure_file(input : 'halt.in', + output : '@BASENAME@', + configuration : script_conf_data, +diff --git openrc-clean/src/librc/librc-daemon.c openrc-workdir/src/librc/librc-daemon.c +index 1902875..ed35d00 100644 +--- openrc-clean/src/librc/librc-daemon.c ++++ openrc-workdir/src/librc/librc-daemon.c +@@ -311,6 +311,15 @@ rc_find_pids(const char *exec, const char *const *argv, uid_t uid, pid_t pid) + return pids; + } + ++#elif defined(__astral__) ++ ++RC_PIDLIST * ++rc_find_pids(const char *exec, const char *const *argv, uid_t uid, pid_t pid) ++{ ++ fprintf(stderr, "rc_find_pids: unimplemented\n"); ++ return NULL; ++} ++ + #else + # error "Platform not supported!" + #endif +diff --git openrc-clean/src/mountinfo/mountinfo.c openrc-workdir/src/mountinfo/mountinfo.c +index c0187b5..75bc7f6 100644 +--- openrc-clean/src/mountinfo/mountinfo.c ++++ openrc-workdir/src/mountinfo/mountinfo.c +@@ -30,8 +30,8 @@ + + # define statfs statvfs + # define F_FLAGS f_flag +-#elif defined(__linux__) || (defined(__FreeBSD_kernel__) && \ +- defined(__GLIBC__)) || defined(__GNU__) ++#elif (defined(__linux__) || (defined(__FreeBSD_kernel__) && \ ++ defined(__GLIBC__)) || defined(__GNU__)) || defined(__astral__) + # include + #endif + +@@ -291,8 +291,8 @@ find_mounts(struct args *args) + return list; + } + +-#elif defined(__linux__) || (defined(__FreeBSD_kernel__) && \ +- defined(__GLIBC__)) || defined(__GNU__) ++#elif (defined(__linux__) || (defined(__FreeBSD_kernel__) && \ ++ defined(__GLIBC__)) || defined(__GNU__)) + static struct mntent * + getmntfile(const char *file) + { +@@ -355,6 +355,47 @@ find_mounts(struct args *args) + return list; + } + ++#elif defined(__astral__) ++ ++static RC_STRINGLIST * ++find_mounts(struct args *args) ++{ ++ FILE *fp; ++ char *buffer; ++ size_t size; ++ char *p; ++ char *from; ++ char *to; ++ char *fst; ++ char *opts; ++ struct mntent *ent; ++ int netdev; ++ RC_STRINGLIST *list; ++ ++ if ((fp = fopen("/etc/mtab", "r")) == NULL) ++ eerrorx("getmntinfo: %s", strerror(errno)); ++ ++ list = rc_stringlist_new(); ++ ++ buffer = NULL; ++ while (xgetline(&buffer, &size, fp) != -1) { ++ netdev = -1; ++ p = buffer; ++ from = strsep(&p, "\t"); ++ to = strsep(&p, "\t"); ++ fst = strsep(&p, "\t"); ++ opts = strsep(&p, "\t"); ++ ++ process_mount(list, args, from, to, fst, opts, 0); ++ free(buffer); ++ buffer = NULL; ++ } ++ free(buffer); ++ fclose(fp); ++ ++ return list; ++} ++ + #else + # error "Operating system not supported!" + #endif +diff --git openrc-clean/src/openrc/rc-logger.c openrc-workdir/src/openrc/rc-logger.c +index e57d380..ea9be18 100644 +--- openrc-clean/src/openrc/rc-logger.c ++++ openrc-workdir/src/openrc/rc-logger.c +@@ -32,7 +32,7 @@ + #include + + #if defined(__linux__) || (defined(__FreeBSD_kernel__) && defined(__GLIBC__)) \ +- || defined(__GNU__) ++ || defined(__GNU__) || defined(__astral__) + # include + #elif defined(__NetBSD__) || defined(__OpenBSD__) + # include +diff --git openrc-clean/src/openrc-init/meson.build openrc-workdir/src/openrc-init/meson.build +index c5c25c0..4bf5b54 100644 +--- openrc-clean/src/openrc-init/meson.build ++++ openrc-workdir/src/openrc-init/meson.build +@@ -1,4 +1,4 @@ +-if os == 'linux' ++if os == 'linux' or os == 'astral' + executable('openrc-init', 'openrc-init.c', + include_directories: incdir, + dependencies: [rc, einfo, shared, dl_dep, selinux_dep], +diff --git openrc-clean/src/openrc-init/openrc-init.c openrc-workdir/src/openrc-init/openrc-init.c +index 8fc21ca..5a4bff5 100644 +--- openrc-clean/src/openrc-init/openrc-init.c ++++ openrc-workdir/src/openrc-init/openrc-init.c +@@ -56,6 +56,10 @@ static const char *rc_default_runlevel = "default"; + static int sigpipe[2] = { -1, -1 }; + static bool quiet = false; + ++#ifdef __astral__ ++static int acpifd; ++#endif ++ + static void do_openrc(const char *runlevel) + { + const char *argv[] = { "openrc", runlevel, NULL }; +@@ -91,7 +95,7 @@ static void init(const char *default_runlevel) + runlevel = rc_default_runlevel; + } + do_openrc(runlevel); +- log_wtmp("reboot", "~~", 0, RUN_LVL, "~~"); ++ //log_wtmp("reboot", "~~", 0, RUN_LVL, "~~"); + } + + static void handle_reexec(char *my_name) +@@ -104,6 +108,9 @@ static void handle_shutdown(const char *runlevel, int cmd) + { + const long ms_to_ns = 1000000L; + struct timespec start, now, tmp, remain; ++#ifdef __astral__ ++ const char *c = ""; ++#endif + + do_openrc(runlevel); + if (!quiet) +@@ -140,7 +147,33 @@ static void handle_shutdown(const char *runlevel, int cmd) + printf("Sending the final KILL signal\n"); + kill(-1, SIGKILL); + sync(); ++ ++#ifdef __linux__ + reboot(cmd); ++#elif defined(__astral__) ++ switch (cmd) { ++ case RB_AUTOBOOT: ++ c = "r"; ++ break; ++ case RB_HALT_SYSTEM: ++ fprintf(stderr, "RB_HALT_SYSTEM unimplemented. Powering off in 5 seconds.\n"); ++ c = "p"; ++ sleep(5); ++ break; ++ case RB_POWER_OFF: ++ c = "p"; ++ break; ++ case RB_KEXEC: ++ fprintf(stderr, "RB_KEXEC unimplemented. Rebooting in 5 seconds.\n"); ++ c = "p"; ++ sleep(5); ++ break; ++ } ++ ++ write(acpifd, c, 1); ++ ++ fprintf(stderr, "/dev/acpid write failed. Please power off the system manually.\n"); ++#endif + } + + static void run_program(const char *prog) +@@ -308,11 +341,27 @@ int main(int argc, char **argv) + if (fifo == -1) + perror("open"); + ++#ifdef __astral__ ++ acpifd = open("/dev/acpi", O_RDWR); ++ if (acpifd == -1) ++ perror("open /dev/acpi"); ++#endif ++ + for (;;) { +- enum { FD_FIFO, FD_SIG, FD_COUNT }; ++ enum { ++ FD_FIFO, ++ FD_SIG, ++#ifdef __astral__ ++ FD_ACPI, ++#endif ++ FD_COUNT ++ }; + struct pollfd pfd[] = { + [FD_FIFO] = { .fd = fifo, .events = POLLIN }, + [FD_SIG] = { .fd = sigpipe[0], .events = POLLIN }, ++#ifdef __astral__ ++ [FD_ACPI] = { .fd = acpifd, .events = POLLIN }, ++#endif + }; + + poll(pfd, FD_COUNT, -1); +@@ -361,6 +410,19 @@ int main(int argc, char **argv) + init(default_runlevel); + } + } ++ ++#ifdef __astral__ ++ if (pfd[FD_ACPI].revents & POLLIN) { ++ read(acpifd, buf, 1); ++ printf("PID1: Received '%c' from /dev/acpi...\n", buf[0]); ++ ++ switch(buf[0]) { ++ case 'p': ++ handle_shutdown("shutdown", RB_POWER_OFF); ++ break; ++ } ++ } ++#endif + } + return 0; + } +diff --git openrc-clean/src/openrc-run/openrc-run.c openrc-workdir/src/openrc-run/openrc-run.c +index 9a39ca0..2c0915e 100644 +--- openrc-clean/src/openrc-run/openrc-run.c ++++ openrc-workdir/src/openrc-run/openrc-run.c +@@ -38,7 +38,7 @@ + #include + + #if defined(__linux__) || (defined(__FreeBSD_kernel__) && defined(__GLIBC__)) \ +- || defined(__GNU__) ++ || defined(__GNU__) || defined(__astral__) + # include + #elif defined(__NetBSD__) || defined(__OpenBSD__) + # include +diff --git openrc-clean/src/openrc-shutdown/meson.build openrc-workdir/src/openrc-shutdown/meson.build +index 6bb7dd6..3db90b7 100644 +--- openrc-clean/src/openrc-shutdown/meson.build ++++ openrc-workdir/src/openrc-shutdown/meson.build +@@ -1,4 +1,4 @@ +-if os == 'linux' ++if os == 'linux' or os == 'astral' + executable('openrc-shutdown', + ['openrc-shutdown.c', 'broadcast.c', 'sysvinit.c'], + include_directories: incdir, +diff --git openrc-clean/src/poweroff/meson.build openrc-workdir/src/poweroff/meson.build +index d4056db..3b4907a 100644 +--- openrc-clean/src/poweroff/meson.build ++++ openrc-workdir/src/poweroff/meson.build +@@ -1,4 +1,4 @@ +-if os == 'linux' and get_option('sysvinit') ++if (os == 'linux' and get_option('sysvinit')) or os == 'astral' + configure_file(input : 'poweroff.in', + output : '@BASENAME@', + configuration : script_conf_data, +diff --git openrc-clean/src/reboot/meson.build openrc-workdir/src/reboot/meson.build +index 7ed1274..520c19f 100644 +--- openrc-clean/src/reboot/meson.build ++++ openrc-workdir/src/reboot/meson.build +@@ -1,4 +1,4 @@ +-if os == 'linux' and get_option('sysvinit') ++if (os == 'linux' and get_option('sysvinit')) or os == 'astral' + configure_file(input : 'reboot.in', + output : '@BASENAME@', + configuration : script_conf_data, +diff --git openrc-clean/src/shared/meson.build openrc-workdir/src/shared/meson.build +index 2241935..28e20c9 100644 +--- openrc-clean/src/shared/meson.build ++++ openrc-workdir/src/shared/meson.build +@@ -11,7 +11,7 @@ shared_sources = [ + version_h, + ] + +-if os == 'linux' ++if os == 'linux' or os == 'astral' + shared_sources += 'wtmp.c' + endif + +diff --git openrc-clean/src/shutdown/meson.build openrc-workdir/src/shutdown/meson.build +index 8080ca3..1d8247a 100644 +--- openrc-clean/src/shutdown/meson.build ++++ openrc-workdir/src/shutdown/meson.build +@@ -1,4 +1,4 @@ +-if os == 'linux' and get_option('sysvinit') ++if (os == 'linux' and get_option('sysvinit')) or os == 'astral' + configure_file(input : 'shutdown.in', + output : '@BASENAME@', + configuration : script_conf_data, diff --git a/recipes/agetty b/recipes/agetty index 0d38682b..974c3463 100644 --- a/recipes/agetty +++ b/recipes/agetty @@ -8,7 +8,7 @@ deps="base" configure() { cp -rp ${source_dir}/* . rm -rf po - build_setsid=yes ./configure --host=x86_64-astral --prefix=${prefix} --disable-all-programs --enable-agetty + build_setsid=yes ./configure --host=x86_64-astral --prefix=${prefix} --disable-all-programs --enable-agetty --disable-plymouth-support } build() { diff --git a/recipes/distro-files b/recipes/distro-files index fc01f19b..f7d977ee 100644 --- a/recipes/distro-files +++ b/recipes/distro-files @@ -22,6 +22,4 @@ package() { ln -fvs /usr/share/games/doom/DOOM1.WAD ${dest_dir}/root/DOOM1.WAD ln -fvs /usr/share/games/doom/DOOM1.WAD ${dest_dir}/home/astral/DOOM1.WAD ln -fvs /usr/share/games/doom/DOOM1.WAD ${dest_dir}/etc/skel/DOOM1.WAD - - copy_install_hook } diff --git a/recipes/init b/recipes/init deleted file mode 100644 index 383e50bc..00000000 --- a/recipes/init +++ /dev/null @@ -1,14 +0,0 @@ -name=init -revision=1 -from_source=init -imagedeps="build-essential" -hostdeps="xbinutils xgcc" -deps="base" - -build() { - make -C ${source_dir} -j ${parallelism} -} - -package() { - make -C ${source_dir} install DESTDIR=${dest_dir} -} diff --git a/recipes/openrc b/recipes/openrc new file mode 100644 index 00000000..32e43738 --- /dev/null +++ b/recipes/openrc @@ -0,0 +1,28 @@ +name=openrc +revision=1 +from_source=openrc +imagedeps="gcc meson ninja-build" +hostdeps="xgcc xbinutils pkgconfig automake autoconf" +deps="base agetty" + +configure() { + meson \ + --cross-file ${base_dir}/util/crossfile \ + --prefix=${prefix} \ + --buildtype=release \ + -Dpam=false \ + -Dbranding='"Astral"' \ + -Dagetty=console,com0 \ + -Dnewnet=false \ + ${source_dir} +} + +build() { + ninja -j${parallelism} +} + +package() { + DESTDIR=${dest_dir} ninja install + echo "respawn_max=1" > ${dest_dir}/etc/conf.d/agetty.com0 + ln -s "sbin/openrc-init" ${dest_dir}/init +} diff --git a/recipes/openssh b/recipes/openssh index 2864ecfd..8d4408a5 100644 --- a/recipes/openssh +++ b/recipes/openssh @@ -17,4 +17,6 @@ package() { install -v -m700 -d ${dest_dir}/var/lib/sshd install -v -d ${dest_dir}/run make install DESTDIR=${dest_dir} + mkdir -p ${dest_dir}/etc/init.d + cp ${base_dir}/service-scripts/sshd ${dest_dir}/etc/init.d } diff --git a/service-scripts/sshd b/service-scripts/sshd new file mode 100755 index 00000000..79ef8ce3 --- /dev/null +++ b/service-scripts/sshd @@ -0,0 +1,25 @@ +#!/sbin/openrc-run + +description="start the OpenSSH server" +supervisor=supervise-daemon +respawn_period="${respawn_period:-60}" +command=/usr/sbin/sshd +command_args_foreground="-D ${sshd_options}" +pidfile="/run/${RC_SVCNAME}.pid" + +depend() { + after net +} + +start_pre() { + export EINFO_QUIET="${quiet:-yes}" + + ssh-keygen -A + + mkdir -p /var/lib/sshd + chmod 0755 /var/lib/sshd +} + +stop_pre() { + export EINFO_QUIET="${quiet:-yes}" +} diff --git a/source-recipes/init b/source-recipes/init deleted file mode 100644 index f063da82..00000000 --- a/source-recipes/init +++ /dev/null @@ -1,7 +0,0 @@ -name=init -version=0 -source_dir="tools/init" - -prepare() { - true -} diff --git a/source-recipes/openrc b/source-recipes/openrc new file mode 100644 index 00000000..b6337a14 --- /dev/null +++ b/source-recipes/openrc @@ -0,0 +1,5 @@ +name=openrc +version=24.2.0 +source_method=tarball +tarball_url="https://github.com/OpenRC/openrc/archive/refs/tags/0.63.1.tar.gz" +tarball_sha512="d1746909275bd2552ccc4a1786eb5f80ac79ba911ce08ffc12dd550f2965f3bea09ac7c4b638f17f495f92238b833ca1886782c9c7bbba868e1c905e82639a2e" diff --git a/tools/init/Makefile b/tools/init/Makefile deleted file mode 100644 index 5a73fc05..00000000 --- a/tools/init/Makefile +++ /dev/null @@ -1,36 +0,0 @@ -.phony: all install -CC=x86_64-astral-gcc -LD=x86_64-astral-gcc - -all: init poweroff reboot acpid - -install: - mkdir -pv "$(DESTDIR)/usr/sbin" - cp -v init "$(DESTDIR)/init" - cp -v poweroff "$(DESTDIR)/usr/sbin/poweroff" - cp -v reboot "$(DESTDIR)/usr/sbin/reboot" - cp -v acpid "$(DESTDIR)/usr/sbin/acpid" - -init: main.o - $(LD) $(LDFLAGS) -o $@ $^ - -poweroff: poweroff.o - $(LD) $(LDFLAGS) -o $@ $^ - -reboot: reboot.o - $(LD) $(LDFLAGS) -o $@ $^ - -acpid: acpid.o - $(LD) $(LDFLAGS) -o $@ $^ - -main.o: main.c - $(CC) -c $(CFLAGS) -o $@ $< - -poweroff.o: poweroff.c - $(CC) -c $(CFLAGS) -o $@ $< - -reboot.o: reboot.c - $(CC) -c $(CFLAGS) -o $@ $< - -acpid.o: acpid.c - $(CC) -c $(CFLAGS) -o $@ $< diff --git a/tools/init/acpid.c b/tools/init/acpid.c deleted file mode 100644 index ff619224..00000000 --- a/tools/init/acpid.c +++ /dev/null @@ -1,44 +0,0 @@ -#include -#include -#include -#include - -#include "common.h" - -int main() { - if (daemon(0, 0)) { - perror("acpid: daemon"); - return EXIT_FAILURE; - } - - int fd = open("/dev/acpi", O_RDONLY); - if (fd == -1) { - perror("acpid: open"); - return EXIT_FAILURE; - } - - for (;;) { - char c; - int n = read(fd, &c, 1); - - int cmdfd = open(COMMAND_FIFO, O_WRONLY); - if (cmdfd == -1) { - perror("acpid: open"); - continue; - } - - switch (c) { - case 'p': - if (write(cmdfd, &c, 1) < 0) - perror("acpid: write"); - break; - default: - fprintf(stderr, "acpid: unknown acpi event %c\n", c); - } - - close(cmdfd); - } - - close(fd); - return EXIT_SUCCESS; -} diff --git a/tools/init/common.h b/tools/init/common.h deleted file mode 100644 index c20903cd..00000000 --- a/tools/init/common.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef _COMMON_H -#define _COMMON_H - -#define COMMAND_POWEROFF 'p' -#define COMMAND_REBOOT 'r' -#define COMMAND_FIFO "/tmp/.initcmd" - -#endif diff --git a/tools/init/main.c b/tools/init/main.c deleted file mode 100644 index 7b2ab877..00000000 --- a/tools/init/main.c +++ /dev/null @@ -1,362 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "common.h" - -static void unblocksignals(void) { - sigset_t signals; - sigfillset(&signals); - sigprocmask(SIG_UNBLOCK, &signals, NULL); -} - -static void sendacpicommand(char c) { - int acpifd = open("/dev/acpi", O_WRONLY); - if (acpifd == -1) { - perror("init: open /dev/acpi"); - goto oops; - } - - write(acpifd, &c, 1); - perror("init: write /dev/acpi"); - - oops: - printf("init: failed to send acpi command. please manually do what is needed.\n"); - for (;;) - sleep(1); -} - -static bool alarmfired; -static void timeout(int signal) { - alarmfired = true; -} - -static void waitforall(bool timeout) { - alarmfired = false; - if (timeout) { - alarm(5); - } - - int err = 0; - errno = 0; - do { - pid_t pid = waitpid(-1, NULL, WNOHANG); - int err = errno; - if (pid == 0) - sleep(1); - } while (errno != ECHILD && alarmfired == false); -} - -static void preparetodie(void) { - printf("init: bringing system down\n"); - - // preapre alarm - struct sigaction sa; - memset(&sa, 0, sizeof(sigaction)); - sa.sa_handler = timeout; - sigaction(SIGALRM, &sa, NULL); - - // unblock sigalarm for timeout - sigset_t signals; - sigemptyset(&signals); - sigaddset(&signals, SIGALRM); - sigprocmask(SIG_UNBLOCK, &signals, NULL); - - printf("init: sending SIGTERM to all processes\n"); - kill(-1, SIGTERM); - waitforall(true); - - printf("init: sending SIGKILL to all processes\n"); - kill(-1, SIGKILL); - waitforall(false); - - printf("init: syncing disks\n"); - sync(); -} - -static void doreboot(void) { - printf("init: rebooting\n"); - sendacpicommand('r'); -} - -static void dopoweroff(void) { - printf("init: powering off\n"); - sendacpicommand('p'); -} - -static void handlecommands(void) { - for (;;) { - int fd = open(COMMAND_FIFO, O_RDONLY); - if (fd == -1) { - perror("init: open command fifo"); - return; - } - - char c; - int num; - for (;;) { - num = read(fd, &c, 1); - if (num == 0) - break; - - if (num == -1) { - if (errno == EINTR) - continue; - - perror("init: read"); - close(fd); - continue; - } - - switch (c) { - case COMMAND_POWEROFF: - preparetodie(); - dopoweroff(); - break; - case COMMAND_REBOOT: - preparetodie(); - doreboot(); - default: - printf("init: unknown command %c\n", c); - } - } - - - close(fd); - } -} - -static void reap(int signum) { - pid_t pid; - - for (;;) { - pid = waitpid(-1, NULL, WNOHANG); - if (pid == 0) - break; - - if (pid == -1) { - if (errno == ECHILD) - break; - - perror("init: waitpid"); - } - } -} - -static void snatchconsole(const char *console) { - int rfd = open(console, O_RDONLY); - int wfd = open(console, O_WRONLY); - close(0); - close(1); - close(2); - - dup2(rfd, 0); - dup2(wfd, 1); - dup2(wfd, 2); - - close(rfd); - close(wfd); -} - -static void dowaitpid(pid_t pid) { - int status; - pid_t retpid; - do { - retpid = waitpid(-1, &status, 0); - if (retpid == -1) { - perror("init: waitpid failed"); - exit(EXIT_FAILURE); - } - } while (retpid != pid); - - if (WEXITSTATUS(status) == EXIT_FAILURE) - exit(EXIT_FAILURE); -} - -static void dorootshell(void) { - printf("init: starting root shell\n"); - - pid_t pid = fork(); - if (pid == -1) { - perror("init: fork failed"); - exit(EXIT_FAILURE); - } - - if (pid == 0) { - // create its own process group and set is as the foreground group - if (setpgid(0, 0) == -1) { - perror("init: setpgrp failed"); - exit(EXIT_FAILURE); - } - - if (tcsetpgrp(0, getpid()) == -1) { - perror("init: tcsetpgrp failed"); - exit(EXIT_FAILURE); - } - - unblocksignals(); - - execl("/usr/bin/bash", "/usr/bin/bash", "-l", NULL); - perror("init: execl /usr/bin/bash failed"); - return exit(EXIT_FAILURE); - } - - handlecommands(); -} - -static void spawn_login_prompt(const char *console) { - pid_t pid = fork(); - if (pid == -1) { - perror("init: fork failed"); - exit(EXIT_FAILURE); - } - - if (pid == 0) { - setsid(); - snatchconsole(console); - unblocksignals(); - execl("/bin/login", NULL); - perror("init: exec /bin/login failed"); - exit(EXIT_FAILURE); - } -} - -static void dologinprompt(const char *console) { - spawn_login_prompt(console); - handlecommands(); -} - -static void dostartwm(void) { - pid_t pid = fork(); - if (pid == -1) { - perror("init: fork failed"); - exit(EXIT_FAILURE); - } - - if (pid == 0) { - unblocksignals(); - execl("/usr/libexec/astral/startwm", NULL); - perror("init: exec /usr/libexec/astral/startwm failed"); - exit(EXIT_FAILURE); - } - - handlecommands(); -} - -int main(int argc, char *argv[]) { - printf("init: Welcome to Astral!\n"); - - // set up signal mask - sigset_t signals; - sigfillset(&signals); - sigprocmask(SIG_SETMASK, &signals, NULL); - - // set up signal actions - struct sigaction sa; - memset(&sa, 0, sizeof(sigaction)); - sa.sa_handler = reap; - sigaction(SIGCHLD, &sa, NULL); - - // set up initial environmental variables - struct passwd* pw = getpwuid(getuid()); - if (pw == NULL) { - perror("init: failed to open /etc/passwd"); - return EXIT_FAILURE; - } - - if (chdir(pw->pw_dir) == -1) { - perror("init: chdir to user home directory failed"); - return EXIT_FAILURE; - } - - setenv("PWD", pw->pw_dir, 1); - setenv("HOME", pw->pw_dir, 1); - setenv("PATH", "/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin", 1); - setenv("TERM", "linux", 1); - //setenv("DISPLAY", ":0", 1); - - // set hostname - char hostname[HOST_NAME_MAX + 1]; - int hostnamefd = open("/etc/hostname", O_RDONLY); - if (hostnamefd == -1) { - // non fatal error - perror("init: failed to open /etc/hostname"); - } else { - int readcount = read(hostnamefd, hostname, HOST_NAME_MAX); - - if (readcount == -1) { - perror("init: failed to read /etc/hostname"); - } else { - hostname[readcount] = '\0'; - for (int i = 0; i < readcount; ++i) { - if (hostname[i] == '\n') - hostname[i] = '\0'; - } - - sethostname(hostname, strlen(hostname)); - } - - - close(hostnamefd); - } - - // run rc to initialize environment (mount filesystems, etc) - printf("init: running /etc/rc\n"); - pid_t pid = fork(); - if (pid == -1) { - perror("init: fork failed"); - return EXIT_FAILURE; - } - - if (pid == 0) { - execl("/usr/bin/bash", "/usr/bin/bash", "/etc/rc", NULL); - perror("init: exec /usr/bin/bash failed"); - return EXIT_FAILURE; - } - - int status = 0; - if (waitpid(pid, &status, 0) == -1) { - perror("init: waitpid failed"); - return EXIT_FAILURE; - } - - if (WEXITSTATUS(status)) { - printf("init: /etc/rc returned failure status %d\n", WEXITSTATUS(status)); - return EXIT_FAILURE; - } - - // unmask sigchild to reap children now - sigdelset(&signals, SIGCHLD); - - printf("init: creating %s\n", COMMAND_FIFO); - if (mkfifo(COMMAND_FIFO, 0600)) { - perror("init: mkfifo failed"); - return EXIT_FAILURE; - } - - // start a login shell in /dev/com0 if it exists and kernel does not enable profiling - if (access("/dev/com0", F_OK) == 0 && access("/dev/prof", F_OK)) - spawn_login_prompt("/dev/com0"); - - if (argc > 1 && strcmp(argv[1], "withlogin") == 0) - dologinprompt("/dev/console"); - - // open /dev/console as the controlling terminal if we're not doing login - printf("init: reopening /dev/console as the controlling terminal\n"); - snatchconsole("/dev/console"); - - if (argc > 1 && strcmp(argv[1], "withx") == 0) - dostartwm(); - - dorootshell(); - __builtin_unreachable(); -} diff --git a/tools/init/poweroff.c b/tools/init/poweroff.c deleted file mode 100644 index e6a47b40..00000000 --- a/tools/init/poweroff.c +++ /dev/null @@ -1,24 +0,0 @@ -#include -#include -#include -#include - -#include "common.h" - -int main() { - char c = COMMAND_POWEROFF; - int fd = open(COMMAND_FIFO, O_WRONLY); - - if (fd == -1) { - perror("poweroff: open"); - return EXIT_FAILURE; - } - - if (write(fd, &c, 1) < 0) { - perror("poweroff: write"); - return EXIT_FAILURE; - } - - close(fd); - return EXIT_SUCCESS; -} diff --git a/tools/init/reboot.c b/tools/init/reboot.c deleted file mode 100644 index 738a5e74..00000000 --- a/tools/init/reboot.c +++ /dev/null @@ -1,24 +0,0 @@ -#include -#include -#include -#include - -#include "common.h" - -int main() { - char c = COMMAND_REBOOT; - int fd = open(COMMAND_FIFO, O_WRONLY); - - if (fd == -1) { - perror("poweroff: open"); - return EXIT_FAILURE; - } - - if (write(fd, &c, 1) < 0) { - perror("poweroff: write"); - return EXIT_FAILURE; - } - - close(fd); - return EXIT_SUCCESS; -}