Ejemplo n.º 1
0
Archivo: nlmon.c Proyecto: el8/nlmon
static int setup_netlink(void)
{
	int rc, id, rcvbufsz = 0;
	struct sockaddr_nl nla;
	socklen_t len;

	nl_fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC);
	if (nl_fd < 0)
		DIE_PERROR("netlink socket failed");

	memset(&nla, 0, sizeof(nla));
	nla.nl_family = AF_NETLINK;

	rc = bind(nl_fd, (struct sockaddr *) &nla, sizeof(struct sockaddr_nl));
	if (rc < 0)
		DIE_PERROR("netlink bind failed");

	len = sizeof(int);
	if (getsockopt(nl_fd, SOL_SOCKET, SO_RCVBUF, &rcvbufsz, &len) < 0)
		fprintf(stderr, "Unable to get socket rcv buf size\n");
	else
		DEBUG("receive buffer size: %d\n", rcvbufsz);

	id = get_family_id(nl_fd);
	if (!id)
		DIE_PERROR("Error getting family id");

	nl_id = id;
	DEBUG("family id %d\n", nl_id);
	return 0;
}
Ejemplo n.º 2
0
bool fpa_simplifier_plugin::reduce(func_decl * f, unsigned num_args, expr * const * args, expr_ref & result) {
    set_reduce_invoked();    

    SASSERT(f->get_family_id() == get_family_id());

    return m_rw.mk_app_core(f, num_args, args, result) == BR_DONE;
}
Ejemplo n.º 3
0
 std::ostream& theory::display_flat_app(std::ostream & out, app * n) const {
     func_decl * d = n->get_decl();
     if (n->get_num_args() == 0) {
         out << d->get_name();
         display_parameters(out, d->get_num_parameters(), d->get_parameters());
     }
     else if (n->get_family_id() == get_family_id()) {
         out << "(" << d->get_name();
         display_parameters(out, d->get_num_parameters(), d->get_parameters());
         ptr_buffer<app> todo;
         todo.push_back(n);
         while (!todo.empty()) {
             n = todo.back();
             todo.pop_back();
             unsigned num = n->get_num_args();
             for (unsigned i = 0; i < num; i++) {
                 app * arg = to_app(n->get_arg(i));
                 if (d->is_associative() && arg->get_decl() == d) {
                     todo.push_back(arg);
                 }
                 else {
                     out << " ";
                     display_app(out, arg);
                 }
             }
         }
         out << ")";
     }
     else {
         out << "#" << n->get_id();
     }
     return out;
 }
Ejemplo n.º 4
0
int open_nl_socket(void)
{
	int fd;
	struct sockaddr_nl local;

	fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC);
	if (fd < 0) {
		printf("Error opening socket (%d)\n", errno);
		return -1;
	}
	printf("fd:%d\n", fd);

	memset(&local, 0, sizeof(local));
	local.nl_family = AF_NETLINK;

	if (bind(fd, (struct sockaddr *) &local, sizeof(local)) < 0) {
		printf("Error binding socket (%d)\n", errno);
		close(fd);
		return -1;
	}
	printf("bind done\n");

	/* Retrieve netlink family Id */
	nl_family_id = get_family_id(fd);
	if (nl_family_id < 0) {
		printf("Error: Could not retreive netlink family id\n");
		close(fd);
		return -1;
	}

	return fd;
}
Ejemplo n.º 5
0
int
genl_client_init ()
{
  reset_nl_attrs ();
  create_nl_socket ();
  get_family_id ();
  return 0;
}
Ejemplo n.º 6
0
 sort* external_relation_plugin::get_relation_sort(relation_signature const& sig) {
     vector<parameter> sorts;
     ast_manager& m = get_ast_manager();
     family_id fid = get_family_id();
     for (unsigned i = 0; i < sig.size(); ++i) {
         sorts.push_back(parameter(sig[i]));
     }
     return m.mk_sort(fid, DL_RELATION_SORT, sorts.size(), sorts.c_ptr());
 }
