Ejemplo n.º 1
0
Archivo: fd.c Proyecto: hellower/gpdb
/*
 * Close temporary files and delete their underlying files.
 *
 * isProcExit: if true, this is being called as the backend process is
 * exiting. If that's the case, we should remove all temporary files; if
 * that's not the case, we are being called for transaction commit/abort
 * and should only remove transaction-local temp files.  In either case,
 * also clean up "allocated" stdio files and dirs.
 */
static void
CleanupTempFiles(bool isProcExit)
{
	Index		i;

	if (SizeVfdCache > 0)
	{
		Assert(FileIsNotOpen(0));		/* Make sure ring not corrupted */
		for (i = 1; i < SizeVfdCache; i++)
		{
			unsigned short fdstate = VfdCache[i].fdstate;

			/*
			 * If we're in the process of exiting a backend process, close
			 * all temporary files. Otherwise, only close temporary files
			 * local to the current transaction.
			 */
			if((fdstate & FD_CLOSE_AT_EOXACT)
			  	||
			   (isProcExit && (fdstate & FD_TEMPORARY))
			  )
			{
				AssertImply( (fdstate & FD_TEMPORARY), VfdCache[i].fileName != NULL);
				FileClose(i);
			}
		}
	}

	workfile_mgr_cleanup();

	while (numAllocatedDescs > 0)
		FreeDesc(&allocatedDescs[0]);
}
Ejemplo n.º 2
0
int ReadTerMailCfg(char *pchFileName, USERDATAOPT *pUserdata,
                   OUTBOUND *pOutbounds, PAREALIST pRetList, PDRIVEREMAP pDriveRemap, ULONG ulOptions)
{
   int rc;
   char TmBbsName[LEN_PATHNAME+1]="";
   char OutboundPath[LEN_PATHNAME+1]="";
   char NetmailPath[LEN_PATHNAME+1]="";
   USERDATAOPT UserData;
   PDESCLIST pDescList=NULL;

   memset(&UserData, 0, sizeof(UserData));

   /* TM_CFG lesen */
   if (rc = ReadTmCfg(pchFileName, TmBbsName,
                      OutboundPath, NetmailPath, &UserData,
                      (ulOptions & READCFG_AREAS)?(&pDescList):NULL))
   {
      if (pDescList)
         FreeDesc(pDescList);
      return rc;
   }

   if (ulOptions & READCFG_USERDATA)
      *pUserdata = UserData;

   if (ulOptions & READCFG_OUTBOUNDS)
      if (OutboundPath[0])
         CopyOutbound(pOutbounds, &UserData, pchFileName, OutboundPath);

   /* TM.BBS lesen */
   if (ulOptions & READCFG_AREAS)
      if (rc = ReadTmBbs(pchFileName, TmBbsName, NetmailPath, &UserData, pDriveRemap, pRetList, pDescList))
      {
         if (pDescList)
            FreeDesc(pDescList);
         return rc;
      }

   if (pDescList)
      FreeDesc(pDescList);

   return CFGFILE_OK;
}
Ejemplo n.º 3
0
/*
 * AtEOSubXact_Files
 *
 * Take care of subtransaction commit/abort.  At abort, we close temp files
 * that the subtransaction may have opened.  At commit, we reassign the
 * files that were opened to the parent subtransaction.
 */
void
AtEOSubXact_Files(bool isCommit, SubTransactionId mySubid,
                  SubTransactionId parentSubid)
{
    Index		i;

    for (i = 0; i < numAllocatedDescs; i++)
    {
        if (allocatedDescs[i].create_subid == mySubid)
        {
            if (isCommit)
                allocatedDescs[i].create_subid = parentSubid;
            else
            {
                /* have to recheck the item after FreeDesc (ugly) */
                FreeDesc(&allocatedDescs[i--]);
            }
        }
    }
}
Ejemplo n.º 4
0
/*
 * Close a directory opened with AllocateDir.
 *
 * Note we do not check closedir's return value --- it is up to the caller
 * to handle close errors.
 */
int
FreeDir(DIR *dir)
{
    int			i;

    DO_DB(elog(LOG, "FreeDir: Allocated %d", numAllocatedDescs));

    /* Remove dir from list of allocated dirs, if it's present */
    for (i = numAllocatedDescs; --i >= 0;)
    {
        AllocateDesc *desc = &allocatedDescs[i];

        if (desc->kind == AllocateDescDir && desc->desc.dir == dir)
            return FreeDesc(desc);
    }

    /* Only get here if someone passes us a dir not in allocatedDescs */
    elog(WARNING, "dir passed to FreeDir was not obtained from AllocateDir");

    return closedir(dir);
}
Ejemplo n.º 5
0
/*
 * Close a file returned by AllocateFile.
 *
 * Note we do not check fclose's return value --- it is up to the caller
 * to handle close errors.
 */
