コード例 #1
0
static void
dump_element(int to, void *to_arg, Eterm x)
{
    if (is_list(x)) {
	erts_print(to, to_arg, "H" WORD_FMT, list_val(x));
    } else if (is_boxed(x)) {
	erts_print(to, to_arg, "H" WORD_FMT, boxed_val(x));
    } else if (is_immed(x)) {
	if (is_atom(x)) {
	    unsigned char* s = atom_tab(atom_val(x))->name;
	    int len = atom_tab(atom_val(x))->len;
	    int i;

	    erts_print(to, to_arg, "A%X:", atom_tab(atom_val(x))->len);
	    for (i = 0; i < len; i++) {
		erts_putc(to, to_arg, *s++);
	    }
	} else if (is_small(x)) {
	    erts_print(to, to_arg, "I%T", x);
	} else if (is_pid(x)) {
	    erts_print(to, to_arg, "P%T", x);
	} else if (is_port(x)) {
	    erts_print(to, to_arg, "p<%bpu.%bpu>",
		       port_channel_no(x), port_number(x));
	} else if (is_nil(x)) {
	    erts_putc(to, to_arg, 'N');
	}
    }
}
コード例 #2
0
ファイル: bif_code.c プロジェクト: aidanhs/teeterl
term_t bif_run_slice2(term_t Pid, term_t Reductions, process_t *ctx)
{
	process_t *proc;
	term_t retval, retval1;
	term_t res;
	if (!is_pid(Pid) || !is_int(Reductions))
		return A_BADARG;
	proc = proc_lookup(pid_serial(Pid));
	res = proc_main(proc, int_value2(Reductions), &retval);

	if (res == AI_DONE)
	{
		//proc_destroy(proc);
		//- process should not be destroyed now
		//- as we may need to notify links first

		retval1 = marshal_term(retval, proc_gc_pool(ctx));
		result(make_tuple2(AI_DONE, retval1, proc_gc_pool(ctx)));
	}
	else
	{
		if (res == AI_YIELD)
			result(res);
		else
		{
			retval1 = marshal_term(retval, proc_gc_pool(ctx));
			result(make_tuple2(res, retval1, proc_gc_pool(ctx)));
		}
	}

	return AI_OK;
}
コード例 #3
0
ファイル: erl_bif_op.c プロジェクト: HansN/otp
BIF_RETTYPE is_pid_1(BIF_ALIST_1)
{
    if (is_pid(BIF_ARG_1)) {
	BIF_RET(am_true);
    }
    BIF_RET(am_false);
}
コード例 #4
0
ファイル: ipnetns.c プロジェクト: Azzik/iproute2
static int netns_pids(int argc, char **argv)
{
	const char *name;
	char net_path[MAXPATHLEN];
	int netns;
	struct stat netst;
	DIR *dir;
	struct dirent *entry;

	if (argc < 1) {
		fprintf(stderr, "No netns name specified\n");
		return EXIT_FAILURE;
	}
	if (argc > 1) {
		fprintf(stderr, "extra arguments specified\n");
		return EXIT_FAILURE;
	}

	name = argv[0];
	snprintf(net_path, sizeof(net_path), "%s/%s", NETNS_RUN_DIR, name);
	netns = open(net_path, O_RDONLY);
	if (netns < 0) {
		fprintf(stderr, "Cannot open network namespace: %s\n",
			strerror(errno));
		return EXIT_FAILURE;
	}
	if (fstat(netns, &netst) < 0) {
		fprintf(stderr, "Stat of netns failed: %s\n",
			strerror(errno));
		return EXIT_FAILURE;
	}
	dir = opendir("/proc/");
	if (!dir) {
		fprintf(stderr, "Open of /proc failed: %s\n",
			strerror(errno));
		return EXIT_FAILURE;
	}
	while((entry = readdir(dir))) {
		char pid_net_path[MAXPATHLEN];
		struct stat st;
		if (!is_pid(entry->d_name))
			continue;
		snprintf(pid_net_path, sizeof(pid_net_path), "/proc/%s/ns/net",
			entry->d_name);
		if (stat(pid_net_path, &st) != 0)
			continue;
		if ((st.st_dev == netst.st_dev) &&
		    (st.st_ino == netst.st_ino)) {
			printf("%s\n", entry->d_name);
		}
	}
	closedir(dir);
	return EXIT_SUCCESS;
	
}
コード例 #5
0
ファイル: bif_code.c プロジェクト: aidanhs/teeterl
term_t bif_destroy_process1(term_t Pid, process_t *ctx)
{
	process_t *proc;
	if (!is_pid(Pid))
		return A_BADARG;
	proc = proc_lookup(pid_serial(Pid));
	if (proc)
		proc_destroy(proc);
	result(A_TRUE);
	return AI_OK;
}
コード例 #6
0
ファイル: hppfs_kern.c プロジェクト: romanalexander/Trickles
static char *dentry_name(struct dentry *dentry, int extra)
{
	struct dentry *parent;
	char *root, *name;
	const char *seg_name;
	int len, seg_len;

	len = 0;
	parent = dentry;
	while(parent->d_parent != parent){
		if(is_pid(parent))
			len += strlen("pid") + 1;
		else len += parent->d_name.len + 1;
		parent = parent->d_parent;
	}
	
	root = "proc";
	len += strlen(root);
	name = kmalloc(len + extra + 1, GFP_KERNEL);
	if(name == NULL) return(NULL);

	name[len] = '\0';
	parent = dentry;
	while(parent->d_parent != parent){
		if(is_pid(parent)){
			seg_name = "pid";
			seg_len = strlen("pid");
		}
		else {
			seg_name = parent->d_name.name;
			seg_len = parent->d_name.len;
		}

		len -= seg_len + 1;
		name[len] = '/';
		strncpy(&name[len + 1], seg_name, seg_len);
		parent = parent->d_parent;
	}
	strncpy(name, root, strlen(root));
	return(name);
}
コード例 #7
0
ファイル: main.cpp プロジェクト: netblue30/firetools
int main(int argc, char *argv[]) {
	int i;
	
	// parse arguments
	for (i = 1; i < argc; i++) {
		if (strcmp(argv[i], "--debug") == 0)
			arg_debug = 1;
		else if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-?") == 0) {
			usage();
			return 0;
		}
		else if (strcmp(argv[i], "--version") == 0) {
			printf("Firetools version " PACKAGE_VERSION "\n");
			return 0;
		}
		else if (*argv[i] == '-') {
			fprintf(stderr, "Error: invalid option\n");
			usage();
			return 1;
		}		
		else
			break;
	}
	
	// in this moment we should have a pid
	if (i == argc || i != (argc - 1) || !is_pid(argv[i])) {
		fprintf(stderr, "Error: process ID expected\n");
		usage();
		return 1;
	}
	pid_t pid = (pid_t) atoi(argv[i]);

	// initialize resources
	Q_INIT_RESOURCE(firemgr);

	QApplication app(argc, argv);
	MainWindow fm(pid);
	fm.show();
	return app.exec();
}
コード例 #8
0
ファイル: erl_nif.c プロジェクト: a5an0/otp
int enif_is_pid(ErlNifEnv* env, ERL_NIF_TERM term)
{
    return is_pid(term);
}
コード例 #9
0
ファイル: Linux.c プロジェクト: carnil/perl-proc-processtable
void OS_get_table()
{
    /* dir walker storage */
    DIR             *dir;
    struct dirent   *dir_ent, *dir_result;
    
    /* all our storage is going to be here */
    struct obstack  mem_pool;
    
    /* container for scaped process values */
    struct procstat *prs;

    /* string containing our local copy of format_str, elements will be
     * lower cased if we are able to figure them out */
    char            *format_str;

    /* initlize a small memory pool for this function */
    obstack_init(&mem_pool);

    /* put the dirent on the obstack, since it's rather large */
    dir_ent = obstack_alloc(&mem_pool, sizeof(struct dirent));

    if ((dir = opendir("/proc")) == NULL)
        return;

    /* Iterate through all the process entries (numeric) under /proc */
    while(readdir_r(dir, dir_ent, &dir_result) == 0 && dir_result) {

        /* Only look at this file if it's a proc id; that is, all numbers */
        if(!is_pid(dir_result->d_name))
            continue;

        /* allocate container for storing process values */
        prs = obstack_alloc(&mem_pool, sizeof(struct procstat));
        bzero(prs, sizeof(struct procstat));

        /* intilize the format string */
        obstack_printf(&mem_pool, get_string(STR_DEFAULT_FORMAT));
        obstack_1grow(&mem_pool, '\0');
        format_str = (char *) obstack_finish(&mem_pool);

        /* get process' uid/guid */
        get_user_info(dir_result->d_name, format_str, prs, &mem_pool);

        /* scrape /proc/${pid}/stat */
        if (get_proc_stat(dir_result->d_name, format_str, prs, &mem_pool) == false) {
            /* did the pid directory go away mid flight? */
            if (pid_exists(dir_result->d_name, &mem_pool) == false)
                continue;
        }

        /* correct values (times) found in /proc/${pid}/stat */
        fixup_stat_values(format_str, prs);

		/* get process' cmndline */
		get_proc_cmndline(dir_result->d_name, format_str, prs, &mem_pool);

        /* get process' cwd & exec values from the symblink */
        eval_link(dir_result->d_name, "cwd", F_CWD, &prs->cwd, format_str,
            &mem_pool);
        eval_link(dir_result->d_name, "exe", F_EXEC, &prs->exec, format_str,
            &mem_pool);

        /* scapre from /proc/{$pid}/status */
        get_proc_status(dir_result->d_name, format_str, prs, &mem_pool);

		/* calculate precent cpu & mem values */
		calc_prec(format_str, prs, &mem_pool);

        /* Go ahead and bless into a perl object */
        bless_into_proc(format_str, field_names,
            prs->uid,			
            prs->gid,			
            prs->pid,			
            prs->comm,			
            prs->ppid,			
            prs->pgrp,			
            prs->sid,			
            prs->tty,			
            prs->flags,			
            prs->minflt,		
            prs->cminflt,		
            prs->majflt,		
            prs->cmajflt,		
            prs->utime,			
            prs->stime,			
            prs->cutime,		
            prs->cstime,		
            prs->priority,		
            prs->start_time,	
            prs->vsize,			
            prs->rss,			
            prs->wchan,			
	    prs->time,			
	    prs->ctime,			
            prs->state,			
            prs->euid,
            prs->suid,
            prs->fuid,
            prs->egid,
            prs->sgid,
            prs->fgid,
            prs->pctcpu,
            prs->pctmem,
            prs->cmndline,
            prs->exec,
            prs->cwd
        );

        /* we want a new prs, for the next itteration */
        obstack_free(&mem_pool, prs);
    }
    
    closedir(dir);

    /* free all our tempoary memory */
    obstack_free(&mem_pool, NULL);
}
コード例 #10
0
ファイル: ipnetns.c プロジェクト: Azzik/iproute2
static int netns_identify(int argc, char **argv)
{
	const char *pidstr;
	char net_path[MAXPATHLEN];
	int netns;
	struct stat netst;
	DIR *dir;
	struct dirent *entry;

	if (argc < 1) {
		fprintf(stderr, "No pid specified\n");
		return EXIT_FAILURE;
	}
	if (argc > 1) {
		fprintf(stderr, "extra arguments specified\n");
		return EXIT_FAILURE;
	}
	pidstr = argv[0];

	if (!is_pid(pidstr)) {
		fprintf(stderr, "Specified string '%s' is not a pid\n",
			pidstr);
		return EXIT_FAILURE;
	}

	snprintf(net_path, sizeof(net_path), "/proc/%s/ns/net", pidstr);
	netns = open(net_path, O_RDONLY);
	if (netns < 0) {
		fprintf(stderr, "Cannot open network namespace: %s\n",
			strerror(errno));
		return EXIT_FAILURE;
	}
	if (fstat(netns, &netst) < 0) {
		fprintf(stderr, "Stat of netns failed: %s\n",
			strerror(errno));
		return EXIT_FAILURE;
	}
	dir = opendir(NETNS_RUN_DIR);
	if (!dir) {
		/* Succeed treat a missing directory as an empty directory */
		if (errno == ENOENT)
			return EXIT_SUCCESS;

		fprintf(stderr, "Failed to open directory %s:%s\n",
			NETNS_RUN_DIR, strerror(errno));
		return EXIT_FAILURE;
	}

	while((entry = readdir(dir))) {
		char name_path[MAXPATHLEN];
		struct stat st;

		if (strcmp(entry->d_name, ".") == 0)
			continue;
		if (strcmp(entry->d_name, "..") == 0)
			continue;

		snprintf(name_path, sizeof(name_path), "%s/%s",	NETNS_RUN_DIR,
			entry->d_name);

		if (stat(name_path, &st) != 0)
			continue;

		if ((st.st_dev == netst.st_dev) &&
		    (st.st_ino == netst.st_ino)) {
			printf("%s\n", entry->d_name);
		}
	}
	closedir(dir);
	return EXIT_SUCCESS;
	
}
コード例 #11
0
ファイル: port_socket.c プロジェクト: aidanhs/teeterl
apr_status_t port_socket_set_option(port_t *self, term_t opt, term_t value)
{
	port_socket_data_t *data = self->data;
	if (opt == A_EXPECT)
	{
		if (!is_int(value))
			return APR_BADARG;
		data->expected_size = int_value2(value);
		if (data->expected_size < 0)
			return APR_BADARG;

		if (!is_pid(self->owner_in))
			return APR_ENOPROC;

		//enough data may already be there
		if (data->expected_size == 0 && buffer_len(data->in_buf) > 0 ||
			data->expected_size > 0 && buffer_len(data->in_buf) >= data->expected_size)
		{
			int len = (data->expected_size == 0)
				?buffer_len(data->in_buf)
				:data->expected_size;
			xpool_t *tmp = xpool_make(self->pool);
			term_t bin = make_binary(intnum(len), buffer_ptr(data->in_buf), tmp);
			term_t msg = make_tuple3(A_TCP, port_id(self, tmp), bin, tmp);
			process_t *proc = proc_lookup(pid_serial(self->owner_in));

			proc_new_mail(proc, msg);
			buffer_consume(data->in_buf, len);
			xpool_destroy(tmp);
		}
		else
			data->packet_expected = 1;
	}
	else if (opt == A_REQUIRE)
	{
		int size;
		if (!is_int(value))
			return APR_BADARG;
		size = int_value2(value);
		if (size < 0 || size > SOCK_OUTBUF_LEN)
			return APR_BADARG;

		data->required_size = size;

		if (buffer_available(data->out_buf) >= size)
		{
			xpool_t *tmp = xpool_make(self->pool);
			int avail = buffer_available(data->out_buf);
			term_t msg = make_tuple3(A_TCP_SPACE, port_id(self, tmp), intnum(avail), tmp);
			process_t *proc = proc_lookup(pid_serial(self->owner_out));

			//TODO: insure that only owner can send to socket

			proc_new_mail(proc, msg);
			xpool_destroy(tmp);

			data->space_required = 0;
		}
		else
			data->space_required = 1;
	}
	else
		return APR_BADARG;
	return APR_SUCCESS;
}
コード例 #12
0
static void signal_pid_completion(void *tinst, struct user_input_state *s) {
    const char *signame;
    int sig;
    int err;
    uid_t euid;
    gid_t egid;
    int saved_errno = 0;
    pid_t pid;
  
    if(is_empty(s->buf)) {
	/*
	 * Any empty buffer indicates that the user didn't want
	 * to signal the process after all.
	 */

	reset_pid(s);
	user_input_set_state(NULL);
        return;
    }

    if(!is_pid(s->buf)) {
	reset_pid(s);
	user_input_set_error_state("invalid pid");
	return;
    }
    
    pid = atoi(s->buf);

    reset_pid(s);

    sig = top_prefs_get_signal(&signame);
    
    /* Temporarily drop permissions. */
    euid = geteuid();
    egid = getegid();
    
    if(-1 == seteuid(getuid())
       || -1 == setegid(getgid())) {
	user_input_set_error_state("missing setuid bit");
	return;
    }
    
    err = kill(pid, sig);

    if(-1 == err)
	saved_errno = errno;

    if(-1 == seteuid(euid)
       || -1 == setegid(egid)) {
	user_input_set_error_state("restoring setuid bit");
	return;
    }

    switch(saved_errno) {
    case EINVAL:
	user_input_set_error_state("invalid signal");
	return;

    case ESRCH:
	user_input_set_error_state("invalid pid");
	return;

    case EPERM:
	user_input_set_error_state("permission error signaling");
	return;
    }

    user_input_set_state(NULL);
}