ddb(4) and usb keyboards

2018-10-13 Thread Colton Lewis
Hello all,

I wish to use the kernel debugger, but triggering it from the system
console causes the computer to stop responding to all keyboard input
and my only way out is a hard reset. I have tried every USB hub on my
system with the same result. I do not currently own another keyboard
to try.

Is this a bug or is there something I am not understanding? While this
dmesg is a recent snapshot, I've seen this before, but was apathetic.

Sincerely,
Colton Lewis
OpenBSD 6.4 (GENERIC.MP) #341: Sun Sep 30 00:31:59 MDT 2018
dera...@amd64.openbsd.org:/usr/src/sys/arch/amd64/compile/GENERIC.MP
real mem = 8497737728 (8104MB)
avail mem = 8230928384 (7849MB)
mpath0 at root
scsibus0 at mpath0: 256 targets
mainbus0 at root
bios0 at mainbus0: SMBIOS rev. 2.8 @ 0xec3b0 (78 entries)
bios0: vendor American Megatrends Inc. version "V10.9" date 04/21/2015
bios0: MSI MS-7817
acpi0 at bios0: rev 2
acpi0: sleep states S0 S3 S4 S5
acpi0: tables DSDT FACP APIC FPDT SSDT SSDT MCFG HPET SSDT SSDT ASF! SSDT BGRT
acpi0: wakeup devices PXSX(S4) RP01(S4) PXSX(S4) PXSX(S4) RP03(S4) PXSX(S4) 
RP04(S4) PXSX(S4) PXSX(S4) RP06(S4) PXSX(S4) PXSX(S4) GLAN(S4) EHC1(S4) 
EHC2(S4) XHC_(S4) [...]
acpitimer0 at acpi0: 3579545 Hz, 24 bits
acpimadt0 at acpi0 addr 0xfee0: PC-AT compat
cpu0 at mainbus0: apid 0 (boot processor)
cpu0: Intel(R) Pentium(R) CPU G3220 @ 3.00GHz, 3000.40 MHz, 06-3c-03
cpu0: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,EST,TM2,SSSE3,SDBG,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,MOVBE,POPCNT,DEADLINE,XSAVE,RDRAND,NXE,PAGE1GB,RDTSCP,LONG,LAHF,ABM,PERF,ITSC,FSGSBASE,ERMS,INVPCID,IBRS,IBPB,STIBP,L1DF,SSBD,SENSOR,ARAT,XSAVEOPT,MELTDOWN
cpu0: 256KB 64b/line 8-way L2 cache
cpu0: smt 0, core 0, package 0
mtrr: Pentium Pro MTRR support, 10 var ranges, 88 fixed ranges
cpu0: apic clock running at 99MHz
cpu0: mwait min=64, max=64, C-substates=0.2.1.2, IBE
cpu1 at mainbus0: apid 2 (application processor)
cpu1: Intel(R) Pentium(R) CPU G3220 @ 3.00GHz, 3000.00 MHz, 06-3c-03
cpu1: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,EST,TM2,SSSE3,SDBG,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,MOVBE,POPCNT,DEADLINE,XSAVE,RDRAND,NXE,PAGE1GB,RDTSCP,LONG,LAHF,ABM,PERF,ITSC,FSGSBASE,ERMS,INVPCID,IBRS,IBPB,STIBP,L1DF,SSBD,SENSOR,ARAT,XSAVEOPT,MELTDOWN
cpu1: 256KB 64b/line 8-way L2 cache
cpu1: smt 0, core 1, package 0
ioapic0 at mainbus0: apid 8 pa 0xfec0, version 20, 24 pins
acpimcfg0 at acpi0
acpimcfg0: addr 0xf800, bus 0-63
acpihpet0 at acpi0: 14318179 Hz
acpiprt0 at acpi0: bus 0 (PCI0)
acpiprt1 at acpi0: bus 2 (RP01)
acpiprt2 at acpi0: bus 3 (RP03)
acpiprt3 at acpi0: bus 4 (RP04)
acpiprt4 at acpi0: bus 6 (RP06)
acpiprt5 at acpi0: bus 1 (PEG0)
acpiprt6 at acpi0: bus -1 (PEG1)
acpiprt7 at acpi0: bus -1 (PEG2)
acpiec0 at acpi0: not present
acpicpu0 at acpi0: C2(350@117 mwait.1@0x20), C1(1000@1 mwait.1), PSS
acpicpu1 at acpi0: C2(350@117 mwait.1@0x20), C1(1000@1 mwait.1), PSS
acpipwrres0 at acpi0: FN00, resource for FAN0
acpipwrres1 at acpi0: FN01, resource for FAN1
acpipwrres2 at acpi0: FN02, resource for FAN2
acpipwrres3 at acpi0: FN03, resource for FAN3
acpipwrres4 at acpi0: FN04, resource for FAN4
acpitz0 at acpi0: critical temperature is 105 degC
acpitz1 at acpi0: critical temperature is 105 degC
acpicmos0 at acpi0
"PNP0C14" at acpi0 not configured
acpibtn0 at acpi0: PWRB
"PNP0C14" at acpi0 not configured
"INT33A0" at acpi0 not configured
"PNP0C0B" at acpi0 not configured
"PNP0C0B" at acpi0 not configured
"PNP0C0B" at acpi0 not configured
"PNP0C0B" at acpi0 not configured
"PNP0C0B" at acpi0 not configured
acpivideo0 at acpi0: GFX0
acpivout0 at acpivideo0: DD1F
cpu0: Enhanced SpeedStep 3000 MHz: speeds: 3000, 2900, 2700, 2600, 2400, 2300, 
2100, 2000, 1800, 1700, 1500, 1400, 1200, 1100, 900, 800 MHz
pci0 at mainbus0 bus 0
pchb0 at pci0 dev 0 function 0 "Intel Core 4G Host" rev 0x06
ppb0 at pci0 dev 1 function 0 "Intel Core 4G PCIE" rev 0x06: msi
pci1 at ppb0 bus 1
radeondrm0 at pci1 dev 0 function 0 "ATI Radeon HD 6450" rev 0x00
drm0 at radeondrm0
radeondrm0: msi
azalia0 at pci1 dev 0 function 1 "ATI Radeon HD 6400 Audio" rev 0x00: msi
azalia0: no supported codecs
xhci0 at pci0 dev 20 function 0 "Intel 8 Series xHCI" rev 0x05: msi, xHCI 1.0
usb0 at xhci0: USB revision 3.0
uhub0 at usb0 configuration 1 interface 0 "Intel xHCI root hub" rev 3.00/1.00 
addr 1
"Intel 8 Series MEI" rev 0x04 at pci0 dev 22 function 0 not configured
ehci0 at pci0 dev 26 function 0 "Intel 8 Series USB" rev 0x05: apic 8 int 16
usb1 at ehci0: USB revision 2.0
uhub1 at usb1 configuration 1 interface 0 "Intel EHCI root hub" rev 2.00/1.00 
addr 1
azalia1 at pci0 dev 27 function 0 "Intel 8 Series HD Audio" rev 0x05: msi
azalia1: codecs: Realtek/0x0887
audio0 at azalia1
ppb1 at pci0 dev 28 function 0 "Intel 8 Series PCIE" rev 0xd5: msi
pci2 at ppb1 bus 2
ppb2 at 

