Пример #1
0
gfarm_error_t
request_nodename(struct gfarm_host_info *host_info,
	struct gfarm_paraccess *pa)
{
	gfarm_error_t e;
	char *canonical_hostname;
	struct sockaddr addr;

	/* dup `host_info->hostname' -> `hostname' */
	canonical_hostname = strdup(host_info->hostname);
	if (canonical_hostname == NULL) {
		e = GFARM_ERR_NO_MEMORY;
		fprintf(stderr, "%s: %s\n", program_name,
		    gfarm_error_string(e));
		return (e);
	}

	e = (*opt_resolv_addr)(
	    canonical_hostname, host_info->port, host_info,
	    &addr, NULL);
	if (e != GFARM_ERR_NO_ERROR) {
		output_process(NULL, canonical_hostname, NULL, NULL, NULL, e);
		return (e);
	}

	return (gfarm_paraccess_request(pa, NULL,
	    canonical_hostname, host_info->port, &addr));
}
Пример #2
0
gfarm_error_t
request_gfsd_cacheinfo(struct gfarm_host_info *host_info,
	struct gfarm_paraccess *pa)
{
	gfarm_error_t e;
	char *canonical_hostname;
	char *str;
	struct sockaddr addr;
	struct gfs_connection *gfs_server;

	/* dup `host_info->hostname' -> `hostname' */
	canonical_hostname = strdup(host_info->hostname);
	if (canonical_hostname == NULL) {
		e = GFARM_ERR_NO_MEMORY;
		fprintf(stderr, "%s: %s\n", program_name,
		    gfarm_error_string(e));
		return (e);
	}

	e = (*opt_resolv_addr)(
	    canonical_hostname, host_info->port, host_info,
	    &addr, NULL);
	if (e != GFARM_ERR_NO_ERROR) {
		output_process(NULL, canonical_hostname, NULL, NULL, NULL, e);
		return (e);
	}

	/* 
	 * Few additions by Kazushi
	 */
	e = gfs_client_connection_acquire_by_host(gfm_server, canonical_hostname, 
		host_info->port, &gfs_server, "192.168.100.1");
	if (e != GFARM_ERR_NO_ERROR) {
		fprintf(stderr, 
		    "Could not establish to connect gfs client (%s)\n", 
			 canonical_hostname);
		return (e);
	}
	
	e = gfs_client_recv_hitrates(gfs_server, &str);
	if (e != GFARM_ERR_NO_ERROR) {
		fprintf(stderr, 
		    "Could not clear hitrate in (%s)\n", 
				canonical_hostname);
		return (e);
	}

	fprintf(stdout, "<%s:%d> -- %s\n", 
	        canonical_hostname, host_info->port, str);
	free(str);

	gfs_client_connection_free(gfs_server);

	/* return (gfarm_paraccess_request(pa, */
	/*     if_hostname, canonical_hostname, info->port, &addr)); */
	return GFARM_ERR_NO_ERROR;
}
Пример #3
0
uint32_t write_pty_slave(fs_node_t * node, uint32_t offset, uint32_t size, uint8_t *buffer) {
	pty_t * pty = (pty_t *)node->device;

	size_t l = 0;
	for (uint8_t * c = buffer; l < size; ++c, ++l) {
		output_process(pty, *c);
	}

	return l;
}
Пример #4
0
gfarm_error_t
request_long_format(struct gfarm_host_info *host_info,
	struct gfarm_paraccess *pa)
{
	gfarm_error_t e;
	struct sockaddr addr;
	struct long_format_parameter *param;
	struct gfarm_host_info *info;

	GFARM_MALLOC(param);
	if (param == NULL) {
		e = GFARM_ERR_NO_MEMORY;
		fprintf(stderr, "%s: %s\n", program_name,
		    gfarm_error_string(e));
		return (e);
	}
	info = &param->info;

	/* dup `*host_info' -> `*info' */
	info->hostname = strdup(host_info->hostname);
	info->port = host_info->port;
	info->nhostaliases = host_info->nhostaliases;
	if (host_info->nhostaliases == 0) {
		info->hostaliases = NULL;
	} else {
		info->hostaliases = gfarm_strarray_dup(host_info->hostaliases);
		if (info->hostaliases == NULL)
			info->nhostaliases = 0;
	}
	info->architecture = strdup(host_info->architecture);
	info->ncpu = host_info->ncpu;
	info->flags = host_info->flags;
	if (info->hostname == NULL || info->architecture == NULL) {
		gfarm_host_info_free(info);
		free(param);
		e = GFARM_ERR_NO_MEMORY;
		fprintf(stderr, "%s: %s\n", program_name,
		    gfarm_error_string(e));
		return (e);
	}

