init: demo execv()

This commit is contained in:
apio 2022-10-12 18:04:27 +02:00
parent e9df5fd663
commit 7a2e313a20
3 changed files with 47 additions and 2 deletions

View File

@ -1,4 +1,4 @@
APPS := init APPS := init sym
APPS_DIR := $(LUNA_ROOT)/apps APPS_DIR := $(LUNA_ROOT)/apps
APPS_SRC := $(APPS_DIR)/src APPS_SRC := $(APPS_DIR)/src

View File

@ -117,7 +117,17 @@ int main()
if (fclose(config) < 0) { perror("fclose"); } if (fclose(config) < 0) { perror("fclose"); }
printf("\n\nPress any key to restart.\n"); sleep(2);
printf("\n\nPress any key to restart.\n\n");
sleep(2);
if (execv("/bin/sym", NULL) < 0)
{
perror("execv");
return 1;
}
return 0; return 0;
} }

35
apps/src/sym.c Normal file
View File

@ -0,0 +1,35 @@
#include <stdio.h>
#include <string.h>
int main()
{
FILE* syms = fopen("/sys/moon.sym", "r");
if (!syms)
{
perror("fopen");
return 1;
}
char buf[1025];
if (fseek(syms, 8000, SEEK_SET) < 0)
{
perror("fseek");
return 1;
}
size_t nread = fread(buf, 1024, 1, syms);
if (ferror(syms))
{
perror("fread");
return 1;
}
buf[nread] = 0;
printf("%s\n", strchr(buf, '\n') + 1);
fclose(syms);
return 0;
}