コード例 #1
0
static int change_tramp(char **argv, char *output, int output_len)
{
	int pid, fds[2], err;
	struct change_pre_exec_data pe_data;

	err = os_pipe(fds, 1, 0);
	if (err < 0) {
		printk(UM_KERN_ERR "change_tramp - pipe failed, err = %d\n",
		       -err);
		return err;
	}
	pe_data.close_me = fds[0];
	pe_data.stdout = fds[1];
	pid = run_helper(change_pre_exec, &pe_data, argv);

	if (pid > 0)	/* Avoid hang as we won't get data in failure case. */
		read_output(fds[0], output, output_len);

	close(fds[0]);
	close(fds[1]);

	if (pid > 0)
		helper_wait(pid);
	return pid;
}
コード例 #2
0
static void etap_change(int op, unsigned char *addr, unsigned char *netmask,
			int fd)
{
	struct addr_change change;
	char *output;
	int n;

	change.what = op;
	memcpy(change.addr, addr, sizeof(change.addr));
	memcpy(change.netmask, netmask, sizeof(change.netmask));
	CATCH_EINTR(n = write(fd, &change, sizeof(change)));
	if (n != sizeof(change)) {
		printk(UM_KERN_ERR "etap_change - request failed, err = %d\n",
		       errno);
		return;
	}

	output = uml_kmalloc(UM_KERN_PAGE_SIZE, UM_GFP_KERNEL);
	if (output == NULL)
		printk(UM_KERN_ERR "etap_change : Failed to allocate output "
		       "buffer\n");
	read_output(fd, output, UM_KERN_PAGE_SIZE);
	if (output != NULL) {
		printk("%s", output);
		kfree(output);
	}
}
コード例 #3
0
static int
dispatch_stderr(gpointer userdata)
{
    svc_action_t *op = (svc_action_t *) userdata;

    return read_output(op->opaque->stderr_fd, op);
}
コード例 #4
0
static int etap_open(void *data)
{
	struct ethertap_data *pri = data;
	char *output;
	int data_fds[2], control_fds[2], err, output_len;

	err = tap_open_common(pri->dev, pri->gate_addr);
	if (err)
		return err;

	err = socketpair(AF_UNIX, SOCK_DGRAM, 0, data_fds);
	if (err) {
		err = -errno;
		printk(UM_KERN_ERR "etap_open - data socketpair failed - "
		       "err = %d\n", errno);
		return err;
	}

	err = socketpair(AF_UNIX, SOCK_STREAM, 0, control_fds);
	if (err) {
		err = -errno;
		printk(UM_KERN_ERR "etap_open - control socketpair failed - "
		       "err = %d\n", errno);
		goto out_close_data;
	}

	err = etap_tramp(pri->dev_name, pri->gate_addr, control_fds[0],
			 control_fds[1], data_fds[0], data_fds[1]);
	output_len = UM_KERN_PAGE_SIZE;
	output = uml_kmalloc(output_len, UM_GFP_KERNEL);
	read_output(control_fds[0], output, output_len);

	if (output == NULL)
		printk(UM_KERN_ERR "etap_open : failed to allocate output "
		       "buffer\n");
	else {
		printk("%s", output);
		kfree(output);
	}

	if (err < 0) {
		printk(UM_KERN_ERR "etap_tramp failed - err = %d\n", -err);
		goto out_close_control;
	}

	pri->data_fd = data_fds[0];
	pri->control_fd = control_fds[0];
	iter_addresses(pri->dev, etap_open_addr, &pri->control_fd);
	return data_fds[0];

out_close_control:
	close(control_fds[0]);
	close(control_fds[1]);
out_close_data:
	close(data_fds[0]);
	close(data_fds[1]);
	return err;
}
コード例 #5
0
ファイル: slip_user.c プロジェクト: FatSunHYS/OSCourseDesign
static int slip_tramp(char **argv, int fd)
{
	struct slip_pre_exec_data pe_data;
	char *output;
	int status, pid, fds[2], err, output_len;

	err = os_pipe(fds, 1, 0);
	if(err < 0){
		printk("slip_tramp : pipe failed, err = %d\n", -err);
		goto out;
	}

	err = 0;
	pe_data.stdin = fd;
	pe_data.stdout = fds[1];
	pe_data.close_me = fds[0];
	err = run_helper(slip_pre_exec, &pe_data, argv, NULL);
	if(err < 0)
		goto out_close;
	pid = err;

	output_len = page_size();
	output = um_kmalloc(output_len);
	if(output == NULL){
		printk("slip_tramp : failed to allocate output buffer\n");
		os_kill_process(pid, 1);
		err = -ENOMEM;
		goto out_free;
	}

	os_close_file(fds[1]);
	read_output(fds[0], output, output_len);
	printk("%s", output);

	CATCH_EINTR(err = waitpid(pid, &status, 0));
	if(err < 0)
		err = errno;
	else if(!WIFEXITED(status) || (WEXITSTATUS(status) != 0)){
		printk("'%s' didn't exit with status 0\n", argv[0]);
		err = -EINVAL;
	}
	else err = 0;

	os_close_file(fds[0]);

out_free:
	kfree(output);
	return err;

out_close:
	os_close_file(fds[0]);
	os_close_file(fds[1]);
out:
	return err;
}
コード例 #6
0
struct fact_table *run_clips(char *cmds)
{
	write_cmd(cmds);

	if (system(CLIPSCMD)) {
		fprintf(stderr, "Cannot start CLIPS environment");
		exit(EXIT_FAILURE);
	}