Ejemplo n.º 7
0
/* initialization */
void cputimer_init(xbt_cpu_timer_t timer)
{
	timer->pid = getpid();
	timer->_nl_sd = netlink_sock_new(NETLINK_GENERIC);
	xbt_assert(timer->_nl_sd >= 0, "error creating Netlink socket to retrieve the time");

	timer->_id = get_family_id(timer);
	xbt_assert(timer->_id, "Error getting family id: %s\n", strerror(errno));

	memset(&(timer->msg), 0, sizeof(struct msgtemplate));
}
Ejemplo n.º 8
0
 relation_base * external_relation_plugin::mk_empty(const relation_signature & s) {
     ast_manager& m = get_ast_manager();        
     sort* r_sort = get_relation_sort(s);
     parameter param(r_sort);
     family_id fid = get_family_id();
     expr_ref e(m.mk_fresh_const("T", r_sort), m);
     expr* args[1] = { e.get() };
     func_decl_ref empty_decl(m.mk_func_decl(fid, OP_RA_EMPTY, 1, &param, 0, (sort*const*)0), m);
     reduce_assign(empty_decl, 0, 0, 1, args);
     return alloc(external_relation, *this, s, e);
 }
Ejemplo n.º 9
0
void bv_decl_plugin::get_offset_term(app * a, expr * & t, rational & offset) const {
    family_id fid = get_family_id();
    if (a->get_num_args() == 2 && is_app_of(a, fid, OP_BADD) && is_app_of(a->get_arg(0), fid, OP_BV_NUM)) {
        unsigned sz;
        func_decl * decl = to_app(a->get_arg(0))->get_decl();
        offset = decl->get_parameter(0).get_rational();
        sz     = decl->get_parameter(1).get_int();
        t      = a->get_arg(1);
        offset = mod(offset, rational::power_of_two(sz));
    }
    else {
        t      = a;
        offset = rational(0);
    }
}
Ejemplo n.º 10
0
 std::ostream& theory::display_app(std::ostream & out, app * n) const {
     func_decl * d = n->get_decl();
     if (n->get_num_args() == 0) {
         out << d->get_name();
         display_parameters(out, d->get_num_parameters(), d->get_parameters());
     }
     else if (n->get_family_id() == get_family_id()) {
         out << "(" << d->get_name();
         display_parameters(out, d->get_num_parameters(), d->get_parameters());
         unsigned num = n->get_num_args();
         for (unsigned i = 0; i < num; i++) {
             out << " ";
             display_app(out, to_app(n->get_arg(i)));
         }
         out << ")";
     }
     else {
         out << "#" << n->get_id();
     }
     return out;
 }
Ejemplo n.º 11
0
int setup_netlink(void)
{
	struct sockaddr_nl snl;
	int s, rv;
	uint16_t id;

	s = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC);
	if (s < 0) {
		log_error("generic netlink socket");
		return s;
	}

	memset(&snl, 0, sizeof(snl));
	snl.nl_family = AF_NETLINK;

	rv = bind(s, (struct sockaddr *) &snl, sizeof(snl));
	if (rv < 0) {
		log_error("gen netlink bind error %d errno %d", rv, errno);
		close(s);
		return rv;
	}

	id = get_family_id(s);
	if (!id) {
		log_error("Error getting family id, errno %d", errno);
		close(s);
		return -1;
	}

	rv = send_genetlink_cmd(s, id, getpid(), DLM_CMD_HELLO, 0, NULL, 0);
	if (rv < 0) {
		log_error("error sending hello cmd, errno %d", errno);
		close(s);
		return -1;
	}

	return s;
}
Ejemplo n.º 12
0
int
init_taskstat (void)
{
	struct sockaddr_nl addr;

	netlink_socket = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC);
	if (netlink_socket < 0)
		goto error;

	memset (&addr, 0, sizeof (addr));
	addr.nl_family = AF_NETLINK;

	if (bind (netlink_socket, (struct sockaddr *) &addr, sizeof (addr)) < 0)
		goto error;

	netlink_taskstats_id = get_family_id (netlink_socket);

	return netlink_taskstats_id >= 0;
