예제 #1
0
파일: talk.c 프로젝트: 274914765/C
int main (int argc, char *argv[])
{
    int index;

    set_program_name (argv[0]);
    iu_argp_init ("talk", program_authors);
    argp_parse (&argp, argc, argv, 0, &index, NULL);

    argc -= index;
    argv += index;

    if (argc == 0)
    {
        printf ("Usage: talk user [ttyname]\n");
        exit (-1);
    }
    if (!isatty (0))
    {
        printf ("Standard input must be a tty, not a pipe or a file\n");
        exit (-1);
    }

    get_names (argc, argv);
    init_display ();
    open_ctl ();
    open_sockt ();
    start_msgs ();
    if (!check_local ())
        invite_remote ();
    end_msgs ();
    set_edit_chars ();
    talk ();
}
예제 #2
0
파일: talk.c 프로젝트: ajinkya93/OpenBSD
int
main(int argc, char *argv[])
{
	if (pledge("stdio rpath inet dns getpw tty", NULL) == -1)
		err(1, "pledge");

	get_names(argc, argv);
	init_display();
	open_ctl();
	open_sockt();
	start_msgs();
	if (!check_local())
		invite_remote();
	end_msgs();
	set_edit_chars();

	if (his_machine_addr.s_addr == my_machine_addr.s_addr) {
		if (pledge("stdio tty", NULL) == -1)
			err(1, "pledge");
	} else {
		if (pledge("stdio inet tty", NULL) == -1)
			err(1, "pledge");
	}

	talk();
	return (0);
}
예제 #3
0
int main(int argc, char **argv)
{
    int hwdep_fd;
    snd_ctl_t *ctl;

    (void) argc;
    (void) argv;

    // Setup the signal handler
    struct sigaction sa = { 0 };
    sa.sa_handler = &handle_signal;

    // Handle standard signals to quit properly
    sigemptyset(&sa.sa_mask);
    sigaction(SIGINT,  &sa, NULL);
    sigaction(SIGHUP,  &sa, NULL);
    sigaction(SIGTERM, &sa, NULL);

    // Open control and hwdep devices
    if (open_hwdep(Y50_HWDEP_DEVICE, &hwdep_fd) != 0
            || open_ctl(Y50_CTL_NAME, &ctl) != 0) {
        return 1;
    }

    // Initialize subwoofer
    lfe_initialize(hwdep_fd);

    // Set initial values
    set_headphones_plugged(&headphones_plugged);
    set_lfe_volume(hwdep_fd, headphones_plugged ? 0 : get_master_volume());

    // Poll events
    while (!doneflag) {
        struct pollfd fds;
        snd_ctl_poll_descriptors(ctl, &fds, 1);

        if (poll(&fds, 1, -1) <= 0) {
            if (errno == EINTR) {
                continue;
            } else {
                perror("poll");
                break;
            }
        }

        unsigned short revents;
        snd_ctl_poll_descriptors_revents(ctl, &fds, 1, &revents);
        if (revents & POLLIN) {
            handle_event(hwdep_fd, ctl);
        }
    }

    // Close resources
    close(hwdep_fd);
    snd_ctl_close(ctl);

    return EXIT_SUCCESS;
}
예제 #4
0
파일: talk.c 프로젝트: kusumi/DragonFlyBSD
int
main(int argc, char **argv)
{
	(void) setlocale(LC_CTYPE, "");

	get_names(argc, argv);
	check_writeable();
	init_display();
	open_ctl();
	open_sockt();
	start_msgs();
	if (!check_local())
		invite_remote();
	end_msgs();
	set_edit_chars();
	talk();
	return 0;
}
예제 #5
0
/**
 * \brief Execute the sequence
 * \param uc_mgr Use case manager
 * \param seq Sequence
 * \return zero on success, otherwise a negative error code
 */
static int execute_sequence(snd_use_case_mgr_t *uc_mgr,
			    struct list_head *seq,
			    struct list_head *value_list1,
			    struct list_head *value_list2,
			    struct list_head *value_list3)
{
	struct list_head *pos;
	struct sequence_element *s;
	char *cdev = NULL;
	snd_ctl_t *ctl = NULL;
	int err = 0;

	list_for_each(pos, seq) {
		s = list_entry(pos, struct sequence_element, list);
		switch (s->type) {
		case SEQUENCE_ELEMENT_TYPE_CDEV:
			cdev = strdup(s->data.cdev);
			if (cdev == NULL)
				goto __fail_nomem;
			break;
		case SEQUENCE_ELEMENT_TYPE_CSET:
			if (cdev == NULL) {
				const char *cdev1 = NULL, *cdev2 = NULL;
				err = get_value3(&cdev1, "PlaybackCTL",
						 value_list1,
						 value_list2,
						 value_list3);
				if (err < 0 && err != ENOENT) {
					uc_error("cdev is not defined!");
					return err;
				}
				err = get_value3(&cdev1, "CaptureCTL",
						 value_list1,
						 value_list2,
						 value_list3);
				if (err < 0 && err != ENOENT) {
					free((char *)cdev1);
					uc_error("cdev is not defined!");
					return err;
				}
				if (cdev1 == NULL || cdev2 == NULL ||
                                    strcmp(cdev1, cdev2) == 0) {
					cdev = (char *)cdev1;
					free((char *)cdev2);
				} else {
					free((char *)cdev1);
					free((char *)cdev2);
				}
			}
			if (ctl == NULL) {
				err = open_ctl(uc_mgr, &ctl, cdev);
				if (err < 0) {
					uc_error("unable to open ctl device '%s'", cdev);
					goto __fail;
				}
			}
			err = execute_cset(ctl, s->data.cset);
			if (err < 0) {
				uc_error("unable to execute cset '%s'\n", s->data.cset);
				goto __fail;
			}
			break;
		case SEQUENCE_ELEMENT_TYPE_SLEEP:
			usleep(s->data.sleep);
			break;
		case SEQUENCE_ELEMENT_TYPE_EXEC:
			err = system(s->data.exec);
			if (err < 0)
				goto __fail;
			break;
		default:
			uc_error("unknown sequence command %i", s->type);
			break;
		}
	}
예제 #6
0
파일: serve.c 프로젝트: kzk/daemonutils
static int cmd_stop(char* name)
{
	int ctl = open_ctl(name);
	write(ctl, "d", 1);
	return 0;
}