	return read_output();
}
コード例 #7
0
ファイル: slip_user.c プロジェクト: PennPanda/linux-repo
static int slip_tramp(char **argv, int fd)
{
	struct slip_pre_exec_data pe_data;
	char *output;
	int pid, fds[2], err, output_len;

	err = os_pipe(fds, 1, 0);
	if (err < 0) {
		printk(UM_KERN_ERR "slip_tramp : pipe failed, err = %d\n",
		       -err);
		goto out;
	}

	err = 0;
	pe_data.stdin = fd;
	pe_data.stdout = fds[1];
	pe_data.close_me = fds[0];
	err = run_helper(slip_pre_exec, &pe_data, argv);
	if (err < 0)
		goto out_close;
	pid = err;

	output_len = UM_KERN_PAGE_SIZE;
	output = kmalloc(output_len, UM_GFP_KERNEL);
	if (output == NULL) {
		printk(UM_KERN_ERR "slip_tramp : failed to allocate output "
		       "buffer\n");
		os_kill_process(pid, 1);
		err = -ENOMEM;
		goto out_free;
	}

	close(fds[1]);
	read_output(fds[0], output, output_len);
	printk("%s", output);

	err = helper_wait(pid, 0, argv[0]);
	close(fds[0]);

out_free:
	kfree(output);
	return err;

out_close:
	close(fds[0]);
	close(fds[1]);
out:
	return err;
}
コード例 #8
0
ファイル: ranking_seneschal.cpp プロジェクト: olivo/BP
bool ranking_synthesis_seneschalt::generate_functions(void)
{
  #if 0
  std::cout << "GENERATE: " << templ << std::endl;
  #endif


  if(instantiate()==nil_exprt())
    return false;

  std::cout << "INPUT IS: " << std::endl;
  system("cat seneschal.input");

  status("Calling seneschal...");
  fine_timet before = current_time();
  system(">seneschal.out ; >seneschal.err; "
         "seneschal seneschal.input 1> seneschal.out 2> seneschal.err");
  solver_time += current_time()-before;
  solver_calls++;


	{
		std::cout << "STDOUT WAS: " << std::endl;
		system("cat seneschal.out");
		std::cout << "STDERR WAS: " << std::endl;
		system("cat seneschal.err");
	}

	exprt rf("nil");
	if(!read_output(rf)) throw ("SENESCHAL ERROR");

//  remove("seneschal.input");
//  remove("seneschal.err");
//  remove("seneschal.out");

  if(rf.id()!="nil")
  {
    if(!extract_ranking_relation(rf))
      return false;

    return true;
  }
  else
    return false;
}
コード例 #9
0
static int etap_open(void *data)
{
	struct ethertap_data *pri = data;
	char *output;
	int data_fds[2], control_fds[2], err, output_len;

	err = tap_open_common(pri->dev, pri->gate_addr);
	if(err) return(err);

	err = os_pipe(data_fds, 0, 0);
	if(err < 0){
		printk("data os_pipe failed - err = %d\n", -err);
		return(err);
	}

	err = os_pipe(control_fds, 1, 0);
	if(err < 0){
		printk("control os_pipe failed - err = %d\n", -err);
		return(err);
	}
	
	err = etap_tramp(pri->dev_name, pri->gate_addr, control_fds[0], 
			 control_fds[1], data_fds[0], data_fds[1]);
	output_len = page_size();
	output = um_kmalloc(output_len);
	read_output(control_fds[0], output, output_len);

	if(output == NULL)
		printk("etap_open : failed to allocate output buffer\n");
	else {
		printk("%s", output);
		kfree(output);
	}

	if(err < 0){
		printk("etap_tramp failed - err = %d\n", -err);
		return(err);
	}

	pri->data_fd = data_fds[0];
	pri->control_fd = control_fds[0];
	iter_addresses(pri->dev, etap_open_addr, &pri->control_fd);
	return(data_fds[0]);
}
コード例 #10
0
ファイル: net_user.c プロジェクト: 12019/hg556a_source
static int change_tramp(char **argv, char *output, int output_len)
{
	int pid, fds[2], err;
	struct change_pre_exec_data pe_data;

	err = os_pipe(fds, 1, 0);
	if(err){
		printk("change_tramp - pipe failed, errno = %d\n", -err);
		return(err);
	}
	pe_data.close_me = fds[0];
	pe_data.stdout = fds[1];
	pid = run_helper(change_pre_exec, &pe_data, argv, NULL);

	close(fds[1]);
	read_output(fds[0], output, output_len);
	waitpid(pid, NULL, 0);	
	return(pid);
}
コード例 #11
0
ファイル: gcr-gnupg-process.c プロジェクト: Distrotech/gcr
static gboolean
on_gnupg_source_status (GcrGnupgProcess *self,
                        GnupgSource *gnupg_source,
                        gint fd)
{
	GByteArray *buffer = g_byte_array_new ();
	gboolean result = TRUE;

	if (!read_output (fd, buffer)) {
		g_warning ("couldn't read status data from gnupg process");
		result = FALSE;
	} else {
		g_string_append_len (gnupg_source->status_buf, (gchar*)buffer->data, buffer->len);
		_gcr_util_parse_lines (gnupg_source->status_buf, buffer->len == 0,
		                       emit_status_for_each_line, self);
	}

	g_byte_array_unref (buffer);
	return result;
}
コード例 #12
0
ファイル: gcr-gnupg-process.c プロジェクト: Distrotech/gcr
static gboolean
on_gnupg_source_output (GcrGnupgProcess *self,
                        GnupgSource *gnupg_source,
                        gint fd)
{
	GByteArray *buffer = g_byte_array_new ();
	gboolean result = TRUE;

	if (!read_output (fd, buffer)) {
		g_warning ("couldn't read output data from gnupg process");
		result = FALSE;
	} else if (buffer->len > 0) {
		g_debug ("received %d bytes of output data", (gint)buffer->len);
		if (self->pv->output != NULL)
			g_output_stream_write_all (self->pv->output, buffer->data, buffer->len,
			                           NULL, gnupg_source->cancellable, NULL);
	}

	g_byte_array_unref (buffer);
	return result;
}
コード例 #13
0
ファイル: slip_user.c プロジェクト: 12019/hg556a_source
static int slip_tramp(char **argv, int fd)
{
	struct slip_pre_exec_data pe_data;
	char *output;
	int status, pid, fds[2], err, output_len;

	err = os_pipe(fds, 1, 0);
	if(err){
		printk("slip_tramp : pipe failed, errno = %d\n", -err);
		return(err);
	}

	err = 0;
	pe_data.stdin = fd;
	pe_data.stdout = fds[1];
	pe_data.close_me = fds[0];
	pid = run_helper(slip_pre_exec, &pe_data, argv, NULL);

	if(pid < 0) err = pid;
	else {
		output_len = page_size();
		output = um_kmalloc(output_len);
		if(output == NULL)
			printk("slip_tramp : failed to allocate output "
			       "buffer\n");

		close(fds[1]);
		read_output(fds[0], output, output_len);
		if(output != NULL){
			printk("%s", output);
			kfree(output);
		}
		if(waitpid(pid, &status, 0) < 0) err = errno;
		else if(!WIFEXITED(status) || (WEXITSTATUS(status) != 0)){
			printk("'%s' didn't exit with status 0\n", argv[0]);
			err = EINVAL;
		}
	}
	return(err);
}
コード例 #14
0
ファイル: parse.c プロジェクト: jkauffman1/bitcoin-iterate
void read_bitcoin_transaction(struct space *space,
			      struct bitcoin_transaction *trans,
			      struct file *f, off_t *poff)
{
	size_t i;
	off_t start = *poff;
	SHA256_CTX sha256;

