Beispiel #1
0
int main (void)
{
	int fd;

	if ((fd = open_fifo (WELL_KNOWN_FIFO)) == -1)
		err_msg ("Can't open FIFO");

	return (0);
}
void* send_info(void* arg){
	ngx_cycle_t *cycle= (ngx_cycle_t*)(arg);
	ngx_proc_send_conf_t  *pbcf;
	pbcf = ngx_proc_get_conf(cycle->conf_ctx, ngx_proc_send_module);

	open_fifo(cycle);
	while(1){
		if(start != end){
			int p = start;
			char out[SENDOUTBUFSIZE + 100];
			memset(out, 0, SENDOUTBUFSIZE + 100);
			sprintf(out, "%s\n", buf[p]);
			if(__sync_bool_compare_and_swap(&start, p, (p + 1) % BUFSIZE)){
				if(*(read_write_mmap + 1) >= *(read_write_mmap + 2) && *(read_write_mmap + 1) + (long)strlen(out) < (long)(pbcf->mmap_dat_size)){
					strcpy(write_file + *(read_write_mmap + 1), out);
					*(read_write_mmap + 1) = *(read_write_mmap + 1) + strlen(out);
				}
				else if(*(read_write_mmap + 1) >= *(read_write_mmap + 2) && *(read_write_mmap + 1) + (long)strlen(out) >= (long)(pbcf->mmap_dat_size)){
					if(((long)strlen(out) - ((long)(pbcf->mmap_dat_size) - *(read_write_mmap + 1)))< *(read_write_mmap + 2)){
						strncpy(write_file + *(read_write_mmap + 1), out, (long)(pbcf->mmap_dat_size) - *(read_write_mmap + 1));
						strcpy(write_file, out + (long)(pbcf->mmap_dat_size) - *(read_write_mmap + 1));
						*(read_write_mmap + 1) = strlen(out) - ((long)(pbcf->mmap_dat_size) - *(read_write_mmap + 1));
					}
				}
				else if(*(read_write_mmap + 1) < *(read_write_mmap + 2) && *(read_write_mmap + 1) + (long)strlen(out) < *(read_write_mmap + 2)){
					strcpy(write_file + *(read_write_mmap + 1), out);
					*(read_write_mmap + 1) = *(read_write_mmap + 1) + strlen(out);

				}
			}
		}
		else{
			usleep(10000);
		}
	}
	return NULL;
}
Beispiel #3
0
int init_hotplug()
{
	printf("\n\033[34m<<<<init_hotplug\033[0m\n");
	/* check if the internal, i.e. non-removable storage was mounted */
	if ((check_mnt_point(INT_STOR) == 0) && (read_dev_properties(INT_STOR, &prop_i_stor) == 0))
		s_status |= ISTORAGE_PRESENT;

	/* check if an external, i.e. removable storage was already mounted */
	if ((check_mnt_point(EXT_STOR) == 0) && (read_dev_properties(EXT_STOR, &prop_e_stor) == 0))
		s_status |= ESTORAGE_ADDED;

	if (s_status == STORAGE_NONE)
		D_WARN("init_hotplug: No internal OR external storage mounted.\n");
	
	if (open_fifo() == -1)
	{
		D_WARN("init_hotplug: open_fifo() failed. Hotplug messages will not be received.\n");
		return -1;
	}

	D_INFO("Hotplug handler initialized.\n");

	return 0;
}
Beispiel #4
0
/*========================================================================
** The Main Procedure
** Initialization and FIFO command dispatch routine.
========================================================================*/
static int real_main(int argc, char *argv[])
	{
	const char function[] = "real_main";
	int option_foreground = FALSE;
	int FIFO;					/* First-in-first-out which feeds us requests */
	sigset_t lock_set;
	struct timeval next_tick;

	/* Initialize internation messages library. */
	#ifdef INTERNATIONAL
	setlocale(LC_ALL, "");
	bindtextdomain(PACKAGE_PPRD, LOCALEDIR);
	textdomain(PACKAGE_PPRD);
	#endif

	/*
	** Set some environment variables, (PATH, IFS, and
	** SHELL) for safety and for the convenience of the
	** programs we launch (HOME, and PPR_VERSION).
	** Remove unnecessary and potentially misleading
	** variables.
	*/
	set_ppr_env();
	prune_env();

	parse_command_line(argc, argv, &option_foreground);

	/* Switch all UIDs to USER_PPR, all GIDS to GROUP_PPR. */
	adjust_ids();

	/* If the --forground switch wasn't used, then dropt into background. */
	if(! option_foreground)
		gu_daemon(PPR_PPRD_UMASK);
	else
		umask(PPR_PPRD_UMASK);

	/* Change the home directory to the PPR home directory: */
	chdir(HOMEDIR);

	/* Create /var/spool/ppr/pprd.pid. */
	create_lock_file();

	/* Signal handlers for silly stuff. */
	signal_restarting(SIGPIPE, signal_ignore);
	signal_restarting(SIGHUP, signal_ignore);

	/* Signal handler for shutdown request. */
	signal_interupting(SIGTERM, sigterm_handler);

	/* Arrange for child termination to be noted. */
	signal_restarting(SIGCHLD, sigchld_handler);

	/* Move /var/spool/ppr/logs/pprd to pprd.old before we call debug()
	   for the first time (below). */
	rename_old_log_file();

	/*
	** This code must come after adjust_ids() and gu_daemon().
	** It makes the first log entry and tells queue-display
	** programs that we are starting up.
	*/
	debug("PPRD startup, pid=%ld", (long)getpid());
	state_update("STARTUP");

	/* Make sure the local node gets the node id of 0. */
	if(! nodeid_is_local_node(nodeid_assign(ppr_get_nodename())))
		fatal(1, "%s(): line %d: assertion failed", function, __LINE__);

	/* Initialize other subsystems. */
	question_init();

	/* Load the printers database. */
	DODEBUG_STARTUP(("loading printers database"));
	load_printers();

	/* Load the groups database. */
	DODEBUG_STARTUP(("loading groups database"));
	load_groups();

	/* Set up the FIFO. */
	DODEBUG_STARTUP(("opening FIFO"));
	FIFO = open_fifo();

	/* Initialize the queue.  This is likely to start printers. */
	DODEBUG_STARTUP(("initializing the queue"));
	initialize_queue();

	/* Schedule the first timer tick. */
	gettimeofday(&next_tick, NULL);
	next_tick.tv_sec += TICK_INTERVAL;

	/*
	** Create a signal block set which will be used to block SIGCHLD except
	** when we are calling select().
	*/
	sigemptyset(&lock_set);
	sigaddset(&lock_set, SIGCHLD);
	sigprocmask(SIG_BLOCK, &lock_set, (sigset_t*)NULL);

	/*
	** This is the Main Loop.  It runs until the sigterm_handler
	** sets sigterm_received.
	*/
	while(!sigterm_received)
		{
		int readyfds;					/* return value from select() */
		fd_set rfds;					/* list of file descriptors for select() to watch */
		struct timeval time_now;		/* the current time */

		DODEBUG_MAINLOOP(("top of main loop"));

		gettimeofday(&time_now, NULL);

		/* If it is time for or past time for the next tick, */
		if(gu_timeval_cmp(&time_now, &next_tick) >= 0)
			{
			readyfds = 0;
			}

		/* If it is not time for the next tick yet, */
		else
			{
			/* Set the select() timeout so that it will return in time for the
			   next tick(). */
			gu_timeval_cpy(&select_tv, &next_tick);
			gu_timeval_sub(&select_tv, &time_now);

			/* Create a file descriptor list which contains only the descriptor
			   of the FIFO. */
			FD_ZERO(&rfds);
			FD_SET(FIFO, &rfds);

			/* Call select() with SIGCHLD unblocked. */
			sigprocmask(SIG_UNBLOCK, &lock_set, (sigset_t*)NULL);
			readyfds = select(FIFO + 1, &rfds, NULL, NULL, &select_tv);
			sigprocmask(SIG_BLOCK, &lock_set, (sigset_t*)NULL);
			}

		/* If there is something to read, */
		if(readyfds > 0)
			{
			if(!FD_ISSET(FIFO, &rfds))
				fatal(0, "%s(): assertion failed: select() returned but FIFO not ready", function);
			do_command(FIFO);
			continue;
			}

		/* If the SIGCHLD handler set the flag, handle child termination.  Once
		   we have done that, we must go back to the top of the loop because
		   we don't really know if it is time for a tick() call yet. */
		if(sigchld_caught)
			{
			sigchld_caught = FALSE;
			reapchild();
			continue;
			}

		/* If there was no error and no file descriptors are ready, then the 
		   timeout must have expired.  Call tick(). */
		if(readyfds == 0)
			{
			tick();
			next_tick.tv_sec += TICK_INTERVAL;
			continue;
			}

		/* If interupted by a system call, restart it. */
		if(errno == EINTR)
			continue;

		/* If we get this far, there was an error. */
		fatal(0, "%s(): select() failed, errno=%d (%s)", function, errno, gu_strerror(errno));
		} /* end of endless while() loop */

	state_update("SHUTDOWN");
	fatal(0, "Received SIGTERM, exiting");
	} /* end of real_main() */