error:
	if (netlink_socket >= 0)
		close (netlink_socket);

	return 0;
}
Ejemplo n.º 13
0
app * fpa_util::mk_internal_to_real_unspecified(unsigned ebits, unsigned sbits) {
    parameter ps[] = { parameter(ebits), parameter(sbits) };
    sort * range = m_a_util.mk_real();
    return m().mk_app(get_family_id(), OP_FPA_INTERNAL_TO_REAL_UNSPECIFIED, 2, ps, 0, 0, range);
}
Ejemplo n.º 14
0
int main(int argc, char *argv[])
{
	int c, rc, rep_len, aggr_len, len2;
	int cmd_type = TASKSTATS_CMD_ATTR_UNSPEC;
	__u16 id;
	__u32 mypid;

	struct nlattr *na;
	int nl_sd = -1;
	int len = 0;
	pid_t tid = 0;
	pid_t rtid = 0;

	int fd = 0;
	int count = 0;
	int write_file = 0;
	int maskset = 0;
	char *logfile = NULL;
	int loop = 0;
	int containerset = 0;
	char *containerpath = NULL;
	int cfd = 0;
	int forking = 0;
	sigset_t sigset;

	struct msgtemplate msg;

	while (!forking) {
		c = getopt(argc, argv, "qdiw:r:m:t:p:vlC:c:");
		if (c < 0)
			break;

		switch (c) {
		case 'd':
			printf("print delayacct stats ON\n");
			print_delays = 1;
			break;
		case 'i':
			printf("printing IO accounting\n");
			print_io_accounting = 1;
			break;
		case 'q':
			printf("printing task/process context switch rates\n");
			print_task_context_switch_counts = 1;
			break;
		case 'C':
			containerset = 1;
			containerpath = optarg;
			break;
		case 'w':
			logfile = strdup(optarg);
			printf("write to file %s\n", logfile);
			write_file = 1;
			break;
		case 'r':
			rcvbufsz = atoi(optarg);
			printf("receive buf size %d\n", rcvbufsz);
			if (rcvbufsz < 0)
				err(1, "Invalid rcv buf size\n");
			break;
		case 'm':
			strncpy(cpumask, optarg, sizeof(cpumask));
			cpumask[sizeof(cpumask) - 1] = '\0';
			maskset = 1;
			printf("cpumask %s maskset %d\n", cpumask, maskset);
			break;
		case 't':
			tid = atoi(optarg);
			if (!tid)
				err(1, "Invalid tgid\n");
			cmd_type = TASKSTATS_CMD_ATTR_TGID;
			break;
		case 'p':
			tid = atoi(optarg);
			if (!tid)
				err(1, "Invalid pid\n");
			cmd_type = TASKSTATS_CMD_ATTR_PID;
			break;
		case 'c':

			/* Block SIGCHLD for sigwait() later */
			if (sigemptyset(&sigset) == -1)
				err(1, "Failed to empty sigset");
			if (sigaddset(&sigset, SIGCHLD))
				err(1, "Failed to set sigchld in sigset");
			sigprocmask(SIG_BLOCK, &sigset, NULL);

			/* fork/exec a child */
			tid = fork();
			if (tid < 0)
				err(1, "Fork failed\n");
			if (tid == 0)
				if (execvp(argv[optind - 1],
				    &argv[optind - 1]) < 0)
					exit(-1);

			/* Set the command type and avoid further processing */
			cmd_type = TASKSTATS_CMD_ATTR_PID;
			forking = 1;
			break;
		case 'v':
			printf("debug on\n");
			dbg = 1;
			break;
		case 'l':
			printf("listen forever\n");
			loop = 1;
			break;
		default:
			usage();
			exit(-1);
		}
	}

	if (write_file) {
		fd = open(logfile, O_WRONLY | O_CREAT | O_TRUNC,
			  S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
		if (fd == -1) {
			perror("Cannot open output file\n");
			exit(1);
		}
	}

	nl_sd = create_nl_socket(NETLINK_GENERIC);
	if (nl_sd < 0)
		err(1, "error creating Netlink socket\n");


	mypid = getpid();
	id = get_family_id(nl_sd);
	if (!id) {
		fprintf(stderr, "Error getting family id, errno %d\n", errno);
		goto err;
	}
	PRINTF("family id %d\n", id);

	if (maskset) {
		rc = send_cmd(nl_sd, id, mypid, TASKSTATS_CMD_GET,
			      TASKSTATS_CMD_ATTR_REGISTER_CPUMASK,
			      &cpumask, strlen(cpumask) + 1);
		PRINTF("Sent register cpumask, retval %d\n", rc);
		if (rc < 0) {
			fprintf(stderr, "error sending register cpumask\n");
			goto err;
		}
	}

	if (tid && containerset) {
		fprintf(stderr, "Select either -t or -C, not both\n");
		goto err;
	}

	/*
	 * If we forked a child, wait for it to exit. Cannot use waitpid()
	 * as all the delicious data would be reaped as part of the wait
	 */
	if (tid && forking) {
		int sig_received;
		sigwait(&sigset, &sig_received);
	}

	if (tid) {
		rc = send_cmd(nl_sd, id, mypid, TASKSTATS_CMD_GET,
			      cmd_type, &tid, sizeof(__u32));
		PRINTF("Sent pid/tgid, retval %d\n", rc);
		if (rc < 0) {
			fprintf(stderr, "error sending tid/tgid cmd\n");
			goto done;
		}
	}

	if (containerset) {
		cfd = open(containerpath, O_RDONLY);
		if (cfd < 0) {
			perror("error opening container file");
			goto err;
		}
		rc = send_cmd(nl_sd, id, mypid, CGROUPSTATS_CMD_GET,
			      CGROUPSTATS_CMD_ATTR_FD, &cfd, sizeof(__u32));
		if (rc < 0) {
			perror("error sending cgroupstats command");
			goto err;
		}
	}
	if (!maskset && !tid && !containerset) {
		usage();
		goto err;
	}

	do {
		rep_len = recv(nl_sd, &msg, sizeof(msg), 0);
		PRINTF("received %d bytes\n", rep_len);

		if (rep_len < 0) {
			fprintf(stderr, "nonfatal reply error: errno %d\n",
				errno);
			continue;
		}
		if (msg.n.nlmsg_type == NLMSG_ERROR ||
		    !NLMSG_OK((&msg.n), rep_len)) {
			struct nlmsgerr *err = NLMSG_DATA(&msg);
			fprintf(stderr, "fatal reply error,  errno %d\n",
				err->error);
			goto done;
		}

		PRINTF("nlmsghdr size=%zu, nlmsg_len=%d, rep_len=%d\n",
		       sizeof(struct nlmsghdr), msg.n.nlmsg_len, rep_len);


		rep_len = GENLMSG_PAYLOAD(&msg.n);

		na = (struct nlattr *) GENLMSG_DATA(&msg);
		len = 0;
		while (len < rep_len) {
			len += NLA_ALIGN(na->nla_len);
			switch (na->nla_type) {
			case TASKSTATS_TYPE_AGGR_TGID:
				/* Fall through */
			case TASKSTATS_TYPE_AGGR_PID:
				aggr_len = NLA_PAYLOAD(na->nla_len);
				len2 = 0;
				/* For nested attributes, na follows */
				na = (struct nlattr *) NLA_DATA(na);
				done = 0;
				while (len2 < aggr_len) {
					switch (na->nla_type) {
					case TASKSTATS_TYPE_PID:
						rtid = *(int *) NLA_DATA(na);
						if (print_delays)
							printf("PID\t%d\n", rtid);
						break;
					case TASKSTATS_TYPE_TGID:
						rtid = *(int *) NLA_DATA(na);
						if (print_delays)
							printf("TGID\t%d\n", rtid);
						break;
					case TASKSTATS_TYPE_STATS:
						count++;
						if (print_delays)
							print_delayacct((struct taskstats *) NLA_DATA(na));
						if (print_io_accounting)
							print_ioacct((struct taskstats *) NLA_DATA(na));
						if (print_task_context_switch_counts)
							task_context_switch_counts((struct taskstats *) NLA_DATA(na));
						if (fd) {
							if (write(fd, NLA_DATA(na), na->nla_len) < 0) {
								err(1,"write error\n");
							}
						}
						if (!loop)
							goto done;
						break;
					case TASKSTATS_TYPE_NULL:
						break;
					default:
						fprintf(stderr, "Unknown nested"
							" nla_type %d\n",
							na->nla_type);
						break;
					}
					len2 += NLA_ALIGN(na->nla_len);
					na = (struct nlattr *)((char *)na +
							       NLA_ALIGN(na->nla_len));
				}
				break;

			case CGROUPSTATS_TYPE_CGROUP_STATS:
				print_cgroupstats(NLA_DATA(na));
				break;
			default:
				fprintf(stderr, "Unknown nla_type %d\n",
					na->nla_type);
			case TASKSTATS_TYPE_NULL:
				break;
			}
			na = (struct nlattr *) (GENLMSG_DATA(&msg) + len);
		}
	} while (loop);
done:
	if (maskset) {
		rc = send_cmd(nl_sd, id, mypid, TASKSTATS_CMD_GET,
			      TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK,
			      &cpumask, strlen(cpumask) + 1);
		printf("Sent deregister mask, retval %d\n", rc);
		if (rc < 0)
			err(rc, "error sending deregister cpumask\n");
	}
err:
	close(nl_sd);
	if (fd)
		close(fd);
	if (cfd)
		close(cfd);
	return 0;
}
Ejemplo n.º 15
0
int main()
{

    nl_sd = create_nl_socket(NETLINK_GENERIC,0);
    if(nl_sd < 0) {
        printf("create failure\n");
        return 0;
    }
    int id = get_family_id(nl_sd);
    struct {
        struct nlmsghdr n;
        struct genlmsghdr g;
        char buf[256];
    } ans;

    struct {
        struct nlmsghdr n;
        struct genlmsghdr g;
        char buf[256];
    } req;
    struct nlattr *na;

    // Send command needed
    req.n.nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN);
    req.n.nlmsg_type = id;
    req.n.nlmsg_flags = NLM_F_REQUEST;
    req.n.nlmsg_seq = 60;
    req.n.nlmsg_pid = getpid();
    req.g.cmd = 1;//DOC_EXMPL_C_ECHO;

    //compose message
    na = (struct nlattr *) GENLMSG_DATA(&req);
    na->nla_type = 1; //DOC_EXMPL_A_MSG
    char * message = "hello world!"; //message
    int mlength = 14;
    na->nla_len = mlength+NLA_HDRLEN; //message length
    memcpy(NLA_DATA(na), message, mlength);
    req.n.nlmsg_len += NLMSG_ALIGN(na->nla_len);

    //send message
    struct sockaddr_nl nladdr;
    int r;

    memset(&nladdr, 0, sizeof(nladdr));
    nladdr.nl_family = AF_NETLINK;

    r = sendto(nl_sd, (char *)&req, req.n.nlmsg_len, 0,
               (struct sockaddr *) &nladdr, sizeof(nladdr));
    int rep_len;

    //kernel says hello first
    rep_len = recv(nl_sd, &ans, sizeof(ans), 0);

    // Validate response message
    if (ans.n.nlmsg_type == NLMSG_ERROR) { //	error
        printf("error received NACK - leaving \n");
        return -1;
    }
    if (rep_len < 0) {
        printf("error receiving reply message via Netlink \n");
        return -1;
    }
    if (!NLMSG_OK((&ans.n), rep_len)) {
        printf("invalid reply message received via Netlink\n");
        return -1;
    }

    rep_len = GENLMSG_PAYLOAD(&ans.n);
    //parse reply message
    na = (struct nlattr *) GENLMSG_DATA(&ans);
    char * result2 = (char *)NLA_DATA(na);
    printf("kernel says: %s\n",result2);


    while(1)
    {
        /* recv sector no. */
        rep_len = recv(nl_sd, &ans, sizeof(ans), 0);
        //int rep_len = recv(nl_sd, &ans, sizeof(ans), 0);
        //int rep_len = recv(nl_sd, &ans, sizeof(ans), 0);

        // Validate response message
        if (ans.n.nlmsg_type == NLMSG_ERROR) { //	error
            printf("error received NACK - leaving \n");
            return -1;
        }
        if (rep_len < 0) {
            printf("error receiving reply message via Netlink \n");
            return -1;
        }
        if (!NLMSG_OK((&ans.n), rep_len)) {
            printf("invalid reply message received via Netlink\n");
            return -1;
        }

        rep_len = GENLMSG_PAYLOAD(&ans.n);
        //parse reply message
        na = (struct nlattr *) GENLMSG_DATA(&ans);
        unsigned long *result = (unsigned long *)NLA_DATA(na);
        printf("Sect No: %lx\n",*result);

        /*recv no of sectors*/
        rep_len = recv(nl_sd, &ans, sizeof(ans), 0);

        // Validate response message
        if (ans.n.nlmsg_type == NLMSG_ERROR) { //	error
            printf("error received NACK - leaving \n");
            return -1;
        }
        if (rep_len < 0) {
            printf("error receiving reply message via Netlink \n");
            return -1;
        }
        if (!NLMSG_OK((&ans.n), rep_len)) {
            printf("invalid reply message received via Netlink\n");
            return -1;
        }

        rep_len = GENLMSG_PAYLOAD(&ans.n);
        //parse reply message
        na = (struct nlattr *) GENLMSG_DATA(&ans);
        unsigned long *result1 = (unsigned long *)NLA_DATA(na);
        printf("No. of Sectors : %lx\n\n",*result1);

    }
    close(nl_sd);


    return 1;
}
Ejemplo n.º 16
0
int main(int argc, char *argv[])
{
	int c, rc, rep_len, aggr_len, len2, cmd_type;
	__u16 id;
	__u32 mypid;

	struct nlattr *na;
	int nl_sd = -1;
	int len = 0;
	pid_t tid = 0;
	pid_t rtid = 0;

	int fd = 0;
	int count = 0;
	int write_file = 0;
	int maskset = 0;
	char *logfile = NULL;
	int loop = 0;
	int containerset = 0;
	char containerpath[1024];
	int cfd = 0;

	struct msgtemplate msg;

	while (1) {
		c = getopt(argc, argv, "qdiw:r:m:t:p:vlC:");
		if (c < 0)
			break;

		switch (c) {
		case 'd':
			printf("print delayacct stats ON\n");
			print_delays = 1;
			break;
		case 'i':
			printf("printing IO accounting\n");
			print_io_accounting = 1;
			break;
		case 'q':
			printf("printing task/process context switch rates\n");
			print_task_context_switch_counts = 1;
			break;
		case 'C':
			containerset = 1;
			strncpy(containerpath, optarg, strlen(optarg) + 1);
			break;
		case 'w':
			logfile = strdup(optarg);
			printf("write to file %s\n", logfile);
			write_file = 1;
			break;
		case 'r':
			rcvbufsz = atoi(optarg);
			printf("receive buf size %d\n", rcvbufsz);
			if (rcvbufsz < 0)
				err(1, "Invalid rcv buf size\n");
			break;
		case 'm':
			strncpy(cpumask, optarg, sizeof(cpumask));
			maskset = 1;
			printf("cpumask %s maskset %d\n", cpumask, maskset);
			break;
		case 't':
			tid = atoi(optarg);
			if (!tid)
				err(1, "Invalid tgid\n");
			cmd_type = TASKSTATS_CMD_ATTR_TGID;
			break;
		case 'p':
			tid = atoi(optarg);
			if (!tid)
				err(1, "Invalid pid\n");
			cmd_type = TASKSTATS_CMD_ATTR_PID;
			break;
		case 'v':
			printf("debug on\n");
			dbg = 1;
			break;
		case 'l':
			printf("listen forever\n");
			loop = 1;
			break;
		default:
			usage();
			exit(1);
		}
	}

	if (write_file) {
		fd = open(logfile, O_WRONLY | O_CREAT | O_TRUNC,
			  S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
		if (fd == -1) {
			perror("Cannot open output file\n");
			exit(1);
		}
	}

	if ((nl_sd = create_nl_socket(NETLINK_GENERIC)) < 0)
		err(1, "error creating Netlink socket\n");


	mypid = getpid();
	id = get_family_id(nl_sd);
	if (!id) {
		fprintf(stderr, "Error getting family id, errno %d\n", errno);
		exit(1);
	}
	PRINTF("family id %d\n", id);

	if (maskset) {
		rc = send_cmd(nl_sd, id, mypid, TASKSTATS_CMD_GET,
			      TASKSTATS_CMD_ATTR_REGISTER_CPUMASK,
			      &cpumask, strlen(cpumask) + 1);
		PRINTF("Sent register cpumask, retval %d\n", rc);
		if (rc < 0) {
			fprintf(stderr, "error sending register cpumask\n");
			exit(1);
		}
	}

	if (tid && containerset) {
		fprintf(stderr, "Select either -t or -C, not both\n");
		exit(1);
	}

	if (tid) {
		rc = send_cmd(nl_sd, id, mypid, TASKSTATS_CMD_GET,
			      cmd_type, &tid, sizeof(__u32));
		PRINTF("Sent pid/tgid, retval %d\n", rc);
		if (rc < 0) {
			fprintf(stderr, "error sending tid/tgid cmd\n");
			exit(1);
		}
	}

	if (containerset) {
		cfd = open(containerpath, O_RDONLY);
		if (cfd < 0) {
			perror("error opening container file");
			exit(1);
		}
#ifdef HAVE_LINUX_CGROUPSTATS_H
		rc = send_cmd(nl_sd, id, mypid, CGROUPSTATS_CMD_GET,
			      CGROUPSTATS_CMD_ATTR_FD, &cfd, sizeof(__u32));
#else
		errno = ENOSYS;
		rc = -1;
#endif
		if (rc < 0) {
			perror("error sending cgroupstats command");
			exit(1);
		}
	}
	if (!maskset && !tid && !containerset) {
		usage();
		exit(1);
	}

	do {
		int i;

		rep_len = recv(nl_sd, &msg, sizeof(msg), 0);
		PRINTF("received %d bytes\n", rep_len);

		if (rep_len < 0) {
			fprintf(stderr, "nonfatal reply error: errno %d\n",
				errno);
			exit(1);
		}
		if (msg.n.nlmsg_type == NLMSG_ERROR ||
		    !NLMSG_OK((&msg.n), rep_len)) {
			struct nlmsgerr *err = NLMSG_DATA(&msg);
			fprintf(stderr, "fatal reply error,  errno %d\n",
				err->error);
			exit(1);
		}

		PRINTF("nlmsghdr size=%zu, nlmsg_len=%d, rep_len=%d\n",
			sizeof(struct nlmsghdr), msg.n.nlmsg_len, rep_len);


		rep_len = GENLMSG_PAYLOAD(&msg.n);

		na = (struct nlattr *) GENLMSG_DATA(&msg);
		len = 0;
		i = 0;
		while (len < rep_len) {
			len += NLA_ALIGN(na->nla_len);
			switch (na->nla_type) {
			case TASKSTATS_TYPE_AGGR_TGID:
				/* Fall through */
			case TASKSTATS_TYPE_AGGR_PID:
				aggr_len = NLA_PAYLOAD(na->nla_len);
				len2 = 0;
				/* For nested attributes, na follows */
				na = (struct nlattr *) NLA_DATA(na);
				done = 0;
				while (len2 < aggr_len) {
					switch (na->nla_type) {
					case TASKSTATS_TYPE_PID:
						rtid = *(int *) NLA_DATA(na);
						if (print_delays)
							printf("PID\t%d\n", rtid);
						break;
					case TASKSTATS_TYPE_TGID:
						rtid = *(int *) NLA_DATA(na);
						if (print_delays)
							printf("TGID\t%d\n", rtid);
						break;
					case TASKSTATS_TYPE_STATS:
						count++;
						if (print_delays)
							print_delayacct((struct taskstats *) NLA_DATA(na));
						if (print_io_accounting)
							print_ioacct((struct taskstats *) NLA_DATA(na));
						if (print_task_context_switch_counts)
							task_context_switch_counts((struct taskstats *) NLA_DATA(na));
						if (fd) {
							if (write(fd, NLA_DATA(na), na->nla_len) < 0) {
								err(1,"write error\n");
							}
						}
						if (!loop)
							goto done;
						break;
					default:
						fprintf(stderr, "Unknown nested"
							" nla_type %d\n",
							na->nla_type);
						break;
					}
					len2 += NLA_ALIGN(na->nla_len);
					na = (struct nlattr *) ((char *) na + len2);
				}
				break;
#if HAVE_LINUX_CGROUPSTATS_H
			case CGROUPSTATS_TYPE_CGROUP_STATS:
				print_cgroupstats(NLA_DATA(na));
				break;
#endif
			default:
				fprintf(stderr, "Unknown nla_type %d\n",
					na->nla_type);
				exit(1);
			}
			na = (struct nlattr *) (GENLMSG_DATA(&msg) + len);
		}
	} while (loop);
done:
	if (maskset) {
		rc = send_cmd(nl_sd, id, mypid, TASKSTATS_CMD_GET,
			      TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK,
			      &cpumask, strlen(cpumask) + 1);
		printf("Sent deregister mask, retval %d\n", rc);
		if (rc < 0)
			err(rc, "error sending deregister cpumask\n");
	}

	close(nl_sd);
	if (fd)
		close(fd);
	if (cfd)
		close(cfd);
	return 0;
}
Ejemplo n.º 17
0
app * fpa_util::mk_internal_to_sbv_unspecified(unsigned ebits, unsigned sbits, unsigned width) {
    parameter ps[] = { parameter(ebits), parameter(sbits), parameter(width) };
    sort * range = m_bv_util.mk_sort(width);
    return m().mk_app(get_family_id(), OP_FPA_INTERNAL_TO_SBV_UNSPECIFIED, 3, ps, 0, 0, range);
}
Ejemplo n.º 18
0
int ResetManager::start() {
    struct sockaddr_nl nladdr;
    int sz = 64 * 1024;
    GENERIC_NETLINK_PACKET ans, req;
    struct nlattr *na;
    int id;
    int mlength;
    const char *message = "HELLO"; //message
    int rc;
    int count = 10;
    
    if(mHandler) {
        LOGD("ResetManager is already started");
        return 0;
    }
    
    mlength = strlen(message) + 1;
    LOGD("Size of initial message: %d  ", mlength);
    memset(&nladdr, 0, sizeof(nladdr));
    nladdr.nl_family = AF_NETLINK;
    nladdr.nl_pid = getpid();
    nladdr.nl_groups = 0xffffffff;

    if ((mSock = socket(AF_NETLINK,
                        SOCK_RAW,NETLINK_GENERIC)) < 0) {
        LOGE("Unable to create uevent socket: %s", strerror(errno));
        return -1;
    }

    if (setsockopt(mSock, SOL_SOCKET, SO_RCVBUFFORCE, &sz, sizeof(sz)) < 0) {
        LOGE("Unable to set uevent socket options: %s", strerror(errno));
        return -1;
    }

    if (bind(mSock, (struct sockaddr *) &nladdr, sizeof(nladdr)) < 0) {
        LOGE("Unable to bind uevent socket: %s", strerror(errno));
        return -1;
    }

    while(count--) {
        /* 2. get family ID */
        id = get_family_id(mSock, "MTK_WIFI");
        if (-1 == id) {
            LOGE("Unable to get family id, Retry");
            usleep(500000);
        } else {
            LOGD("[MTK_WIFI] family id = %d\n", id);
            break;
        }
    }
    
    /* 2.9 Check WiFi Driver Support Chip Reset*/
    if(id < 0) {
        close(mSock);
        mSock = -1;
        LOGW("WiFi Driver Cannot Support Chip Reset, Abort ResetManager");
        return -1;
    }

    /* 3. Prepare Dummy command */
    req.n.nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN);
    req.n.nlmsg_type = id;
    req.n.nlmsg_flags = NLM_F_REQUEST;
    req.n.nlmsg_seq = 60;
    req.n.nlmsg_pid = getpid();
    req.g.cmd = 1; //MTK_WIFI_COMMAND_BIND
    
    na = (struct nlattr *) GENLMSG_DATA(&req);
    na->nla_type = 1; //MTK_WIFI_ATTR_MSG
    na->nla_len = mlength + NLA_HDRLEN; //message length
    memcpy(NLA_DATA(na), message, mlength);
    req.n.nlmsg_len += NLMSG_ALIGN(na->nla_len);

    LOGD("Reset Manager Prepare Dummy command");
    
    /* 3.1 Send Command for binding */
    memset(&nladdr, 0, sizeof(nladdr));
    nladdr.nl_family = AF_NETLINK;

    rc = sendto(mSock, (char *)&req, req.n.nlmsg_len, 0,
            (struct sockaddr *) &nladdr, sizeof(nladdr));
    
    LOGD("Reset Manager Send Command for binding");
    
    mHandler = new ResetHandler(mCl, mSock);
    if (mHandler->start()) {
        LOGE("Unable to start ResetHandler: %s", strerror(errno));
        return -1;
    }
    return 0;
}
Ejemplo n.º 19
0
 void external_relation_plugin::mk_filter_fn(sort* s, app* condition, func_decl_ref& f) {
     ast_manager& m = get_ast_manager();
     family_id fid  = get_family_id();
     parameter param(condition);
     f = m.mk_func_decl(fid, OP_RA_FILTER, 1, &param, 1, &s);
 }
Ejemplo n.º 20
0
simplifier_plugin * user_simplifier_plugin::mk_fresh() {
    ast_manager & m = get_manager();
    user_simplifier_plugin * new_sp = alloc(user_simplifier_plugin, m.get_family_name(get_family_id()), m);
    new_sp->m_reduce_app_fptr      = m_reduce_app_fptr;
    new_sp->m_reduce_eq_fptr       = m_reduce_eq_fptr;
    new_sp->m_reduce_distinct_fptr = m_reduce_distinct_fptr;
    return new_sp;
}