	trans->version = pull_u32(f, poff);
	trans->input_count = pull_varint(f, poff);
	trans->input = space_alloc_arr(space,
				       struct bitcoin_transaction_input,
				       trans->input_count);
	for (i = 0; i < trans->input_count; i++)
		read_input(space, f, poff, trans->input + i);
	trans->output_count = pull_varint(f, poff);
	trans->output = space_alloc_arr(space,
					struct bitcoin_transaction_output,
					trans->output_count);
	for (i = 0; i < trans->output_count; i++)
               read_output(space, f, poff, trans->output + i);
	trans->lock_time = pull_u32(f, poff);

	/* Bitcoin uses double sha (it's not quite known why...) */
	SHA256_Init(&sha256);
	if (likely(f->mmap)) {
		SHA256_Update(&sha256, f->mmap + start, *poff - start);
	} else {
		u8 *buf = tal_arr(NULL, u8, *poff - start);
		file_read(f, start, *poff - start, buf);
		SHA256_Update(&sha256, buf, *poff - start);
		tal_free(buf);
	}
	SHA256_Final(trans->sha256, &sha256);

	SHA256_Init(&sha256);
	SHA256_Update(&sha256, trans->sha256, sizeof(trans->sha256));
	SHA256_Final(trans->sha256, &sha256);
	trans->len = *poff - start;
}
コード例 #15
0
static void etap_change(int op, unsigned char *addr, unsigned char *netmask,
			int fd)
{
	struct addr_change change;
	char *output;
	int n;

	change.what = op;
	memcpy(change.addr, addr, sizeof(change.addr));
	memcpy(change.netmask, netmask, sizeof(change.netmask));
	n = os_write_file(fd, &change, sizeof(change));
	if(n != sizeof(change))
		printk("etap_change - request failed, err = %d\n", -n);
	output = um_kmalloc(page_size());
	if(output == NULL)
		printk("etap_change : Failed to allocate output buffer\n");
	read_output(fd, output, page_size());
	if(output != NULL){
		printk("%s", output);
		kfree(output);
	}
}
コード例 #16
0
ファイル: execnt.c プロジェクト: TuZZiX/ROS_IDE_inc
void exec_wait()
{
    int i = -1;
    int exit_reason;  /* reason why a command completed */

    /* Wait for a command to complete, while snarfing up any output. */
    while ( 1 )
    {
        /* Check for a complete command, briefly. */
        i = try_wait( 500 );
        /* Read in the output of all running commands. */
        read_output();
        /* Close out pending debug style dialogs. */
        close_alerts();
        /* Process the completed command we found. */
        if ( i >= 0 ) { exit_reason = EXIT_OK; break; }
        /* Check if a command ran out of time. */
        i = try_kill_one();
        if ( i >= 0 ) { exit_reason = EXIT_TIMEOUT; break; }
    }

    /* We have a command... process it. */
    {
        DWORD exit_code;
        timing_info time;
        int rstat;

        /* The time data for the command. */
        record_times( cmdtab[ i ].pi.hProcess, &time );

        /* Removed the used temporary command file. */
        if ( cmdtab[ i ].command_file->size )
            unlink( cmdtab[ i ].command_file->value );

        /* Find out the process exit code. */
        GetExitCodeProcess( cmdtab[ i ].pi.hProcess, &exit_code );

        /* The dispossition of the command. */
        if ( interrupted() )
            rstat = EXEC_CMD_INTR;
        else if ( exit_code )
            rstat = EXEC_CMD_FAIL;
        else
            rstat = EXEC_CMD_OK;

        /* Call the callback, may call back to jam rule land. */
        (*cmdtab[ i ].func)( cmdtab[ i ].closure, rstat, &time,
            cmdtab[ i ].buffer_out->value, cmdtab[ i ].buffer_err->value,
            exit_reason );

        /* Clean up our child process tracking data. No need to clear the
         * temporary command file name as it gets reused.
         */
        closeWinHandle( &cmdtab[ i ].pi.hProcess );
        closeWinHandle( &cmdtab[ i ].pi.hThread );
        closeWinHandle( &cmdtab[ i ].pipe_out[ EXECCMD_PIPE_READ ] );
        closeWinHandle( &cmdtab[ i ].pipe_out[ EXECCMD_PIPE_WRITE ] );
        closeWinHandle( &cmdtab[ i ].pipe_err[ EXECCMD_PIPE_READ ] );
        closeWinHandle( &cmdtab[ i ].pipe_err[ EXECCMD_PIPE_WRITE ] );
        string_renew( cmdtab[ i ].buffer_out );
        string_renew( cmdtab[ i ].buffer_err );
    }
}
コード例 #17
0
ファイル: services_linux.c プロジェクト: jjzhang/pacemaker
gboolean
services_os_action_execute(svc_action_t* op, gboolean synchronous)
{
    int rc, lpc;
    int stdout_fd[2];
    int stderr_fd[2];

    if (pipe(stdout_fd) < 0) {
        crm_err( "pipe() failed");
    }

    if (pipe(stderr_fd) < 0) {
        crm_err( "pipe() failed");
    }

    op->pid = fork();
    switch (op->pid) {
    case -1:
        crm_err( "fork() failed");
        close(stdout_fd[0]);
        close(stdout_fd[1]);
        close(stderr_fd[0]);
        close(stderr_fd[1]);
        return FALSE;

    case 0:                /* Child */
        /* Man: The call setpgrp() is equivalent to setpgid(0,0)
         * _and_ compiles on BSD variants too
         * need to investigate if it works the same too.
         */
        setpgid(0, 0);
        close(stdout_fd[0]);
        close(stderr_fd[0]);
        if (STDOUT_FILENO != stdout_fd[1]) {
            if (dup2(stdout_fd[1], STDOUT_FILENO) != STDOUT_FILENO) {
                crm_err( "dup2() failed (stdout)");
            }
            close(stdout_fd[1]);
        }
        if (STDERR_FILENO != stderr_fd[1]) {
            if (dup2(stderr_fd[1], STDERR_FILENO) != STDERR_FILENO) {
                crm_err( "dup2() failed (stderr)");
            }
            close(stderr_fd[1]);
        }

        /* close all descriptors except stdin/out/err and channels to logd */
        for (lpc = getdtablesize() - 1; lpc > STDERR_FILENO; lpc--) {
            close(lpc);
        }

        /* Setup environment correctly */
        add_OCF_env_vars(op);

        /* execute the RA */
        execvp(op->opaque->exec, op->opaque->args);

        switch (errno) { /* see execve(2) */
        case ENOENT:  /* No such file or directory */
        case EISDIR:   /* Is a directory */
            rc = PCMK_OCF_NOT_INSTALLED;
            break;
        case EACCES:   /* permission denied (various errors) */
            rc = PCMK_OCF_INSUFFICIENT_PRIV;
            break;
        default:
            rc = PCMK_OCF_UNKNOWN_ERROR;
            break;
        }
        _exit(rc);
    }

    /* Only the parent reaches here */
    close(stdout_fd[1]);
    close(stderr_fd[1]);

    op->opaque->stdout_fd = stdout_fd[0];
    set_fd_opts(op->opaque->stdout_fd, O_NONBLOCK);

    op->opaque->stderr_fd = stderr_fd[0];
    set_fd_opts(op->opaque->stderr_fd, O_NONBLOCK);

    if (synchronous) {
        int status = 0;
        int timeout = (1 + op->timeout) / 1000;
        crm_trace("Waiting for %d", op->pid);
        while ((op->timeout < 0 || timeout > 0) && waitpid(op->pid, &status, WNOHANG) <= 0) {
            sleep(1);
            read_output(op->opaque->stdout_fd, op);
            read_output(op->opaque->stderr_fd, op);
            timeout--;
        }

        crm_trace("Child done: %d", op->pid);
        if (timeout == 0) {
            int killrc = kill(op->pid, 9 /*SIGKILL*/);

            op->rc = PCMK_OCF_UNKNOWN_ERROR;
            op->status = PCMK_LRM_OP_TIMEOUT;
            crm_warn("%s:%d - timed out after %dms", op->id, op->pid,
                    op->timeout);

            if (killrc && errno != ESRCH) {
                crm_err("kill(%d, KILL) failed: %d", op->pid, errno);
            }

        } else if (WIFEXITED(status)) {
            op->status = PCMK_LRM_OP_DONE;
            op->rc = WEXITSTATUS(status);
            crm_info("Managed %s process %d exited with rc=%d", op->id, op->pid,
                   op->rc);

        } else if (WIFSIGNALED(status)) {
            int signo = WTERMSIG(status);
            op->status = PCMK_LRM_OP_ERROR;
            crm_err("Managed %s process %d exited with signal=%d", op->id,
                   op->pid, signo);
        }
#ifdef WCOREDUMP
        if (WCOREDUMP(status)) {
            crm_err("Managed %s process %d dumped core", op->id, op->pid);
        }
#endif

        read_output(op->opaque->stdout_fd, op);
        read_output(op->opaque->stderr_fd, op);

    } else {
        crm_trace("Async waiting for %d - %s", op->pid, op->opaque->exec);
        mainloop_add_child(op->pid, op->timeout, op->id, op,
                           operation_finished);

        op->opaque->stdout_gsource = mainloop_add_fd(op->id,
            op->opaque->stdout_fd,
            op,
            &stdout_callbacks);

        op->opaque->stderr_gsource = mainloop_add_fd(op->id,
            op->opaque->stderr_fd,
            op,
            &stderr_callbacks);
    }

    return TRUE;
}
コード例 #18
0
ファイル: moga.c プロジェクト: AnkitMish/moga-sw
void processor_run(int iter_num, char folder[], char inputs[]) {
    
    //initialize variables (make global only if using private copies in this subroutine (OpenMPI))
    double A[3], rho[3], B[3], lambda[2], gamma_3b[2]; //allocates variables, note/recall equilvalences in gammas/rmax_3bs
    double err_a, elast, chi_sq; // allocates objectives, namely error in a, elastic (multiply these to get single objective) and chi_sq
    char file[200], path[200], c,dc[20];
    int bands;

    // create folder for this instance of gulp run (now done in first copy cell step)

   //printf("I am processor = %d and I will create this %s folder\n", myid + 1, folder);

    //if (iter_num == 0)
    	mkdir(folder,S_IRWXU);
    // copy cell, forcefield, etc. into folder
    
    const char *gulp_in[2] = {"cell","forcefield"};
    int i;
    
    for(i=0;i<2;i++) {      // copies "cell" and "forcefield" into new folder
        strcpy(file,gulp_in[i]);
        strcpy(path,folder);
        strcat(path,"/");
        strcat(path,file);
        
        file_copy(file,path);
    }
    
    chdir(folder);   //enter folder

    // scans line for variables
    sscanf(inputs,"%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf",&A[0],&A[1],&A[2],&rho[0],&rho[1],&rho[2],&B[0],&B[1],&B[2],&lambda[0],&lambda[1],&gamma_3b[0],&gamma_3b[1]);

    modify_input(A,rho,B,lambda,gamma_3b); // modifies "forcefield" file

    FILE *gulp_input;

    gulp_input = fopen("in.gulp","w"); // create gulp input file
    fprintf(gulp_input, "optim relax conp comp phon nofreq\n");
    fclose(gulp_input);
    
    strcpy(file,"cell");
    strcpy(path,"in.gulp");
    file_copy(file,path); // appends "cell" to in.gulp
    
    strcpy(file,"forcefield");
    file_copy(file,path); // appends "forcefield" to in.gulp
   
    gulp_input = fopen("in.gulp","a");
    // 183 105 211
    fclose(gulp_input);

    const char *segment[3] = {"G_M","M_K","K_G"};
    
    for(i=0;i<3;i++) {
        
        strcpy(dc,segment[i]);
        mkdir(dc,S_IRWXU); // creates directory for segment
        
        strcpy(file,"in.gulp");
        strcpy(path,dc);
        strcat(path,"/");
        strcat(path,file);  // copies in.gulp into new directory
        
        file_copy(file,path);
        
        FILE *seg_in;
        seg_in = fopen(path,"a");
        
        if (i == 0) { // I know this method of setup is dumb, but it was a lot easier than modifying my previous method.
            fprintf(seg_in,"dispersion 1 %d \n", 183); // what is 183 here? Better as variable?
            fprintf(seg_in,"0.0 0.0 0.0 to 0.5 0.0 0.0\n");
        } else if (i == 1) {
            fprintf(seg_in,"dispersion 1 %d \n", 106); // what is 183 here? Better as variable?
            fprintf(seg_in,"0.5 0.0 0.0 to 0.33333 0.33333 0.0\n");
        } else if (i == 2) {
            fprintf(seg_in,"dispersion 1 %d \n", 211); // what is 183 here? Better as variable?
            fprintf(seg_in,"0.33333 0.33333 0.0 to 0.0 0.0 0.0\n");
        }
        
        fprintf(seg_in,"output phon phonon\n");
        fprintf(seg_in,"shrink 5 5 5\n\n");
        
        fclose(seg_in);
        
        chdir(dc); // enter segment directory
        
        system("/home/pv-02/hpc-23/kris658/SOFTWARE/GULP/Src/Linux/gulp < in.gulp > afterfit.out"); // runs gulp
        
        chdir(".."); // exits new directory
    }
    
    chdir(segment[0]); // arbitrary choice of segment for objectives 1 & 2 (same for all)
    read_output(&err_a,&elast); // extracts objective 1 & 2: error in lattice constant a and error in elastic constant
    
    //printf("error_a: %lf\n", err_a);
    //printf("elast: %lf\n", elast);
    
    chdir(".."); // moves back to 'folder' directory to read all segments for phonon dispersion chi squared calculation
    chi_sq = phonon_disp();  // may need to modify paths (don't know where phonon_disp() is placed by gulp)

    FILE *output;

    output = fopen("ga_line","w"); // writes to a single line text document ga_line -> sloppy workaround to avoid race conditions. Find something more intellegent!

    fprintf(output,"%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf\n",A[0],A[1],A[2],rho[0],rho[1],rho[2],B[0],B[1],B[2],lambda[0],lambda[1],gamma_3b[0],gamma_3b[1],err_a,elast,chi_sq);
    
    chdir("..");
    fclose(output);
    
   
    
}
コード例 #19
0
gboolean
services_os_action_execute(svc_action_t * op, gboolean synchronous)
{
    int rc, lpc;
    int stdout_fd[2];
    int stderr_fd[2];
    sigset_t mask;
    sigset_t old_mask;

    if (pipe(stdout_fd) < 0) {
        crm_err("pipe() failed");
    }

    if (pipe(stderr_fd) < 0) {
        crm_err("pipe() failed");
    }

    if (synchronous) {
        sigemptyset(&mask);
        sigaddset(&mask, SIGCHLD);
        sigemptyset(&old_mask);

        if (sigprocmask(SIG_BLOCK, &mask, &old_mask) < 0) {
            crm_perror(LOG_ERR, "sigprocmask() failed");
        }
    }

    op->pid = fork();
    switch (op->pid) {
        case -1:
            crm_err("fork() failed");
            close(stdout_fd[0]);
            close(stdout_fd[1]);
            close(stderr_fd[0]);
            close(stderr_fd[1]);
            return FALSE;

        case 0:                /* Child */
            /* Man: The call setpgrp() is equivalent to setpgid(0,0)
             * _and_ compiles on BSD variants too
             * need to investigate if it works the same too.
             */
            setpgid(0, 0);
            close(stdout_fd[0]);
            close(stderr_fd[0]);
            if (STDOUT_FILENO != stdout_fd[1]) {
                if (dup2(stdout_fd[1], STDOUT_FILENO) != STDOUT_FILENO) {
                    crm_err("dup2() failed (stdout)");
                }
                close(stdout_fd[1]);
            }
            if (STDERR_FILENO != stderr_fd[1]) {
                if (dup2(stderr_fd[1], STDERR_FILENO) != STDERR_FILENO) {
                    crm_err("dup2() failed (stderr)");
                }
                close(stderr_fd[1]);
            }

            /* close all descriptors except stdin/out/err and channels to logd */
            for (lpc = getdtablesize() - 1; lpc > STDERR_FILENO; lpc--) {
                close(lpc);
            }

#if SUPPORT_CIBSECRETS
            if (replace_secret_params(op->rsc, op->params) < 0) {
                /* replacing secrets failed! */
                if (safe_str_eq(op->action,"stop")) {
                    /* don't fail on stop! */
                    crm_info("proceeding with the stop operation for %s", op->rsc);

                } else {
                    crm_err("failed to get secrets for %s, "
                            "considering resource not configured", op->rsc);
                    _exit(PCMK_OCF_NOT_CONFIGURED);
                }
            }
#endif
            /* Setup environment correctly */
            add_OCF_env_vars(op);

            /* execute the RA */
            execvp(op->opaque->exec, op->opaque->args);

            switch (errno) {    /* see execve(2) */
                case ENOENT:   /* No such file or directory */
                case EISDIR:   /* Is a directory */
                    rc = PCMK_OCF_NOT_INSTALLED;
#if SUPPORT_NAGIOS
                    if (safe_str_eq(op->standard, "nagios")) {
                        rc = NAGIOS_NOT_INSTALLED;
                    }
#endif
                    break;
                case EACCES:   /* permission denied (various errors) */
                    rc = PCMK_OCF_INSUFFICIENT_PRIV;
#if SUPPORT_NAGIOS
                    if (safe_str_eq(op->standard, "nagios")) {
                        rc = NAGIOS_INSUFFICIENT_PRIV;
                    }
#endif
                    break;
                default:
                    rc = PCMK_OCF_UNKNOWN_ERROR;
                    break;
            }
            _exit(rc);
    }

    /* Only the parent reaches here */
    close(stdout_fd[1]);
    close(stderr_fd[1]);

    op->opaque->stdout_fd = stdout_fd[0];
    set_fd_opts(op->opaque->stdout_fd, O_NONBLOCK);

    op->opaque->stderr_fd = stderr_fd[0];
    set_fd_opts(op->opaque->stderr_fd, O_NONBLOCK);

    if (synchronous) {
        int status = 0;
        int timeout = op->timeout;
        int sfd = -1;
        time_t start = -1;
        struct pollfd fds[3];
        int wait_rc = 0;

        sfd = signalfd(-1, &mask, 0);
        if (sfd < 0) {
            crm_perror(LOG_ERR, "signalfd() failed");
        }

        fds[0].fd = op->opaque->stdout_fd;
        fds[0].events = POLLIN;
        fds[0].revents = 0;

        fds[1].fd = op->opaque->stderr_fd;
        fds[1].events = POLLIN;
        fds[1].revents = 0;

        fds[2].fd = sfd;
        fds[2].events = POLLIN;
        fds[2].revents = 0;

        crm_trace("Waiting for %d", op->pid);
        start = time(NULL);
        do {
            int poll_rc = poll(fds, 3, timeout);

            if (poll_rc > 0) {
                if (fds[0].revents & POLLIN) {
                    read_output(op->opaque->stdout_fd, op);
                }

                if (fds[1].revents & POLLIN) {
                    read_output(op->opaque->stderr_fd, op);
                }

                if (fds[2].revents & POLLIN) {
                    struct signalfd_siginfo fdsi;
                    ssize_t s;

                    s = read(sfd, &fdsi, sizeof(struct signalfd_siginfo));
                    if (s != sizeof(struct signalfd_siginfo)) {
                        crm_perror(LOG_ERR, "Read from signal fd %d failed", sfd);

                    } else if (fdsi.ssi_signo == SIGCHLD) {
                        wait_rc = waitpid(op->pid, &status, WNOHANG);

                        if (wait_rc < 0){
                            crm_perror(LOG_ERR, "waitpid() for %d failed", op->pid);

                        } else if (wait_rc > 0) {
                            break;
                        }
                    }
                }

            } else if (poll_rc == 0) {
                timeout = 0;
                break;

            } else if (poll_rc < 0) {
                if (errno != EINTR) {
                    crm_perror(LOG_ERR, "poll() failed");
                    break;
                }
            }

            timeout = op->timeout - (time(NULL) - start) * 1000;

        } while ((op->timeout < 0 || timeout > 0));

        crm_trace("Child done: %d", op->pid);
        if (wait_rc <= 0) {
            int killrc = kill(op->pid, SIGKILL);

            op->rc = PCMK_OCF_UNKNOWN_ERROR;
            if (op->timeout > 0 && timeout <= 0) {
                op->status = PCMK_LRM_OP_TIMEOUT;
                crm_warn("%s:%d - timed out after %dms", op->id, op->pid, op->timeout);

            } else {
                op->status = PCMK_LRM_OP_ERROR;
            }

            if (killrc && errno != ESRCH) {
                crm_err("kill(%d, KILL) failed: %d", op->pid, errno);
            }
            /*
             * From sigprocmask(2):
             * It is not possible to block SIGKILL or SIGSTOP.  Attempts to do so are silently ignored.
             *
             * This makes it safe to skip WNOHANG here
             */
            waitpid(op->pid, &status, 0);

        } else if (WIFEXITED(status)) {
            op->status = PCMK_LRM_OP_DONE;
            op->rc = WEXITSTATUS(status);
            crm_info("Managed %s process %d exited with rc=%d", op->id, op->pid, op->rc);

        } else if (WIFSIGNALED(status)) {
            int signo = WTERMSIG(status);

            op->status = PCMK_LRM_OP_ERROR;
            crm_err("Managed %s process %d exited with signal=%d", op->id, op->pid, signo);
        }
#ifdef WCOREDUMP
        if (WCOREDUMP(status)) {
            crm_err("Managed %s process %d dumped core", op->id, op->pid);
        }
#endif

        read_output(op->opaque->stdout_fd, op);
        read_output(op->opaque->stderr_fd, op);

        close(op->opaque->stdout_fd);
        close(op->opaque->stderr_fd);
        close(sfd);

        if (sigismember(&old_mask, SIGCHLD) == 0) {
            if (sigprocmask(SIG_UNBLOCK, &mask, NULL) < 0) {
                crm_perror(LOG_ERR, "sigprocmask() to unblocked failed");
            }
        }

    } else {
        crm_trace("Async waiting for %d - %s", op->pid, op->opaque->exec);
        mainloop_child_add(op->pid, op->timeout, op->id, op, operation_finished);

        op->opaque->stdout_gsource = mainloop_add_fd(op->id,
                                                     G_PRIORITY_LOW,
                                                     op->opaque->stdout_fd, op, &stdout_callbacks);

        op->opaque->stderr_gsource = mainloop_add_fd(op->id,
                                                     G_PRIORITY_LOW,
                                                     op->opaque->stderr_fd, op, &stderr_callbacks);
    }

    return TRUE;
}
コード例 #20
0
int main(int ac, char *av[])
{
	int ret=0;

	if(ac != 2 && ac != 3){
		usage(av[0]);
		return -1;
	}
	if(strncmp(INIT, av[1], strlen(INIT)) == 0){
		if(init_gpio() == -1)
			return -1;
	}
	else if(strncmp(POWER, av[1], strlen(POWER)) == 0){
		if(ac == 2){
			if((ret = read_register(M_POWER)) == -1)
				return -1;
			printf("%d\n", ret);
		}
		else{
			if((ret = write_register(av[2], M_POWER)) == -1)
				return -1;
		}
	}
	else if(strncmp(RESET1, av[1], strlen(RESET1)) == 0){
		if(ac == 2){
			if((ret = read_register(M_RESET1)) == -1)
				return -1;
			printf("%d\n", ret);
		}
		else{
			if((ret = write_register(av[2], M_RESET1)) == -1)
				return -1;
		}
	}
	else if(strncmp(RESET2, av[1], strlen(RESET2)) == 0){
		if(ac == 2){
			if((ret = read_register(M_RESET2)) == -1)
				return -1;
			printf("%d\n", ret);
		}
		else{
			if((ret = write_register(av[2], M_RESET2)) == -1)
				return -1;
		}
	}
	else if(strncmp(USBRST, av[1], strlen(USBRST)) == 0){
		if(ac == 2){
			if((ret = read_register(M_USBRST)) == -1)
				return -1;
			printf("%d\n", ret);
		}
		else{
			if((ret = write_register(av[2], M_USBRST)) == -1)
				return -1;
		}
	}
	else if(strncmp(UARTINI, av[1], strlen(UARTINI)) == 0){
	}
	else if(strncmp(AREAIND, av[1], strlen(AREAIND)) == 0){
	}
	else if(strncmp(PSHOLD, av[1], strlen(PSHOLD)) == 0){
	}
	else if(strncmp(RSTCHK, av[1], strlen(RSTCHK)) == 0){
	}
	else if(strncmp(RI, av[1], strlen(RI)) == 0){
	}
	else if(strncmp(FUPSTS, av[1], strlen(FUPSTS)) == 0){
	}
	else if(strncmp(ANT0, av[1], strlen(ANT0)) == 0){
	}
	else if(strncmp(ANT1, av[1], strlen(ANT1)) == 0){
	}
	else if(strncmp(MOSIND, av[1], strlen(MOSIND)) == 0){
	}
	else if(strncmp(RAW, av[1], strlen(RAW)) == 0){
		unsigned char val[2];

		if(read_gpio(val) < 0)
			return -1;
		printf("input: %02x %02x\n", val[1], val[0]);
		if(read_config(val) < 0)
			return -1;
		printf("config: %02x %02x\n", val[1], val[0]);
		if(read_output(val) < 0)
			return -1;
		printf("output: %02x %02x\n", val[1], val[0]);
	}
	else{
		usage(av[0]);
		return -1;
	}

	return ret;
}
コード例 #21
0
int main() {
    /*  First we need to create XML descriptions of the Extents that we mean to use.  For this
        example we will use two ExtentTypes--one for reads and one for writes.  DataSeries doesn't
        like to mix different types of records, so we need separate types for reads and writes if
        we want each field to be non-null. */

    const char* read_xml =
            "<ExtentType name=\"ExtentType1\">"
            "  <field name=\"timestamp\" type=\"int64\" />"
            "  <field name=\"requested_bytes\" type=\"int64\" />"
            "  <field name=\"actual_bytes\" type=\"int64\" />"
            "</ExtentType>\n";

    const char* write_xml =
            "<ExtentType name=\"ExtentType2\">"
            "  <field name=\"timestamp\" type=\"int64\" />"
            "  <field name=\"bytes\" type=\"int64\" />"
            "</ExtentType>\n";

    /*  Next we need to put both of these in an ExtentType library which
        will be the first thing written to the file. */

    ExtentTypeLibrary types_for_file;
    const ExtentType::Ptr read_type = types_for_file.registerTypePtr(read_xml);
    const ExtentType::Ptr write_type = types_for_file.registerTypePtr(write_xml);

    /*  Then we open a file to write the records to. This will overwrite an existing file.
        DataSeries files can not be updated once closed. */

    DataSeriesSink output_file("writing_a_file.ds");
    output_file.writeExtentLibrary(types_for_file);

    /*  Now, we create structures for writing the individual
        types.  Note that each type of extent is stored separately.
        The ExtentSeries will allow us to set the fields in each
        record that we create.  We'll split the records into
        approximately 1024 byte chunks uncompressed. */

    ExtentSeries read_series;
    OutputModule read_output(output_file, read_series, read_type, 1024);
    ExtentSeries write_series;
    OutputModule write_output(output_file, write_series, write_type, 1024);

    /*  These are handles to the fields in the "current record" of
        each ExtentSeries. */

    Int64Field read_timestamp(read_series, "timestamp");
    Int64Field read_requested_bytes(read_series, "requested_bytes");
    Int64Field read_actual_bytes(read_series, "actual_bytes");

    Int64Field write_timestamp(write_series, "timestamp");
    Int64Field write_bytes(write_series, "bytes");

    BOOST_FOREACH(const char* record, original_records) {
        boost::cmatch match;
        boost::regex_match(record, record_regex);
        if (match[submatches::read].matched) {
            /*  Create a new record and set its fields. */
            read_output.newRecord();
            read_timestamp.set(get_field(match, submatches::read_timestamp));
            read_requested_bytes.set(get_field(match, submatches::read_requested));
            read_actual_bytes.set(get_field(match, submatches::read_actual));
        } else if (match[submatches::write].matched) {
            /*  Create a new record and set its fields. */
            write_output.newRecord();
            write_timestamp.set(get_field(match, submatches::write_timestamp));
            write_bytes.set(get_field(match, submatches::write_bytes));
        }
    }
コード例 #22
0
ファイル: execnt.c プロジェクト: 4ukuta/core
int exec_wait()
{
    int i = -1;

    /* Handle naive make1() which does not know if cmds are running. */
    if ( !cmdsrunning )
        return 0;

    /* Wait for a command to complete, while snarfing up any output. */
    do
    {
        /* Check for a complete command, briefly. */
        i = try_wait(500);
        /* Read in the output of all running commands. */
        read_output();
        /* Close out pending debug style dialogs. */
        close_alerts();
        /* Check if a command ran out of time. */
        if ( i < 0 ) i = try_kill_one();
    }
    while ( i < 0 );

    /* We have a command... process it. */
    --cmdsrunning;
    {
        timing_info time;
        int rstat;

        /* The time data for the command. */
        record_times( cmdtab[ i ].pi.hProcess, &time );

        /* Clear the temp file. */
        if ( cmdtab[ i ].tempfile_bat )
        {
            unlink( cmdtab[ i ].tempfile_bat );
            BJAM_FREE( cmdtab[ i ].tempfile_bat );
            cmdtab[ i ].tempfile_bat = NULL;
        }

        /* Find out the process exit code. */
        GetExitCodeProcess( cmdtab[ i ].pi.hProcess, &cmdtab[ i ].exit_code );

        /* The dispossition of the command. */
        if ( intr )
            rstat = EXEC_CMD_INTR;
        else if ( cmdtab[ i ].exit_code != 0 )
            rstat = EXEC_CMD_FAIL;
        else
            rstat = EXEC_CMD_OK;

        /* Output the action block. */
        out_action(
            cmdtab[ i ].action.size     > 0 ? cmdtab[ i ].action.value     : 0,
            cmdtab[ i ].target.size     > 0 ? cmdtab[ i ].target.value     : 0,
            cmdtab[ i ].command.size    > 0 ? cmdtab[ i ].command.value    : 0,
            cmdtab[ i ].buffer_out.size > 0 ? cmdtab[ i ].buffer_out.value : 0,
            cmdtab[ i ].buffer_err.size > 0 ? cmdtab[ i ].buffer_err.value : 0,
            cmdtab[ i ].exit_reason );

        /* Call the callback, may call back to jam rule land. Assume -p0 in
         * effect so only pass buffer containing merged output.
         */
        (*cmdtab[ i ].func)(
            cmdtab[ i ].closure,
            rstat,
            &time,
            cmdtab[ i ].command.value,
            cmdtab[ i ].buffer_out.value );

        /* Clean up the command data, process, etc. */
        string_free( &cmdtab[ i ].action  ); string_new( &cmdtab[ i ].action  );
        string_free( &cmdtab[ i ].target  ); string_new( &cmdtab[ i ].target  );
        string_free( &cmdtab[ i ].command ); string_new( &cmdtab[ i ].command );
        if ( cmdtab[ i ].pi.hProcess   ) { CloseHandle( cmdtab[ i ].pi.hProcess   ); cmdtab[ i ].pi.hProcess   = 0; }
        if ( cmdtab[ i ].pi.hThread    ) { CloseHandle( cmdtab[ i ].pi.hThread    ); cmdtab[ i ].pi.hThread    = 0; }
        if ( cmdtab[ i ].pipe_out[ 0 ] ) { CloseHandle( cmdtab[ i ].pipe_out[ 0 ] ); cmdtab[ i ].pipe_out[ 0 ] = 0; }
        if ( cmdtab[ i ].pipe_out[ 1 ] ) { CloseHandle( cmdtab[ i ].pipe_out[ 1 ] ); cmdtab[ i ].pipe_out[ 1 ] = 0; }
        if ( cmdtab[ i ].pipe_err[ 0 ] ) { CloseHandle( cmdtab[ i ].pipe_err[ 0 ] ); cmdtab[ i ].pipe_err[ 0 ] = 0; }
        if ( cmdtab[ i ].pipe_err[ 1 ] ) { CloseHandle( cmdtab[ i ].pipe_err[ 1 ] ); cmdtab[ i ].pipe_err[ 1 ] = 0; }
        string_free( &cmdtab[ i ].buffer_out ); string_new( &cmdtab[ i ].buffer_out );
        string_free( &cmdtab[ i ].buffer_err ); string_new( &cmdtab[ i ].buffer_err );
        cmdtab[ i ].exit_code = 0;
        cmdtab[ i ].exit_reason = EXIT_OK;
    }

    return 1;
}