? rc ? runscript Index: rc.c =================================================================== RCS file: /var/cvsroot/gentoo/src/embedded/baselayout-lite/src/rc.c,v retrieving revision 1.1 diff -u -b -B -w -p -r1.1 rc.c --- rc.c 27 Feb 2005 04:55:13 -0000 1.1 +++ rc.c 27 Feb 2005 07:10:32 -0000 @@ -52,7 +52,7 @@ int main(int argc, char **argv) { if(argc != 2) { fprintf(stderr, "Wrong number of args\nIt's best to let init handle this\n"); - exit(1); + exit(EXIT_FAILURE); } printf("Entering runlevel %s\n", argv[1]); @@ -60,29 +60,27 @@ int main(int argc, char **argv) { /* we only support 1 runlevel dir for boot+shutdown, so resolve deps for that dir then do stuff */ - rlvldir=opendir(RUNLEVEL_DIR); + if ((rlvldir=opendir(RUNLEVEL_DIR)) == NULL) { + perror(RUNLEVEL_DIR); + exit(EXIT_FAILURE); + } while((svc_script=readdir(rlvldir)) != NULL) { FILE *f1; char path[500]; char line[500]; - char *command; - - command=(void *)malloc(1000); - memset(command, 0, 1000); if((ret=strncmp(".", svc_script->d_name, 1)) == 0) continue; //printf("%s\n", svc_script->d_name); - sprintf(path, "%s/%s", RUNLEVEL_DIR, svc_script->d_name); + snprintf(path, sizeof(path)-1, "%s/%s", RUNLEVEL_DIR, svc_script->d_name); //printf("%s\n", path); - f1=fopen(path, "r"); - while(fgets(line, 499, f1)) { - if(strstr(line, "before *")) { - /* start everything with "before *", and mark it as started */ - printf("Starting %s\n", svc_script->d_name); - snprintf(command, 999, "%s%s start", INIT_DIR, svc_script->d_name); - system(command); + if ((f1=fopen(path, "r")) == NULL) { + perror(path); + exit(EXIT_FAILURE); + } + while(fgets(line, sizeof(line)-1, f1)) { + if(strstr(line, "before *")) { mark_started(svc_script->d_name); } } @@ -97,21 +95,43 @@ int main(int argc, char **argv) { if(is_started(svc_script->d_name) == TRUE) continue; else { - char *command; - command=(void *)malloc(1000); - memset(command, 0, 1000); - snprintf(command, 999, "%s%s start", INIT_DIR, svc_script->d_name); - system(command); mark_started(svc_script->d_name); } } - return 0; + exit(EXIST_SUCESS); } int mark_started(char *script) { + char *command = NULL; + char *cmdline[] = { "start", 0 }; + + /* start everything with "before *", and mark it as started */ + printf("Starting %s\n", script); + + asprintf(command, "%s%s", INIT_DIR, script); + + /* so we can get return values and decide if we should call mark_started() */ + if ((execvp(command, cmdline)) == 0) + free(command); + mkdir("/var/lib/init.d/started/", 0755); + chdir("/var/lib/init.d/started/"); + symlink(command, basename(script)); + return TRUE; + } + free(command); return FALSE; } int is_started(char *script) { + char *script_cache; + + asprintf(script_cache, "/var/lib/init.d/started/%s", + basename(script)); + + if ((access(script_cache, F_OK)) == 0) { + free(script_cache); + return TRUE; + } + free(script_cache); return FALSE; } Index: runscript.c =================================================================== RCS file: /var/cvsroot/gentoo/src/embedded/baselayout-lite/src/runscript.c,v retrieving revision 1.1 diff -u -b -B -w -p -r1.1 runscript.c --- runscript.c 27 Feb 2005 04:55:13 -0000 1.1 +++ runscript.c 27 Feb 2005 07:10:32 -0000 @@ -15,16 +15,14 @@ int main(int argc, char **argv) { char *word; FILE *init_script_FILE; - - line=(void *)malloc(1000); - memset(line, 0, 1000); - /* if we don't have the right number of args, fail */ if(argc < 3) { printf("Invalid number of arguments"); exit(1); } + line=(void *)malloc(1000); + memset(line, 0, 1000); /* find the deps, and make sure all the right stuff is started first */ init_script_FILE=fopen(argv[1], "r"); @@ -50,6 +48,7 @@ int main(int argc, char **argv) { */ find_alias(alias, word); printf("%s\n", alias); + free(alias); } } else if(strstr(line, "\tuse")) { /* optional deps that have to be started before if they are in RUNLEVEL_DIR */ @@ -69,7 +68,7 @@ int main(int argc, char **argv) { } } } - + free(line); runscript(argv[1], argv[2]); return 0; @@ -123,6 +122,7 @@ int in_runlevel(char *script) { continue; if((ret=strcmp(svc_script->d_name, script)) == 0) { /* we have a match */ + free(alias); return TRUE; } printf("%s: %s-%s\n", __func__, script, svc_script->d_name); @@ -130,6 +130,7 @@ int in_runlevel(char *script) { printf("%s\n", alias); //printf("%s==%s:%d\n", svc_script->d_name, script, ret); } + free(alias); return FALSE; } @@ -164,10 +165,14 @@ int find_alias(char *alias, char *script printf("%s: %s\n", svc_script->d_name, aliasline); if(strcmp(aliasline, script) == 0) { strcpy(alias, aliasline); + free(svc_script_path); + free(line); return TRUE; } } } + free(svc_script_path); + free(line); } return FALSE; }