Beispiel #1
0
int ipcs_main(int argc UNUSED_PARAM, char **argv)
{
	int id = 0;
	unsigned flags = 0;
	unsigned opt;
	char *opt_i;
#define flag_print	(1<<0)
#define flag_msg	(1<<1)
#define flag_sem	(1<<2)
#define flag_shm	(1<<3)

	opt = getopt32(argv, "i:aqsmtcplu", &opt_i);
	if (opt & 0x1) { // -i
		id = xatoi(opt_i);
		flags |= flag_print;
	}
	if (opt & 0x2) flags |= flag_msg | flag_sem | flag_shm; // -a
	if (opt & 0x4) flags |= flag_msg; // -q
	if (opt & 0x8) flags |= flag_sem; // -s
	if (opt & 0x10) flags |= flag_shm; // -m
	if (opt & 0x20) format = TIME; // -t
	if (opt & 0x40) format = CREATOR; // -c
	if (opt & 0x80) format = PID; // -p
	if (opt & 0x100) format = LIMITS; // -l
	if (opt & 0x200) format = STATUS; // -u

	if (flags & flag_print) {
		if (flags & flag_shm) {
			print_shm(id);
			fflush_stdout_and_exit(EXIT_SUCCESS);
		}
		if (flags & flag_sem) {
			print_sem(id);
			fflush_stdout_and_exit(EXIT_SUCCESS);
		}
		if (flags & flag_msg) {
			print_msg(id);
			fflush_stdout_and_exit(EXIT_SUCCESS);
		}
		bb_show_usage();
	}

	if (!(flags & (flag_shm | flag_msg | flag_sem)))
		flags |= flag_msg | flag_shm | flag_sem;
	bb_putchar('\n');

	if (flags & flag_shm) {
		do_shm();
		bb_putchar('\n');
	}
	if (flags & flag_sem) {
		do_sem();
		bb_putchar('\n');
	}
	if (flags & flag_msg) {
		do_msg();
		bb_putchar('\n');
	}
	fflush_stdout_and_exit(EXIT_SUCCESS);
}
Beispiel #2
0
int ipcs_main(int argc UNUSED_PARAM, char **argv)
{
	int format = 0;
	unsigned opt;
	char *opt_i;

	opt = getopt32(argv, "i:aqsmtcplu", &opt_i);
#define flag_msg (1<<2)
#define flag_sem (1<<3)
#define flag_shm (1<<4)
	if (opt & (1<<5)) format = TIME; // -t
	if (opt & (1<<6)) format = CREATOR; // -c
	if (opt & (1<<7)) format = PID; // -p
	if (opt & (1<<8)) format = LIMITS; // -l
	if (opt & (1<<9)) format = STATUS; // -u

	if (opt & (1<<0)) { // -i
		int id;

		id = xatoi(opt_i);
		if (opt & flag_shm) {
			print_shm(id);
			fflush_stdout_and_exit(EXIT_SUCCESS);
		}
		if (opt & flag_sem) {
			print_sem(id);
			fflush_stdout_and_exit(EXIT_SUCCESS);
		}
		if (opt & flag_msg) {
			print_msg(id);
			fflush_stdout_and_exit(EXIT_SUCCESS);
		}
		bb_show_usage();
	}

	if ((opt & (1<<1)) // -a
	 || !(opt & (flag_msg | flag_sem | flag_shm)) // none of -q,-s,-m == all
	) {
		opt |= flag_msg | flag_sem | flag_shm;
	}

	bb_putchar('\n');

	if (opt & flag_msg) {
		do_msg(format);
		bb_putchar('\n');
	}
	if (opt & flag_shm) {
		do_shm(format);
		bb_putchar('\n');
	}
	if (opt & flag_sem) {
		do_sem(format);
		bb_putchar('\n');
	}
	fflush_stdout_and_exit(EXIT_SUCCESS);
}
Beispiel #3
0
int main(int argc, char **argv)
{
	int		c;
	int		readcount = 0;
	int		msglen = 0;
	int		fd;
	const char	*name;

	while ((c = getopt(argc, argv, "hm:r:v")) != EOF) {
		switch (c) {
		case 'm':
			msglen = atoi(optarg);
			if (msglen < 0)
				goto usage;
			continue;
		case 'r':
			readcount = atoi(optarg);
			if (readcount < 0)
				goto usage;
			continue;
		case 'v':
			verbose++;
			continue;
		case 'h':
		case '?':
usage:
			fprintf(stderr,
				"usage: %s [-h] [-m N] [-r N] /dev/spidevB.D\n",
				argv[0]);
			return 1;
		}
	}

	if ((optind + 1) != argc)
		goto usage;
	name = argv[optind];

	fd = open(name, O_RDWR);
	if (fd < 0) {
		perror("open");
		return 1;
	}

	dumpstat(name, fd);

	if (msglen)
		do_msg(fd, msglen);

	if (readcount)
		do_read(fd, readcount);

	close(fd);
	return 0;
}
Beispiel #4
0
void
iconize(WIND w)
{
	char	*s, name[9];
	ICONWIND iw;
	WORD	e, i, msg[8];

	s = strrchr(w->name, '\\');
	if (!s) s = w->name;
	strncpy(name, s+1, 8);
	name[8] = '\0';
	if ((s = strchr(name, '.'))
	||  (s = strchr(name, ' ')))
		*s = 0;
	i = iw_new(wsid, w->rwind.g_x, w->rwind.g_y, name,
				viewfile, BLACK, WHITE, w);
	if (i > 0)
	{
		iw = (ICONWIND)w_lookup(i);
		iw->w.do_button = iw_button;
		w_closed(w, msg);
		w->info[0] = 0;
		wind_sstr(w->id, WF_INFO, w->info);
		for(;;) {
			e = evnt_multi(MU_MESAG|MU_TIMER, 0,0,0,
							0,0,0,0,0, 0,0,0,0,0,
							msg, 100,0, &i, &i, &i, &i, &i, &i);
			if (e & MU_MESAG)
				do_msg(msg);
			else if ((e & MU_TIMER) && wind_update(TRY_UPDATE))
				break;
		}
		wind_update(END_UPDATE);

		graf_mouse(M_OFF, NULL);
		iw_drag(iw, 0, 0);
		graf_mouse(M_ON, NULL);

		wind_open(iw->w.id, iw->w.rwind.g_x, iw->w.rwind.g_y,
				  iw->w.rwind.g_w, iw->w.rwind.g_h);
	}
}
Beispiel #5
0
void take_message(void)
{
    int		bytes;
    int		i;
    MESG *	md;

    for (EVER) {	/* not really forever...returns are in the loop */
	if ((md = mlisten()) == NULL)
	    switch(errno) {
	      case EAGAIN:
	      case EINTR:
		return;

	      case ENOMEM:
		mallocfail();
		/* NOTREACHED */

	      default:
		fail ("Unexpected streams error in mlisten (%s).\n" , PERROR);
	    }
	
	/*
	 * Check for a dropped connection to a child.
	 * Normally a child should tell us that it is dying
	 * (with S_SHUTDOWN or S_SEND_CHILD), but it may have
	 * died a fast death. We'll simulate the message we
	 * wanted to get so we can use the same code to clean up.
	 */
	if ((md->event & POLLHUP) && !(md->event & POLLIN) ||
	    (md->event & (POLLERR|POLLNVAL))) {
		switch (md->type) {

		case MD_CHILD:
			/*
			 * If the message descriptor is found in the
			 * exec table, it must be an interface pgm,
			 * notification, etc. Otherwise, it must be
			 * a network child.
			 */
			for (i = 0; Exec_Table[i] != NULL; i++)
				if (Exec_Table[i]->md == md)
					break;

			if (Exec_Table[i] != NULL) {
				(void) putmessage(Message, S_CHILD_DONE,
					Exec_Table[i]->key, 0, 0);
			} else {
				(void) putmessage(Message, S_SHUTDOWN, 1);
			}
			bytes = 1;
			break;

		default:
			bytes = -1;
			break;

		}

	} else {
		if (md->readfd == -1) { /* something happened to the readfd */
			syslog(LOG_DEBUG, "take_message: readfd is -1");
			return;
		}
		bytes = mread(md, Message, MSGMAX);
	}

	switch (bytes) {
	  case -1:
	    if (errno == EINTR)
		return;
	    else
		fail ("Unexpected streams error (%s).\n" , PERROR);
	    break;

	  case 0:
	    break;

	  default:
	    if (do_msg(md))
		return;
	    break;
	}
    }
}
Beispiel #6
0
static void bye(void *msg)
{
	do_msg("bye", msg);
}
Beispiel #7
0
static void hello(void *msg)
{
	do_msg("hello", msg);
}
Beispiel #8
0
static LRESULT CALLBACK wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
    int x, y, w, h;
    msg_t m;

    x = GET_X_LPARAM(lparam);
    y = GET_Y_LPARAM(lparam);
    w = LOWORD(lparam);
    h = HIWORD(lparam);

    switch (msg) {
    case WM_CLOSE:
        PostQuitMessage(0);
        break;
    case WM_SIZE:
        if (init_done)
            do_resize(w, h);
        break;
    case WM_MOVE:
        break;
    case WM_EXITSIZEMOVE:
        break;
    case WM_MOUSELEAVE:
        tracking = 0;
        break;
    case WM_MOUSEMOVE:
        if (clipcursor)
            update_clip(hwnd); //TODO: shouldnt be here

        if (!tracking) {
            TrackMouseEvent(&tme);
            tracking = 1;
        }
        input_mmove(&input, x, y, 0);
        break;
    case WM_LBUTTONDOWN:
        input_mdown(&input, x, y, 0, 0);
        break;
    case WM_LBUTTONUP:
        input_mup(&input, x, y, 0, 0);
        break;
    case WM_RBUTTONDOWN:
        input_mdown(&input, x, y, 0, 2);
        break;
    case WM_RBUTTONUP:
        input_mup(&input, x, y, 0, 2);
        break;
    case WM_MBUTTONDOWN:
        input_mdown(&input, x, y, 0, 1);
        break;
    case WM_MBUTTONUP:
        input_mup(&input, x, y, 0, 1);
        break;
    case WM_MOUSEWHEEL:
        input_mwheel(&input, (double) (int16_t)HIWORD(wparam) / 120.0);
        break;
    case WM_KEYDOWN:
        if (wparam == VK_F1) {
            if (!clipcursor)
                update_clip(hwnd);
            else
                ClipCursor(0);
            clipcursor = !clipcursor;
            break;
        }
        input_keydown(&input, wparam, wparam);
        break;
    case WM_KEYUP:
        input_keyup(&input, wparam);
        break;
    case WM_USER:
        m.v = wparam;
        do_msg(m.id, m.v8, m.v16, m.value, (void*)lparam);
        break;
    default:
        return DefWindowProc(hwnd, msg, wparam, lparam);
    }

    return 0;
}
Beispiel #9
0
int main (int argc, char **argv)
{
	int opt, msg = 0, shm = 0, sem = 0, id = 0, specific = 0;
	char format = NOTSPECIFIED;
	int unit = IPC_UNIT_DEFAULT;
	static const struct option longopts[] = {
		{"id", required_argument, NULL, 'i'},
		{"queues", no_argument, NULL, 'q'},
		{"shmems", no_argument, NULL, 'm'},
		{"semaphores", no_argument, NULL, 's'},
		{"all", no_argument, NULL, 'a'},
		{"time", no_argument, NULL, 't'},
		{"pid", no_argument, NULL, 'p'},
		{"creator", no_argument, NULL, 'c'},
		{"limits", no_argument, NULL, 'l'},
		{"summary", no_argument, NULL, 'u'},
		{"human", no_argument, NULL, OPT_HUMAN},
		{"bytes", no_argument, NULL, 'b'},
		{"version", no_argument, NULL, 'V'},
		{"help", no_argument, NULL, 'h'},
		{NULL, 0, NULL, 0}
	};
	char options[] = "i:qmsatpclubVh";

	setlocale(LC_ALL, "");
	bindtextdomain(PACKAGE, LOCALEDIR);
	textdomain(PACKAGE);
	atexit(close_stdout);

	while ((opt = getopt_long(argc, argv, options, longopts, NULL)) != -1) {
		switch (opt) {
		case 'i':
			id = atoi (optarg);
			specific = 1;
			break;
		case 'a':
			msg = shm = sem = 1;
			break;
		case 'q':
			msg = 1;
			break;
		case 'm':
			shm = 1;
			break;
		case 's':
			sem = 1;
			break;
		case 't':
			format = TIME;
			break;
		case 'c':
			format = CREATOR;
			break;
		case 'p':
			format = PID;
			break;
		case 'l':
			format = LIMITS;
			break;
		case 'u':
			format = STATUS;
			break;
		case OPT_HUMAN:
			unit = IPC_UNIT_HUMAN;
			break;
		case 'b':
			unit = IPC_UNIT_BYTES;
			break;
		case 'h':
			usage(stdout);
		case 'V':
			printf(UTIL_LINUX_VERSION);
			return EXIT_SUCCESS;
		default:
			usage(stderr);
		}
	}

	if (specific && (msg + shm + sem != 1))
		errx (EXIT_FAILURE,
		      _("when using an ID, a single resource must be specified"));
	if (specific) {
		if (msg)
			print_msg (id, unit);
		if (shm)
			print_shm (id, unit);
		if (sem)
			print_sem (id);
	} else {
		if (!msg && !shm && !sem)
			msg = shm = sem = 1;
		printf ("\n");
		if (msg) {
			do_msg (format, unit);
			printf ("\n");
		}
		if (shm) {
			do_shm (format, unit);
			printf ("\n");
		}
		if (sem) {
			do_sem (format);
			printf ("\n");
		}
	}
	return EXIT_SUCCESS;
}