Example #1
0
int
main(int argc, char **argv)
{
	procargs(&argc,&argv);

	/* XXX This has grown to the point that it should be cleaned up.
	 */
	if (debugflag) {
		if (ioctl(fd,SCIOCDEBUG,&debuglevel) == -1)
			err(errno, "SCIODEBUG");
	} else if (commandflag) {
		char *fmt;

		if (argc < 1) {
			fprintf(stderr, "Need the command format string.\n");
			usage();
		}


		fmt = argv[0];

		argc -= 1;
		argv += 1;

		do_cmd(fd, fmt, argc, argv);
	} else if (modeflag)
		mode_edit(fd, modepage, editflag, argc, argv);

	exit(0);
}
Example #2
0
int main(int argc, char *argv[])
{
   int ret, i;
   char *ipatsfile;
   float *feats, *targs;
   char **class_set;
   int *classes;
   int nPats, nInps, nOuts;
   float *means, *stddevs;

   /* Process the command line arguments */
   procargs(argc, argv, &ipatsfile);

   /* Read in the input feature vector file */
   if((ret = read_bin_nnpats(ipatsfile, &feats, &targs, &classes,
                  &class_set, &nPats, &nInps, &nOuts))){
      exit(ret);
   }

   /* Do not need target vectors and class information to   */
   /* compute global statistics across feature vector coef, */
   /* so deallocate these other resources. */
   free(targs);
   free(classes);
   for(i = 0; i < nOuts; i++)
      free(class_set[i]);
   free(class_set);

   /* Compute the mean and stddev for each feature vector coef */
   if((ret = comp_znorm_stats(&means, &stddevs, feats, nPats, nInps))){
      free(feats);
      exit(ret);
   }

   /* Report the resulting statistics to stdout */
   for(i = 0; i < nInps; i++){
      printf("%f\t%e\n", means[i], stddevs[i]);
   }

   /* Deallocate remaining resources */
   free(feats);
   free(means);
   free(stddevs);

   /* Exit successful */
   exit(0);
}
Example #3
0
/*************************************************************************
**************************************************************************
   main - Entry point.

   Input:
      argc - number of command line arguments
      argv - array of string values of command line arguments
**************************************************************************/
int main(int argc, char **argv)
{
   int read_status, i;
   char *filename;
   const CAN_CONFIG *conf = NULL, *next_conf;
   CAN_CONTEXT file_stats, conf_stats, total_stats;
   ANSI_NIST *ansi_nist;
   char *config_files[MAX_CONFIG_FILES];
   int config_count;

   init_result_accumulator(&total_stats, "Grand Total");

   config_files[0] = DEFAULT_CONFIG_FILE;

   procargs(argc, argv, config_files, MAX_CONFIG_FILES, &config_count);

   for (i = 0; i < config_count; i++) {
      init_result_accumulator(&conf_stats, config_files[i]);
      next_conf = read_config(&conf_stats, conf);   
      if (NULL == next_conf) {
	 return EXIT_FAILURE;
      }
      aggregate_result_accumulator(&total_stats, &conf_stats);
      conf = next_conf;
   }

   for (i = optind; argv[i] != NULL; i++) {
      filename = argv[i];
      init_result_accumulator(&file_stats, filename);

      read_status = read_ANSI_NIST_file(filename, &ansi_nist);
      if(read_status != 0) {
	 ++file_stats.issue[LOGTP_EXEC-LOGTP_BASE][LOGL_ERROR-LOGL_BASE];

      } else {
	 check_ansi_nist(conf, ansi_nist, &file_stats);
	 free_ANSI_NIST(ansi_nist);
      }
      aggregate_result_accumulator(&total_stats, &file_stats);
   }

   if (optind+1 < argc) {
      report_result_accumulator(conf, &total_stats, TRUE);
   }

   return EXIT_SUCCESS;
}
Example #4
0
proc_args getProcRawArgs(int pid, size_t argmax) {
  proc_args args;
  std::vector<char> procargs(argmax);
  int mib[3] = {CTL_KERN, KERN_PROCARGS2, pid};
  if (sysctl(mib, 3, procargs.data(), &argmax, nullptr, 0) == -1 ||
      argmax == 0) {
    return args;
  }

  // The number of arguments is an integer in front of the result buffer.
  int nargs = 0;
  memcpy(&nargs, procargs.data(), sizeof(nargs));
  // Walk the \0-tokenized list of arguments until reaching the returned 'max'
  // number of arguments or the number appended to the front.
  const char* current_arg = &procargs[0] + sizeof(nargs);
  // Then skip the exec/program name.
  auto exec_name = std::string(current_arg);
  current_arg += exec_name.size() + 1;
  while (current_arg < &procargs[argmax]) {
    // Skip optional null-character padding.
    if (*current_arg == '\0') {
      current_arg++;
      continue;
    }

    auto string_arg = std::string(current_arg);
    if (string_arg.size() > 0) {
      if (nargs > 0) {
        // The first nargs are CLI arguments, afterward they are environment.
        args.args.push_back(string_arg);
        nargs--;
      } else {
        size_t idx = string_arg.find_first_of("=");
        if (idx != std::string::npos && idx > 0) {
          args.env[string_arg.substr(0, idx)] = string_arg.substr(idx + 1);
        }
      }
    }
    current_arg += string_arg.size() + 1;
  }
  return args;
}
Example #5
0
int main(int argc, char *argv[])
{
   char *ifile, *ofile;
   ANSI_NIST *ansi_nist;
   int ret;

   procargs(argc, argv, &ifile, &ofile);

   if((ret = read_fmttext_file(ifile, &ansi_nist)))
      exit(ret);

   if((ret = write_ANSI_NIST_file(ofile, ansi_nist))){
      free_ANSI_NIST(ansi_nist);
      exit(ret);
   }

   fprintf(stderr, "ANSI_NIST bytes = %d\n", ansi_nist->num_bytes);

   free_ANSI_NIST(ansi_nist);
   exit(0);
}
Example #6
0
int main(int argc, char *argv[])
{
   char *ifile, *ofile;
   int ret;
   ANSI_NIST *ansi_nist;

   /* Process command line arguments. */
   procargs(argc, argv, &ifile, &ofile);

   /* Read in an ANSI/NIST file into memory. */
   if((ret = read_ANSI_NIST_file(ifile, &ansi_nist)))
      exit(ret);

   /* Convert Type-9 records. */
   if((ret = iafis2nist_type_9s(ansi_nist))){
      free_ANSI_NIST(ansi_nist);
      exit(ret);
   }

   /* Convert any Type-4&6 records to Type-13&14. */
   if((ret = iafis2nist_fingerprints(ansi_nist))){
      free_ANSI_NIST(ansi_nist);
      exit(ret);
   }

   /* Write out new ANSI/NIST file. */
   if((ret = write_ANSI_NIST_file(ofile, ansi_nist))){
      free_ANSI_NIST(ansi_nist);
      exit(ret);
   }

   /* Deallocate working memory. */
   free_ANSI_NIST(ansi_nist);

   /* Exit normally. */
   exit(0);
}
Example #7
0
int main(int argc, char *argv[])
{
   unsigned char *data, **pdata, *filename;
   int ret, i, w, h, d, img_type, dlen;
   seg_rec_coords *fing_boxes;
   int ppi, lossyflag = 0;
   int nf;


   procargs(argc, argv);

   if (old_style_args_flag) {
      /* This code supports the old-style invocation using 7 arguments
	 and allowing different kinds of image files. */

      /* FGP 1-12 is single finger : 13-14 four finger slaps : 15 for
	 two thumbs : Craig said it would be good to eliminate 23 and
	 use 15 instead.  -- jck */
      if(fgp < 1 && fgp > 14 && fgp != 15) {
	 fprintf(stderr, "ERROR: %s: Invalid FGP (%d). "
		 "Expecting 1-14 or 15 (Two thumbs)\n", argv[0], fgp);
	 exit(-2);
      }
      if(fgp < 15 && fgp > 12)
	 nf = 4;
      else if(fgp == 15)
	 nf = 2;
      else
	 nf = 1;

      /* READ THE INPUT FILE */
      if((ret = read_and_decode_grayscale_image(ifile, &img_type, &data, &dlen,
						&w, &h, &d, &ppi)))
	 exit(ret);
      
      /* TRY TO SEGMENT FINGER IMAGE */
      if((ret = segment_fingers(data, w, h, &fing_boxes, nf, fgp, bthr_adj,
				rot_search)))
	 exit(ret);
      
      
      /* PARSE FINGERS FROM ORIGINAL FINGER IMAGE */
      if((ret = parse_segfing(&pdata, data, w, h, fing_boxes, nf, rot_seg)))
	 exit(ret);
      
      free(data);
      
      /* OUTPUT RESULTS TO FILE */
      filename = basename(ifile);
      if((ret = write_parsefing(filename, -1, fgp, comp, ppi, 
				lossyflag, pdata, fing_boxes, nf, rot_seg)))
	 exit(ret);
      
      free(fing_boxes);
      for(i = 0; i < nf; i++)
	 free(pdata[i]);
      free(pdata);
      /* End of code supporting old-style interface. */

   } else {			/* ANSI/NIST file */
      /* This code, from here to the end, supports the new-style
	 interface for processing several images within ANSI/NIST files. */
      ANSI_NIST *ansi_nist, *new_ansi_nist;
      RECORD *imgrecord;
      FIELD *impfield, *fgpfield;
      char *fgp_str, *endp;
      int rec_i, imgrecord_i, img_id, impfield_i, imp, matches = 0;
      double ppmm;
      int img_fgp, img_bthr_adj;  /* per-image values */
      char *filename;

      if (read_ANSI_NIST_file(ifile, &ansi_nist) < 0)
	 exit(EXIT_FAILURE);

      if (ofile != NULL) {
	 if (copy_ANSI_NIST(&new_ansi_nist, ansi_nist) < 0) 
	    exit(EXIT_FAILURE);
      }

      if (NULL == (filename = malloc(strlen(ifile)+1))) {
	 fprintf(stderr, "ERROR : cannot allocate %d bytes for filename %s\n",
		 strlen(ifile)+1, ifile);
	 exit(EXIT_FAILURE);
      }
      
      /* this loop's index jumps from one grayprint to the next */
      for ( rec_i = 1;
	    (ret = lookup_ANSI_NIST_grayprint(&imgrecord, &imgrecord_i,
					      rec_i, ansi_nist)) > 0; 
	    rec_i = imgrecord_i + 1 ) {

	 /* Skip latent images. */
	 if (!lookup_IMP_field(&impfield, &impfield_i, imgrecord))
	    continue;
	 imp = (int)strtol((char *)impfield->subfields[0]->items[0]->value,
			   &endp, 10);
	 if ('\0' != *endp) {
	    fprintf(stderr, "ERROR : main : corrupt IMP value: %s\n",
		    (char *)impfield->subfields[0]->items[0]->value);
	    exit(EXIT_FAILURE);
	 }
	 if (imp_is_latent(imp))
	    continue;

	 /* Skip records that don't match our command-line criteria. */
	 if (select_ANSI_NIST_record(imgrecord, opt_rec_sel) <= 0)
	    continue;
	 

	 /* If we get this far it's the right kind of image. */
	 ++matches;
	 
	 /* Figure out the finger position code. */
	 if (TYPE_4_ID == imgrecord->type) {
	    img_id = BIN_IMAGE_ID;
	    fgpfield = imgrecord->fields[FGP_ID-1];
	 } else if (TYPE_14_ID == imgrecord->type) {
	    img_id = DAT2_ID;
	    fgpfield = imgrecord->fields[FGP3_ID-1];
	 } else {
	    fprintf(stderr, "WARNING : main : skipped unexpected record type "
		    "index %d, Type-%u\n", imgrecord_i+1, imgrecord->type);
	    continue;
	 }
	 
	 if (UNSET == fgp) {
	    if ( fgpfield->subfields[0]->num_items > 1 && 
		 (TYPE_14_ID == imgrecord->type || 
		  strtol((char *)fgpfield->subfields[0]->items[1]->value,
			 &endp, 10) != 255) ) {
	       if ('\0' != *endp) {
		  fprintf(stderr, "ERROR : main : corrupt FGP value: %s\n",
			  (char *)fgpfield->subfields[0]->items[1]->value);
		  exit(EXIT_FAILURE);
	       }
	       fprintf(stderr, "WARNING : main : multiple items in subfield, "
		       " using only the first, [%d.%u.1] [Type-%u.03%u]\n", 
		       imgrecord_i+1, fgpfield->field_int+1,
		       imgrecord->type, fgpfield->field_int+1);
	    }
	    fgp_str = (char *)fgpfield->subfields[0]->items[0]->value;
	    img_fgp = strtol(fgp_str, &endp, 10);
	    if ('\0' != *endp) {
	       fprintf(stderr, "WARNING : main : currupt FGP value: %s\n",
		       fgp_str);
	       exit(EXIT_FAILURE);
	    }
	 } else {
	    img_fgp = fgp;
	 }

	 /* Determine expected number of fingers in image. */
	 if (19 == img_fgp) 	/* ignore TIP or EJI images */
	    continue;
	 else if (img_fgp == 13 || img_fgp == 14)
	    nf = 4;
	 else if (15 == img_fgp)
	    nf = 2;
	 else
	    nf = 1;
	 
	 /* Turn on binary threshold adjustment for non-livescan
	    prints, assuming they are from inked-paper. */
	 if (UNSET == bthr_adj) {
	    img_bthr_adj = !imp_is_live_scan(imp);
	 } else {
	    img_bthr_adj = bthr_adj;
	 }
	 
	 if (UNSET == comp)
	    comp = 0;		/* default compression */

	 if (UNSET == rot_search)
	    rot_search = 0;	/* default search rotation */

	 if (UNSET == rot_seg)
	    rot_seg = 0;	/* default output rotation */

	 if (verbose)
	    fprintf(stderr, "record index %d, Type-%u, fgp=%d, nf=%d, "
		    "imp=%d, bthr_adj=%d, rot_search=%d, comp=%d, rot_seg=%d\n",
		    imgrecord_i+1, imgrecord->type, img_fgp, nf,
		    imp, img_bthr_adj, rot_search, comp, rot_seg);

	 ret = decode_ANSI_NIST_image(&data, &w, &h, &d, &ppmm,
				      ansi_nist, imgrecord_i, 1);
	 if (ret < 0)
	    exit(EXIT_FAILURE);
	 else if (0 == ret)
	    continue;		/* unsuitable image ignored */
	 
	 ppi = sround(ppmm * MM_PER_INCH);
	 
	 if (segment_fingers(data, w, h, &fing_boxes, nf, img_fgp,
			     img_bthr_adj, rot_search))
	    exit(EXIT_FAILURE);

	 if (parse_segfing(&pdata, data, w, h, fing_boxes, nf, rot_seg))
	    exit(EXIT_FAILURE);

	 if (ofile != NULL) {
	    /* Convert Type-4 to 14 if necessary. */
	    if (TYPE_4_ID == imgrecord->type) {
	       RECORD *new_imgrecord;

	       ret = iafis2nist_fingerprint(&new_imgrecord, new_ansi_nist,
					    imgrecord_i);
	       if (ret < 0)
		  exit(EXIT_FAILURE);
	       else if (ret > 0) {
		  if (insert_ANSI_NIST_record_frmem(imgrecord_i, new_imgrecord,
						    new_ansi_nist))
		     exit(EXIT_FAILURE);
		  if (delete_ANSI_NIST_record(imgrecord_i+1, new_ansi_nist))
		     exit(EXIT_FAILURE);
	       }
	    }
	    
	    if (insert_parsefing(new_ansi_nist, imgrecord_i,
				 img_fgp, fing_boxes, nf, rot_search))
	       exit(EXIT_FAILURE);

	 }

	 if (output_images) {
	   /* write_parsefing calls fileroot, which is destructive */
	   strcpy(filename, ifile);

            if (write_parsefing(basename(filename), imgrecord_i, img_fgp, comp,
				ppi, lossyflag, pdata, fing_boxes, nf, rot_seg))
	       exit(EXIT_FAILURE);
	 }
	 
	 /* clean up before the next time around */
	 free(data);
	 free(fing_boxes);
	 for(i = 0; i < nf; i++)
	    free(pdata[i]);
	 free(pdata);
      }
      
      if (0 == matches)
	 fprintf(stderr, "WARNING : nfseg : no images match the criteria\n");

      if (ret < 0)
	 exit(EXIT_FAILURE);

      if (ofile != NULL && write_ANSI_NIST_file(ofile, new_ansi_nist) < 0)
	 exit(EXIT_FAILURE);
   }

   return(EXIT_SUCCESS);
}
Example #8
0
int main( int argc, char **argv)
{
   int ret;
   int rawflag;                   /* raw input data or Ihead image */
   char *outext;                  /* ouput file extension */
   char *ifile, ofile[MAXPATHLEN];  /* file names */
   int ilen;
   int width, height;             /* image parameters */
   int depth, ppi;
   unsigned char *idata, *odata;  /* image pointers */
   int lossyflag;                 /* data loss flag */
   NISTCOM *nistcom;              /* NIST Comment */
   char *ppi_str;


   procargs(argc, argv, &outext, &ifile, &rawflag);

   ret = read_raw_from_filesize(ifile, &idata, &ilen);
   if(ret)
      exit(ret);

   ret = wsq_decode_mem(&odata, &width, &height, &depth, &ppi, &lossyflag, idata, ilen);
   if(ret){
      free(idata);
      exit(ret);
   }

   if(debug > 1)
      fprintf(stderr, "Image pixmap constructed\n");

   fileroot(ifile);
   sprintf(ofile, "%s.%s", ifile, NCM_EXT);

   /* Get NISTCOM from compressed data file */
   ret = getc_nistcom_wsq(&nistcom, idata, ilen);
   if(ret){
      free(idata);
      exit(ret);
   }
   free(idata);
   /* WSQ decoder always returns ppi=-1, so believe PPI in NISTCOM, */
   /* if it already exists. */
   ppi_str = (char *)NULL;
   if(nistcom != (NISTCOM *)NULL){
      ret = extractfet_ret(&ppi_str, NCM_PPI, nistcom);
      if(ret){
         free(odata);
         freefet(nistcom);
         exit(ret);
      }
   }
   if(ppi_str != (char *)NULL){
      ppi = atoi(ppi_str);
      free(ppi_str);
   }

   /* Combine NISTCOM with image features */
   ret = combine_wsq_nistcom(&nistcom, width, height, depth, ppi, lossyflag,
		   0.0 /* will be deleted next */);
   if(ret){
     free(odata);
     if(nistcom != (NISTCOM *)NULL)
        freefet(nistcom);
     exit(ret);
   }
   ret = del_wsq_nistcom(nistcom);
   if(ret){
     free(odata);
     freefet(nistcom);
     exit(ret);
   }

   /* Write NISTCOM */
   ret = writefetfile_ret(ofile, nistcom);
   if(ret){
     free(odata);
     freefet(nistcom);
     exit(ret);
   }
   freefet(nistcom);

   /* Write decoded image file. */
   sprintf(ofile, "%s.%s", ifile, outext);
   ret = write_raw_or_ihead(!rawflag, ofile, odata, width, height, depth, ppi);
   if(ret){
      free(odata);
      exit(ret);
   }
   free(odata);

   if(debug > 1)
      fprintf(stdout, "Image pixmap written to %s\n", ofile);

   exit(0);
}
Example #9
0
int
main(int argc, char *argv[])
{
	struct stackmark smark, smark2;
	volatile int state;
	char *shinit;

	(void) setlocale(LC_ALL, "");
	initcharset();
	state = 0;
	if (setjmp(main_handler.loc)) {
		switch (exception) {
		case EXEXEC:
			exitstatus = exerrno;
			break;

		case EXERROR:
			exitstatus = 2;
			break;

		default:
			break;
		}

		if (state == 0 || iflag == 0 || ! rootshell ||
		    exception == EXEXIT)
			exitshell(exitstatus);
		reset();
		if (exception == EXINT)
			out2fmt_flush("\n");
		popstackmark(&smark);
		FORCEINTON;				/* enable interrupts */
		if (state == 1)
			goto state1;
		else if (state == 2)
			goto state2;
		else if (state == 3)
			goto state3;
		else
			goto state4;
	}
	handler = &main_handler;
#ifdef DEBUG
	opentrace();
	trputs("Shell args:  ");  trargs(argv);
#endif
	rootpid = getpid();
	rootshell = 1;
	init();
	setstackmark(&smark);
	setstackmark(&smark2);
	procargs(argc, argv);
	pwd_init(iflag);
	if (iflag)
		chkmail(1);
	if (argv[0] && argv[0][0] == '-') {
		state = 1;
		read_profile("/etc/profile");
state1:
		state = 2;
		if (privileged == 0)
			read_profile("${HOME-}/.profile");
		else
			read_profile("/etc/suid_profile");
	}
state2:
	state = 3;
	if (!privileged && iflag) {
		if ((shinit = lookupvar("ENV")) != NULL && *shinit != '\0') {
			state = 3;
			read_profile(shinit);
		}
	}
state3:
	state = 4;
	popstackmark(&smark2);
	if (minusc) {
		evalstring(minusc, sflag ? 0 : EV_EXIT);
	}
	if (sflag || minusc == NULL) {
state4:	/* XXX ??? - why isn't this before the "if" statement */
		cmdloop(1);
	}
	exitshell(exitstatus);
	/*NOTREACHED*/
	return 0;
}
Example #10
0
int main(int argc, char *argv[])
{
   int ret, n, rawflag;
   char *outext;                   /* ouput file extension */
   char *ifile, ofile[MAXPATHLEN]; /* file names */
   FILE *outfp;                    /* output file pointer */
   int  width, height, depth, ppi, ilen, olen;  /* image parameters */
   unsigned char *idata, *odata;           /* image pointers */
   int hor_sampfctr[MAX_CMPNTS], vrt_sampfctr[MAX_CMPNTS];
   int n_cmpnts;
   int fsize;


   procargs(argc, argv, &outext, &ifile,
            &width, &height, &depth, &ppi, &rawflag,
            hor_sampfctr, vrt_sampfctr, &n_cmpnts);

   if((ret = filesize(ifile)) < 0)
      exit(ret);
   fsize = ret;

   if((ret = test_image_size(fsize, width, height, hor_sampfctr,
                            vrt_sampfctr, n_cmpnts, 0)))
      exit(ret);

   if((ret = read_raw_from_filesize(ifile, &idata, &ilen)))
      exit(ret);

   if(debug > 0)
      fprintf(stdout, "File %s read\n", ifile);


   if((ret = not2intrlv_mem(&odata, &olen, idata, width, height, depth,
                           hor_sampfctr, vrt_sampfctr, n_cmpnts))){
      free(idata);
      exit(ret);
   }
   free(idata);

   if(debug > 0)
      fprintf(stdout, "Image data converted to interleaved\n");

   /* Write interleaved image file. */
   fileroot(ifile);
   sprintf(ofile, "%s.%s", ifile, outext);

   /* If H,V's are specified on command line, then YCbCr ... */
   /* so write a raw output file. */
   if(argc == 7){
      if((outfp = fopen(ofile, "wb")) == NULL) {
         fprintf(stderr, "ERROR: main : fopen : %s\n",ofile);
         free(odata);
         exit(-5);
      }

      if((n = fwrite(odata, 1, olen, outfp)) != olen){
         fprintf(stderr, "ERROR: main : fwrite : ");
         /* MDG added '%' to 's' to fix syntax error on 05/09/2005 */
         fprintf(stderr, "only %d of %d bytes written from file %s\n",
                 n, olen, ofile);
         free(odata);
         exit(-6);
      }
      fclose(outfp);
   }
   /* Otherwise, H,V's not specified on command line, so component planes */
   /* are all the same size ... so "possibly" write an IHead file. */
   else{
      if((ret = write_raw_or_ihead(!rawflag, ofile,
                                  odata, width, height, depth, ppi))){
         free(odata);
         exit(ret);
      }
   }

   if(debug > 0)
      fprintf(stdout, "Image data written to file %s\n", ofile);

   free(odata);

   exit(0);
}
Example #11
0
int
main(int argc, char **argv)
{
	char *shinit;
	volatile int state;
	struct jmploc jmploc;
	struct stackmark smark;
	int login;
  int i;

  for (i = 1; i < argc; i++) {
    if (0 == strcmp(argv[i], "--help") ||
        0 == strcmp(argv[i], "-h")) {
      sxsh_print_usage();
      return (0);
    }
    if (0 == strcmp(argv[i], "--version") ||
        0 == strcmp(argv[i], "-v")) {
      sxsh_print_version();
      return (0);
    }
  } 

#ifdef __GLIBC__
	dash_errno = __errno_location();
#endif

#if PROFILE
	monitor(4, etext, profile_buf, sizeof profile_buf, 50);
#endif
	state = 0;
	if (unlikely(setjmp(jmploc.loc))) {
		int e;
		int s;

		reset();

		e = exception;

		s = state;
		if (e == EXEXIT || s == 0 || iflag == 0 || shlvl)
			exitshell();

		if (e == EXINT
#if ATTY
		 && (! attyset() || equal(termval(), "emacs"))
#endif
		 ) {
			out2c('\n');
#ifdef FLUSHERR
			flushout(out2);
#endif
		}
		popstackmark(&smark);
		FORCEINTON;				/* enable interrupts */
		if (s == 1)
			goto state1;
		else if (s == 2)
			goto state2;
		else if (s == 3)
			goto state3;
		else
			goto state4;
	}
	handler = &jmploc;
#ifdef DEBUG
	opentrace();
	trputs("Shell args:  ");  trargs(argv);
#endif
	rootpid = getpid();
	init();
	setstackmark(&smark);
	login = procargs(argc, argv);
	if (login) {
		state = 1;
		read_profile("/etc/profile");
state1:
		state = 2;
		read_profile("$HOME/.profile");
	}
state2:
	state = 3;
	if (
#ifndef linux
		getuid() == geteuid() && getgid() == getegid() &&
#endif
		iflag
	) {
		if ((shinit = lookupvar("ENV")) != NULL && *shinit != '\0') {
			read_profile(shinit);
		}
	}
	popstackmark(&smark);
state3:
	state = 4;
	if (minusc)
		evalstring(minusc, sflag ? 0 : EV_EXIT);

	if (sflag || minusc == NULL) {
state4:	/* XXX ??? - why isn't this before the "if" statement */
		cmdloop(1);
	}
#if PROFILE
	monitor(0);
#endif
#if GPROF
	{
		extern void _mcleanup(void);
		_mcleanup();
	}
#endif
	exitshell();
	/* NOTREACHED */
}
Example #12
0
int
main(int argc, char **argv)
{
	struct jmploc jmploc;
	struct stackmark smark;
	volatile int state;
	char *shinit;

	setlocale(LC_ALL, "");

	/* Just a --version for show. */
	if (argc > 1
	 && argv[1][0] == '-'
	 && argv[1][1] == '-') {
		if (!strcmp(&argv[1][2], "version")) {
			printf("kmk_ash - kBuild version %d.%d.%d\n",
				   KBUILD_VERSION_MAJOR, KBUILD_VERSION_MINOR, KBUILD_VERSION_PATCH);
			return 0;
		}
		if (!strcmp(&argv[1][2], "help")) {
			printf("usage: kmk_ash [-aCefnuvxIimqVEb] [+aCefnuvxIimqVEb] [-o option_name]\n"
				   "               [+o option_name] [command_file [argument ...]]\n"
				   "   or: kmk_ash -c [-aCefnuvxIimqVEb] [+aCefnuvxIimqVEb] [-o option_name]\n"
				   "               [+o option_name] command_string [command_name [argument ...]]\n"
				   "   or: kmk_ash -s [-aCefnuvxIimqVEb] [+aCefnuvxIimqVEb] [-o option_name]\n"
				   "               [+o option_name] [argument ...]\n"
				   "   or: kmk_ash --help\n"
				   "   or: kmk_ash --version\n",
				   argv[0], argv[0], argv[0], argv[0], argv[0]);
			return 0;
		}
	}

#if PROFILE
	monitor(4, etext, profile_buf, sizeof profile_buf, 50);
#endif
	state = 0;
	if (setjmp(jmploc.loc)) {
		/*
		 * When a shell procedure is executed, we raise the
		 * exception EXSHELLPROC to clean up before executing
		 * the shell procedure.
		 */
		switch (exception) {
		case EXSHELLPROC:
			rootpid = getpid();
			rootshell = 1;
			minusc = NULL;
			state = 3;
			break;

		case EXEXEC:
			exitstatus = exerrno;
			break;

		case EXERROR:
			exitstatus = 2;
			break;

		default:
			break;
		}

		if (exception != EXSHELLPROC) {
			if (state == 0 || iflag == 0 || ! rootshell)
				exitshell(exitstatus);
		}
		reset();
		if (exception == EXINT
#if ATTY
		 && (! attyset() || equal(termval(), "emacs"))
#endif
		 ) {
			out2c('\n');
			flushout(&errout);
		}
		popstackmark(&smark);
		FORCEINTON;				/* enable interrupts */
		if (state == 1)
			goto state1;
		else if (state == 2)
			goto state2;
		else if (state == 3)
			goto state3;
		else
			goto state4;
	}
	handler = &jmploc;
#ifdef DEBUG
#if DEBUG == 2
	debug = 1;
#endif
	opentrace();
	trputs("Shell args:  ");  trargs(argv);
#endif
	rootpid = getpid();
	rootshell = 1;
#ifdef _MSC_VER
    {
        extern void init_syntax(void);
        init_syntax();
    }
#endif
	init();
	setstackmark(&smark);
	procargs(argc, argv);
	if (argv[0] && argv[0][0] == '-') {
		state = 1;
#ifndef KMK
		read_profile("/etc/profile");
#endif
state1:
		state = 2;
#ifndef KMK
		read_profile(".profile");
#endif
	}
state2:
	state = 3;
#ifndef KMK
	if (getuid() == geteuid() && getgid() == getegid()) {
		if ((shinit = lookupvar("ENV")) != NULL && *shinit != '\0') {
			state = 3;
			read_profile(shinit);
		}
	}
#endif
state3:
	state = 4;
	if (sflag == 0 || minusc) {
		static int sigs[] =  {
		    SIGINT, SIGQUIT, SIGHUP,
#ifdef SIGTSTP
		    SIGTSTP,
#endif
		    SIGPIPE
		};
#define SIGSSIZE (sizeof(sigs)/sizeof(sigs[0]))
		int i;

		for (i = 0; i < SIGSSIZE; i++)
		    setsignal(sigs[i], 0);
	}

	if (minusc)
		evalstring(minusc, 0);

	if (sflag || minusc == NULL) {
state4:	/* XXX ??? - why isn't this before the "if" statement */
		cmdloop(1);
	}
#if PROFILE
	monitor(0);
#endif
	exitshell(exitstatus);
	/* NOTREACHED */
}
Example #13
0
int main(int argc, char **argv)
{
   int ret, sd_id;
   char *outext, *ifile, ofile[MAXPATHLEN];
   FILE *infp;
   IHEAD *ihead;
   int width, height, depth, ppi;
   unsigned char *tidata, *idata, *odata, *ocdata;
   int i, complen, olen, oclen;
   IMG_DAT *img_dat;
   NISTCOM *nistcom;
   char *comment_text;
   int sampfctr;

   procargs(argc, argv, &sd_id, &outext, &ifile);

   infp = fopen(ifile, "rb");
   if(infp == (FILE *)NULL) {
      fprintf(stderr, "Error opening file %s for reading\n", ifile);
      exit(-2);
   }

   ihead = readihdr(infp);
   if(ihead == (IHEAD *)NULL) {
      fprintf(stderr, "Error reading IHEAD header\n");
      exit(-3);
   }

   sscanf(ihead->height,"%d", &height);
   sscanf(ihead->width,"%d", &width);
   sscanf(ihead->depth,"%d", &depth);
   sscanf(ihead->density,"%d", &ppi);
   sscanf(ihead->complen,"%d", &complen);

   /* Construct NISTCOM */
   if((ret = sd_ihead_to_nistcom(&nistcom, ihead, sd_id))){
      free(ihead);
      exit(ret);
   }
   free(ihead);
   if(sd_id == 14){
      if((ret = combine_wsq_nistcom(&nistcom, width, height, depth, ppi,
                                   1, -1.0 /* unknown bitrate */))){
         freefet(nistcom);
         exit(ret);
      }
   }
   else{
      if((ret = combine_jpegl_nistcom(&nistcom, width, height, depth, ppi,
                                   0, 1, (int *)NULL, (int *)NULL, 0, PRED4))){
         freefet(nistcom);
         exit(ret);
      }
   }

   /* Convert NISTCOM to string. */
   if((ret = fet2string(&comment_text, nistcom))){
      freefet(nistcom);
      exit(ret);
   }
   freefet(nistcom);

   /* Switch on converter, supplying a NISTCOM ... */
   /* If SD14 ... WSQ convert. */
   if(sd_id == 14){
      /* Convert image data to new format in memory. */
      if((ret = wsq14_2_wsq(&odata, &olen, infp))) {
         fclose(infp);
         free(comment_text);
         exit(ret);
      }
      fclose(infp);
      /* Add comment text into new data format stream. */
      if((ret = add_comment_wsq(&ocdata, &oclen, odata, olen,
                                (unsigned char *)comment_text))){
         free(odata);
         free(comment_text);
         exit(ret);
      }
      free(odata);
      odata = ocdata;
      olen = oclen;
   }
   /* Otherwise, SD 4,9,10,18 ... JPEGL convert. */
   else{
      if((tidata = (unsigned char *)malloc(complen)) == (unsigned char *)NULL){
         fprintf(stderr, "ERROR : %s : malloc : tidata\n", argv[0]);
         exit(-4);
      }

      i = fread(tidata, sizeof(unsigned char), complen, infp);
      if(i != complen) {
         fprintf(stderr, "Error reading compressed data from %s\n", ifile);
         free(tidata);
         exit(-5);
      }
      fclose(infp);

      if(debug > 0)
         fprintf(stdout, "File %s read\n", ifile);

      if((idata = (unsigned char *)malloc(width*height))==(unsigned char *)NULL){
         fprintf(stderr, "ERROR : %s : malloc : idata\n", argv[0]);
         free(tidata);
         free(comment_text);
         exit(-6);
      }

      if((ret = jpegl_sd4_decode_mem(tidata, complen,
                                    width, height, depth, idata))){
         free(tidata);
         free(comment_text);
         free(idata);
         exit(ret);
      }
      free(tidata);
      if(debug > 0){
         fprintf(stdout, "Done decode JPEGL SD4 image\n");
         fprintf(stdout, "Starting JPEGL compression\n");
      }

      /* Used to setup integer array of length 1 initialized to 1. */
      sampfctr = 1;
      if((ret = setup_IMG_DAT_nonintrlv_encode(&img_dat, idata,
                                       width, height, depth, ppi,
                                       &sampfctr, &sampfctr, 1,
                                       0, PRED4))) {
         free(comment_text);
         free(idata);
         exit(ret);
      }

      if(debug > 0)
         fprintf(stdout, "Image structure initialized\n");

      if((ret = jpegl_encode_mem(&odata, &olen, img_dat, comment_text))){
         free(comment_text);
         free_IMG_DAT(img_dat, FREE_IMAGE);
         exit(ret);
      }
      free(comment_text);
      free_IMG_DAT(img_dat, FREE_IMAGE);
   }

   if(debug > 0)
      fprintf(stdout, "Image data converted, reformatted byte length = %d\n",
              olen);

   /* Write reformatted file. */

   fileroot(ifile);
   sprintf(ofile, "%s.%s", ifile, outext);

   if((ret = write_raw_from_memsize(ofile, odata, olen))){
      free(odata);
      exit(ret);
   }

   if(debug > 0)
      fprintf(stdout, "Image data written to file %s\n", ofile);

   free(odata);
   exit(0);
}
Example #14
0
int main(int argc, char *argv[])
{
   int ret, rawflag, img_type;
   unsigned char *idata, *odata;
   int ilen, width, height, depth, ppi, lossyflag;
   IHEAD *ihead;
   FILE *fp;
   char *outext, *ifile, ofile[MAXPATHLEN];
   NISTCOM *nistcom;


   procargs(argc, argv, &outext, &ifile, &rawflag);
   /* Set ppi to unknown */
   ppi = -1;
   nistcom = (NISTCOM *)NULL;

   /* Check image type */
   ret = read_raw_from_filesize(ifile, &idata, &ilen);
   if(ret)
      exit(ret);

   ret = image_type(&img_type, idata, ilen);
   if(ret) {
      free(idata);
      exit(ret);
   }
   free(idata);

   /* Open image file for reading based on image type */
   if((fp = fopen(ifile,"rb")) == NULL) {
      fprintf(stderr, "ERROR: main : fopen : %s\n",ifile);
      exit(-1);
   }
   /* If img_type is ihead ... */
   if(img_type == IHEAD_IMG){
      /* Read ihead header and check for WSQ_SD14 compression */
      ihead = readihdr(fp);
      if(atoi(ihead->compress) != WSQ_SD14){
         fprintf(stderr, "ERROR : main : input image not WSQ_SD14 compressed\n");
         fprintf(stderr, "        compression = %d, WSQ_SD14 = %d\n",
                 atoi(ihead->compress), WSQ_SD14);
         fclose(fp);
         free(ihead);
         exit(-1);
      }

      /* Get ppi from ihead header */
      sscanf(ihead->density,"%d", &ppi);

      /* Create a nistcom for the image attributes */
      ret = sd_ihead_to_nistcom(&nistcom, ihead, 14);
      if(ret) {
         fclose(fp);
         free(ihead);
         exit(ret);
      }
      free(ihead);
   }
   /* If image not WSQ_IMG or IHEAD_IMG, ERROR!!! */
   else if(img_type != WSQ_IMG) {
      fprintf(stderr, "ERROR : main : Invalid image\n");
      fprintf(stderr, "Expected a WSQ_SD14 compressed image in\n");
      fprintf(stderr, "either raw or ihead format.\n");
      fclose(fp);
      exit(-1);
   }

   /* Decode compressed image */
   ret = wsq14_decode_file(&odata, &width, &height, &depth, &lossyflag, fp);
   if(ret){
      fclose(fp);
      if(img_type == IHEAD_IMG)
         freefet(nistcom);
      exit(ret);
   }
   fclose(fp);

   if(debug > 1)
      fprintf(stderr, "Image pixmap constructed\n");

   /* Combine image attributes into current nistcom */
   ret = combine_wsq_nistcom(&nistcom, width, height, depth, ppi, lossyflag, -1.0);
   if(ret){
     if(img_type == IHEAD_IMG)
        freefet(nistcom);
     free(odata);
     exit(ret);
   }
   ret = del_wsq_nistcom(nistcom);
   if(ret){
      free(odata);
      freefet(nistcom);
      exit(ret);
   }

   fileroot(ifile);
   sprintf(ofile, "%s.%s", ifile, NCM_EXT);
   /* Write NISTCOM */
   ret = writefetfile_ret(ofile, nistcom);
   if(ret){
     freefet(nistcom);
     free(odata);
     exit(ret);
   }
   freefet(nistcom);

   /* Write decompressed image */
   sprintf(ofile, "%s.%s", ifile, outext);
   ret = write_raw_or_ihead(!rawflag, ofile, odata, width, height, depth, ppi);
   if(ret){
      free(odata);
      exit(ret);
   }
   free(odata);

   if(debug > 1)
      fprintf(stderr, "Image pixmap written to %s\n", ofile);

   exit(0);
}
Example #15
0
int main(int argc, char *argv[])
{
   int ret, rawflag;
   char *outext;                   /* ouput file extension */
   char *ifile, ofile[MAXPATHLEN]; /* file names */
   int width, height, depth, ppi, ilen, olen;  /* image parameters */
   IHEAD *ihead;
   unsigned char *idata, *odata;           /* image pointers */
   int hor_sampfctr[MAX_CMPNTS], vrt_sampfctr[MAX_CMPNTS];
   int n_cmpnts;


   procargs(argc, argv, &outext, &ifile, &rawflag,
            &width, &height, &depth, &ppi,
            hor_sampfctr, vrt_sampfctr, &n_cmpnts);

   /* If H,V's are specified on command line, then YCbCr ... */
   /* so read a raw input file. */
   if(argc == 7){
      if((ret = read_raw_from_filesize(ifile, &idata, &ilen)))
         exit(ret);

      if((ret = test_image_size(ilen, width, height, hor_sampfctr,
                               vrt_sampfctr, n_cmpnts, 1)))
         exit(ret);
   }
   else{
      /* If raw image flagged... */
      if(rawflag) {
         if((ret = read_raw(ifile, &idata, &width, &height, &depth)))
            exit(ret);
      }
      /* Otherwise, input image is an IHead image */
      else {
         if((ret = read_ihead(ifile, &ihead, &idata, &width, &height, &depth)))
            exit(ret);
      }
   }

   if(debug > 0)
      fprintf(stdout, "File %s read\n", ifile);


   /* If IHead image file ... */
   if(!rawflag){
      /* Get PPI from IHead. */
      ppi = get_density(ihead);
      free(ihead);
   }

   if((ret = intrlv2not_mem(&odata, &olen, idata, width, height, depth,
                           hor_sampfctr, vrt_sampfctr, n_cmpnts))){
      free(idata);
      exit(ret);
   }
   free(idata);

   if(debug > 0)
      fprintf(stdout, "Image data converted to non-interleaved\n");

   fileroot(ifile);
   sprintf(ofile, "%s.%s", ifile, outext);

   if((ret = write_raw_from_memsize(ofile, odata, olen))){
      free(odata);
      exit(ret);
   }

   if(debug > 0)
      fprintf(stdout, "Image data written to file %s\n", ofile);

   free(odata);

   exit(0);
}
Example #16
0
int
main(int argc, char **argv)
{
	struct stackmark smark;
	volatile int state;
	char *shinit;
	uid_t uid;
	gid_t gid;

	uid = getuid();
	gid = getgid();

	max_user_fd = fcntl(0, F_MAXFD);
	if (max_user_fd < 2)
		max_user_fd = 2;

	setlocale(LC_ALL, "");

	posix = getenv("POSIXLY_CORRECT") != NULL;
#if PROFILE
	monitor(4, etext, profile_buf, sizeof profile_buf, 50);
#endif
	state = 0;
	if (setjmp(main_handler.loc)) {
		/*
		 * When a shell procedure is executed, we raise the
		 * exception EXSHELLPROC to clean up before executing
		 * the shell procedure.
		 */
		switch (exception) {
		case EXSHELLPROC:
			rootpid = getpid();
			rootshell = 1;
			minusc = NULL;
			state = 3;
			break;

		case EXEXEC:
			exitstatus = exerrno;
			break;

		case EXERROR:
			exitstatus = 2;
			break;

		default:
			break;
		}

		if (exception != EXSHELLPROC) {
			if (state == 0 || iflag == 0 || ! rootshell ||
			    exception == EXEXIT)
				exitshell(exitstatus);
		}
		reset();
		if (exception == EXINT) {
			out2c('\n');
			flushout(&errout);
		}
		popstackmark(&smark);
		FORCEINTON;				/* enable interrupts */
		if (state == 1)
			goto state1;
		else if (state == 2)
			goto state2;
		else if (state == 3)
			goto state3;
		else
			goto state4;
	}
	handler = &main_handler;
#ifdef DEBUG
#if DEBUG >= 2
	debug = 1;	/* this may be reset by procargs() later */
#endif
	opentrace();
	trputs("Shell args:  ");  trargs(argv);
#if DEBUG >= 3
	set_debug(((DEBUG)==3 ? "_@" : "++"), 1);
#endif
#endif
	rootpid = getpid();
	rootshell = 1;
	init();
	initpwd();
	setstackmark(&smark);
	procargs(argc, argv);

	/*
	 * Limit bogus system(3) or popen(3) calls in setuid binaries,
	 * by requiring the -p flag
	 */
	if (!pflag && (uid != geteuid() || gid != getegid())) {
		setuid(uid);
		setgid(gid);
		/* PS1 might need to be changed accordingly. */
		choose_ps1();
	}

	if (argv[0] && argv[0][0] == '-') {
		state = 1;
		read_profile("/etc/profile");
 state1:
		state = 2;
		read_profile(".profile");
	}
 state2:
	state = 3;
	if ((iflag || !posix) &&
	    getuid() == geteuid() && getgid() == getegid()) {
		struct stackmark env_smark;

		setstackmark(&env_smark);
		if ((shinit = lookupvar("ENV")) != NULL && *shinit != '\0') {
			state = 3;
			read_profile(expandenv(shinit));
		}
		popstackmark(&env_smark);
	}
 state3:
	state = 4;
	line_number = 1;	/* undo anything from profile files */

	if (sflag == 0 || minusc) {
		static int sigs[] =  {
		    SIGINT, SIGQUIT, SIGHUP, 
#ifdef SIGTSTP
		    SIGTSTP,
#endif
		    SIGPIPE
		};
#define SIGSSIZE (sizeof(sigs)/sizeof(sigs[0]))
		size_t i;

		for (i = 0; i < SIGSSIZE; i++)
		    setsignal(sigs[i], 0);
	}

	if (minusc)
		evalstring(minusc, sflag ? 0 : EV_EXIT);

	if (sflag || minusc == NULL) {
 state4:	/* XXX ??? - why isn't this before the "if" statement */
		cmdloop(1);
		if (iflag) {
			out2str("\n");
			flushout(&errout);
		}
	}
#if PROFILE
	monitor(0);
#endif
	line_number = plinno;
	exitshell(exitstatus);
	/* NOTREACHED */
}
Example #17
0
File: main.c Project: cbsd/cbsd
int
main(int argc, char *argv[])
{
	struct stackmark smark, smark2;
	volatile int state;
	char *shinit;

#ifdef CBSD
	char *MY_APP = NULL;
	char *cbsdpath = NULL;
	char *workdir = NULL;
	char *cbsd_disable_history = NULL; //getenv
	chdir("/var/empty");
	/* Only use history when stdin is a tty. */
	if ( isatty(0) && isatty(1) ) {
		cbsd_enable_history = 1;
	}
#endif

	(void) setlocale(LC_ALL, "");
	initcharset();
	state = 0;
	if (setjmp(main_handler.loc)) {
		switch (exception) {
		case EXEXEC:
			exitstatus = exerrno;
			break;

		case EXERROR:
			exitstatus = 2;
			break;

		default:
			break;
		}

		if (state == 0 || iflag == 0 || ! rootshell ||
		    exception == EXEXIT)
			exitshell(exitstatus);
		reset();
		if (exception == EXINT)
			out2fmt_flush("\n");
		popstackmark(&smark);
		FORCEINTON;				/* enable interrupts */
		if (state == 1)
			goto state1;
		else if (state == 2)
			goto state2;
		else if (state == 3)
			goto state3;
		else
			goto state4;
	}
	handler = &main_handler;
#ifdef DEBUG
	opentrace();
	trputs("Shell args:  ");  trargs(argv);
#endif
	rootpid = getpid();
	rootshell = 1;
	INTOFF;
	initvar();
	setstackmark(&smark);
	setstackmark(&smark2);

#ifdef CBSD
	if (argc>1) {
		if (!strcmp(argv[1],"--help")) {
			system("/usr/local/bin/cbsd help");
			exit(0);
		} else {
			if (!strcmp(argv[1],"version")) {
				printf("%s\n",VERSION);
				exit(0);
			}
		}
	}

	cbsd_disable_history=lookupvar("NO_CBSD_HISTORY");

	if ( cbsd_disable_history != NULL ) cbsd_enable_history=0;

	workdir=lookupvar("workdir");

	if ( workdir == NULL )  {
		read_profile("/etc/rc.conf");
		setvarsafe("workdir", lookupvar("cbsd_workdir"), 0);
	}

	workdir=lookupvar("workdir");
	if ( workdir == NULL ) {
		out2fmt_flush("cbsd: no workdir defined\n");
		exitshell(1);
	}

	setvarsafe("PS1","cbsd@\\h> ",1);
	setvarsafe("workdir",workdir,1);
	workdir=lookupvar("workdir"); //  ^^ after "setsave*" original is free
	cbsdpath = calloc(MAXPATHLEN, sizeof(char *));

	if (argv[1]) {
		setvarsafe("CBSD_APP",basename(argv[1]),1);
	}

	if (cbsdpath == NULL) {
		out2fmt_flush("cbsd: out of memory for cbsdpath\n");
		exitshell(1);
	}

	// %s/modules must be first for opportunity to have a module commands greater priority than the original CBSD command.
	// This makes it possible to write a 3rd party modules with altered functionality of the original code.
	sprintf(cbsdpath,"%s/modules:%s/bin:%s/sbin:%s/tools:%s/jailctl:%s/nodectl:%s/system:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin",workdir,cbsd_distdir,cbsd_distdir,cbsd_distdir,cbsd_distdir,cbsd_distdir,cbsd_distdir);
	setvarsafe("PATH",cbsdpath,1);
	ckfree(cbsdpath);

	// read global params first (disable/enable colors, repos etc..)
	read_profile("${workdir}/etc/defaults/global.conf");
	read_profile("${workdir}/etc/global.conf");

	if (lookupvar("NOCOLOR") != NULL ) {
		putenv("NOCOLOR=1");
	}

	// non-interactive global env
	if (lookupvar("NOINTER") != NULL ) {
		setvarsafe("inter","1",1);
		putenv("inter=0");
	}

	read_profile("/usr/local/cbsd/cbsd.conf");
	read_profile("${workdir}/etc/defaults/logger.conf");
	read_profile("${workdir}/etc/logger.conf");

	if (cbsd_enable_history==1) {
		cbsd_history_file=calloc(MAXPATHLEN, sizeof(char *));
		sprintf(cbsd_history_file,"%s/%s",workdir,CBSD_HISTORYFILE);
	}

#endif

	procargs(argc, argv);
	pwd_init(iflag);
	INTON;
#ifndef CBSD
	if (iflag)
		chkmail(1);
#endif
	if (argv[0] && argv[0][0] == '-') {
		state = 1;
		read_profile("/etc/profile");
state1:
		state = 2;
		if (privileged == 0)
			read_profile("${HOME-}/.profile");
		else
			read_profile("/etc/suid_profile");
	}
state2:
	state = 3;
	if (!privileged && iflag) {
		if ((shinit = lookupvar("ENV")) != NULL && *shinit != '\0') {
			state = 3;
			read_profile(shinit);
		}
	}
state3:
	state = 4;
	popstackmark(&smark2);
	if (minusc) {
		evalstring(minusc, sflag ? 0 : EV_EXIT);
	}
state4:
	if (sflag || minusc == NULL) {
		cmdloop(1);
	}
	exitshell(exitstatus);
	/*NOTREACHED*/
	return 0;
}
Example #18
0
SH_NORETURN_1 void
shell_main(shinstance *psh, int argc, char **argv)
{
	struct jmploc jmploc;
	struct stackmark smark;
	volatile int state;
	char *shinit;

	state = 0;
	if (setjmp(jmploc.loc)) {
		/*
		 * When a shell procedure is executed, we raise the
		 * exception EXSHELLPROC to clean up before executing
		 * the shell procedure.
		 */
		switch (psh->exception) {
		case EXSHELLPROC:
			psh->rootpid = /*getpid()*/ psh->pid;
			psh->rootshell = 1;
			psh->minusc = NULL;
			state = 3;
			break;

		case EXEXEC:
			psh->exitstatus = psh->exerrno;
			break;

		case EXERROR:
			psh->exitstatus = 2;
			break;

		default:
			break;
		}

		if (psh->exception != EXSHELLPROC) {
			if (state == 0 || iflag(psh) == 0 || ! psh->rootshell)
				exitshell(psh, psh->exitstatus);
		}
		reset(psh);
		if (psh->exception == EXINT
#if ATTY
		 && (! attyset(psh) || equal(termval(psh), "emacs"))
#endif
		 ) {
			out2c(psh, '\n');
			flushout(&psh->errout);
		}
		popstackmark(psh, &smark);
		FORCEINTON;				/* enable interrupts */
		if (state == 1)
			goto state1;
		else if (state == 2)
			goto state2;
		else if (state == 3)
			goto state3;
		else
			goto state4;
	}
	psh->handler = &jmploc;
	psh->rootpid = /*getpid()*/ psh->pid;
	psh->rootshell = 1;
#ifdef DEBUG
#if DEBUG == 2
	debug(psh) = 1;
#endif
	opentrace(psh);
	trputs(psh, "Shell args:  ");  trargs(psh, argv);
#endif

	init(psh);
	setstackmark(psh, &smark);
	procargs(psh, argc, argv);
	if (argv[0] && argv[0][0] == '-') {
		state = 1;
		read_profile(psh, "/etc/profile");
state1:
		state = 2;
		read_profile(psh, ".profile");
	}
state2:
	state = 3;
	if (sh_getuid(psh) == sh_geteuid(psh) && sh_getgid(psh) == sh_getegid(psh)) {
		if ((shinit = lookupvar(psh, "ENV")) != NULL && *shinit != '\0') {
			state = 3;
			read_profile(psh, shinit);
		}
	}
state3:
	state = 4;
	if (sflag(psh) == 0 || psh->minusc) {
		static int sigs[] =  {
		    SIGINT, SIGQUIT, SIGHUP,
#ifdef SIGTSTP
		    SIGTSTP,
#endif
		    SIGPIPE
		};
#define SIGSSIZE (sizeof(sigs)/sizeof(sigs[0]))
		unsigned i;

		for (i = 0; i < SIGSSIZE; i++)
		    setsignal(psh, sigs[i], 0);
	}

	if (psh->minusc)
		evalstring(psh, psh->minusc, 0);

	if (sflag(psh) || psh->minusc == NULL) {
state4:	/* XXX ??? - why isn't this before the "if" statement */
		cmdloop(psh, 1);
	}
	exitshell(psh, psh->exitstatus);
	/* NOTREACHED */
}