示例#1
0
void
close_fake_pipes(void)
{
    FILE_NODE *p = file_list;
    char xbuff[100];

    /* close input pipes first to free descriptors for children */
    while (p) {
	if (p->type == PIPE_IN) {
	    FINclose((FIN *) p->ptr);
	    unlink(tmp_file_name(p->pid, xbuff));
	}
	p = p->link;
    }
    /* doit again */
    p = file_list;
    while (p) {
	if (p->type == PIPE_OUT) {
	    if (fclose(p->ptr) != 0) {
		close_error(p);
	    }
	    close_fake_outpipe(p->name->str, p->pid);
	}
	p = p->link;
    }
}
示例#2
0
//	////////////////////////////////////////////////////////////////////////////
void LogHandlerXFile::OpenFileImpl(const char *file_name)
{
	boost::shared_ptr<std::ofstream> tmp_file_ptr(
		new std::ofstream(file_name,
			(!(my_flags_ & DoNotAppend)) ?
			(std::ios_base::app | std::ios_base::ate) :
			(std::ios_base::app | std::ios_base::trunc)));

	if (tmp_file_ptr->fail())
		ThrowErrno("Open attempt failed.");

//	CODE NOTE: LogFileHandler buffering test code. To be removed.
std::streambuf *new_buffer_ptr =
	tmp_file_ptr->rdbuf()->pubsetbuf(TestFileBuffer, sizeof(TestFileBuffer));
if (new_buffer_ptr == NULL)
	ThrowErrno("Attempt to set the log file buffer size to " +
		AnyToString(sizeof(TestFileBuffer)) + " bytes failed.");

	{
		std::string               tmp_file_name(file_name);
		boost::mutex::scoped_lock my_lock(the_lock_);
		if ((out_file_ptr_ != NULL) && out_file_ptr_->is_open()) {
			out_file_ptr_->flush();
			out_file_ptr_->close();
			out_file_ptr_.reset();
		}
		out_file_ptr_.swap(tmp_file_ptr);
		out_file_name_.swap(tmp_file_name);
	}
}
示例#3
0
int
close_fake_outpipe(char *command,
		   int tid)	/* identifies the temp file */
{
    char xbuff[256];
    char *tmpname = tmp_file_name(tid, xbuff + 163);
    int retval;

    sprintf(xbuff, "%s < %s", command, tmpname);
    retval = DOSexec(xbuff);
    (void) unlink(tmpname);
    return retval;
}
示例#4
0
PTR
get_pipe(char *command,
	 int type, int *tmp_idp)
{
    PTR retval;
    char xbuff[256];
    char *tmpname;

    *tmp_idp = next_tmp;
    tmpname = tmp_file_name(next_tmp, xbuff + 163);

    if (type == PIPE_OUT) {
	retval = (PTR) fopen(tmpname, (binmode() & 2) ? "wb" : "w");
    } else {
	sprintf(xbuff, "%s > %s", command, tmpname);
	tmp_idp[1] = DOSexec(xbuff);
	retval = (PTR) FINopen(tmpname, 0);
    }

    next_tmp++;
    return retval;
}
示例#5
0
int
file_close(STRING * sval)
{
    FILE_NODE *p;
    FILE_NODE *q = 0;		/* trails p */
    FILE_NODE *hold;
    char *name = sval->str;
    int retval = -1;

    p = file_list;
    while (p) {
	if (strcmp(name, p->name->str) == 0) {
	    /* found */

	    /* Remove it from the list first because we might be called
	       again if an error occurs leading to an infinite loop.

	       Note that we don't have to consider the list corruption
	       caused by a recursive call because it will never return. */

	    if (q == 0)
		file_list = p->link;
	    else
		q->link = p->link;

	    switch (p->type) {
	    case F_TRUNC:
	    case F_APPEND:
		if (fclose((FILE *) p->ptr) != 0) {
		    close_error(p);
		}
		retval = 0;
		break;

	    case PIPE_OUT:
		if (fclose((FILE *) p->ptr) != 0) {
		    close_error(p);
		}
#ifdef  HAVE_REAL_PIPES
		retval = wait_for(p->pid);
#endif
#ifdef  HAVE_FAKE_PIPES
		retval = close_fake_outpipe(p->name->str, p->pid);
#endif
		break;

	    case F_IN:
		FINclose((FIN *) p->ptr);
		retval = 0;
		break;

	    case PIPE_IN:
		FINclose((FIN *) p->ptr);

#ifdef  HAVE_REAL_PIPES
		retval = wait_for(p->pid);
#endif
#ifdef  HAVE_FAKE_PIPES
		{
		    char xbuff[100];
		    unlink(tmp_file_name(p->pid, xbuff));
		    retval = p->inpipe_exit;
		}
#endif
		break;
	    }

	    hold = p;
	    p = p->link;
	    free_filenode(hold);
	} else {
	    q = p;
	    p = p->link;
	}
    }

    return retval;
}