Beispiel #5
0
            static void mkfifo_t(pid_t pid)
            {
                int n,ret,ref,nread,nwrite;
                char buf[MAX];
                memset(buf,'\0',MAX);
                char  * fp = NULL;
                int status ;
                int nwait ;
                int *ret_r =NULL;
                int *ret_w =NULL;
                int *ref_r = NULL;
                int *ref_w = NULL;
                int nr;
                
                
                ret = mkfifo(FIFO,0777);
                if (ret == -1) 
                    perror("mkfifo");
                // open son process and father process
                pid = fork();
                if (pid<0) 
                    printf("child process creat failed\n");
                else if (pid ==0) {
                    sleep(4);
                    printf("child process read start......\n");
                
                // child read from fifo that from father
                    ret_r = open_fifo(FIFO,O_RDONLY);
                    nread = read(*ret_r,buf,sizeof(buf));
                    if (nread == -1) 
                        perror("child read");
                    printf("the child read:%s\n",buf );

                    // /the child to write to father
                    printf("child process write start......\n");
                    ret_w = open_fifo(FIFO_t,O_WRONLY);
                    nr = write(*ret_w,"hello",6);
                    if (nr == -1) 
                        perror(" child write");

                    exit(0);
                }
                // the next is father
                printf("the father process start.....\n");
                fp = fgets(buf,sizeof(buf),stdin);
                if (fp == NULL) 
                    printf("fgets errno\n"); /* code */ 
                n = strlen(buf);
                printf("strlen of read buf: %d\n",n );
                if (fp[--n] == '\n') {
                    printf("the end file flag is '\\n'.\n");
                    fp[n] = '\0';
                }
                for (int i = 0; i < n; ++i) 
                    printf("%c\n",fp[i]);
                /* code */ 
                
/*                the father to write to child*/
                ref_r = open_fifo(FIFO,O_WRONLY);
                nwrite = write(*ref_r,buf,strlen(buf));
                if (nwrite == -1) {
                    if (errno == EINTR)
                        printf("the error is happened by signal int\n");
                    /* code */        
                    perror("father write");
                /* code */
                }
                
                /*                the father to read from child*/ 
                ref_w = open_fifo(FIFO_t,O_RDONLY);
                memset(buf,'\0',MAX);
                nread = read(*ref_w,buf,sizeof(buf)); 
                if (nread == -1)
                    perror("father read");
                printf("the father successfully:%s\n", buf);
                
                
                // putchar('\n');
                nwait = waitpid(pid,&status,0);
                if (nwait == -1) 
                    perror("waitpid");
                /* code */
                else
                    printf("the waitpid id :%d\n",status );
                
                
            
            }
