=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/audioctl/audioctl.c,v retrieving revision 1.44 retrieving revision 1.45 diff -c -r1.44 -r1.45 *** src/usr.bin/audioctl/audioctl.c 2022/12/26 19:16:00 1.44 --- src/usr.bin/audioctl/audioctl.c 2023/01/08 06:58:07 1.45 *************** *** 1,4 **** ! /* $OpenBSD: audioctl.c,v 1.44 2022/12/26 19:16:00 jmc Exp $ */ /* * Copyright (c) 2016 Alexandre Ratchov * --- 1,4 ---- ! /* $OpenBSD: audioctl.c,v 1.45 2023/01/08 06:58:07 ratchov Exp $ */ /* * Copyright (c) 2016 Alexandre Ratchov * *************** *** 43,48 **** --- 43,49 ---- #define STR 2 #define ENC 3 int type; + int show; int set; } fields[] = { {"name", &rname.name, NULL, STR}, *************** *** 63,73 **** }; const char usagestr[] = ! "usage: audioctl [-f file]\n" ! " audioctl [-n] [-f file] name ...\n" " audioctl [-nq] [-f file] name=value ...\n"; ! int fd, show_names = 1, quiet = 0; /* * parse encoding string (examples: s8, u8, s16, s16le, s24be ...) --- 64,74 ---- }; const char usagestr[] = ! "usage: audioctl [-f file] [-w wait_sec]\n" ! " audioctl [-n] [-f file] [-w wait_sec] name ...\n" " audioctl [-nq] [-f file] name=value ...\n"; ! int fd, show_names = 1, quiet = 0, wait_sec = 0; /* * parse encoding string (examples: s8, u8, s16, s16le, s24be ...) *************** *** 198,217 **** char *lhs, *rhs; int set = 0; - if (ioctl(fd, AUDIO_GETSTATUS, &rstatus) == -1) - err(1, "AUDIO_GETSTATUS"); - if (ioctl(fd, AUDIO_GETDEV, &rname) == -1) - err(1, "AUDIO_GETDEV"); - if (ioctl(fd, AUDIO_GETPAR, &rpar) == -1) - err(1, "AUDIO_GETPAR"); - if (ioctl(fd, AUDIO_GETPOS, &rpos) == -1) - err(1, "AUDIO_GETPOS"); if (argc == 0) { ! for (f = fields; f->name != NULL; f++) { ! printf("%s=", f->name); ! print_field(f, f->raddr); ! printf("\n"); ! } } AUDIO_INITPAR(&wpar); for (; argc > 0; argc--, argv++) { --- 199,207 ---- char *lhs, *rhs; int set = 0; if (argc == 0) { ! for (f = fields; f->name != NULL; f++) ! f->show = 1; } AUDIO_INITPAR(&wpar); for (; argc > 0; argc--, argv++) { *************** *** 231,245 **** parse_field(f, f->waddr, rhs); f->set = 1; set = 1; ! } else { if (show_names) printf("%s=", f->name); print_field(f, f->raddr); printf("\n"); } } if (!set) return; if (ioctl(fd, AUDIO_SETPAR, &wpar) == -1) err(1, "AUDIO_SETPAR"); if (ioctl(fd, AUDIO_GETPAR, &wpar) == -1) --- 221,261 ---- parse_field(f, f->waddr, rhs); f->set = 1; set = 1; ! } else ! f->show = 1; ! } ! ! if (set && wait_sec) ! errx(1, "Can't set variables wait_secically"); ! ! while (1) { ! if (ioctl(fd, AUDIO_GETSTATUS, &rstatus) == -1) ! err(1, "AUDIO_GETSTATUS"); ! if (ioctl(fd, AUDIO_GETDEV, &rname) == -1) ! err(1, "AUDIO_GETDEV"); ! if (ioctl(fd, AUDIO_GETPAR, &rpar) == -1) ! err(1, "AUDIO_GETPAR"); ! if (ioctl(fd, AUDIO_GETPOS, &rpos) == -1) ! err(1, "AUDIO_GETPOS"); ! for (f = fields; f->name != NULL; f++) { ! if (!f->show) ! continue; if (show_names) printf("%s=", f->name); print_field(f, f->raddr); printf("\n"); } + + if (wait_sec == 0) + break; + + /* ioctls are fast, we neglect drift from real-time clock */ + sleep(wait_sec); } + if (!set) return; + if (ioctl(fd, AUDIO_SETPAR, &wpar) == -1) err(1, "AUDIO_SETPAR"); if (ioctl(fd, AUDIO_GETPAR, &wpar) == -1) *************** *** 261,269 **** main(int argc, char **argv) { char *path = "/dev/audioctl0"; int c; ! while ((c = getopt(argc, argv, "anf:q")) != -1) { switch (c) { case 'a': /* ignored, compat */ break; --- 277,286 ---- main(int argc, char **argv) { char *path = "/dev/audioctl0"; + const char *errstr; int c; ! while ((c = getopt(argc, argv, "anf:qw:")) != -1) { switch (c) { case 'a': /* ignored, compat */ break; *************** *** 275,280 **** --- 292,302 ---- break; case 'q': quiet = 1; + break; + case 'w': + wait_sec = strtonum(optarg, 1, INT_MAX, &errstr); + if (errstr != NULL) + errx(1, "wait is %s: %s", errstr, optarg); break; default: fputs(usagestr, stderr);