Re: added flush and quiet options to script(1)
On 07/16/18 18:11, bijan wrote: On 07/13/18 22:35, bijan wrote: Hi tech. While trying to test liveshell[1], I noticed the script(1) from base is missing the -f option, flushing the output after each write, which is kinda critical for monitoring the output file by another process. the Linux script utility uses fflush(3) after each write (duhh) but I'm not sure if anything more than removing buffering operation from the stream is necessary. So here's the diff which is working for me ping! no one is interested or am I missing something? added -f for quiet option out of boredom Now that I noticed my mail client was messing with the diff's format (after hitting send), I should first apologize for the unnecessary noise on the list. Just checked that attaching the Diff is safe to call it a day for now. Thank you -- Bijan Ebrahimi diff --git usr.bin/script/script.1 usr.bin/script/script.1 index f10ec2d4b..55e7e6868 100644 --- usr.bin/script/script.1 +++ usr.bin/script/script.1 @@ -38,7 +38,7 @@ .Nd make typescript of terminal session .Sh SYNOPSIS .Nm script -.Op Fl a +.Op Fl afq .Op Fl c Ar command .Op Ar file .Sh DESCRIPTION @@ -71,6 +71,10 @@ Run .Ar command instead of an interactive shell. To run a command with arguments, enclose both in quotes. +.It Fl f +Flush the output after each write. +.It Fl q +Only print errors and warnings. .El .Pp The script ends when the forked program exits (a control-D diff --git usr.bin/script/script.c usr.bin/script/script.c index 2e4173941..a58b618d5 100644 --- usr.bin/script/script.c +++ usr.bin/script/script.c @@ -85,7 +85,7 @@ volatile sig_atomic_t sigdeadstatus; volatile sig_atomic_t flush; struct termios tt; -int istty; +int istty, qflg; __dead void done(int); void dooutput(void); @@ -104,11 +104,11 @@ main(int argc, char *argv[]) char ibuf[BUFSIZ]; char *cmd; ssize_t cc, off; - int aflg, ch; + int aflg, fflg, ch; cmd = NULL; - aflg = 0; - while ((ch = getopt(argc, argv, "ac:")) != -1) + aflg = fflg = 0; + while ((ch = getopt(argc, argv, "ac:fq")) != -1) switch(ch) { case 'a': aflg = 1; @@ -116,8 +116,14 @@ main(int argc, char *argv[]) case 'c': cmd = optarg; break; + case 'f': + fflg = 1; + break; + case 'q': + qflg = 1; + break; default: - fprintf(stderr, "usage: %s [-a] [-c command] [file]\n", + fprintf(stderr, "usage: %s [-afq] [-c command] [file]\n", __progname); exit(1); } @@ -132,6 +138,9 @@ main(int argc, char *argv[]) if ((fscript = fopen(fname, aflg ? "a" : "w")) == NULL) err(1, "%s", fname); + if (fflg) + setvbuf(fscript, NULL, _IONBF, 0); + if (isatty(0)) { if (tcgetattr(STDIN_FILENO, ) == 0 && ioctl(STDIN_FILENO, TIOCGWINSZ, ) == 0) @@ -140,7 +149,8 @@ main(int argc, char *argv[]) if (openpty(, , NULL, , ) == -1) err(1, "openpty"); - (void)printf("Script started, output file is %s\n", fname); + if (qflg) + (void)printf("Script started, output file is %s\n", fname); if (istty) { struct termios rtt = tt; @@ -350,7 +360,8 @@ done(int eval) } else { if (istty) (void)tcsetattr(STDIN_FILENO, TCSAFLUSH, ); - (void)printf("Script done, output file is %s\n", fname); + if (qflg) + (void)printf("Script done, output file is %s\n", fname); } exit(eval); }
Re: add -f option to script(1)
On 07/13/18 22:35, bijan wrote: Hi tech. While trying to test liveshell[1], I noticed the script(1) from base is missing the -f option, flushing the output after each write, which is kinda critical for monitoring the output file by another process. the Linux script utility uses fflush(3) after each write (duhh) but I'm not sure if anything more than removing buffering operation from the stream is necessary. So here's the diff which is working for me ping! no one is interested or am I missing something? added -f for quiet option out of boredom -- Bijan Ebrahimi diff --git usr.bin/script/script.1 usr.bin/script/script.1 index f10ec2d4b..55e7e6868 100644 --- usr.bin/script/script.1 +++ usr.bin/script/script.1 @@ -38,7 +38,7 @@ .Nd make typescript of terminal session .Sh SYNOPSIS .Nm script -.Op Fl a +.Op Fl afq .Op Fl c Ar command .Op Ar file .Sh DESCRIPTION @@ -71,6 +71,10 @@ Run .Ar command instead of an interactive shell. To run a command with arguments, enclose both in quotes. +.It Fl f +Flush the output after each write. +.It Fl q +Only print errors and warnings. .El .Pp The script ends when the forked program exits (a control-D diff --git usr.bin/script/script.c usr.bin/script/script.c index 2e4173941..a58b618d5 100644 --- usr.bin/script/script.c +++ usr.bin/script/script.c @@ -85,7 +85,7 @@ volatile sig_atomic_t sigdeadstatus; volatile sig_atomic_t flush; struct termios tt; -intistty; +intistty, qflg; __dead void done(int); void dooutput(void); @@ -104,11 +104,11 @@ main(int argc, char *argv[]) char ibuf[BUFSIZ]; char *cmd; ssize_t cc, off; - int aflg, ch; + int aflg, fflg, ch; cmd = NULL; - aflg = 0; - while ((ch = getopt(argc, argv, "ac:")) != -1) + aflg = fflg = 0; + while ((ch = getopt(argc, argv, "ac:fq")) != -1) switch(ch) { case 'a': aflg = 1; @@ -116,8 +116,14 @@ main(int argc, char *argv[]) case 'c': cmd = optarg; break; + case 'f': + fflg = 1; + break; + case 'q': + qflg = 1; + break; default: - fprintf(stderr, "usage: %s [-a] [-c command] [file]\n", + fprintf(stderr, "usage: %s [-afq] [-c command] [file]\n", __progname); exit(1); } @@ -132,6 +138,9 @@ main(int argc, char *argv[]) if ((fscript = fopen(fname, aflg ? "a" : "w")) == NULL) err(1, "%s", fname); + if (fflg) + setvbuf(fscript, NULL, _IONBF, 0); + if (isatty(0)) { if (tcgetattr(STDIN_FILENO, ) == 0 && ioctl(STDIN_FILENO, TIOCGWINSZ, ) == 0) @@ -140,7 +149,8 @@ main(int argc, char *argv[]) if (openpty(, , NULL, , ) == -1) err(1, "openpty"); - (void)printf("Script started, output file is %s\n", fname); + if (qflg) + (void)printf("Script started, output file is %s\n", fname); if (istty) { struct termios rtt = tt; @@ -350,7 +360,8 @@ done(int eval) } else { if (istty) (void)tcsetattr(STDIN_FILENO, TCSAFLUSH, ); - (void)printf("Script done, output file is %s\n", fname); + if (qflg) + (void)printf("Script done, output file is %s\n", fname); } exit(eval); }
add -f option to script(1)
Hi tech. While trying to test liveshell[1], I noticed the script(1) from base is missing the -f option, flushing the output after each write, which is kinda critical for monitoring the output file by another process. the Linux script utility uses fflush(3) after each write (duhh) but I'm not sure if anything more than removing buffering operation from the stream is necessary. So here's the diff which is working for me 1: http://liveshell.43z.one/ -- Bijan Ebrahimi diff --git usr.bin/script/script.1 usr.bin/script/script.1 index f10ec2d4b..48a9d683f 100644 --- usr.bin/script/script.1 +++ usr.bin/script/script.1 @@ -38,7 +38,7 @@ .Nd make typescript of terminal session .Sh SYNOPSIS .Nm script -.Op Fl a +.Op Fl af .Op Fl c Ar command .Op Ar file .Sh DESCRIPTION @@ -71,6 +71,8 @@ Run .Ar command instead of an interactive shell. To run a command with arguments, enclose both in quotes. +.It Fl f +Flush the output after each write. .El .Pp The script ends when the forked program exits (a control-D diff --git usr.bin/script/script.c usr.bin/script/script.c index 2e4173941..b23e1c4d4 100644 --- usr.bin/script/script.c +++ usr.bin/script/script.c @@ -1,4 +1,4 @@ -/* $OpenBSD: script.c,v 1.34 2018/01/21 20:18:20 jasper Exp $ */ +/* $OpenBSD: script.c,v 0.34 2018/01/21 20:18:20 jasper Exp $ */ /* $NetBSD: script.c,v 1.3 1994/12/21 08:55:43 jtc Exp $ */ /* @@ -104,11 +104,11 @@ main(int argc, char *argv[]) char ibuf[BUFSIZ]; char *cmd; ssize_t cc, off; - int aflg, ch; + int aflg, fflg, ch; cmd = NULL; - aflg = 0; - while ((ch = getopt(argc, argv, "ac:")) != -1) + aflg = fflg = 0; + while ((ch = getopt(argc, argv, "ac:f")) != -1) switch(ch) { case 'a': aflg = 1; @@ -116,8 +116,11 @@ main(int argc, char *argv[]) case 'c': cmd = optarg; break; + case 'f': + fflg = 1; + break; default: - fprintf(stderr, "usage: %s [-a] [-c command] [file]\n", + fprintf(stderr, "usage: %s [-af] [-c command] [file]\n", __progname); exit(1); } @@ -132,6 +135,9 @@ main(int argc, char *argv[]) if ((fscript = fopen(fname, aflg ? "a" : "w")) == NULL) err(1, "%s", fname); + if (fflg) + setvbuf(fscript, NULL, _IONBF, 0); + if (isatty(0)) { if (tcgetattr(STDIN_FILENO, ) == 0 && ioctl(STDIN_FILENO, TIOCGWINSZ, ) == 0)
Re: on-line kernel debugging
On 02/02/18 04:31, David Gwynne wrote: On 28 Jan 2018, at 04:07, bijan <bijanebrah...@riseup.net> wrote: Thank you (for the quick response) and sorry if I was not as clear as I should have been! what I meant and was hoping to find was a source code debugger support, like gdb[1], where one can debug a running kernel with full access to the source code in a gdb session environment from a remote machine. I'm new to OpenBSD and found kgdb(7)[2] manual from 6.1 describing the process very similar to what I do daily with FreeBSD but (as I mentioned earlier) the code seems to be removed since 6.2. So, is there any alternative for remote debugging a running OpenBSD kernel using gdb? anyhow, I appreciate it if one can point me to the right direction and I don't mind any hard work in the process :-) i dont think we support kgdb anymore, but we do support running gdb inside a system against its running kernel. to do this, you need to have the kern.allowkmem sysctl set, which is best done via /etc/sysctl.conf. Great ... Thanks :-) I should definitely try this one Anyhow, I recently studied the FreeBSD source code for it's implementation of kdb and briefly examined the implementation and changes of ddb(4) in OpenBSD source code. It seems to me that it's possible to add support for multiple debuggers like gdb (as a standalone back-end or as a ddb command) to OpenBSD kernel as well (since the remote protocol is quiet small and the infrastructures looks pretty much the same as FreeBSD to me). I'm not quiet sure if I'm capable of porting the code, but if no-one is interested (or is free to do the job), I will definitely give it a try. So, is there anything one should know why such feature is missing? Or any reason to prevent such effort in the first place? Thanks B.E after that you'll need a kernel with debug symbols in it. the easiest way to get that is just build a kernel. there'll be a bsd.gdb next to the bsd it produces. then you can do this: dlg@v215 GENERIC.MP$ pwd /usr/obj/sys/arch/sparc64/compile/GENERIC.MP dlg@v215 GENERIC.MP$ ls bsd bsd.gdb -rwxrwx--- 1 dlg wobj 10193351 Feb 2 10:58 bsd -rwxrwx--- 1 dlg wobj 3915 Feb 2 10:58 bsd.gdb dlg@v215 GENERIC.MP$ cat /etc/sysctl.conf kern.allowkmem=1 dlg@v215 GENERIC.MP$ sysctl kern.allowkmem kern.allowkmem=1 dlg@v215 GENERIC.MP$ sudo gdb bsd.gdb GNU gdb 6.3 Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "sparc64-unknown-openbsd6.2"... (gdb) target kvm #0 mi_switch () at /usr/src/sys/kern/sched_bsd.c:410 410 cpu_switchto(p, nextproc); (gdb) print copyright $1 = "Copyright (c) 1982, 1986, 1989, 1991, 1993\n\tThe Regents of the University of California. All rights reserved.\nCopyright (c) 1995-2017 OpenBSD. All rights reserved. https://www.OpenBSD.org\n; the important thing is the "target kvm" inside gdb, which relies on allowkmem. because of the allowkmem requirement, this recommended for use on development boxes only. dlg
Re: list only names of interfaces in ifconfig.8
On 01/28/18 21:24, bijan wrote: Hi, Added -l argument to ifconfig to only print names of interfaces. (Maybe a lame excuse from me for being too lazy but FreeBSD supports it too) Missed the usage string, Update! >From 2d00dbc563db1f2581342cbf02a83cbb3a6a5966 Mon Sep 17 00:00:00 2001 From: Bijan Ebrahimi <bijanebrah...@riseup.net> Date: Fri, 19 Jan 2018 18:18:24 +0330 Subject: [PATCH] added printing list names --- sbin/ifconfig/ifconfig.8 | 7 ++- sbin/ifconfig/ifconfig.c | 37 - 2 files changed, 42 insertions(+), 2 deletions(-) diff --git sbin/ifconfig/ifconfig.8 sbin/ifconfig/ifconfig.8 index ef9592cf3..6055fa4aa 100644 --- sbin/ifconfig/ifconfig.8 +++ sbin/ifconfig/ifconfig.8 @@ -39,7 +39,7 @@ .Nd configure network interface parameters .Sh SYNOPSIS .Nm ifconfig -.Op Fl AaC +.Op Fl AaCl .Op Ar interface .Op Ar address_family .Oo @@ -88,6 +88,11 @@ This is the default, if no parameters are given to Print the names of all network pseudo-devices that can be created dynamically at runtime using .Nm Cm create . +.It Fl l +Causes +.Nm +to print names of all existing interfaces. +.Nm . .It Ar interface The .Ar interface diff --git sbin/ifconfig/ifconfig.c sbin/ifconfig/ifconfig.c index 4a0f4d632..3505287c4 100644 --- sbin/ifconfig/ifconfig.c +++ sbin/ifconfig/ifconfig.c @@ -232,6 +232,7 @@ void unsettrunkport(const char *, int); void settrunkproto(const char *, int); void trunk_status(void); void list_cloners(void); +void list_names(void); #ifndef SMALL void carp_status(void); @@ -632,6 +633,7 @@ main(int argc, char *argv[]) const struct afswtch *rafp = NULL; int create = 0; int Cflag = 0; + int lflag = 0; int gflag = 0; int i; @@ -659,6 +661,10 @@ main(int argc, char *argv[]) case 'g': gflag = 1; break; + case 'l': +lflag = 1; +nomore = 1; +break; case 'C': Cflag = 1; nomore = 1; @@ -695,6 +701,10 @@ main(int argc, char *argv[]) list_cloners(); return (0); } + if (lflag) { + list_names(); + return (0); + } if (gflag) { if (argc == 0) printgroupattribs(name); @@ -1147,6 +1157,31 @@ list_cloners(void) free(buf); } +void +list_names(void) +{ + int count = 0; + struct ifaddrs *ifap, *ifa; + const char *if_name = NULL; + + if (getifaddrs() != 0) + err(1, "getifaddrs"); + + for (ifa = ifap; ifa; ifa = ifa->ifa_next) { + if (if_name == ifa->ifa_name) + continue; + if_name = ifa->ifa_name; + if (count++ > 0) + printf(" "); + printf ("%s", ifa->ifa_name); + } + + if (if_name != NULL) + printf("\n"); + + freeifaddrs(ifap); +} + #define RIDADDR 0 #define ADDR 1 #define MASK 2 @@ -5453,7 +5488,7 @@ __dead void usage(void) { fprintf(stderr, - "usage: ifconfig [-AaC] [interface] [address_family] " + "usage: ifconfig [-AaCl] [interface] [address_family] " "[address [dest_address]]\n" "\t\t[parameters]\n"); exit(1); -- 2.14.2
list only names of interfaces in ifconfig.8
Hi, Added -l argument to ifconfig to only print names of interfaces. (Maybe a lame excuse from me for being too lazy but FreeBSD supports it too) Hope it helps, B.E >From dc4f0f8d85a9aa2007b47139f6d609c9830bbfc3 Mon Sep 17 00:00:00 2001 From: Bijan Ebrahimi <bijanebrah...@riseup.net> Date: Fri, 19 Jan 2018 18:18:24 +0330 Subject: [PATCH] added printing names of all inetrfaces to ifconfig --- sbin/ifconfig/ifconfig.8 | 7 ++- sbin/ifconfig/ifconfig.c | 35 +++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git sbin/ifconfig/ifconfig.8 sbin/ifconfig/ifconfig.8 index ef9592cf3..6055fa4aa 100644 --- sbin/ifconfig/ifconfig.8 +++ sbin/ifconfig/ifconfig.8 @@ -39,7 +39,7 @@ .Nd configure network interface parameters .Sh SYNOPSIS .Nm ifconfig -.Op Fl AaC +.Op Fl AaCl .Op Ar interface .Op Ar address_family .Oo @@ -88,6 +88,11 @@ This is the default, if no parameters are given to Print the names of all network pseudo-devices that can be created dynamically at runtime using .Nm Cm create . +.It Fl l +Causes +.Nm +to print names of all existing interfaces. +.Nm . .It Ar interface The .Ar interface diff --git sbin/ifconfig/ifconfig.c sbin/ifconfig/ifconfig.c index 4a0f4d632..c4c9a1527 100644 --- sbin/ifconfig/ifconfig.c +++ sbin/ifconfig/ifconfig.c @@ -232,6 +232,7 @@ void unsettrunkport(const char *, int); void settrunkproto(const char *, int); void trunk_status(void); void list_cloners(void); +void list_names(void); #ifndef SMALL void carp_status(void); @@ -632,6 +633,7 @@ main(int argc, char *argv[]) const struct afswtch *rafp = NULL; int create = 0; int Cflag = 0; + int lflag = 0; int gflag = 0; int i; @@ -659,6 +661,10 @@ main(int argc, char *argv[]) case 'g': gflag = 1; break; + case 'l': +lflag = 1; +nomore = 1; +break; case 'C': Cflag = 1; nomore = 1; @@ -695,6 +701,10 @@ main(int argc, char *argv[]) list_cloners(); return (0); } + if (lflag) { + list_names(); + return (0); + } if (gflag) { if (argc == 0) printgroupattribs(name); @@ -1147,6 +1157,31 @@ list_cloners(void) free(buf); } +void +list_names(void) +{ + int count = 0; + struct ifaddrs *ifap, *ifa; + const char *if_name = NULL; + + if (getifaddrs() != 0) + err(1, "getifaddrs"); + + for (ifa = ifap; ifa; ifa = ifa->ifa_next) { + if (if_name == ifa->ifa_name) + continue; + if_name = ifa->ifa_name; + if (count++ > 0) + printf(" "); + printf ("%s", ifa->ifa_name); + } + + if (if_name != NULL) + printf("\n"); + + freeifaddrs(ifap); +} + #define RIDADDR 0 #define ADDR 1 #define MASK 2 -- 2.14.2
Re: on-line kernel debugging
Thank you (for the quick response) and sorry if I was not as clear as I should have been! what I meant and was hoping to find was a source code debugger support, like gdb[1], where one can debug a running kernel with full access to the source code in a gdb session environment from a remote machine. I'm new to OpenBSD and found kgdb(7)[2] manual from 6.1 describing the process very similar to what I do daily with FreeBSD but (as I mentioned earlier) the code seems to be removed since 6.2. So, is there any alternative for remote debugging a running OpenBSD kernel using gdb? anyhow, I appreciate it if one can point me to the right direction and I don't mind any hard work in the process :-) [1]: https://www.freebsd.org/doc/en/books/developers-handbook/kerneldebug-online-gdb.html [2]: https://man.openbsd.org/OpenBSD-6.1/kgdb.7 On 01/27/18 21:00, Todd C. Miller wrote: On Sat, 27 Jan 2018 20:46:18 +0330, bijan wrote: does OpenBSD support on-line kernel debugging as FreeBSD does[1]? Yes, see the ddb(4) manual page. - todd
on-line kernel debugging
Hi! (Don't know if tech@ is the right place to ask such questions, just hope it is) does OpenBSD support on-line kernel debugging as FreeBSD does[1]? The only document I managed to find was a fairly old one[2] by QEMU over GNU/Linux but it seems kgdb(7) is removed since 6.2 (apparently for not even working before[3]). Thank you! [1]: https://www.freebsd.org/doc/en/books/developers-handbook/kerneldebug-online-ddb.html [2]: https://markshroyer.com/2013/01/debugging-openbsd-via-qemu/ [3]: https://github.com/openbsd/src/commits/master/sys/sys/kgdb.h
Re: make mpls_input take struct ifnet *ifp as an argument
(forwarded from misc@) Hi, while reading the changes in OpenBSD source code (hopefully to learn more), I've notice the usage of Uninitialized variable. Looks like the latest commit unintentionally removed the assignment line (sorry for the github link): https://github.com/openbsd/src/commit/5c53b9324545b7febab2dcf52402199d72b231d3?diff=split#diff-3efc580dfa272b2173162f5950c92484R86 The following should bring back (the possibly) unwanted change.s Hope it helps unless I missed something diff --git a/sys/netmpls/mpls_input.c b/sys/netmpls/mpls_input.c index 34fe7314d..fff3564c8 100644 --- a/sys/netmpls/mpls_input.c +++ b/sys/netmpls/mpls_input.c @@ -76,13 +76,15 @@ mpls_input(struct ifnet *ifp, struct mbuf *m) } shim = mtod(m, struct shim_hdr *); - #ifdef MPLS_DEBUG printf("mpls_input: iface %s label=%d, ttl=%d BoS %d\n", - ifp->if_xname, MPLS_LABEL_GET(shim->shim_label), ttls, hasbos); + ifp->if_xname, MPLS_LABEL_GET(shim->shim_label), + MPLS_LABEL_GET(shim->shim_label), + MPLS_BOS_ISSET(shim->shim_label)); #endif /* check and decrement TTL */ + ttl = MPLS_LABEL_GET(shim->shim_label); if (--ttl == 0) { /* TTL exceeded */ m = mpls_do_error(m, ICMP_TIMXCEED, ICMP_TIMXCEED_INTRANS, 0);