int
FreeFile(FILE *file)
{
    int			i;

    DO_DB(elog(LOG, "FreeFile: Allocated %d", numAllocatedDescs));

    /* Remove file from list of allocated files, if it's present */
    for (i = numAllocatedDescs; --i >= 0;)
    {
        AllocateDesc *desc = &allocatedDescs[i];

        if (desc->kind == AllocateDescFile && desc->desc.file == file)
            return FreeDesc(desc);
    }

    /* Only get here if someone passes us a file not in allocatedDescs */
    elog(WARNING, "file passed to FreeFile was not obtained from AllocateFile");

    return fclose(file);
}
Ejemplo n.º 6
0
Archivo: fd.c Proyecto: hellower/gpdb
/*
 * Close a directory opened with AllocateDir.
 *
 * Note we do not check closedir's return value --- it is up to the caller
 * to handle close errors.
 */
int
FreeDir(DIR *dir)
{
	int			i;

	DO_DB(elog(LOG, "FreeDir: Allocated %d", numAllocatedDescs));

	/* Remove dir from list of allocated dirs, if it's present */
	for (i = numAllocatedDescs; --i >= 0;)
	{
		AllocateDesc *desc = &allocatedDescs[i];

		if (desc->kind == AllocateDescDir && desc->desc.dir == dir)
			return FreeDesc(desc);
	}

	/* Only get here if someone passes us a dir not in allocatedDescs */
	elog(LOG, "directory to be closed was not opened through the virtual file descriptor system");
	Assert(false);

	return closedir(dir);
}
Ejemplo n.º 7
0
Archivo: fd.c Proyecto: hellower/gpdb
/*
 * Close a file returned by AllocateFile.
 *
 * Note we do not check fclose's return value --- it is up to the caller
 * to handle close errors.
 */
int
FreeFile(FILE *file)
{
	int			i;

	DO_DB(elog(LOG, "FreeFile: Allocated %d", numAllocatedDescs));

	/* Remove file from list of allocated files, if it's present */
	for (i = numAllocatedDescs; --i >= 0;)
	{
		AllocateDesc *desc = &allocatedDescs[i];

		if (desc->kind == AllocateDescFile && desc->desc.file == file)
			return FreeDesc(desc);
	}

	/* Only get here if someone passes us a file not in allocatedDescs */
	elog(LOG, "file to be closed was not opened through the virtual file descriptor system");
	Assert(false);

	return fclose(file);
}
Ejemplo n.º 8
0
Archivo: fd.c Proyecto: hellower/gpdb
/*
 * AtEOSubXact_Files
 *
 * Take care of subtransaction commit/abort.  At abort, we close temp files
 * that the subtransaction may have opened.  At commit, we reassign the
 * files that were opened to the parent subtransaction.
 */
void
AtEOSubXact_Files(bool isCommit, SubTransactionId mySubid,
				  SubTransactionId parentSubid)
{
	Index		i;

	if (SizeVfdCache > 0)
	{
		Assert(FileIsNotOpen(0));		/* Make sure ring not corrupted */
		for (i = 1; i < SizeVfdCache; i++)
		{
			unsigned short fdstate = VfdCache[i].fdstate;

			if ((fdstate & FD_CLOSE_AT_EOXACT) &&
				VfdCache[i].create_subid == mySubid)
			{
				if (isCommit)
					VfdCache[i].create_subid = parentSubid;
				else if (VfdCache[i].fileName != NULL)
					FileClose(i);
			}
		}
	}

	for (i = 0; i < numAllocatedDescs; i++)
	{
		if (allocatedDescs[i].create_subid == mySubid)
		{
			if (isCommit)
				allocatedDescs[i].create_subid = parentSubid;
			else
			{
				/* have to recheck the item after FreeDesc (ugly) */
				FreeDesc(&allocatedDescs[i--]);
			}
		}
	}
}
Ejemplo n.º 9
0
/*
 * Close temporary files and delete their underlying files.
 *
 * isProcExit: if true, this is being called as the backend process is
 * exiting. If that's the case, we should remove all temporary files; if
 * that's not the case, we are being called for transaction commit/abort
 * and should only remove transaction-local temp files.  In either case,
 * also clean up "allocated" stdio files and dirs.
 */
static void
CleanupTempFiles(bool isProcExit)
{
    Index		i;

    if (SizeVfdCache > 0)
    {
        Assert(FileIsNotOpen(0));		/* Make sure ring not corrupted */
        for (i = 1; i < SizeVfdCache; i++)
        {
            unsigned short fdstate = VfdCache[i].fdstate;

            if ((fdstate & FD_TEMPORARY) && VfdCache[i].fileName != NULL)
            {
                /*
                 * If we're in the process of exiting a backend process, close
                 * all temporary files. Otherwise, only close temporary files
                 * local to the current transaction. They should be closed
                 * by the ResourceOwner mechanism already, so this is just
                 * a debugging cross-check.
                 */
                if (isProcExit)
                    FileClose(i);
                else if (fdstate & FD_XACT_TEMPORARY)
                {
                    elog(WARNING,
                         "temporary file %s not closed at end-of-transaction",
                         VfdCache[i].fileName);
                    FileClose(i);
                }
            }
        }
    }

    /* Clean up "allocated" stdio files and dirs. */
    while (numAllocatedDescs > 0)
        FreeDesc(&allocatedDescs[0]);
}