add micro-init and configs, fixed builder

This commit is contained in:
Your Name 2023-12-23 20:13:26 +03:00
parent c01af93635
commit 24ea8341af
69 changed files with 221 additions and 63 deletions

View File

@ -12,7 +12,7 @@ if [ -z $CC ]; then
fi
if [ -z $projects ]; then
projects="console-tools coreutils sysutils-linux findutils networking miscutils shell loginutils procps"
projects="init console-tools coreutils sysutils-linux findutils networking miscutils shell loginutils procps"
fi
#Compile
@ -26,7 +26,7 @@ for project in $projects; do
cd $PROJECT_DIR/$i
echo " * Compile" $i
chmod -v +x build.sh
env CC=$CC CFLAGS="$CFLAGS -I$PROJECT_DIR -I$PROJECT_DIR/include/libmu -lm" OUTPUT="-o $PROJECT_DIR"/bin/$(basename $i) ./build.sh
env CC=$CC CFLAGS="$CFLAGS -I$PROJECT_DIR -I$PROJECT_DIR/include/libmu -lm" OUTPUT="$PROJECT_DIR"/bin/ ./build.sh
cd $PROJECT_DIR
done
echo

View File

@ -28,6 +28,13 @@
#define LS_FIFO_COLOR LS_LINK_COLOR
#define LS_EXE_COLOR "\033[1;32m"
/* Init scripts */
#ifdef INIT
char *INIT_POWEROFF[] = {"/etc/rc.poweroff"};
char *INIT_START[] = {"/etc/rc.init"};
#define INIT_MSG "Starting micro-init..."
#endif
/* Max args (xargs) */
#define NARGS 1024

2
configs/passwd Normal file
View File

@ -0,0 +1,2 @@
root::0:0:root:/usr/root:/bin/sh
nobody:*:65534:65534:nobody:/nonexistent:/bin/false

9
configs/rc.init Executable file
View File

@ -0,0 +1,9 @@
#!/bin/sh
echo "Mounting.."
mount -t proc /proc
mount -t sysfs /sys
mount -t devtmpfs /dev
mount -t tmpfs /tmp
echo "Starting shell..."
sh

8
configs/rc.poweroff Executable file
View File

@ -0,0 +1,8 @@
#!/bin/sh
echo "Umounting..."
umount /proc
umount /sys
umount /dev
umount /tmp
echo "Poweroff..."

1
configs/resolv.conf Normal file
View File

@ -0,0 +1 @@
nameserver 192.168.0.1

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View File

@ -64,7 +64,6 @@ void format(char *str) {
int main(int argc, char **argv) {
unsigned int n_flag = 0;
int i;
for (i = 1; i < argc; i++) {
if (argv[i][0] != '-')

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View File

@ -113,7 +113,7 @@ int main(int argc, char **argv) {
else {
int fd = open(argv[i], O_RDONLY);
if (fd < 0) {
fprintf(stderr, "wc: %s\n", strerror(errno));
fprintf(stderr, "wc: %s: %s\n", argv[i], strerror(errno));
return 1;
}

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

5
src/init/init/build.sh Executable file
View File

@ -0,0 +1,5 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC
mv reboot $OUTPUT/reboot
mv poweroff $OUTPUT/poweroff

68
src/init/init/init.c Normal file
View File

@ -0,0 +1,68 @@
#define INIT
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/reboot.h>
#include <sys/wait.h>
#include "config.h"
void poweroff(int sig) {
printf("Syncing...\n");
sync();
if (sig == SIGUSR1)
reboot(RB_POWER_OFF);
else if (sig == SIGKILL)
reboot(RB_AUTOBOOT);
}
void execute(char *argv[], sigset_t *set) {
pid_t pid;
if ((pid = fork()) == 0) {
sigprocmask(SIG_UNBLOCK, set, NULL);
setsid();
execvp(argv[0], argv);
fprintf(stderr, "init: %s\n", strerror(errno));
exit(1);
}
int status = 0;
waitpid(pid, &status, 0);
if (status != 0) {
fprintf(stderr, "init: Init script returned %d\nRebooting...", status);
poweroff(SIGKILL);
}
}
int main(void) {
if (getpid() != 1) {
fprintf(stderr, "init: PID Must be 1\n");
return 1;
}
chdir("/");
printf("%s\n", INIT_MSG);
/* Start main service */
sigset_t set;
sigprocmask(SIG_BLOCK, &set, NULL);
execute(INIT_START, &set);
/* Sig handler */
int sig = 0;
while (1) {
if (sigwait(&set, &sig) == 0)
if (sig == SIGKILL || sig == SIGUSR1) {
execute(INIT_POWEROFF, &set);
poweroff(sig);
}
}
return 0;
}

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
echo ./*.c $CFLAGS -o rc | xargs $CC
mv rc $OUTPUT/sh

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View File

@ -1,2 +1,3 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC