コード例 #1
0
ファイル: service.c プロジェクト: Veilen/xinetd
/*
 * Steps:
 *      1. Deactivate the service
 *      2. Free all memory used by the service and free the service itself
 *
 * Since this function may free all memory associated with the service as
 * well as the memory pointed by sp, only the value of sp should be used
 * after this call if the return value is 0 (i.e. no dereferencing of sp).
 *
 * Special services are never deactivated.
 */
int svc_release( struct service *sp )
{
   char *sid = SVC_ID( sp ) ;
   const char *func = "svc_release" ;

   if ( SVC_REFCOUNT(sp) == 0 )
   {
      msg( LOG_ERR, func, "%s: svc_release with 0 count", sid ) ;
      return( 0 ) ;
   }
   
   SVC_REFCOUNT(sp)-- ;
   if ( SVC_REFCOUNT(sp) == 0 )
   {
      if ( debug.on )
         msg( LOG_DEBUG, func, "ref count of service %s dropped to 0", sid ) ;
      if ( ! SC_IS_SPECIAL( SVC_CONF( sp ) ) )
      {
         if ( SVC_LOG(sp) )
            log_end( SC_LOG( SVC_CONF( sp ) ), SVC_LOG(sp) ) ;
         svc_deactivate( sp ) ;
         svc_free( sp ) ;
         sp = NULL;
      }
      else      /* this shouldn't happen */
         msg( LOG_WARNING, func,
            "ref count of special service %s dropped to 0", sid ) ;
      return( 0 ) ;
   }
   else
      return( SVC_REFCOUNT(sp) ) ;
}
コード例 #2
0
ファイル: commands.c プロジェクト: siddhugit/Operating-System
static int cmd_free(int argc, char *argv[])
/*
*   function definition for memory free command. Calls myFree() to free
*   memory passed as an argument.
*   Parameters:
*       o int argc- number of arguments
*       o char *argv[] - array of arguments  
*   Return : 0 if successful, otherwise 1
*   sets my_errno to TOO_MANY_ARGUMENTS if more than two argument is passed,
*	sets my_errno to if less than two arguments are passed.
*/
{
	char tempstr[1024];
	if(argc > 2)
	{
		my_errno = TOO_MANY_ARGUMENTS;
		return 1;
	}
	if(argc > 2)
	{
		my_errno = TOO_MANY_ARGUMENTS;
		return 1;
	}
	if(argc < 2 )
	{
		my_errno = TOO_FEW_ARGUMENTS;
		return 1;
	}
	char *endPtr;
	void *ptr = (void*)strtoul(argv[1],&endPtr,0);
	if(endPtr == argv[1] || *endPtr != '\0')
 	{
		my_errno = NOT_VALID_ARGUMENT;
		return 1;
	}
	my_errno = NONE_ERROR;
	svc_free(ptr);
	if(my_errno != NONE_ERROR)
	{
		return 1;
	}
	sprintf(tempstr,"Memory freed successfully\r\n");uprintf(tempstr);
	return 0;
}
コード例 #3
0
ファイル: bootos.c プロジェクト: fsebentley/Novo7Tools
int BootOS_detect_os_type(void **var4, void **bootAddrBuf,
        struct BootIni *bootIni, int *logoOff)
{
    int res;
    unsigned miscPartFistSect;
    int partNo;
    char miscPartBuf[1024];
    struct MBR mbr;
    struct OSImageScript imgScript;
    int requestedBootMode;