Beispiel #6
0
rtems_task Init(
  rtems_task_argument argument
)
{
  void *alloc_ptr = (void *)0;
  int num_opens = 0;
  int index = 0;

  TEST_BEGIN();

  puts( "Creating all barriers" );
  create_all_barriers();

  puts( "Creating all semaphores" );
  create_all_semaphores();

  puts( "Creating FIFO" );
  create_fifo();

  puts( "Opening FIFO.. expect ENOMEM (semaphore for pipe could not be created)" );
  open_fifo(ENOMEM, O_RDWR);

  delete_semaphore();

  alloc_ptr = malloc( malloc_free_space() - 4 );
  puts("Opening FIFO.. expect ENOMEM since no memory is available");
  open_fifo(ENOMEM, O_RDWR);

  free(alloc_ptr);
  puts( "Opening FIFO.. expect ENOMEM (barrier-1 for pipe could not be created)" );
  open_fifo(ENOMEM, O_RDWR);

  delete_barrier();
  puts( "Opening FIFO.. expect ENOMEM (barrier-2 for pipe could not be created" );
  open_fifo(ENOMEM, O_RDWR);

  delete_barrier();
  puts( "Opening FIFO.. expect ENOMEM (semaphore-1 for pipe could not be created" );
  open_fifo(ENOMEM, O_RDWR);

  delete_semaphore();
  puts( "Opening FIFO in RDWR mode. Expect OK" );
  open_fifo(0, O_RDWR);
  ++num_opens;

  puts( "Opening FIFO in non blocking RDONLY mode. Expect OK");
  open_fifo(0, O_RDONLY | O_NONBLOCK);
  ++num_opens;

  puts( "Opening FIFO in non blocking WRONLY mode. Expect ENXIO");
  open_fifo(ENXIO, O_WRONLY | O_NONBLOCK);
  ++num_opens;

  puts("\nMultiple opens\n");
  index = 0;
  do {

    printf("%d... ", index+1);
    open_fifo(0, O_RDONLY | O_NONBLOCK);
    ++index;
  } while ( index < NUM_OPEN_REQ - num_opens );

  TEST_END();

  rtems_test_exit(0);
}
Beispiel #7
0
int main(int argc, char ** argv) {
  int ec_fifo, ce_fifo, es_fifo, se_fifo;
  FILE* fp;
  ssize_t msg_size;
  uint8_t *buff;
  char client_nm[NM_LENGTH], client_nm_tmp[NM_LENGTH];
  uint8_t rsa_tmp[RSA_LENGTH], rsa_tmp2[RSA_LENGTH];
  BIGNUM /**bn_n, *bn_d,*/ *bn_client_e, *bn_client_n, *bn_r;
  char client_cipher_suite;
  uint8_t sym_id, hash_id, public_id;
  uint8_t k[K_SIZE] = {0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1};
  int i, done;
  int k_len, c_hex_len, c_len;
  uint8_t g[HASH_LENGTH], g1[HASH_LENGTH];
  uint8_t c[MSG_SIZE_MAX];
  unsigned int tmp;

  assert(K_SIZE == 8);

  bn_client_e = BN_new();
  bn_client_n = BN_new();
  bn_r = BN_new();


  /* Mandatory arguments */
  if (!argv[1] || !argv[2] || !argv[3] || !argv[4] ||
      !argv[1] || !argv[2] || !argv[3] || !argv[4]) {
    fprintf(stderr, "%s [server->eve fifo] [eve->server fifo] [eve->client fifo] [client->eve fifo]\n", argv[0]);
    exit(1);
  }

  se_fifo = open_channel(argv[1]);
  es_fifo = open_channel(argv[2]);
  ec_fifo = open_fifo(argv[3]);
  ce_fifo = open_fifo(argv[4]);

  /* wait real client to connect */
  fprintf(stderr,"(E) Waiting connection...\n");
  if (wait_connection(ce_fifo) < 0) {
    fprintf(stderr,"(E) Communication error...\n");
    goto next;
  }
  /* connect to server */
  write_msg(es_fifo, (const u_int8_t *)CONNECTION_STRING, strlen(CONNECTION_STRING));

  forward_string(se_fifo, ec_fifo, OK_STRING);

  /* Server authentication */
  /* client challange */
  forward_msg(ce_fifo, es_fifo);
  /* server response to challange */
  forward_msg(se_fifo, ec_fifo);

  /* Client authentication */
  /* Client name */
  msg_size = forward_msg_read(ce_fifo, es_fifo, &buff);

  /*  vvvv  copy-paste from server  vvvv  */
  buff[msg_size] = '\0';
  strncpy((char *)client_nm, (const char *) buff, NM_LENGTH);
  /* EXTRACT from (names[],c_puk[],n[]) the pair (c_puk[i],n[i]) where names[i] = nm */
  if ((fp = fopen("server_folder/clients_rsa64_public_keys.txt", "r")) == NULL) {
    fprintf(stderr, "Error while getting clients RSA public keys...\n");
    goto next;
  }
  done = 0;
  while (!feof(fp)) {
    fscanf(fp, "%129s %129s %129s", client_nm_tmp, rsa_tmp, rsa_tmp2);
    if (strcmp(client_nm_tmp, client_nm) == 0) {
      done = 1;
      break;
    }
  }
  if (done == 0) {
    fprintf(stderr, "Error: unrecognized client\n");
    goto next;
  }
  fclose(fp);

  BN_hex2bn(&bn_client_n, (const char *) rsa_tmp);
  BN_hex2bn(&bn_client_e, (const char *) rsa_tmp2);

  /*  ^^^^  copy-paste from server  ^^^^  */
  /* now I know client name and pub key */

  /* server challange */
  forward_msg(se_fifo, ec_fifo);
  /* client response */
  forward_msg(ce_fifo, es_fifo);


  /* Negotiation of the cipher suite */
  /* cipher suite c -> s */
  forward_msg_read(ce_fifo, es_fifo, &buff);

  /*  vvvv  copy-paste from server  vvvv  */
  client_cipher_suite = buff[0];
  cipher_suite_table(client_cipher_suite, &sym_id, &hash_id, &public_id);
  /*  ^^^^  copy-paste from server  ^^^^  */


  /* Negotiation of the private key */
  /* k already set as an arbitrary key */

  /*  vvvv  copy-paste from server  vvvv  */

  if (sym_id == 1) {
    k_len = 3;
  }
  else {
    k_len = K_SIZE;
  }
  BN_bin2bn(k, k_len, bn_r);

  /* If we're using RSA512 read the correct key (we have the 64bit one) */
  if (public_id == 6) {
    if ((fp = fopen("server_folder/clients_rsa512_public_keys.txt", "r")) == NULL) {
      fprintf(stderr, "Error while getting clients RSA public keys...\n");
      goto next;
    }
    done = 0;
    while (!feof(fp)) {
      fscanf(fp, "%129s %129s %129s", client_nm_tmp, rsa_tmp, rsa_tmp2);
      if (strcmp(client_nm_tmp, client_nm) == 0) {
        done = 1;
        break;
      }
    }
    if (done == 0) {
      fprintf(stderr, "Error: unrecognized client\n");
      goto next;
    }
    fclose(fp);

    BN_hex2bn(&bn_client_n, (const char *) rsa_tmp);
    BN_hex2bn(&bn_client_e, (const char *) rsa_tmp2);
  }

  /* ENCRYPT key */
  rsa_encrypt(bn_r, bn_client_e, bn_client_n);

  /* WRITE encrypted k to C */
  buff = (uint8_t *) BN_bn2hex(bn_r);
  if ((write_msg(ec_fifo, buff, strlen((char *) buff))) < 0) {
    fprintf(stderr, "Error while sending C to the client...\n");
    goto next;
  }
  OPENSSL_free(buff);

  /* Encrypted communication */
  if ((msg_size = read_msg(ce_fifo,&buff)) < 0) {
    fprintf(stderr, "Error while reading message from the client...\n");
    goto next;
  }

  c_hex_len = msg_size - HASH_LENGTH * 2;
  if (c_hex_len <= 0) {
    fprintf(stderr, "Error, malformed message...\n");
    goto next;
  }

  c_len = c_hex_len / 2;
  for (i=0; i<msg_size; i+=2) {
    if (i < c_hex_len) {
      sscanf((char *) (buff+i), "%02x", &tmp);
      c[i/2] = (uint8_t) tmp;
    }
    else {
      sscanf((char *) (buff+i), "%02x", &tmp);
      g[(i - c_hex_len) / 2] = (uint8_t) tmp;
    }
  }

  /* Decrypt C */
  decrypt(sym_id, c, c_len, k);

  /* COMPUTE G' = H(M) */
  sponge_hash(c, c_len, g1);

  c[c_len] = '\0';

  /* CHECK G' = G */
  done = 1;
  for (i=0; i<HASH_LENGTH; i++) {
    if (g[i] != g1[i]) {
      done = 0;
    }
  }

  /* If the check fails print error message */
  if (done == 0) {
    if ((write_msg(ec_fifo, (uint8_t *) CORRUPTED_STRING, strlen(CORRUPTED_STRING))) < 0) {
      fprintf(stderr, "Error while writing to the client...\n");
      goto next;
    }
  }

  /* PUT M' on a file */
  if ((fp = fopen("eve_folder/received_messages.txt", "a+")) == NULL) {
    fprintf(stderr, "Error while saving message...\n");
    fclose(fp);
    goto next;
  }
  fprintf(fp, "%s", c);
  fflush(stdout);
  fprintf(stdout, "MESSAGGIO SEGRETO >>>%s<<< FINE MESSAGGIO SEGRETO\n", c);
  fflush(stdout);
  fclose(fp);

  /* WRITE ok message to C */
  if ((write_msg(ec_fifo, (uint8_t *) DECRYPTED_STRING, strlen(DECRYPTED_STRING))) < 0) {
    fprintf(stderr, "Error while writing C to the client...\n");
    goto next;
  }

  /*  ^^^^  copy-paste from server  ^^^^  */



 next:

  /*close_channels ...!*/

  BN_free(bn_client_n);
  BN_free(bn_client_e);
  BN_free(bn_r);

  exit(0);
}
Beispiel #8
0
static void attach_debugger(int fd, short event, void *arg)
{
    orte_app_context_t *app;
    unsigned char fifo_cmd;
    int rc;
    int32_t ljob;
    orte_job_t *jdata;

    /* read the file descriptor to clear that event, if necessary */
    if (fifo_active) {
	opal_event_del(&attach);
	fifo_active = false;

        rc = read(attach_fd, &fifo_cmd, sizeof(fifo_cmd));
	if (!rc) {
	    /* reopen device to clear hangup */
	    open_fifo();
	    return;
	}
        if (1 != fifo_cmd) {
            /* ignore the cmd */
            goto RELEASE;
        }
    }

    if (!MPIR_being_debugged && !orte_debugger_base.test_attach) {
        /* false alarm */
        goto RELEASE;
    }

    opal_output_verbose(1, orte_debugger_base.output,
                        "%s Attaching debugger %s", ORTE_NAME_PRINT(ORTE_PROC_MY_NAME),
                        (NULL == orte_debugger_base.test_daemon) ? MPIR_executable_path : orte_debugger_base.test_daemon);

    /* a debugger has attached! All the MPIR_Proctable
     * data is already available, so we only need to
     * check to see if we should spawn any daemons
     */
    if ('\0' != MPIR_executable_path[0] || NULL != orte_debugger_base.test_daemon) {
        /* can only have one debugger */
        if (NULL != orte_debugger_daemon) {
            opal_output(0, "-------------------------------------------\n"
                        "Only one debugger can be used on a job.\n"
                        "-------------------------------------------\n");
            goto RELEASE;
        }
        opal_output_verbose(2, orte_debugger_base.output,
                            "%s Spawning debugger daemons %s",
                            ORTE_NAME_PRINT(ORTE_PROC_MY_NAME),
                            (NULL == orte_debugger_base.test_daemon) ?
                            MPIR_executable_path : orte_debugger_base.test_daemon);
        /* this will be launched just like a regular job,
         * so we do not use the global orte_debugger_daemon
         * as this is reserved for co-location upon startup
         */
        jdata = OBJ_NEW(orte_job_t);
        /* create a jobid for these daemons - this is done solely
         * to avoid confusing the rest of the system's bookkeeping
         */
        orte_plm_base_create_jobid(jdata);
        /* flag the job as being debugger daemons */
        jdata->controls |= ORTE_JOB_CONTROL_DEBUGGER_DAEMON;
        /* unless directed, we do not forward output */
        if (!MPIR_forward_output) {
            jdata->controls &= ~ORTE_JOB_CONTROL_FORWARD_OUTPUT;
        }
        /* add it to the global job pool */
        ljob = ORTE_LOCAL_JOBID(jdata->jobid);
        opal_pointer_array_set_item(orte_job_data, ljob, jdata);
        /* create an app_context for the debugger daemon */
        app = OBJ_NEW(orte_app_context_t);
        if (NULL != orte_debugger_base.test_daemon) {
            app->app = strdup(orte_debugger_base.test_daemon);
        } else {
            app->app = strdup((char*)MPIR_executable_path);
        }

	jdata->state = ORTE_JOB_STATE_INIT;

        opal_argv_append_nosize(&app->argv, app->app);
        build_debugger_args(app);
        opal_pointer_array_add(jdata->apps, app);
        jdata->num_apps = 1;
        /* setup the mapping policy to bynode so we get one
         * daemon on each node
         */
        jdata->map = OBJ_NEW(orte_job_map_t);
        jdata->map->policy = ORTE_MAPPING_BYNODE;
	jdata->map->npernode = 1;
        /* now go ahead and spawn this job */
        if (ORTE_SUCCESS != (rc = orte_plm.spawn(jdata))) {
            ORTE_ERROR_LOG(rc);
        }
    }
        
 RELEASE:
    /* reset the read or timer event */
    if (0 == orte_debugger_mpirx_check_rate) {
        fifo_active = true;
        opal_event_add(&attach, 0);
    } else if (!MPIR_being_debugged) {
	ORTE_TIMER_EVENT(orte_debugger_mpirx_check_rate, 0, attach_debugger);
    }

    /* notify the debugger that all is ready */
    MPIR_Breakpoint();
}
Beispiel #9
0
/**
 * Initialization of data structures for running under a debugger
 * using an extended MPICH/TotalView parallel debugger interface.  Before the
 * spawn we need to check if we are being run under a TotalView-like
 * debugger; if so then inform applications via an MCA parameter.
 */
