mirror of
https://github.com/Soccera1/init.git
synced 2026-02-04 05:33:41 +01:00
Fix script execution and duplicate script execution
This commit is contained in:
parent
2c0968f41b
commit
2c9e0af72b
7 changed files with 14 additions and 9 deletions
2
examples/app.sh
Normal file → Executable file
2
examples/app.sh
Normal file → Executable file
|
|
@ -1,2 +1,2 @@
|
||||||
db.sh network.sh
|
# db.sh network.sh
|
||||||
echo "Application service started"
|
echo "Application service started"
|
||||||
|
|
|
||||||
4
examples/db.sh
Normal file → Executable file
4
examples/db.sh
Normal file → Executable file
|
|
@ -1,2 +1,2 @@
|
||||||
network.sh
|
# network.sh
|
||||||
echo "Database service started"
|
echo "Database service started"
|
||||||
0
examples/logging.sh
Normal file → Executable file
0
examples/logging.sh
Normal file → Executable file
2
examples/network.sh
Normal file → Executable file
2
examples/network.sh
Normal file → Executable file
|
|
@ -1,2 +1,2 @@
|
||||||
logging.sh
|
# logging.sh
|
||||||
echo "Network service started"
|
echo "Network service started"
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,3 @@
|
||||||
#define INIT_DIRECTORY "/home/lily/init/examples"
|
#define INIT_DIRECTORY "/home/lily/init/examples"
|
||||||
#define SHELL "/bin/sh"
|
#define SHELL "/bin/sh"
|
||||||
|
#define DEPENDENCY_PREFIX "#"
|
||||||
|
|
@ -21,7 +21,7 @@ void check_init() {
|
||||||
|
|
||||||
void run(int runlevel) {
|
void run(int runlevel) {
|
||||||
char command[1024];
|
char command[1024];
|
||||||
snprintf(command, sizeof(command), "%s %s/%d", SHELL, INIT_DIRECTORY, runlevel);
|
snprintf(command, sizeof(command), "cd %s && PATH=\"$PATH:%s\" %s %d", INIT_DIRECTORY, INIT_DIRECTORY, SHELL, runlevel);
|
||||||
system(command);
|
system(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -30,9 +30,9 @@ int main(int argc, char* argv[]) {
|
||||||
printf("Usage: %s <runlevel>\n", argv[0]);
|
printf("Usage: %s <runlevel>\n", argv[0]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
char runlevel = argv[1][0];
|
int runlevel = atoi(argv[1]);
|
||||||
|
|
||||||
check_init();
|
check_init();
|
||||||
run;
|
run(runlevel);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -94,7 +94,11 @@ void solve_dependencies(char runlevel) {
|
||||||
if (f) {
|
if (f) {
|
||||||
char line[1024];
|
char line[1024];
|
||||||
if (fgets(line, sizeof(line), f)) {
|
if (fgets(line, sizeof(line), f)) {
|
||||||
char *token = strtok(line, " \t\n\r");
|
char *start = line;
|
||||||
|
if (strncmp(line, DEPENDENCY_PREFIX, strlen(DEPENDENCY_PREFIX)) == 0) {
|
||||||
|
start += strlen(DEPENDENCY_PREFIX);
|
||||||
|
}
|
||||||
|
char *token = strtok(start, " \t\n\r");
|
||||||
while (token && s->num_dependencies < MAX_DEPS) {
|
while (token && s->num_dependencies < MAX_DEPS) {
|
||||||
strncpy(s->dependencies[s->num_dependencies++], token, MAX_NAME);
|
strncpy(s->dependencies[s->num_dependencies++], token, MAX_NAME);
|
||||||
token = strtok(NULL, " \t\n\r");
|
token = strtok(NULL, " \t\n\r");
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue