Exemple #1
0
/* --- main loop of the simple shell --- */
int main(int argc, char* argv[]) {

  signal(SIGINT, sig_handler);

  /* initialize the shell */
  char *cmdline;
  char *hostname[HOSTNAMEMAX]; /* changed to a pointer */
  int terminate = 0;
  Shellcmd shellcmd;

  if (gethostname(hostname)) {
    /* parse commands until exit or ctrl-c */
    while (!terminate) {
      printf("%s:$", *hostname);
      if (cmdline = readline(" ")) {
	if(*cmdline) {
	  add_history(cmdline);
	  if (parsecommand(cmdline, &shellcmd)) {
	    terminate = executeshellcmd(&shellcmd);
	  }
	}
	free(cmdline);
      } else terminate = 1;
    }
    free(*hostname);
    printf("Exiting bosh.\n");
  }

  return EXIT_SUCCESS;
}
Exemple #2
0
/* --- main loop of the simple shell --- */
int main(int argc, char* argv[]) {
  signal(SIGINT, SIG_IGN); // Ignore Ctrl + C - so we don't close the shell
  /* initialize the shell */
  char *cmdline;
  char hostname[HOSTNAMEMAX];
  int terminate = 0;
  Shellcmd shellcmd;
  
  if (gethostnamefromproc(hostname)) {

    /* parse commands until exit or ctrl-c */
    while (!terminate) {
      printf("%s", hostname);
      if (strcmp(cmdline = readline(":# "), "exit") != 0) {
	if(*cmdline) {
          add_history(cmdline);
          if (parsecommand(cmdline, &shellcmd)) {
            terminate = executeshellcmd(&shellcmd);
          }
	}
	free(cmdline);
      } else terminate = 1;
    }
    printf("Exiting BOSH.\n");
  }

  return EXIT_SUCCESS;
}
Exemple #3
0
/* --- main loop of the simple shell --- */
int main(int argc, char* argv[]) {

  /* Set the SIGINT (Ctrl-C) signal handler to sigintHandler 
    Refer http://en.cppreference.com/w/c/program/signal */
  signal(SIGINT, sigintHandler);

  /* initialize the shell */
  char *cmdline;
  char hostname[HOSTNAMEMAX];
  int terminate = 0;
  Shellcmd shellcmd;
  
  if (gethostname(hostname)) {

    /* parse commands until exit or ctrl-c */
    while (!terminate) {
      printf("%s", hostname);
      if (cmdline = readline(":# ")) {
      	if(*cmdline) {
          if(strcmp(cmdline, "exit") == 0) {
             break;
          } 
      	  add_history(cmdline);
      	  if (parsecommand(cmdline, &shellcmd)) {
            pid_t pid = fork(); //Make a child process that calls the commands
            if(pid == 0)
            {
              currentPId = getpid();
              terminate = executeshellcmd(&shellcmd);
              return;
            }
            else {
            int status;
            waitpid(pid, &status, 0);
            }
      	  }
      	}
    	 free(cmdline);
      } else terminate = 1;
    }
    printf("Exiting bosh.\n");
  }    
    
  return EXIT_SUCCESS;
}
Exemple #4
0
Fichier : bosh.c Projet : Jelb/BOSC
/* --- main loop of the simple shell --- */
int main(int argc, char* argv[]) {

  /* initialize the shell */
  char *cmdline;
  char hostname[HOSTNAMEMAX];
  int terminate = 0;
  Shellcmd shellcmd;
  
  //char cmd[100];
  //sprintf(cmd, "/bin/ls");
  //system(cmd);
  


  if (gethostname(hostname)) {

    /* parse commands until exit or ctrl-c */
    while (!terminate) {
      printf("%s", hostname);
      if (cmdline = readline(":# ")) {
	      if(*cmdline) {
	        add_history(cmdline);
	        if (parsecommand(cmdline, &shellcmd)) {
	          terminate = executeshellcmd(&shellcmd);
	        }
	      }
	      free(cmdline);
      } else {
        terminate = 1;
      }
    }

    printf("Exiting bosh.\n");
  }  
  return EXIT_SUCCESS;
}