void init_before_spawn(orte_job_t *jdata)
{
    char *env_name;
    orte_app_context_t *app;
    int i;
    int32_t ljob;
    char *attach_fifo;

    if (!MPIR_being_debugged && !orte_in_parallel_debugger) {
        /* if we were given a test debugger, then we still want to
         * colaunch it
         */
        if (NULL != orte_debugger_base.test_daemon) {
            opal_output_verbose(2, orte_debugger_base.output,
                                "%s No debugger test daemon specified",
                                ORTE_NAME_PRINT(ORTE_PROC_MY_NAME));
            goto launchit;
        }
        /* if we were given an auto-detect rate, then we want to setup
         * an event so we periodically do the check
         */
        if (0 < orte_debugger_mpirx_check_rate) {
            opal_output_verbose(2, orte_debugger_base.output,
                                "%s Setting debugger attach check rate for %d seconds",
                                ORTE_NAME_PRINT(ORTE_PROC_MY_NAME),
                                orte_debugger_mpirx_check_rate);
            ORTE_TIMER_EVENT(orte_debugger_mpirx_check_rate, 0, attach_debugger);
        } else {
            /* create the attachment FIFO and put it into MPIR, setup readevent */
            /* create a FIFO name in the session dir */
            attach_fifo = opal_os_path(false, orte_process_info.job_session_dir, "debugger_attach_fifo", NULL);
            if ((mkfifo(attach_fifo, FILE_MODE) < 0) && errno != EEXIST) {
                opal_output(0, "CANNOT CREATE FIFO %s: errno %d", attach_fifo, errno);
                free(attach_fifo);
                return;
            }
            strncpy(MPIR_attach_fifo, attach_fifo, MPIR_MAX_PATH_LENGTH - 1);
	    free (attach_fifo);
	    open_fifo ();
        }
        return;
    }
    
 launchit:
    opal_output_verbose(2, orte_debugger_base.output,
                        "%s: Spawned by a debugger",
                        ORTE_NAME_PRINT(ORTE_PROC_MY_NAME));

    /* tell the procs they are being debugged */
    env_name = mca_base_param_environ_variable("orte", 
                                               "in_parallel_debugger", NULL);
    
    for (i=0; i < jdata->apps->size; i++) {
        if (NULL == (app = (orte_app_context_t*)opal_pointer_array_get_item(jdata->apps, i))) {
            continue;
        }
        opal_setenv(env_name, "1", true, &app->env);
    }
    free(env_name);

    /* check if we need to co-spawn the debugger daemons */
    if ('\0' != MPIR_executable_path[0] || NULL != orte_debugger_base.test_daemon) {
        /* can only have one debugger */
        if (NULL != orte_debugger_daemon) {
            opal_output(0, "-------------------------------------------\n"
                        "Only one debugger can be used on a job.\n"
                        "-------------------------------------------\n");
            ORTE_UPDATE_EXIT_STATUS(ORTE_ERROR_DEFAULT_EXIT_CODE);
            return;
        }
        opal_output_verbose(2, orte_debugger_base.output,
                            "%s Cospawning debugger daemons %s",
                            ORTE_NAME_PRINT(ORTE_PROC_MY_NAME),
                            (NULL == orte_debugger_base.test_daemon) ?
                            MPIR_executable_path : orte_debugger_base.test_daemon);
        /* add debugger info to launch message */
        orte_debugger_daemon = OBJ_NEW(orte_job_t);
        /* create a jobid for these daemons - this is done solely
         * to avoid confusing the rest of the system's bookkeeping
         */
        orte_plm_base_create_jobid(orte_debugger_daemon);
        /* flag the job as being debugger daemons */
        orte_debugger_daemon->controls |= ORTE_JOB_CONTROL_DEBUGGER_DAEMON;
        /* unless directed, we do not forward output */
        if (!MPIR_forward_output) {
            orte_debugger_daemon->controls &= ~ORTE_JOB_CONTROL_FORWARD_OUTPUT;
        }
        /* add it to the global job pool */
        ljob = ORTE_LOCAL_JOBID(orte_debugger_daemon->jobid);
        opal_pointer_array_set_item(orte_job_data, ljob, orte_debugger_daemon);
        /* create an app_context for the debugger daemon */
        app = OBJ_NEW(orte_app_context_t);
        if (NULL != orte_debugger_base.test_daemon) {
            app->app = strdup(orte_debugger_base.test_daemon);
        } else {
            app->app = strdup((char*)MPIR_executable_path);
        }
        opal_argv_append_nosize(&app->argv, app->app);
        build_debugger_args(app);
        opal_pointer_array_add(orte_debugger_daemon->apps, app);
        orte_debugger_daemon->num_apps = 1;
    }
    return;
}