Re: Problems with a quad Realtek NIC

2018-10-13 Thread Nick Holland
On 10/12/18 21:42, Martin Hanson wrote:
>> It is preferable to just include the whole dmesg directly in the mail
>> Better still, when it's a "sometimes works" problem, include a "diff -u"
>> between the two (the context to show where the lines are added/removed).
> 
> I have pasted a "diff -u" on https://paste

FYI...  I don't click on links for stuff that should be in-message.

I suspect I'm not alone.


But yes, I agree with Stuart, sounds like a HW problem.  When things
come and go without changing, that pretty well screams "hw".  Different
OSs may work around different hw bugs differently, but it's still a HW
bug.  In your case, looks like the BIOS isn't initializing the PCI-PCI
bridges properly.

> +ppb1 at pci1 dev 0 function 0
> vendor "ASMedia", unknown product 0x1184 rev 0x00
> +pci2 at ppb1 bus 2
> +ppb2 at pci2 dev 1 function 0 vendor "ASMedia", unknown product 0x1184
> rev 0x00: not configured by system firmware
   ===
> +ppb3 at pci2 dev 3 function 0 vendor "ASMedia", unknown product 0x1184

(man ppb)

And yes, while Realteks used to be condemned and insulted, the new
network devices on many ARM boards is making Realteks look good. At
least their limitations are understood and dealt with well in SW.