	param->if_hostname = NULL;
	e = (*opt_resolv_addr)(info->hostname, info->port, info,
	    &addr, &param->if_hostname);
	if (e != GFARM_ERR_NO_ERROR) {
		output_process(param, info->hostname, NULL, NULL, NULL, e);
		return (e);
	}

	return (gfarm_paraccess_request(pa, param, info->hostname, info->port,
	    &addr));
}
Пример #5
0
void
output_object(dwg_object* obj){
  if (!obj)
    {
      printf("object is NULL\n");
      return;
    }

  if (dwg_get_type(obj)== DWG_TYPE_VERTEX_MESH)
    {
      output_process(obj);
    }
}
Пример #6
0
void
output_object(dwg_object* obj){
  if (!obj)
    {
      printf("object is NULL\n");
      return;
    }

  if (dwg_get_type(obj)== DWG_TYPE_DIMENSION_ANG3PT)
    {
      output_process(obj);
    }
}
Пример #7
0
static void
gfarm_paraccess_callback(struct gfarm_paraccess *pa, struct gfarm_access *a,
	struct gfs_client_load *load, struct gfs_connection *gfs_server,
	gfarm_error_t e)
{
	output_process(a->closure, a->canonical_hostname, &a->peer_addr,
	    load, gfs_server, e);

	/* bring this back to the free slot list */
	a->next = pa->free_list;
	pa->free_list = a;
	pa->nfree++;
}
Пример #8
0
void
output_object(dwg_object* obj){
  if (!obj)
    {
      printf("object is NULL\n");
      return;
    }

  if (dwg_get_type(obj)== DWG_TYPE_POLYLINE_2D)
    {
      output_process(obj);
    }
}
int main(int argc, char *argv[]){
	pid_t pid;

	// initialize shared memory for IPCs
	shared_memory();

	pid = fork();
	switch(pid){
		case -1:
			// process creation failed
			die("process creation failed");
		case 0:
			// input process
			pid = fork();
			switch(pid){
				case -1:
					// process creation failed
					die("process creation failed");
				case 0:
					// event key process (input)
					return eventkey_process();
				default:
					// input process
					return input_process();
			}
		default:
			pid = fork();
			switch(pid){
				case -1:
					// process creation failed
					die("process creation failed");
				case 0:
					// output process
					return output_process();
				default:
					// main process
					main_process();
			}
	}

	free_shared();

	return 0;
}
Пример #10
0
/*------------------------------------------------------------------------------------------------------------------ 
-- FUNCTION: main 
-- 
-- DATE: January 16, 2014 
-- 
-- REVISIONS:  
-- 
-- DESIGNER: Robin Hsieh 
-- 
-- PROGRAMMER: Robin Hsieh 
-- 
-- INTERFACE: int main()
-- 
-- RETURNS: int - Returns 0 when the program ends.
-- 
-- NOTES:
-- This function is the main function of the program. It will create 2 pipes, 3 processes, and listen to 2 signals.
-- The 2 pipes will be used to transfer characters to translate and output processes. The 3 processes being created
-- are the translate process, and the output process (the main process is a process it self). And the 2 signals 
-- that are being waited upon is the signal ctrl+c that the user can use, as well as when the user decides to 
-- terminates the program.
--
------------------------------------------------------------------------------------------------------------------*/
int main()
{
    system("stty raw igncr -echo");

    pid_t childpid = 0;
    pid_t outputProcess = 0;
    pid_t translateProcess = 0;
    int i = 0;
    int c = 0;

    char buffer[BUFFER_SIZE] = "";

    int output_pipe[2];
    int translate_pipe[2];

    signal(SIGINT, catch_int);
    signal(SIGUSR1, catch_usr1);

    //creating the output pipe
    if(pipe(output_pipe) < 0)
    {
        perror("pipe call");
        exit(1);
    }

    //creating the translate pipe
    if(pipe(translate_pipe) < 0)
    {
        perror("pipe call");
        exit(1);
    }

    for(i = 1; i <3; i++)
    {
        if((childpid = fork()) <= 0)
        {
            if(i == 1)
            {
                outputProcess = getpid();
            }
            else if(i == 2)
            {
                translateProcess = getpid();
            }
            break;
        }
    }
    if(getpid() == outputProcess)
    {
        // Output Process
        output_process(output_pipe[READ_PIPE], c);
    }
    else if(getpid() == translateProcess)
    {
        // Translate Process
        translate_process(translate_pipe[READ_PIPE], c, output_pipe[WRITE_PIPE], buffer);
    }
    else
    {
        //Main Process
        while((c = getchar()) != EOF)
        {
            if(c == 11)
            {
                printf("\r\n");
                fflush(stdout);
                exit_program(translateProcess, outputProcess);
            }
            
            write(output_pipe[WRITE_PIPE], &c, 1);
            write(translate_pipe[WRITE_PIPE], &c, 1);

            if(c == 'T')
            {
                exit_program(translateProcess, outputProcess);
            }
        }
    }
    return 0;
}
Пример #11
0
static void input_process(pty_t * pty, uint8_t c) {
	if (pty->tios.c_lflag & ICANON) {
		debug_print(INFO, "Processing for character %d in canon mode", c);
		if (c == pty->tios.c_cc[VKILL]) {
			while (pty->canon_buflen > 0) {
				pty->canon_buflen--;
				pty->canon_buffer[pty->canon_buflen] = '\0';
				if (pty->tios.c_lflag & ECHO) {
					output_process(pty, '\010');
					output_process(pty, ' ');
					output_process(pty, '\010');
				}
			}
			return;
		}
		if (c == pty->tios.c_cc[VERASE]) {
			/* Backspace */
			if (pty->canon_buflen > 0) {
				pty->canon_buflen--;
				pty->canon_buffer[pty->canon_buflen] = '\0';
				if (pty->tios.c_lflag & ECHO) {
					output_process(pty, '\010');
					output_process(pty, ' ');
					output_process(pty, '\010');
				}
			}
			return;
		}
		if (c == pty->tios.c_cc[VINTR]) {
			if (pty->tios.c_lflag & ECHO) {
				output_process(pty, '^');
				output_process(pty, '@' + c);
				output_process(pty, '\n');
			}
			clear_input_buffer(pty);
			if (pty->fg_proc) {
				send_signal(pty->fg_proc, SIGINT);
			}
			return;
		}
		if (c == pty->tios.c_cc[VQUIT]) {
			if (pty->tios.c_lflag & ECHO) {
				output_process(pty, '^');
				output_process(pty, '@' + c);
				output_process(pty, '\n');
			}
			clear_input_buffer(pty);
			if (pty->fg_proc) {
				send_signal(pty->fg_proc, SIGQUIT);
			}
			return;
		}
		pty->canon_buffer[pty->canon_buflen] = c;
		if (pty->tios.c_lflag & ECHO) {
			output_process(pty, c);
		}
		if (pty->canon_buffer[pty->canon_buflen] == '\n') {
			pty->canon_buflen++;
			dump_input_buffer(pty);
			return;
		}
		if (pty->canon_buflen == pty->canon_bufsize) {
			dump_input_buffer(pty);
			return;
		}
		pty->canon_buflen++;
		return;
	} else if (pty->tios.c_lflag & ECHO) {
		output_process(pty, c);
	}
	IN(c);
}
Пример #12
0
/*
 * Main function that will create all the process for processing the input
 */