    res = -1;
    memset(&imgScript, 0, sizeof(imgScript));
    if( (requestedBootMode = bootModeReqestByKey()) > 0) {
        miscPartFistSect = 0;
        svc_diskread(0, 2, &mbr);
        for(partNo = 0; partNo < mbr.PartCount; ++partNo) {
            if(strcmp("misc", mbr.array[partNo].name) == 0) {
                miscPartFistSect = mbr.array[partNo].addrlo;
                svc_diskread(miscPartFistSect, 1, miscPartBuf);
                memset(miscPartBuf, 0, 32);
                if(requestedBootMode == 1) {
                    strcpy(miscPartBuf, "boot-fastboot");
                    wlibc_uprintf("fastboot mode\n");
                } else if(requestedBootMode == 2) {
                    strcpy(miscPartBuf, "boot-recovery");
                    wlibc_uprintf("recovery mode\n");
                }
                svc_diskwrite(miscPartFistSect, 1, miscPartBuf);
                break;
            }
        }
    }
    res = script_patch("c:\\linux\\linux.ini", &imgScript, 1);
    if(res < 0) {
        wlibc_uprintf("NO OS to Boot\n");
    } else { 
        wlibc_uprintf("test for multi os boot with display\n");
        res = PreBootOS(&imgScript, bootAddrBuf, var4, logoOff);
    }
    svc_free(bootIni);
    return res;
}
コード例 #4
0
ファイル: bootos.c プロジェクト: fsebentley/Novo7Tools
static int fnL42801894(struct OSImageScript *imgScript,
        void **bootAddrBuf,
        void **var6)
{
    int fdesc = 0;
    int imgNo;
    int fileSize = 0;
    void *loadAddr;

    wlibc_uprintf("load kernel start\n");
    for(imgNo = 0; imgNo < imgScript->segmentSectionCount; ++imgNo) {
        if(imgNo != 1) {
            loadAddr = imgScript->images[imgNo].baseAddr;
        } else { 
            loadAddr = svc_alloc(65536);
        }
        if(loadAddr == 0) {
            wlibc_uprintf("img file %s base addres is NULL\n", loadAddr);
            return -1;
        }
        fdesc = svc_open(imgScript->images[imgNo].name, "rb");
        if(fdesc == 0) {
            wlibc_uprintf("open img file %s failed\n",
                    imgScript->images[imgNo].name);
            goto fail;
        }
        fileSize = svc_filesize(fdesc);
        if( fileSize > imgScript->images[imgNo].maxSize ) {
            wlibc_uprintf(
                "the img file %s length %d is larger than img max size %d\n",
                imgScript->images[imgNo].name, fileSize,
                imgScript->images[imgNo].maxSize);
            goto fail;

        }
        svc_read(loadAddr, 1, fileSize, fdesc);
        svc_close(fdesc);
        imgScript->images[imgNo].fileLen = fileSize;
        if(imgNo == 1) {
            do_boot_linux(imgScript->images[1].baseAddr, loadAddr, fileSize);
            svc_free(loadAddr);
        }
        loadAddr = 0;
        fdesc = 0;
        fileSize = 0;
    }
    loadAddr = imgScript->baseAddr;
    if(loadAddr == 0) {
        wlibc_uprintf("no script could be filed\n");
    } else { 
        /* 0x42F00000 - c:\script.bin contents */
        memcpy(loadAddr, (const void*)0x42F00000, imgScript->maxSize);
        imgScript->param776 = imgScript->maxSize;
    }
    *bootAddrBuf = imgScript->images[0].baseAddr;
    *var6 = imgScript->images[1].baseAddr;
    wlibc_uprintf("load kernel successed\n");
    return 0;

fail:
    if(fdesc != 0) {
        svc_close(fdesc);
    }
    wlibc_uprintf("load kernel failed\n");
    return -1;
}
コード例 #5
0
int main(int argc, char **argv)
{
   int    ch, stat, ncols, count, failed, missing, warning;

   int    icntr1;
   int    icntr2;
   int    istatfile;

   int    cntr1;
   int    cntr2;

   char   statfile[MAXSTR];

   char   tblfile [MAXSTR];
   char   fitfile [MAXSTR];
   char   statdir [MAXSTR];

   char   line    [MAXSTR];
   char   msg     [MAXSTR];
   char   val     [MAXSTR];
   char   status  [32];

   double a;
   double b;
   double c;
   double crpix1;
   double crpix2;
   int    xmin;
   int    xmax;
   int    ymin;
   int    ymax;
   double xcenter;
   double ycenter;
   double npixel;
   double rms;
   double boxx;
   double boxy;
   double boxwidth;
   double boxheight;
   double boxangle;

   FILE   *fstat;
   FILE   *fout;

   SVC *svc=NULL;



   /***************************************/
   /* Process the command-line parameters */
   /***************************************/

   debug = 0;

   opterr = 0;

   fstatus = stdout;

   while ((ch = getopt(argc, argv, "ds:")) != EOF) 
   {
      switch (ch) 
      {
         case 'd':
            debug = 1;
            break;

         case 's':
            if((fstatus = fopen(optarg, "w+")) == (FILE *)NULL)
            {
               printf("[struct stat=\"ERROR\", msg=\"Cannot open status file: %s\"]\n",
                  optarg);
               exit(1);
            }
            break;

         default:
            printf("[struct stat=\"ERROR\", msg=\"Usage: %s [-d] [-s statusfile] statfiles.tbl fits.tbl statdir\"]\n", argv[0]);
            exit(1);
            break;
      }
   }

   if (argc - optind < 3) 
   {
      printf("[struct stat=\"ERROR\", msg=\"Usage: %s [-d] [-s statusfile] statfiles.tbl fits.tbl statdir\"]\n", argv[0]);
      exit(1);
   }

   strcpy(tblfile, argv[optind]);
   strcpy(fitfile, argv[optind + 1]);
   strcpy(statdir, argv[optind + 2]);

   fout = fopen(fitfile, "w+");

   if(fout == (FILE *)NULL)
   {
      fprintf(fstatus, "[struct stat=\"ERROR\", msg=\"Can't open output file.\"]\n");
      fflush(stdout);
      exit(1);
   }


   /**************************************************/ 
   /* Open the difference fit status file list table */
   /**************************************************/ 

   ncols = topen(tblfile);

   if(ncols <= 0)
   {
      fprintf(fstatus, "[struct stat=\"ERROR\", msg=\"Invalid statfiles metadata file: %s\"]\n",
         tblfile);
      exit(1);
   }

   icntr1    = tcol( "cntr1");
   icntr2    = tcol( "cntr2");
   istatfile = tcol( "stat");

   if(icntr1    < 0
   || icntr2    < 0
   || istatfile < 0)
   {
      fprintf(fstatus, "[struct stat=\"ERROR\", msg=\"Need columns: cntr1 cntr2 plus minus diff\"]\n");
      exit(1);
   }


   /***************************************/ 
   /* Read the records and call mFitPlane */
   /***************************************/ 

   count   = 0;
   failed  = 0;
   missing = 0;
   warning = 0;

   fprintf(fout, "| plus|minus|       a    |      b     |      c     | crpix1  | crpix2  | xmin | xmax | ymin | ymax | xcenter | ycenter |  npixel |    rms     |    boxx    |    boxy    |  boxwidth  | boxheight  |   boxang   |\n");
   fflush(fout);

   while(1)
   {
      stat = tread();

      if(stat < 0)
         break;

      cntr1 = atoi(tval(icntr1));
      cntr2 = atoi(tval(icntr2));

      strcpy(statfile, statdir);
      strcat(statfile, "/");
      strcat(statfile, tval(istatfile));

      if(checkFile(statfile))
      {
         ++count;
         ++missing;
         continue;
      }

      fstat = fopen(statfile, "r");

      if(fstat == (FILE *)NULL)
      {
         ++count;
         ++missing;
         continue;
      }


      if(fgets(line, MAXSTR, fstat) == (char *)NULL)
      {
         ++count;
         ++missing;
         continue;
      }

      svc=svc_struct(line); 

      strcpy( status, svc_val(line, "stat", val));

      if(strcmp( status, "ABORT") == 0)
      {
         strcpy( msg, svc_val(line, "msg", val ));

         fprintf(fstatus, "[struct stat=\"ERROR\", msg=\"%s\"]\n", msg);
         fflush(stdout);

         exit(1);
      }

      ++count;
      if(strcmp( status, "ERROR") == 0)
         ++failed;
      else if(strcmp( status, "WARNING") == 0)
         ++warning;
      else
      {
         a         = atof(svc_val(line, "a", val));
         b         = atof(svc_val(line, "b", val));
         c         = atof(svc_val(line, "c", val));
         crpix1    = atof(svc_val(line, "crpix1", val));
         crpix2    = atof(svc_val(line, "crpix2", val));
         xmin      = atoi(svc_val(line, "xmin", val));
         xmax      = atoi(svc_val(line, "xmax", val));
         ymin      = atoi(svc_val(line, "ymin", val));
         ymax      = atoi(svc_val(line, "ymax", val));
         xcenter   = atof(svc_val(line, "xcenter", val));
         ycenter   = atof(svc_val(line, "ycenter", val));
         npixel    = atof(svc_val(line, "npixel", val));
         rms       = atof(svc_val(line, "rms", val));
         boxx      = atof(svc_val(line, "boxx", val));
         boxy      = atof(svc_val(line, "boxy", val));
         boxwidth  = atof(svc_val(line, "boxwidth", val));
         boxheight = atof(svc_val(line, "boxheight", val));
         boxangle  = atof(svc_val(line, "boxang", val));


         fprintf(fout, " %5d %5d %12.5e %12.5e %12.5e %9.2f %9.2f %6d %6d %6d %6d %9.2f %9.2f %9.0f %12.5e %12.1f %12.1f %12.1f %12.1f %12.1f\n",
            cntr1, cntr2, a, b, c, crpix1, crpix2, xmin, xmax, ymin, ymax,
            xcenter, ycenter, npixel, rms, boxx, boxy, boxwidth, boxheight, boxangle);
         fflush(fout);
      }

      svc_free(svc);

      fclose(fstat);
   }

   fprintf(fstatus, "[struct stat=\"OK\", count=%d, failed=%d, missing=%d, warning=%d]\n", count, failed, missing, warning);
   fflush(stdout);

   exit(0);
}
コード例 #6
0
ファイル: utils.c プロジェクト: atikinn/EOS
void 
efree(void *ptr) {
    svc_free(ptr);
}