Exemple #1
0
extern int
disp_close(void)			/* close our display process */
{
	if (dpout == NULL)
		return(-1);
	myeye.rng = 0;
	disp_result(DS_SHUTDOWN, 0, NULL);
	fclose(dpout);
	dpout = NULL;
	return(dpd.running ? close_process(&dpd) : 0);

}
Exemple #2
0
void
quit(				/* exit gracefully */
	int	code
)
{
	if (ourdisplay != NULL)
		dev_close();
	/* if (rtpd.pid > 0) { */
	if (rtpd.running) {
		if (close_process(&rtpd) > 0)
			wputs("bad exit status from rtrace\n");
		/* rtpd.pid = 0; */
	}
	exit(code);
}
void test_socketOnErrors(int ret){
        if (ret == 0) {
            
                /**Server closed connection*/
		errorPrint("Connection closed while trying to read/write");
                if (get_guiruns()!=0){
                        guiShowErrorDialog("Error: Die Verbindung zum Server wurde getrennt!", 1);
                        sem_wait(&semaphore_socket);
                }else{
                        errorPrint("Error: Die Verbindung zum Server wurde getrennt!");
                        close_process();
                        sem_wait(&semaphore_socket);
                }
	}
	if (ret < 0) {
                /**Avoids the printing of the error message, when the user clicked on the close button, of the window
                  *Problem: When there is no close(get_socket()) in game_onAnswerClicked(), then the game of the other player 
                  *(appears only, if there is only one more player left)
                  *moves on, until the user, who pushed the "x"-Button of his game window, pushes also the OK-Button, of the
                  *appearing message dialog*/
                if(closeSocketOnEndGame!=0){
                
                }else{
                        /**Read/write error*/
                        errorPrint("Cannot read from/write to socket: %s", strerror(errno));
                        if (get_guiruns()!=0){
                                guiShowErrorDialog("Error: Fehler beim schreib/lesezugriff auf den Socket!", 1);
                                sem_wait(&semaphore_socket);
                        }else{
                                errorPrint("Error: Fehler beim schreib/lesezugriff auf den Socket!");
                                close_process();
                                sem_wait(&semaphore_socket);
                        }
                }
	}
}
Exemple #4
0
extern int
end_rtrace(void)			/* close rtrace process(es) */
{
	int	status = 0, rv;

	if (nprocs > 1)
		killpersist();
	while (nprocs > 0) {
		rv = close_process(&rtpd[--nprocs]);
		if (rv > 0)
			status = rv;
	}
	free((void *)rtbuf);
	rtbuf = NULL;
	maxqlen = 0;
	return(status);
}
int
main( int argc, char **argv )
{
	SUBPROC proc;
	FILE *inf, *outf;
	int res;
	char ret[1024];
	char *command[]= {"word", "gappy word", "\"quoted words\"", "'squoted words'", NULL};

    res = open_process(&proc, command)
	if (res == 0) {
		printf("open_process() failed with return value 0\n");
		return -1;
	}
	printf("process opened with return value: %d, pid: %d,  r: %d,  w: %d\n",
			res, proc.pid, proc.r, proc.w);
	inf = fdopen(proc.r, "rb");
	outf = fdopen(proc.w, "wb");
	fprintf(outf,"0 0 0 0 1 0\n");
	fflush(outf);
	fgets(ret, sizeof(ret), inf);
	printf("%s\n",ret);
	close_process(&proc);
}
Exemple #6
0
int exec_program_v(const char *working_directory,
	struct strbuf *output, struct strbuf *error_output,
	int flags, const char **argv)
{
	int fdout[2], fderr[2];
	int s1 = -1, s2 = -1;	/* backups of stdin, stdout, stderr */

	pid_t pid;
	int status = 0;
	int ret;

	struct strbuf strout = STRBUF_INIT, strerr = STRBUF_INIT;
	if (!output)
		output = &strout;
	if (!error_output)
		error_output = &strerr;

	reporter *debug = QUIETMODE & flags ? _debug_git : _debug_git_mbox;

	if (!git_path()) {
		debug("[ERROR] Could not find git path");
		return -1;
	}

	if (pipe(fdout) < 0) {
		return -ERR_RUN_COMMAND_PIPE;
	}
	s1 = dup(1);
	dup2(fdout[1], 1);

	flags |= WAITMODE;

	if (pipe(fderr) < 0) {
		if (output)
			close_pair(fdout);
		return -ERR_RUN_COMMAND_PIPE;
	}
	s2 = dup(2);
	dup2(fderr[1], 2);

	flags |= WAITMODE;

	pid = fork_process(argv[0], argv, working_directory);

	if (s1 >= 0)
		dup2(s1, 1), close(s1);
	if (s2 >= 0)
		dup2(s2, 2), close(s2);

	if (pid < 0) {
		close_pair(fdout);
		close_pair(fderr);
		return -ERR_RUN_COMMAND_FORK;
	}

	close(fdout[1]);
	close(fderr[1]);

	if (WAITMODE & flags) {
		ret = wait_for_process(pid, MAX_PROCESSING_TIME,
				&status);
		if (ret) {
			if (ret < 0) {
				debug_git("[ERROR] wait_for_process failed (%d); "
					"wd: %s; cmd: %s",
					status,
					working_directory,
					argv[0]);

				status = -1;
			}

			strbuf_read(output, fdout[0], 0);
			debug_git("STDOUT:\r\n%s\r\n*** end of STDOUT ***\r\n", output->buf);

			strbuf_read(error_output, fderr[0], 0);
			debug_git("STDERR:\r\n%s\r\n*** end of STDERR ***\r\n", error_output->buf);
		} else {
			status = -ERR_RUN_COMMAND_WAITPID_NOEXIT;
			debug_git("[ERROR] process timed out; "
				"wd: %s; cmd: %s",
				working_directory, argv[0]);
		}
	}
	close_process(pid);

	close(fdout[0]);
	close(fderr[0]);

	strbuf_release(&strerr);
	strbuf_release(&strout);

	return status;
}
Exemple #7
0
int main( int argc , char *argv[] )
{
	
	if( argc == 1 )
	{
		usage();
		exit(0);
	}
	
	argv++; argc--;

	/* 启动服务 */
	if (strcmp(*argv, "start") == 0) 
	{
		argv++; argc--;
		start_process(argc, argv);
	}
	else if (strcmp(*argv, "add") == 0) 
	{
		/* 新增服务 */
		argv++; argc--;
		add_process(argc, argv);
	} 
	else if (strcmp(*argv, "reload") == 0) 
	{
		/* 重载服务 */
		argv++; argc--;
		mod_process(argc, argv);
	}
	else if (strcmp(*argv, "close") == 0) 
	{
		/* 关闭服务 */
		argv++; argc--;
		stop_process(argc, argv);
	} 
	else if (strcmp(*argv, "force") == 0) 
	{
		/* 关闭服务 */
		argv++; argc--;
		force_stop_process(argc, argv);
	} 
	else if (strcmp(*argv, "view") == 0) 
	{
		/* 查看服务 */
		argv++; argc--;
		view_process(argc, argv);
	} 
	else if (strcmp(*argv, "stop") == 0) 
	{
		/* 停止服务 */
		argv++; argc--;
		close_process(argc, argv);
	} 
	else 
	{
		printf("无效的参数:%s\n", *argv);
		usage();
	}
	
	return 0;
	
}