Bump version

This commit is contained in:
Mark
2020-04-07 23:40:37 +03:00
parent 815aa5c2a3
commit c017ff9023
15 changed files with 224 additions and 134 deletions
+32 -16
View File
@@ -11,25 +11,35 @@ DIRS=$(O) \
$(O)/vsh
HDRS=$(shell find $(S) -type f -name "*.h")
STAGE_BIN=$(STAGE)/init \
$(STAGE)/bin/ls \
$(STAGE)/bin/sh \
$(STAGE)/bin/hexd \
$(STAGE)/bin/date \
$(STAGE)/bin/uname \
$(STAGE)/bin/rm \
$(STAGE)/bin/mkdir \
$(STAGE)/bin/mount \
$(STAGE)/bin/umount \
$(STAGE)/bin/login \
$(STAGE)/bin/sh \
$(STAGE)/bin/ls \
$(STAGE)/bin/rm \
$(STAGE)/bin/reboot \
$(STAGE)/bin/mkdir \
$(STAGE)/bin/netctl \
$(STAGE)/bin/netmeow \
$(STAGE)/bin/netdump \
$(STAGE)/bin/mouse \
$(STAGE)/bin/vsh
$(STAGE)/bin/date \
$(STAGE)/bin/login
# TODO
# newlib: gettimeofday is broken?
# newlib: port mount()/umount()
# newlib: port reboot()
# $(STAGE)/bin/reboot \
# $(STAGE)/bin/netctl \
# $(STAGE)/bin/netmeow \
# $(STAGE)/bin/netdump \
# $(STAGE)/bin/ping \
# $(STAGE)/bin/mouse \
# $(STAGE)/bin/ase \
# $(STAGE)/bin/vsh
# $(STAGE)/bin/com \
# $(STAGE)/bin/ase \
# $(STAGE)/bin/su \
sh_OBJS=$(O)/sh/sh.o \
@@ -46,19 +56,25 @@ vsh_OBJS=$(O)/vsh/vsh.o \
usr_CFLAGS=-ggdb \
-msse \
-msse2 \
-O2 \
-O0 \
-Wall \
-Werror \
-Wno-char-subscripts \
-ffreestanding
usr_LDFLAGS=-lgcc \
-static
all: mkdirs $(O)/initrd.img
all: mkdirs lua $(O)/initrd.img
clean:
rm -rf $(O)
make -j5 -C ../lua clean
lua:
make -C ../lua yggdrasil
mkdir -p $(STAGE)/bin
cp ../lua/lua $(STAGE)/bin/lua
#chmod 04711 $(STAGE)/bin/su
$(O)/initrd.img: mkstage-etc $(STAGE_BIN)
@@ -68,7 +84,7 @@ mkdirs:
mkdir -p $(DIRS)
mkstage-etc:
mkdir -p $(STAGE)/dev $(STAGE)/mnt $(STAGE)/bin
mkdir -p $(STAGE)/dev $(STAGE)/mnt $(STAGE)/bin $(STAGE)/sys
cp -r etc $(STAGE)
# Application building
+23 -7
View File
@@ -1,9 +1,11 @@
#include <sys/termios.h>
#include <sys/select.h>
#include <termios.h>
#include <sys/ioctl.h>
#include <string.h>
#include <assert.h>
#include <stdlib.h>
#include <fcntl.h>
#include <stdio.h>
#define MIN(x, y) ((x) < (y) ? (x) : (y))
@@ -20,6 +22,7 @@
#define MODE_COMMAND 1
#define MODE_INSERT 2
static struct termios tc, tc_old;
static int term_width = 0;
static int term_height = 0;
@@ -360,13 +363,13 @@ static void ase_line_insert(struct ase_buffer *buf, int br) {
buf->c_col = 0;
} else {
//for (ssize_t i = buf->line_count; i > buf->c_row; --i) {
// buf->lines[i].length = buf->lines[i - 1].length;
// memcpy(buf->lines[i].text_data, buf->lines[i - 1].text_data, buf->lines[i - 1].length);
//}
//buf->lines[buf->c_row].length = 0;
//buf->c_col = 0;
//++buf->line_count;
for (ssize_t i = buf->line_count; i > buf->c_row; --i) {
buf->lines[i].length = buf->lines[i - 1].length;
memcpy(buf->lines[i].text_data, buf->lines[i - 1].text_data, buf->lines[i - 1].length);
}
buf->lines[buf->c_row].length = 0;
buf->c_col = 0;
++buf->line_count;
}
}
@@ -408,6 +411,7 @@ static void key_insert(struct ase_buffer *buf, int ch) {
static void cmd_exec(struct ase_buffer *buf) {
if (!strcmp(buf->cmd_buf, "q")) {
tcsetattr(STDIN_FILENO, TCSANOW, &tc_old);
printf("\033[2J\033[1;1f");
exit(0);
} else if (!strncmp(buf->cmd_buf, "e ", 2)) {
@@ -434,6 +438,18 @@ int main(int argc, char **argv) {
term_width = ws.ws_col;
term_height = ws.ws_row;
if (tcgetattr(STDIN_FILENO, &tc_old) != 0) {
perror("Failed to get terminal settings");
return -1;
}
memcpy(&tc, &tc_old, sizeof(struct termios));
tc.c_lflag = 0;
tc.c_iflag &= ~ICANON;
if (tcsetattr(STDIN_FILENO, TCSANOW, &tc) != 0) {
perror("Failed to set terminal settings");
return -1;
}
buf.mode = MODE_NORMAL;
buf.cmd_len = 0;
+6 -5
View File
@@ -1,16 +1,17 @@
#include <sys/time.h>
#include <string.h>
#include <unistd.h>
#include <stdio.h>
#include <time.h>
int main(int argc, char **argv) {
// Ignore arguments
struct timeval tv0;
char buf[256];
gettimeofday(&tv0, NULL);
struct tm tm0;
gmtime_r(&tv0.tv_sec, &tm0);
printf("%04u-%02u-%02u %02u:%02u:%02u\n",
tm0.tm_year, tm0.tm_mon, tm0.tm_mday,
tm0.tm_hour, tm0.tm_min, tm0.tm_sec);
strftime(buf, sizeof(buf), "%c\n", &tm0);
write(STDOUT_FILENO, buf, strlen(buf));
return 0;
}
+3 -3
View File
@@ -7,12 +7,12 @@
#define LINE_LENGTH 16
static void line_print(size_t off, const char *line, size_t len) {
printf("%08x: ", off);
printf("%08zx: ", off);
for (size_t i = 0; i < LINE_LENGTH; ++i) {
// XXX: This is needed because I didn't implement h/hh modifiers in printf
uint64_t byte = (uint64_t) line[i] & 0xFF;
uint8_t byte = line[i];
if (i < len) {
printf("%02x", byte);
printf("%02hhx", byte);
} else {
printf(" ");
}
+17 -11
View File
@@ -5,12 +5,14 @@
#include <unistd.h>
#include <assert.h>
#include <string.h>
#include <termios.h>
#include <sys/termios.h>
#include <signal.h>
#include <stdio.h>
#include <errno.h>
#include <pwd.h>
#include <sys/gets2.h>
struct spwd {
char *sp_namp;
char *sp_pwdp;
@@ -62,12 +64,13 @@ static ssize_t getline(char *buf, size_t lim, int echo) {
}
static int getspnam_r(const char *name, struct spwd *sp, char *buf, size_t buf_size) {
int fd = open("/etc/shadow", O_RDONLY, 0);
if (fd < 0) {
return fd;
int fp = open("/etc/shadow", O_RDONLY, 0);
if (fp < 0) {
return -1;
}
while (gets_safe(fd, buf, buf_size) > 0) {
// TODO POSIX
while (gets_safe(fp, buf, buf_size)) {
char *p0 = strchr(buf, ':');
if (!p0) {
break;
@@ -84,13 +87,13 @@ static int getspnam_r(const char *name, struct spwd *sp, char *buf, size_t buf_s
continue;
}
close(fd);
close(fp);
sp->sp_namp = buf;
sp->sp_pwdp = p0 + 1;
return 0;
}
close(fd);
close(fp);
errno = ENOENT;
return -1;
}
@@ -105,7 +108,7 @@ static int loginuid(uid_t uid, gid_t gid, const char *sh) {
if (sh_pid == 0) {
if (setuid(uid) || setgid(gid)) {
perror("login");
exit(-1);
_exit(-1);
}
setpgid(0, 0);
@@ -113,10 +116,10 @@ static int loginuid(uid_t uid, gid_t gid, const char *sh) {
ioctl(STDIN_FILENO, TIOCSPGRP, &pid);
const char *argp[] = { sh, NULL };
exit(execve(sh, (char *const *) argp, NULL));
_exit(execve(sh, (char *const *) argp, NULL));
} else {
int st;
waitpid(sh_pid, &st);
waitpid(sh_pid, &st, 0);
// Regain control of the terminal
int pgid = getpgid(0);
ioctl(STDIN_FILENO, TIOCSPGRP, &pgid);
@@ -173,11 +176,13 @@ int main(int argc, char **argv) {
while (1) {
if (attempt == 3) {
puts2("\033[2J\033[1;1f");
printf("\033[2J\033[1;1f");
fflush(stdout);
attempt = 0;
}
printf("login: ");
fflush(stdout);
if (getline(line_buf, sizeof(line_buf), 1) < 0) {
break;
}
@@ -190,6 +195,7 @@ int main(int argc, char **argv) {
if (sp.sp_pwdp[0] != 0) {
printf("password: ");
fflush(stdout);
if (getline(line_buf, sizeof(line_buf), 0) < 0) {
++attempt;
continue;
+6 -6
View File
@@ -111,21 +111,21 @@ static int ls_dir(const char *path, int flags) {
break;
case DT_BLK:
case DT_CHR:
write(STDOUT_FILENO, COLOR_DEV, 5);
fputs(COLOR_DEV, stdout);
break;
case DT_DIR:
write(STDOUT_FILENO, COLOR_DIR, 5);
fputs(COLOR_DIR, stdout);
break;
default:
write(STDOUT_FILENO, COLOR_UNKNOWN, 5);
fputs(COLOR_UNKNOWN, stdout);
break;
}
}
write(STDOUT_FILENO, ent->d_name, strlen(ent->d_name));
fputs(ent->d_name, stdout);
if (flags & LS_COLOR) {
write(STDOUT_FILENO, COLOR_RESET, 4);
fputs(COLOR_RESET, stdout);
}
putchar('\n');
fputc('\n', stdout);
}
}
+10 -8
View File
@@ -1,5 +1,6 @@
#include <sys/mount.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
@@ -91,15 +92,16 @@ int main(int argc, char **argv) {
}
// Check that "dst" is a directory
if ((res = stat(dst, &st)) != 0) {
perror(dst);
return -1;
}
// TODO: stat() is fucked
//if ((res = stat(dst, &st)) != 0) {
// perror(dst);
// return -1;
//}
if ((st.st_mode & S_IFMT) != S_IFDIR) {
printf("%s: Not a directory\n", dst);
return -1;
}
//if ((st.st_mode & S_IFMT) != S_IFDIR) {
// printf("%s: Not a directory\n", dst);
// return -1;
//}
// Do the magic stuff
if ((res = mount(src, dst, type, mount_flags, NULL)) != 0) {
+56 -49
View File
@@ -9,9 +9,9 @@
static int running = 1;
static int mx = 40;
static int my = 12;
static double mx_d = 40, my_d = 12;
//static int mx = 40;
//static int my = 12;
//static double mx_d = 40, my_d = 12;
static int con_width, con_height;
@@ -19,47 +19,47 @@ static void signal_handle(int signum) {
running = 0;
}
static void kb_handle(char *buf, size_t len) {
if (buf[0] == 'q') {
running = 0;
}
}
static void ms_handle(char *buf, size_t len) {
for (size_t i = 0; i < len / 5; ++i) {
char type = buf[i * 5 + 0];
switch (type) {
case 'd': {
int16_t dx = *(int16_t *) &buf[i * 5 + 1];
int16_t dy = *(int16_t *) &buf[i * 5 + 3];
mx_d += (double) dx / 4.0;
my_d -= (double) dy / 12.0;
if (mx_d < 0) {
mx_d = 0;
}
if (mx_d >= con_width - 1) {
mx_d = con_width - 2;
}
if (my_d < 0) {
my_d = 0;
}
if (my_d >= con_height - 1) {
my_d = con_height - 2;
}
mx = mx_d;
my = my_d;
puts2("\033[2J\033[1;1f");
printf("\033[%d;%dfX\033[%d;%df", my + 1, mx + 1, my + 1, mx + 1);
}
break;
}
}
}
//static void kb_handle(char *buf, size_t len) {
// if (buf[0] == 'q') {
// running = 0;
// }
//}
//
//static void ms_handle(char *buf, size_t len) {
// for (size_t i = 0; i < len / 5; ++i) {
// char type = buf[i * 5 + 0];
//
// switch (type) {
// case 'd': {
// int16_t dx = *(int16_t *) &buf[i * 5 + 1];
// int16_t dy = *(int16_t *) &buf[i * 5 + 3];
//
// mx_d += (double) dx / 4.0;
// my_d -= (double) dy / 12.0;
//
// if (mx_d < 0) {
// mx_d = 0;
// }
// if (mx_d >= con_width - 1) {
// mx_d = con_width - 2;
// }
//
// if (my_d < 0) {
// my_d = 0;
// }
// if (my_d >= con_height - 1) {
// my_d = con_height - 2;
// }
//
// mx = mx_d;
// my = my_d;
// puts2("\033[2J\033[1;1f");
// printf("\033[%d;%dfX\033[%d;%df", my + 1, mx + 1, my + 1, mx + 1);
// }
// break;
// }
// }
//}
int main(int argc, char **argv) {
fd_set fds;
@@ -68,7 +68,7 @@ int main(int argc, char **argv) {
struct winsize winsz;
int kb_fd = STDIN_FILENO, ms_fd;
char buf[512];
ssize_t len;
//ssize_t len;
signal(SIGINT, signal_handle);
@@ -109,13 +109,20 @@ int main(int argc, char **argv) {
if (res != 0) {
if (FD_ISSET(ms_fd, &fds)) {
len = read(ms_fd, buf, sizeof(buf));
ms_handle(buf, len);
read(ms_fd, buf, sizeof(buf));
printf("Mouse\n");
//ms_handle(buf, len);
}
if (FD_ISSET(kb_fd, &fds)) {
len = read(kb_fd, buf, sizeof(buf));
kb_handle(buf, len);
read(kb_fd, buf, sizeof(buf));
printf("Keyboard\n");
//kb_handle(buf, len);
if (buf[0] == 'q') {
break;
}
}
} else {
printf("Timeout\n");
}
}
+24 -5
View File
@@ -1,5 +1,6 @@
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/select.h>
#include <stdio.h>
#define LINE_LENGTH 16
@@ -54,6 +55,9 @@ int main(int argc, char **argv) {
size_t salen;
char buf[4096];
int fd = socket(AF_PACKET, SOCK_RAW, 0);
fd_set fds;
struct timeval tv;
int res;
if (fd < 0) {
perror("socket()");
@@ -61,14 +65,29 @@ int main(int argc, char **argv) {
}
while (1) {
ssize_t len = recvfrom(fd, buf, sizeof(buf), &sa, &salen);
FD_ZERO(&fds);
FD_SET(fd, &fds);
tv.tv_sec = 1;
tv.tv_usec = 0;
if (len < 0) {
perror("recvfrom()");
break;
res = select(fd + 1, &fds, NULL, NULL, &tv);
if (res < 0) {
perror("select()");
}
packet_dump(buf, len);
if (res > 0) {
ssize_t len = recvfrom(fd, buf, sizeof(buf), &sa, &salen);
if (len < 0) {
perror("recvfrom()");
break;
}
packet_dump(buf, len);
} else {
printf("Timed out\n");
}
}
return 0;
+16
View File
@@ -0,0 +1,16 @@
#include <sys/socket.h>
#include <arpa/inet.h>
#include <stdio.h>
int main(int argc, char **argv) {
int sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_ICMP);
if (sock < 0) {
perror("socket()");
return -1;
}
close(sock);
return 0;
}
+2 -3
View File
@@ -1,6 +1,5 @@
#include <sys/netctl.h>
#include <sys/mount.h>
#include <sys/mman.h>
#include <sys/wait.h>
#include <assert.h>
#include <unistd.h>
@@ -27,8 +26,8 @@ int main(int argc, char **argv) {
mount(NULL, "/sys", "sysfs", 0, NULL);
mount("/dev/sda1", "/mnt", NULL, 0, NULL);
uint32_t inaddr = 0x0A000001;
netctl("eth0", NETCTL_SET_INADDR, &inaddr);
//uint32_t inaddr = 0x0A000001;
//netctl("eth0", NETCTL_SET_INADDR, &inaddr);
return start_login();
}
+15 -14
View File
@@ -2,6 +2,7 @@
#include <sys/stat.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include "builtin.h"
#include "config.h"
@@ -101,19 +102,19 @@ DEF_BUILTIN(stat) {
return -1;
}
printf("device %u\n", st.st_dev);
printf("inode %u\n", st.st_ino);
printf("mode %u\n", st.st_mode);
printf("nlink %u\n", st.st_nlink);
printf("uid %u\n", st.st_uid);
printf("gid %u\n", st.st_gid);
printf("rdev %u\n", st.st_rdev);
printf("size %u\n", st.st_size);
printf("atime %u\n", st.st_atime);
printf("mtime %u\n", st.st_mtime);
printf("ctime %u\n", st.st_ctime);
printf("blksize %u\n", st.st_blksize);
printf("blocks %u\n", st.st_blocks);
printf("device %u\n", st.st_dev);
printf("inode %u\n", st.st_ino);
printf("mode %u\n", st.st_mode);
printf("nlink %u\n", st.st_nlink);
printf("uid %u\n", st.st_uid);
printf("gid %u\n", st.st_gid);
printf("rdev %u\n", st.st_rdev);
printf("size %u\n", st.st_size);
printf("atime %u\n", st.st_atime);
printf("mtime %u\n", st.st_mtime);
printf("ctime %u\n", st.st_ctime);
printf("blksize %u\n", st.st_blksize);
printf("blocks %u\n", st.st_blocks);
return 0;
}
@@ -193,7 +194,7 @@ DEF_BUILTIN(exec) {
}
DEF_BUILTIN(clear) {
puts2("\033[2J\033[1;1f");
printf("\033[2J\033[1;1f");
return 0;
}
+3 -1
View File
@@ -2,7 +2,9 @@
#include <sys/ioctl.h>
#include <sys/wait.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <ctype.h>
#include <stdio.h>
@@ -65,7 +67,7 @@ static int cmd_spawn(const char *path, const struct cmd_exec *cmd, int *cmd_res)
setpgid(0, 0);
exit(execve(path, (char *const *) cmd->args, NULL));
} else {
if (waitpid(pid, cmd_res) != 0) {
if (waitpid(pid, cmd_res, 0) != 0) {
perror("waitpid()");
}
+4
View File
@@ -1,4 +1,5 @@
//#include <sys/select.h>
#include <unistd.h>
#include <stdio.h>
//#define KEY_UP (256)
@@ -91,6 +92,9 @@ int readline(char *buf, size_t lim) {
buf[len - 1] = 0;
}
//printf("Got len = %ld\n", len);
//while (1);
//int len = 0;
//int cur = 0;
//int chr;
+7 -6
View File
@@ -1,4 +1,5 @@
#include <sys/utsname.h>
#include <sys/gets2.h>
#include <sys/fcntl.h>
#include <unistd.h>
#include <signal.h>
@@ -21,7 +22,7 @@ static void update_prompt(void) {
struct utsname _u;
struct passwd _p;
struct passwd *p;
char pwbuf[512];
char pwbuf[256];
p_uid = getuid();
@@ -32,11 +33,9 @@ static void update_prompt(void) {
if (uname(&_u) != 0) {
perror("uname()");
p_hostname[0] = 0;
} else {
strcpy(p_hostname, _u.nodename);
}
if (getpwuid_r(p_uid, &_p, pwbuf, sizeof(pwbuf), &p) != 0) {
perror("getpwuid_r()");
p_username[0] = 0;
@@ -55,13 +54,13 @@ static void display_prompt(void) {
putchar(p_uid == 0 ? '#' : '$');
break;
case 'h':
puts2(p_hostname);
fputs(p_hostname, stdout);
break;
case 'u':
puts2(p_username);
fputs(p_username, stdout);
break;
case 'd':
puts2(p_cwd);
fputs(p_cwd, stdout);
break;
default:
putchar('%');
@@ -74,6 +73,8 @@ static void display_prompt(void) {
++p;
}
fflush(stdout);
}
static void signal_handle(int signum) {