Exemplo n.º 1
0
/*
 * Entry point of the application
 */
int main(void) {
    char** line;

    

    signal(SIGINT, signalHandler);

    /* Read a line of input from the keyboard */
    line = promptAndRead();
    
    /* While the line was blank or the user didn't type exit */
    while (line[0] == NULL || (strcmp(line[0], "exit") != 0)) {
        int lineIndex = 0; /* An index into the line array */

        /* Ignore blank lines */
        if (line[lineIndex] != NULL) {
            int   status;
            char* args[MAX_ARGS]; /* A processes arguments */

            /* Dig out the arguments for a single process */
            parseArgs(args, line, &lineIndex);

            if (strcmp(args[0], "ls") == 0) {
                doLs(args);
            } else if (strcmp(args[0], "rm") == 0) {
                doRm(args);
            } else {
                /* Fork off a child process */
                childPid = forkWrapper();

                if (CHILD_PID(childPid)) {
                    /* The child shell continues to process the command line */
                    continueProcessingLine(line, &lineIndex, args);
                } else {
                   
                    
                    waitpid(childPid, &status, 0); /* The parent process will wait for the child
                                                      to die */

                    printf("Child %d exited with status %d\n", childPid, status);
                }
            }
        }

        /* Read the next line of input from the keyboard */
        line = promptAndRead();
    }

    /* User must have typed "exit", time to gracefully exit. */
    return 0;
}
Exemplo n.º 2
0
int
main(int argc, char **argv)
{
   int status;
   rodsArguments_t myRodsArgs;
   rodsEnv myEnv;
   int i, j, didOne;
   char objPath[MAX_NAME_LEN];
   int maxCmdTokens=20;
   char *cmdToken[20];
   int argOffset;
   rcComm_t *Conn;
   rErrMsg_t errMsg;
   char *mySubName;
   char *myName;

   status = parseCmdLineOpt(argc, argv, "lvVh", 0, &myRodsArgs);
   if (status) {
      printf("Use -h for help\n");
      exit(1);
   }

   if (myRodsArgs.help==True) {
      usage("");
      exit(0);
   } 

   argOffset = myRodsArgs.optind;
 
   status = getRodsEnv (&myEnv);
   if (status < 0) {
      rodsLog (LOG_ERROR, "main: getRodsEnv error. status = %d",
	       status);
      exit (1);
   }
   strncpy(objPath,myEnv.rodsCwd,MAX_NAME_LEN);

   for (i=0;i<maxCmdTokens;i++) {
      cmdToken[i]="";
   }
   j=0;
   for (i=argOffset;i<argc;i++) {
      cmdToken[j++]=argv[i];
   }

   Conn = rcConnect (myEnv.rodsHost, myEnv.rodsPort, myEnv.rodsUserName,
                     myEnv.rodsZone, 0, &errMsg);

   if (Conn == NULL) {
      myName = rodsErrorName(errMsg.status, &mySubName);
      rodsLog(LOG_ERROR, "rcConnect failure %s (%s) (%d) %s",
	      myName,
	      mySubName,
	      errMsg.status,
	      errMsg.msg);
      exit (2);
   }

   status = clientLogin(Conn);
   if (status != 0) {
      rcDisconnect(Conn);
      exit (3);
   }

   if (strcmp(cmdToken[0],"ldt")==0) {
      if (*cmdToken[1]=='\0') {
	 cmdToken[1]=" ";  /* just for subsequent checks below */
      }
   }

   if (*cmdToken[1]=='\0') {
      usage("");
      exit(1);
   }

   if (*cmdToken[1]=='/') {
      rstrcpy(objPath, cmdToken[1], MAX_NAME_LEN);
   }
   else {
      rstrcat(objPath, "/", MAX_NAME_LEN);
      rstrcat(objPath, cmdToken[1], MAX_NAME_LEN);
   }

   didOne=0;
   if (strcmp(cmdToken[0],"ls")==0) {
      int longOption;
      if (myRodsArgs.longOption) longOption=1;
      if (myRodsArgs.verbose) longOption=1;
      doLs(Conn, objPath, longOption);
      didOne=1;
   }
   if (strcmp(cmdToken[0],"ldt")==0) {
      doListDataTypes(Conn);
      didOne=1;
   }

   if (strcmp(cmdToken[0],"mod")==0) {
      char theTime[TIME_LEN+20];

      if (*cmdToken[2]=='\0') {
	 usage("");
	 exit(1);
      }
      if (strcmp(cmdToken[2],"datatype")==0) {
	 if (*cmdToken[3]=='\0') {
	    usage("");
	    exit(1);
	 }	    
	 status = doModDatatype(Conn, objPath, cmdToken[3]);
	 didOne=1;
      }
      else if (strcmp(cmdToken[2],"comment")==0) {
	 if (*cmdToken[3]=='\0') {
	    usage("");
	    exit(1);
	 }
	 if (*cmdToken[4]=='\0') {
             status = doModComment(Conn, objPath, -1, cmdToken[3]);
         }
         else {
             status = doModComment(Conn, objPath, atoi(cmdToken[3]), cmdToken[4]);
         }
	 
	 didOne=1;
      }
      else {
	 rstrcpy(theTime, cmdToken[2], TIME_LEN);
	 status=0;
	 if (*cmdToken[2]=='+') {
	    rstrcpy(theTime, cmdToken[2]+1, TIME_LEN); /* skip the + */
	    status = checkDateFormat(theTime);      /* check and convert the time value */
	    getOffsetTimeStr(theTime, theTime);     /* convert delta format to now + this*/
	 } else {
	    status = checkDateFormat(theTime);      /* check and convert the time value */
	 }
	 if (status==0) {
	    status = doMod(Conn, objPath, theTime);
	    didOne=1;
	 }
	 else {
	    printf("Invalid time format input\n");
	 }
      }
   }

   printErrorStack(Conn->rError);

   rcDisconnect(Conn);

   if (didOne==0) {
      usage("");
      exit(1);
   }

   exit(0);
}