Most people don't need the absolute best HW.  But in your case, you
probably want those PCI-PCI bridges configured. :)

Nick.



Re: VMM sh: time sleep 30 takes 56 seconds

2018-10-13 Thread Daniel Bolgheroni
On Sat, Oct 13, 2018 at 01:08:23AM +, Jordan Geoghegan wrote:
> Hello,
> 
> Not sure if this is a bug or not, so I thought I would ask misc@ first.
> 
> I was writing a script in my vmm guest that involved killing and restarting
> a long running process every hour using sleep "3600", and I noticed it ended
> up sleeping for 2 hours and 56 minutes, rather than an hour.
> 
> To test, I ran "time sleep 30" and got this result:
> 
> vmm$ time sleep 30
>     0m57.50s real 0m00.00s user 0m00.00s system
> 
> When run on bare metal, I get this result:
> 
> server$ time sleep 30
>     0m30.00s real 0m00.00s user 0m00.00s system
> 
> I have "sysctl kern.timecounter.hardware=tsc" set in the vm to prevent clock
> drift, otherwise the vm clock runs at around half speed.
> 
> When "time sleep 30" is run on a vm without "sysctl
> kern.timecounter.hardware=tsc" set, it reports the correct amount of time
> being spent sleeping, but since the clock runs at around half speed without
> tsc enabled, it still ends up sleeping for almost a minute.
> 
> The host machine is running 6.3 stable, the guest is running the latest
> snapshot. I tried running a 6.3-stable guest with the same results.
> 
> Has this been fixed in current? I don't have a vmm capable machine available
> running current, I only own spare macppc and i386 hardware which runs
> current.

I get the same results as yours also with a -current vm running on
-current, also with kern.timecounter.hardware=tsc on the vm.

# time sleep 30
0m59.99s real 0m00.00s user 0m00.00s system
# time sleep 30
1m00.30s real 0m00.00s user 0m00.00s system
# time sleep 30
1m00.30s real 0m00.00s user 0m00.00s system
#

I don't know if it's somehow related to the same interrupt thing, but I
also get a slow scroll when attached to the console.