int main() {

  // pipes that used to pass the data
  int input_pipe[2];
  int carriage_handler_pipe[2];
  int asterisk_handler_pipe[2];

  // Children pid
  pid_t carriage_process_pid;
  pid_t asterisks_process_pid;
  pid_t output_pid;

  // create pipes to connect processes
  if (pipe(input_pipe) == -1) {
    perror("creating input pipe");
    exit(1);
  }
  if (pipe(carriage_handler_pipe) == -1) {
    perror("creating newline handler pipe");
    exit(1);
  }
  if (pipe(asterisk_handler_pipe) == -1) {
    perror("creating asterisk handler pipe");
    exit(1);
  }

  // fork the chile processes
  if ((carriage_process_pid = fork()) == -1) {
    perror("fork carriage processing");
    exit(1);
  }
  if (carriage_process_pid != 0) {  // parent process
    close(input_pipe[READ]);
    input_process(input_pipe[WRITE]);
    wait(&carriage_process_pid);
  } else {  // chile process
    if ((asterisks_process_pid = fork()) == -1) {
      perror("fork asterisks processing");
      exit(1);
    }
    if (asterisks_process_pid != 0) {  // parent process
      close(input_pipe[WRITE]);
      close(carriage_handler_pipe[READ]);
      carriage_processing_process(input_pipe[READ],
                                  carriage_handler_pipe[WRITE]);
      wait(&asterisks_process_pid);
    } else {  // child process
      if ((output_pid = fork()) == -1) {
        perror("fork output");
        exit(1);
      }
      if (output_pid != 0) {  // parent process
        close(carriage_handler_pipe[WRITE]);
        close(asterisk_handler_pipe[READ]);
        asterisks_processing_process(carriage_handler_pipe[READ],
                                     asterisk_handler_pipe[WRITE]);
        wait(&output_pid);
      } else {  // child process
        close(asterisk_handler_pipe[WRITE]);
        output_process(asterisk_handler_pipe[READ]);
      }
    }
  }
  return 0;
}