diff --git a/.vscode/settings.json b/.vscode/settings.json index afdfee8b..bb3d5d1d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -168,8 +168,9 @@ "mmio.h": "c", "stdint-gcc.h": "c", "acpi.h": "c", - "assert.h": "c" - }, + "assert.h": "c", + "sys_version.h": "c" +}, "C_Cpp.errorSquiggles": "Enabled", "esbonio.sphinx.confDir": "", "rust-analyzer.cargo.target": "x86_64-unknown-none", diff --git a/user/apps/about/.gitignore b/user/apps/about/.gitignore new file mode 100644 index 00000000..3e4b7a5e --- /dev/null +++ b/user/apps/about/.gitignore @@ -0,0 +1 @@ +sys_version.h \ No newline at end of file diff --git a/user/apps/about/Makefile b/user/apps/about/Makefile index b34ed553..52ae42aa 100644 --- a/user/apps/about/Makefile +++ b/user/apps/about/Makefile @@ -1,7 +1,15 @@ +# 获得当前git提交的sha1,并截取前8位 +GIT_COMMIT_SHA1=$(shell git log -n 1 | head -n 1 | cut -d ' ' -f 2 | cut -c1-8) + all: about.o ld -b elf64-x86-64 -z muldefs -o $(tmp_output_dir)/about $(shell find . -name "*.o") $(shell find $(sys_libs_dir) -name "*.o") -T about.lds objcopy -I elf64-x86-64 -R ".eh_frame" -R ".comment" -O elf64-x86-64 $(tmp_output_dir)/about $(output_dir)/about.elf -about.o: about.c + +about.o: version_header about.c $(CC) $(CFLAGS) -c about.c -o about.o + +# 生成版本头文件sys_version.h +version_header: about.c + @echo "#define DRAGONOS_GIT_COMMIT_SHA1 \"$(GIT_COMMIT_SHA1)\"" > sys_version.h diff --git a/user/apps/about/about.c b/user/apps/about/about.c index b0bed91d..f1771aa9 100644 --- a/user/apps/about/about.c +++ b/user/apps/about/about.c @@ -1,3 +1,4 @@ +#include "sys_version.h" // 这是系统的版本头文件,在编译过程中自动生成 #include #include #include @@ -18,8 +19,10 @@ void print_copyright() printf(" DragonOS - An opensource operating system.\n"); printf(" Copyright: fslongjin & DragonOS Community. 2022, All rights reserved.\n"); printf(" Version: "); - put_string("V0.1.1 - 20221127\n", COLOR_GREEN, COLOR_BLACK); - printf(" You can visit the project via:\n"); + put_string("V0.1.2\n", COLOR_GREEN, COLOR_BLACK); + printf(" Git commit SHA1: %s\n", DRAGONOS_GIT_COMMIT_SHA1); + printf(" Build time: %s %s\n", __DATE__, __TIME__); + printf(" \nYou can visit the project via:\n"); printf("\n"); put_string(" Official Website: https://DragonOS.org\n", COLOR_INDIGO, COLOR_BLACK); put_string(" GitHub: https://github.com/fslongjin/DragonOS\n", COLOR_ORANGE, COLOR_BLACK); @@ -34,13 +37,9 @@ void print_copyright() int main() { - // printf("Hello World!\n"); print_ascii_logo(); print_copyright(); - // exit(0); - // while (1) - // ; return 0; } \ No newline at end of file diff --git a/user/apps/shell/cmd.c b/user/apps/shell/cmd.c index 69788309..77545757 100644 --- a/user/apps/shell/cmd.c +++ b/user/apps/shell/cmd.c @@ -39,26 +39,38 @@ const static int total_built_in_cmd_num = sizeof(shell_cmds) / sizeof(struct bui */ static char *get_target_filepath(const char *filename, int *result_path_len) { - int cwd_len = strlen(shell_current_path); + char *file_path = NULL; + if (filename[0] != '/') + { + int cwd_len = strlen(shell_current_path); - // 计算文件完整路径的长度 - *result_path_len = cwd_len + strlen(filename); + // 计算文件完整路径的长度 + *result_path_len = cwd_len + strlen(filename); - char *file_path = (char *)malloc(*result_path_len + 2); + file_path = (char *)malloc(*result_path_len + 2); - memset(file_path, 0, *result_path_len + 2); + memset(file_path, 0, *result_path_len + 2); - strcpy(file_path, shell_current_path); + strncpy(file_path, shell_current_path, cwd_len); - // 在文件路径中加入斜杠 - if (cwd_len > 1) - file_path[cwd_len] = '/'; + // 在文件路径中加入斜杠 + if (cwd_len > 1) + file_path[cwd_len] = '/'; - // 拼接完整路径 - if (filename[0] == '/') - strcat(file_path, filename + 1); - else + // 拼接完整路径 strcat(file_path, filename); + } + else + { + *result_path_len = strlen(filename); + file_path = (char *)malloc(*result_path_len + 2); + + memset(file_path, 0, *result_path_len + 2); + + strncpy(file_path, filename, *result_path_len); + if(filename[(*result_path_len)-1]!='/') + file_path[*result_path_len] = '/'; + } return file_path; } @@ -483,7 +495,8 @@ int shell_cmd_exec(int argc, char **argv) // 如果不指定后台运行,则等待退出 if (strcmp(argv[argc - 1], "&") != 0) waitpid(pid, &retval, 0); - else{ + else + { // 输出子进程的pid printf("[1] %d\n", pid); }