OpenBSD 6.4 (GENERIC.MP) #364: Thu Oct 11 13:30:23 MDT 2018
dera...@amd64.openbsd.org:/usr/src/sys/arch/amd64/compile/GENERIC.MP
real mem = 8451125248 (8059MB)
avail mem = 8185724928 (7806MB)
mpath0 at root
scsibus0 at mpath0: 256 targets
mainbus0 at root
bios0 at mainbus0: SMBIOS rev. 2.6 @ 0xdae9c000 (64 entries)
bios0: vendor LENOVO version "8DET73WW (1.43 )" date 10/12/2016
bios0: LENOVO 4291MV7
acpi0 at bios0: rev 2
acpi0: sleep states S0 S3 S4 S5
acpi0: tables DSDT FACP SLIC SSDT SSDT SSDT HPET APIC MCFG ECDT ASF! TCPA SSDT 
SSDT DMAR UEFI UEFI UEFI
acpi0: wakeup devices LID_(S3) SLPB(S3) IGBE(S4) EXP4(S4) EXP7(S4) EHC1(S3) 
EHC2(S3) HDEF(S4)
acpitimer0 at acpi0: 3579545 Hz, 24 bits
acpihpet0 at acpi0: 14318179 Hz
acpimadt0 at acpi0 addr 0xfee0: PC-AT compat
cpu0 at mainbus0: apid 0 (boot processor)
cpu0: Intel(R) Core(TM) i5-2520M CPU @ 2.50GHz, 2492.33 MHz, 06-2a-07
cpu0: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,SMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,NXE,RDTSCP,LONG,LAHF,PERF,ITSC,IBRS,IBPB,STIBP,L1DF,SSBD,SENSOR,ARAT,XSAVEOPT,MELTDOWN
cpu0: 256KB 64b/line 8-way L2 cache
cpu0: smt 0, core 0, package 0
mtrr: Pentium Pro MTRR support, 10 var ranges, 88 fixed ranges
cpu0: apic clock running at 99MHz
cpu0: mwait min=64, max=64, C-substates=0.2.1.1.2, IBE
cpu1 at mainbus0: apid 1 (application processor)
cpu1: Intel(R) Core(TM) i5-2520M CPU @ 2.50GHz, 2491.91 MHz, 06-2a-07
cpu1: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,SMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,NXE,RDTSCP,LONG,LAHF,PERF,ITSC,IBRS,IBPB,STIBP,L1DF,SSBD,SENSOR,ARAT,XSAVEOPT,MELTDOWN
cpu1: 256KB 64b/line 8-way L2 cache
cpu1: smt 1, core 0, package 0
cpu2 at mainbus0: apid 2 (application processor)
cpu2: Intel(R) Core(TM) i5-2520M CPU @ 2.50GHz, 2491.91 MHz, 06-2a-07
cpu2: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,SMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,NXE,RDTSCP,LONG,LAHF,PERF,ITSC,IBRS,IBPB,STIBP,L1DF,SSBD,SENSOR,ARAT,XSAVEOPT,MELTDOWN
cpu2: 256KB 64b/line 8-way L2 cache
cpu2: smt 0, core 1, package 0
cpu3 at mainbus0: apid 3 (application processor)
cpu3: Intel(R) Core(TM) i5-2520M CPU @ 2.50GHz, 2491.91 MHz, 06-2a-07
cpu3: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,SMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,NXE,RDTSCP,LONG,LAHF,PERF,ITSC,IBRS,IBPB,STIBP,L1DF,SSBD,SENSOR,ARAT,XSAVEOPT,MELTDOWN
cpu3: 256KB 64b/line 8-way L2 cache
cpu3: smt 1, core 1, package 0
ioapic0 at mainbus0: apid 2 pa 0xfec0, version 20, 24 pins
acpimcfg0 at acpi0
acpimcfg0: addr 0xf800, bus 0-63
acpiec0 

No panic output in dmesg, and using sendbug?

2018-10-13 Thread Sijmen J. Mulder
Hi,

My vintage Dell Inspiron 510m laptop experiences panics with recent
snapshots and fails to boot the latest with a core dump.

I've read the following:

https://www.openbsd.org/report.html
https://man.openbsd.org/crash

But I can't figure out how to make this work. Questions:

 1. Neither the ddb output of the panics of the running system nor the
boot time end up in dmesg. How do I get them?

 2. I don't have experience with email admin, but can I trust smtpd to
succeed delivering my email without further set up considering I'm
on a residential connection and and not using a regular SMTP server?
Should I use -P instead and use my regular email client?

Sijmen



usbd_free_xfer: xfer=0xffffff041e9651e0 not free

2018-10-13 Thread Leo Unglaub

