Пример #1
0
void kmain(void)
{

	init_bss();
	init_ro();

	setup_kernel_memory();
	setup_pages();
	setup_ints();
	setup_tss();
	setup_paging();
	setup_faults();
	setup_fs();
	setup_syscalls();

	init_devs();

	char vendor[12];
	if (has_cpuid()) {
		cpuid_string(0, vendor);
		dprintf("CPU Vendor ID: %s\n");
	}

	fexec("/prgm/start", 0, NULL, NULL);
	start_scheduler();

	asm volatile ("sti");
	asm volatile ("hlt");

	/* We should never reach this */
	assert(0);
}
Пример #2
0
int
main(int argc, char *argv[])
{
    int rc, ch;
    char *argv0 = argv[0];

    while ((ch = getopt(argc, argv, "v")) != -1) {
        switch (ch) {
        case 'v':
            Verbose=1;
            break;
        default:
            usage();
        }
    }
    argc -= optind;
    argv += optind;

    if (argc<1)
        usage();

    while(argv[0] != NULL) {
        char newurl[MaxPathSize];

        printf("Expand %s:\n", argv[0]);
        rc = expandURL(newurl, argv[0]);
        if (rc==-1)
            warnx("Cannot expand %s", argv[0]);
        else
            printf("Expanded URL: %s\n", newurl);

        /* test out connection caching */
        if (1) {
            char *s, buf[MaxPathSize];

            if ((s=getenv(PKG_FTPIO_CNT)) && atoi(s)>0) {
                (void) snprintf(buf, sizeof(buf),"%d", atoi(s)-1);
                setenv(PKG_FTPIO_CNT, buf, 1);

                printf("%s>>> %s -v %s\n", s, argv0, argv[0]);
                fexec(argv0, "-v", argv[0], NULL);
            }
        }

        printf("\n\n\n");
        argv++;
    }

    ftp_stop();

    return 0;
}
Пример #3
0
/* run the doFile with given parameters */
static int build(char *const target, char *const redoTarget, char *const doFile, char *const basename){
    if(!fileExists(doFile)){
        fprintf(stderr, "error: %s: no such file or directory\n", doFile);
        return -1;
    } else {
        int ret = fexec(doFile, redoTarget, basename);
        if(ret == 0){
            int e;
            ret = rename(redoTarget, target);
            e = errno; /* we should save this somewhere */
            if(ret){
                if(e == ENOENT){
                    /* phony target */
                    fprintf(stderr, "debug: phony target detected\n");
                    ret = 0;
                } else {
                    perror("rename");
                }
            }
        }
        return ret;
    }
}
Пример #4
0
handle_t fexec_sc(const char * prgm, int argc, const char ** argv)
{
	process * p = fexec(prgm, argc, argv);
	if (p == NULL) return INVALID_HANDLE;
	return p->first->handle;
}
Пример #5
0
int main(int argc, char *argv[], char *envp[]) {
   int oldPipe[2];
   int newPipe[2];
   int i = 0;
   if(debug) printf("DEBUG ENABLED.\n");
   cmds = calloc(32, sizeof(int));
   _args = calloc(256, sizeof(char*));
   while(1){
      oldPipe[0] = -1;
	   oldPipe[1] = -1;
      newPipe[0] = -1;
	   newPipe[1] = -1;
      cmd_count = redir_in = redir_out = 
         i = cmd_current = cmd_start = cmd_end = 0;
      printf(" dShell$ ");
      getline();
      if(_args[1] == NULL)
         continue;
      pipe_count = 0;  
      if(operror)
         continue;
      if(debug){
      for(i = 0; cmds[i] != -1; i++) {
         printf("cmds[%d]: ", i);
         if(cmds[i]>-1)
            printf("_args[%d]: %s\n", cmds[i], _args[cmds[i]]);
         else
            printf("%d\n", cmds[i]);
      }
      }
      /* 
       * Syntax parsing is complete. 
       * Now we need to do another parse up to each semicolon or newline
       * in order to prep for execution.
       * A note about cmds array structure:
       *    Even indices are command name or file name indices in _args.
       *    Odd indices are operators (or the end of the line).
       */
      i = 0;
      cmd_end = -1;
      while(cmd_start != cmd_end){
         if(debug)
         while(cmds[cmd_start] == -2){
            cmd_start++;}
         if(cmds[cmd_start] == -1){
            if(debug)
               printf("No input detected.\n");
            break;
         }
         /* -1 is EOL. -2 is ; */
         i = cmd_start + 1;
         if(cmds[i] == -1)
            cmd_end = i;
         while(i != cmd_end){
            if(debug)
            /* Parse for operators in this phrase. */
            switch(cmds[i]){
               /* -10 is < */
               case -10: redir_in = 1; i+=2; break; 
               /* -11 is > */
               case -11: redir_out = 1; i+=2; break; 
               /* -12 is | */   
               case -12: pipe_count++; i+=2; break; 
               case -1:
               case -2:  cmd_end = i; break;
               /* Error! */
               default:  fprintf(stderr, "Unrecognized operator sigil.\n");
                         exit(1);
            }
         }
         /* TODO: Validate that commands and files exist? */
         if(debug){
         printf("redir_in:\t%d", redir_in);
         printf("\tredir_out:\t%d", redir_out);
         printf("\tpipe_count:\t%d\n", pipe_count);
         printf("cmd_indices:\t%d, %d\n", cmd_start, cmd_end);
         }
         /*
          * We should be ready to execute up to the first semicolon
          * or newline now; that position is noted by cmd_end.
          */
         /* For each command in the phrase... */
         exec_failed = 0;
         for(cmd_current = cmd_start; cmd_current <= cmd_end; cmd_current+=2){
            int cmd_push = 0;
            int return_status = 0;
            int open_failed = 0;
            int pipe_failed = 0;
            /* Set up the file descriptors if necessary. */
            if(redir_in){
               if(debug)
                  printf("Generating redir_in descriptor to %s.\n", _args[cmds[cmd_current+2]]);
               if(oldPipe[0] > -1) close(oldPipe[0]);
               oldPipe[0] = open(_args[cmds[cmd_current+2]], O_RDONLY);
               if(oldPipe[0] < 0)
                  open_failed++;
               redir_in--;
               cmd_push+=2;
            }
            if(!redir_out && !pipe_count){
               if(newPipe[1] > -1) close(newPipe[1]);
               if(newPipe[0] > -1) close(newPipe[0]);
               newPipe[1] = -1; newPipe[0] = -1;
            }
            if(redir_out && !pipe_count){
               if(debug)
                  printf("Generating redir_out descriptor to %s.\n", _args[cmds[cmd_current+2]]);
               if(newPipe[1] > -1) close(newPipe[1]);
               newPipe[1] = open(_args[cmds[cmd_current+2]], O_CREAT | O_WRONLY, 0755);
               if(newPipe[1] < 0)
                  open_failed++;
               redir_out--;
               cmd_push +=2;
            }
            if(pipe_count){
               if(debug) printf("Generating pipes.\n");
               if(pipe(newPipe))
                  pipe_failed++;
               --pipe_count;
            } 
            if(open_failed){
               fprintf(stderr, "Opening file %s failed. Did you forget to include the path? \n\tNot executing %s or further. Beware of broken pipes.\n", _args[cmds[cmd_current+2]], _args[cmds[cmd_current]]);
               exec_failed++;
               break;
            }
            if(pipe_failed){
               fprintf(stderr, "Opening a pipe for %s failed. Halting further execution and resetting shell. \n\tBeware of broken pipes.\n", _args[cmds[cmd_current]]);
               exec_failed++;
               break;
            }
            if(debug) printf("fexecing %s.\n", _args[cmds[cmd_current]]);
            fexec(cmd_current, oldPipe, newPipe); 
            if(cmd_push)
               cmd_current += cmd_push;
         }
      return_status = 0;
      if(exec_failed)
         fprintf(stderr, "Something went wrong. Waiting for open children...\n");
      if(newPipe[0]>=0) close(newPipe[0]);
      if(newPipe[1]>=0) close(newPipe[1]);
      if(oldPipe[0]>=0) close(oldPipe[0]);
      if(oldPipe[1]>=0) close(oldPipe[1]);
      while(printf("Waiting...\n") && waitpid(-1, &return_status, 0) != -1){
         if(debug) printf("A child returned with status %d\n", return_status);
         if(return_status)
            fprintf(stderr, "Parent: A child returned an exit code indicating failure.\n");
      }
      if(exec_failed)
         break;
      if(cmds[cmd_end] == -2 && cmds[cmd_end+1] != -1)
         cmd_start = cmd_end++;
      else
         cmd_start = cmd_end;
      }
   }  
  return 0;
}