init: demo execv()
This commit is contained in:
parent
e9df5fd663
commit
7a2e313a20
@ -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
|
||||||
|
@ -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
35
apps/src/sym.c
Normal 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;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user