Hello,
i just upgraded to the latest snapshot and i noticed that all my 
external USB drives are not working anymore. (i tryed 3 different 
external drives) As soon as i plug them into an USB port I get the 
following message in my dmesg:



usbd_free_xfer: xfer=0xff041e9651e0 not free


I tryed all ports on my computer. USB2 and USB3, I both get the same 
error message. After that error message the drives does not show up in 
dmesg or in sysctl hw.disknames.


In the snapshot from 2 weeks ago it still worked fine. Is this an error 
on my side or an error? The one thing that looks strange to me is that 
the dmesg starts different than it normally does.


Here is some information about my system.
Thanks and greetings
Leo

# sysctl 
kern.ostype=OpenBSD

kern.osrelease=6.4
kern.osrevision=201811
kern.version=OpenBSD 6.4 (GENERIC.MP) #364: Thu Oct 11 13:30:23 MDT 2018
dera...@amd64.openbsd.org:/usr/src/sys/arch/amd64/compile/GENERIC.MP

kern.maxvnodes=42324
kern.maxproc=1310
kern.maxfiles=7030
kern.argmax=262144
kern.securelevel=1
kern.hostname=batdesk.wayne-data.enterprises
kern.hostid=0
kern.clockrate=tick = 1, tickadj = 40, hz = 100, profhz = 100, stathz = 100
kern.dnsjackport=0
kern.posix1version=200809
kern.ngroups=16
kern.job_control=1
kern.saved_ids=1
kern.boottime=Sat Oct 13 18:38:44 2018
kern.domainname=
kern.maxpartitions=16
kern.rawpartition=2
kern.maxthread=1950
kern.nthreads=305
kern.osversion=GENERIC.MP#364
kern.somaxconn=128
kern.sominconn=80
kern.nosuidcoredump=1
kern.fsync=1
kern.sysvmsg=1
kern.sysvsem=1
kern.sysvshm=1
kern.msgbufsize=98256
kern.malloc.buckets=16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144,524288
kern.malloc.bucket.16=(calls = 20627 total_allocated = 3584 total_free = 138 
elements = 256 high watermark = 1280 could_free = 0)
kern.malloc.bucket.32=(calls = 13359 total_allocated = 2688 total_free = 114 
elements = 128 high watermark = 640 could_free = 0)
kern.malloc.bucket.64=(calls = 48033 total_allocated = 2496 total_free = 330 
elements = 64 high watermark = 320 could_free = 726)
kern.malloc.bucket.128=(calls = 58193 total_allocated = 11360 total_free = 319 
elements = 32 high watermark = 160 could_free = 16)
kern.malloc.bucket.256=(calls = 39460 total_allocated = 720 total_free = 71 
elements = 16 high watermark = 80 could_free = 1)
kern.malloc.bucket.512=(calls = 4892 total_allocated = 320 total_free = 21 
elements = 8 high watermark = 40 could_free = 0)
kern.malloc.bucket.1024=(calls = 6959 total_allocated = 552 total_free = 10 
elements = 4 high watermark = 20 could_free = 104)
kern.malloc.bucket.2048=(calls = 1343 total_allocated = 68 total_free = 9 
elements = 2 high watermark = 10 could_free = 13)
kern.malloc.bucket.4096=(calls = 3062 total_allocated = 625 total_free = 24 
elements = 1 high watermark = 5 could_free = 1022)
kern.malloc.bucket.8192=(calls = 747 total_allocated = 249 total_free = 8 
elements = 1 high watermark = 5 could_free = 85)
kern.malloc.bucket.16384=(calls = 1510 total_allocated = 26 total_free = 0 
elements = 1 high watermark = 5 could_free = 0)
kern.malloc.bucket.32768=(calls = 185 total_allocated = 12 total_free = 0 
elements = 1 high watermark = 5 could_free = 0)
kern.malloc.bucket.65536=(calls = 2574 total_allocated = 4 total_free = 0 
elements = 1 high watermark = 5 could_free = 0)
kern.malloc.bucket.131072=(calls = 25 total_allocated = 5 total_free = 0 
elements = 1 high watermark = 5 could_free = 0)
kern.malloc.bucket.262144=(calls = 0 total_allocated = 0 total_free = 0 
elements = 1 high watermark = 5 could_free = 0)
kern.malloc.bucket.524288=(calls = 11 total_allocated = 11 total_free = 0 
elements = 1 high watermark = 5 could_free = 0)
kern.malloc.kmemnames=free,,devbuf,,pcb,rtableifaddr,soopts,sysctl,counters,,ioctlops,iov,mount,,NFS_req,NFS_mount,,vnodes,namecache,UFS_quota,UFS_mount,shm,VM_map,sem,dirhash,ACPI,VM_pmapfile,file_desc,,proc,subproc,VFS_cluster,,,MFS_node,,,Export_Host,NFS_srvsock,,NFS_daemon,ip_moptions,in_multi,ether_multi,mrt,ISOFS_mount,ISOFS_node,MSDOSFS_mount,MSDOSFS_fat,MSDOSFS_node,ttys,exec,miscfs_mount,fusefs_mount,pfkey_data,tdb,xform_data,,pagedep,inodedep,newblk,,,indirdep,VM_swap,,UVM_amap,UVM_aobj,,USB,USB_device,USB_HC,,memdesc,,,crypto_data,,IPsec_credsemuldata,ip6_options,NDP,,,temp,NTFS_mount,NTFS_node,NTFS_fnode,NTFS_dir,NTFS_hash,NTFS_attr,NTFS_data,NTFS_decomp,NTFS_vrun,kqueue,,SYN_cache,UDF_mount,UDF_file_entry,UDF_file_id,,AGP_Memory,DRM
kern.malloc.kmemstat.free=(inuse = 0, calls = 0, memuse = 0K, limblocks = 0, 
mapblocks = 0, maxused = 0K, limit = 78644K, spare = 0, sizes = (none))
kern.malloc.kmemstat.devbuf=(inuse = 2348, calls = 8920, memuse = 7417K, 
limblocks = 0, mapblocks = 0, maxused = 7565K, limit = 78644K, spare = 0, sizes 
= (16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,524288))
kern.malloc.kmemstat.pcb=(inuse = 204, calls = 296, memuse = 32K, limblocks = 
0, mapblocks = 0, maxused 

Re: ksh equivalent to shell-expand-line

2018-10-13 Thread Hajime Edakawa
Forgive me for sending so many email.

I've rewritten code again one last time.  I'm not sure if this is correct.
I was able to learn shell through these emails. I really appreciate it.

Best regards,
Hajime Edakawa

Index: emacs.c
===
RCS file: /cvs/src/bin/ksh/emacs.c,v
retrieving revision 1.85
diff -u -p -r1.85 emacs.c
--- emacs.c 18 Jun 2018 17:03:58 -  1.85
+++ emacs.c 13 Oct 2018 06:04:46 -
@@ -201,6 +201,7 @@ static int  x_fold_lower(int);
 static int x_fold_upper(int);
 static int x_set_arg(int);
 static int x_comment(int);
+static int x_expand_alias_sub(int);
 #ifdef DEBUG
 static int x_debug_info(int);
 #endif
@@ -258,6 +259,7 @@ static const struct x_ftab x_ftab[] = {
{ x_fold_upper, "upcase-word",  XF_ARG },
{ x_set_arg,"set-arg",  XF_NOBIND },
{ x_comment,"comment",  0 },
+   { x_expand_alias_sub,   "expand-alias-substitute",  0 },
{ 0, 0, 0 },
 #ifdef DEBUG
{ x_debug_info, "debug-info",   0 },
@@ -1492,6 +1494,7 @@ x_init_emacs(void)
kb_add(x_comp_file, CTRL('['), CTRL('X'), 0);
kb_add(x_comp_list, CTRL('I'), 0);
kb_add(x_comp_list, CTRL('['), '=', 0);
+   kb_add(x_expand_alias_sub,  CTRL('['), CTRL('E'), 0);
kb_add(x_del_back,  CTRL('?'), 0);
kb_add(x_del_back,  CTRL('H'), 0);
kb_add(x_del_char,  CTRL('['), '[', '3', '~', 0);
/* delete */
@@ -1982,6 +1985,95 @@ x_comment(int c)
return KSTD;
 }

+static int
+x_expand_alias_sub(int c)
+{
+   struct tbl *tp;
+   Area *saved_atemp;
+   const char *sep = str_val(local("IFS", 0));
+   char s[2];
+   char *cp;
+   char *begin, *word;
+   char *tmp, *tok, *state;
+   char *input, *output;
+   int skip = 0;
+   int ch, bufsize;
+   size_t len = 0;
+
+   if (xep == xbuf) {
+   x_e_putc(BEL);
+   return KSTD;
+   }
+
+   cp = xbuf;
+   while (cp != xep && ctype(*cp, C_IFSWS))
+   skip += x_size(*cp++);
+
+   begin = cp;
+   if (cp != xep && letter(*cp)) {
+   cp++;
+   len++;
+   while (cp != xep && letnum(*cp)) {
+   cp++;
+   len++;
+   }
+   }
+
+   if (len > 0) {
+   word = str_nsave(begin, len, ATEMP);
+   tp = ktsearch(, word, hash(word));
+   if (tp && (tp->flag & ISSET)) {
+   tmp = str_save(tp->val.s, ATEMP);
+   tok = strtok_r(tmp, sep, );
+   if (tok && strcmp(word, tok)) {
+   x_goto(xbuf + skip);
+   x_delete(len, false);
+   x_ins(tp->val.s);
+   }
+   afree(tmp, ATEMP);
+   }
+   afree(word, ATEMP);
+   }
+
+   input = str_save(xbuf, ATEMP);
+   saved_atemp = ATEMP;
+   newenv(E_ERRH);
+   if (sigsetjmp(genv->jbuf, 0))
+   output = NULL;
+   else
+   output = str_save(substitute(input, 0), saved_atemp);
+   quitenv(NULL);
+
+   if (!output) {
+   x_e_putc(BEL);
+   return KSTD;
+   }
+
+   bufsize = x_size_str(xbuf);
+   x_goto(xbuf);
+   x_delete(bufsize, false);
+
+   s[0] = ' ';
+   s[1] = '\0';
+   while (isspace((unsigned char)*output)) {
+   output++;
+   x_ins(s);
+   }
+
+   while ((ch = *output++)) {
+   if (isprint(ch)) {
+   s[0] = ch;
+   s[1] = '\0';
+   x_ins(s);
+   } else if (ch == '\r' || ch == '\n') {
+   s[0] = ' ';
+   s[1] = '\0';
+   x_ins(s);
+   }
+   }
+
+   return KSTD;
+}

 /* NAME:
  *  x_prev_histword - recover word from prev command
>
> I send the email once again because missing tab space.
> I'm sorry that to send extra email.
>
> Index: emacs.c
> ===
> RCS file: /cvs/src/bin/ksh/emacs.c,v
> retrieving revision 1.85
> diff -u -p -r1.85 emacs.c
> --- emacs.c 18 Jun 2018 17:03:58 -  1.85
> +++ emacs.c 10 Oct 2018 23:26:49 -
> @@ -201,6 +201,7 @@ static int  x_fold_lower(int);
>  static int x_fold_upper(int);
>  static int x_set_arg(int);
>  static int x_comment(int);
> +static int x_expand_alias_sub(int);
>  #ifdef DEBUG
>  static int x_debug_info(int);
>  #endif
> @@ -258,6 +259,7 @@ static const struct x_ftab x_ftab[] = {
> { x_fold_upper, "upcase-word",