From owner-svn-soc-all@FreeBSD.ORG Sun Jul 29 10:38:37 2012 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id A5514106566B for ; Sun, 29 Jul 2012 10:38:35 +0000 (UTC) (envelope-from syuu@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Sun, 29 Jul 2012 10:38:35 +0000 Date: Sun, 29 Jul 2012 10:38:35 +0000 From: syuu@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20120729103835.A5514106566B@hub.freebsd.org> Cc: Subject: socsvn commit: r239890 - in soc2012/syuu/bhyve-bios: lib/libbiosemul usr.sbin/bhyve X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 29 Jul 2012 10:38:37 -0000 Author: syuu Date: Sun Jul 29 10:38:35 2012 New Revision: 239890 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=239890 Log: libbiosemul SEGV fixes Modified: soc2012/syuu/bhyve-bios/lib/libbiosemul/Makefile soc2012/syuu/bhyve-bios/lib/libbiosemul/bios.c soc2012/syuu/bhyve-bios/lib/libbiosemul/biosemul.c soc2012/syuu/bhyve-bios/lib/libbiosemul/biosemul.h soc2012/syuu/bhyve-bios/lib/libbiosemul/doscmd.h soc2012/syuu/bhyve-bios/lib/libbiosemul/int13.c soc2012/syuu/bhyve-bios/lib/libbiosemul/register.h soc2012/syuu/bhyve-bios/usr.sbin/bhyve/Makefile soc2012/syuu/bhyve-bios/usr.sbin/bhyve/bios_call.c soc2012/syuu/bhyve-bios/usr.sbin/bhyve/fbsdrun.c Modified: soc2012/syuu/bhyve-bios/lib/libbiosemul/Makefile ============================================================================== --- soc2012/syuu/bhyve-bios/lib/libbiosemul/Makefile Sun Jul 29 09:23:32 2012 (r239889) +++ soc2012/syuu/bhyve-bios/lib/libbiosemul/Makefile Sun Jul 29 10:38:35 2012 (r239890) @@ -14,7 +14,7 @@ FONTHDRS= font8x8.h font8x14.h font8x16.h CLEANFILES= ${FONTFILES} ${FONTHDRS} -CFLAGS+= -DNO_X +CFLAGS+= -DNO_X -g cp437-8x8.pcf.gz: cp437-8x8.pcf.gz.uu uudecode ${.CURDIR}/cp437-8x8.pcf.gz.uu Modified: soc2012/syuu/bhyve-bios/lib/libbiosemul/bios.c ============================================================================== --- soc2012/syuu/bhyve-bios/lib/libbiosemul/bios.c Sun Jul 29 09:23:32 2012 (r239889) +++ soc2012/syuu/bhyve-bios/lib/libbiosemul/bios.c Sun Jul 29 10:38:35 2012 (r239890) @@ -38,33 +38,33 @@ #include "mouse.h" #include "com.h" -#define BIOS_copyright 0xfe000 -#define BIOS_reset 0xfe05b -#define BIOS_nmi 0xfe2c3 -#define BIOS_hdisk_table 0xfe401 -#define BIOS_boot 0xfe6f2 -#define BIOS_comm_table 0xfe729 -#define BIOS_comm_io 0xfe739 -#define BIOS_keyboard_io 0xfe82e -#define BIOS_keyboard_isr 0xfe987 -#define BIOS_fdisk_io 0xfec59 -#define BIOS_fdisk_isr 0xfef57 -#define BIOS_disk_parms 0xfefc7 -#define BIOS_printer_io 0xfefd2 -#define BIOS_video_io 0xff065 -#define BIOS_video_parms 0xff0a4 -#define BIOS_mem_size 0xff841 -#define BIOS_equipment 0xff84d -#define BIOS_cassette_io 0xff859 -#define BIOS_video_font 0xffa6e -#define BIOS_time_of_day 0xffe6e -#define BIOS_timer_int 0xffea5 -#define BIOS_vector 0xffef3 -#define BIOS_dummy_iret 0xfff53 -#define BIOS_print_screen 0xfff54 -#define BIOS_hard_reset 0xffff0 -#define BIOS_date_stamp 0xffff5 -#define BIOS_hardware_id 0xffffe +#define BIOS_copyright (lomem_addr + 0xfe000) +#define BIOS_reset (lomem_addr + 0xfe05b) +#define BIOS_nmi (lomem_addr + 0xfe2c3) +#define BIOS_hdisk_table (lomem_addr + 0xfe401) +#define BIOS_boot (lomem_addr + 0xfe6f2) +#define BIOS_comm_table (lomem_addr + 0xfe729) +#define BIOS_comm_io (lomem_addr + 0xfe739) +#define BIOS_keyboard_io (lomem_addr + 0xfe82e) +#define BIOS_keyboard_isr (lomem_addr + 0xfe987) +#define BIOS_fdisk_io (lomem_addr + 0xfec59) +#define BIOS_fdisk_isr (lomem_addr + 0xfef57) +#define BIOS_disk_parms (lomem_addr + 0xfefc7) +#define BIOS_printer_io (lomem_addr + 0xfefd2) +#define BIOS_video_io (lomem_addr + 0xff065) +#define BIOS_video_parms (lomem_addr + 0xff0a4) +#define BIOS_mem_size (lomem_addr + 0xff841) +#define BIOS_equipment (lomem_addr + 0xff84d) +#define BIOS_cassette_io (lomem_addr + 0xff859) +#define BIOS_video_font (lomem_addr + 0xffa6e) +#define BIOS_time_of_day (lomem_addr + 0xffe6e) +#define BIOS_timer_int (lomem_addr + 0xffea5) +#define BIOS_vector (lomem_addr + 0xffef3) +#define BIOS_dummy_iret (lomem_addr + 0xfff53) +#define BIOS_print_screen (lomem_addr + 0xfff54) +#define BIOS_hard_reset (lomem_addr + 0xffff0) +#define BIOS_date_stamp (lomem_addr + 0xffff5) +#define BIOS_hardware_id (lomem_addr + 0xffffe) static u_char disk_params[] = { 0xdf, 2, 0x25, 2, 0x0f, 0x1b, 0xff, 0x54, 0xf6, 0x0f, 8, @@ -166,7 +166,9 @@ void bios_init(void) { +#if 0 int i, j, k; +#endif u_char *jtab; #if 0 struct timeval tv; @@ -198,7 +200,7 @@ *(u_short *)BIOS_mem_size = 0xffcd; *(u_short *)BIOS_equipment = 0xffcd; *(u_short *)BIOS_vector = 0xffcd; - *(u_char *)0xffff2 = 0xcf; /* IRET */ + *(u_char *)(lomem_addr + 0xffff2) = 0xcf; /* IRET */ memcpy((u_char *)BIOS_disk_parms, disk_params, sizeof(disk_params)); memcpy((u_char *)BIOS_comm_table, comm_table, sizeof(comm_table)); @@ -217,6 +219,7 @@ *(u_char *)BIOS_hardware_id = 0xfc; /* Identify as a PC/AT */ +#if 0 /* * Interrupt revectors F000:0000 - F000:03ff */ @@ -241,6 +244,7 @@ ++j; } } +#endif /* * Misc variables from F000:0400 - F000:0fff Modified: soc2012/syuu/bhyve-bios/lib/libbiosemul/biosemul.c ============================================================================== --- soc2012/syuu/bhyve-bios/lib/libbiosemul/biosemul.c Sun Jul 29 09:23:32 2012 (r239889) +++ soc2012/syuu/bhyve-bios/lib/libbiosemul/biosemul.c Sun Jul 29 10:38:35 2012 (r239890) @@ -55,6 +55,8 @@ #if 0 #include #endif +#include +#include #include "doscmd.h" #include "tty.h" @@ -107,20 +109,21 @@ static struct vm86_init_args kargs; #endif -#define HDISK_CYL 0 -#define HDISK_HEAD 0 -#define HDISK_TRACK 0 -#define HDISK_FILE "diskdev" +#define HDISK_CYL 130 +#define HDISK_HEAD 255 +#define HDISK_TRACK 63 +#define HDISK_FILE "/home/syuu/test.img" /* lobotomise */ void biosemul_init(char *lomem) { lomem_addr = lomem; + ivec = (u_int32_t *)lomem_addr; debugf = stderr; - debug_set(0); /* debug any D_TRAPS without intnum */ - #if 0 + debug_set(0); /* debug any D_TRAPS without intnum */ + /* Call init functions */ if (raw_kbd) console_init(); @@ -138,8 +141,6 @@ video_bios_init(); disk_bios_init(); cmos_init(); -#endif -#if 0 timer_init(); /* iomap_init(); */ @@ -766,3 +767,170 @@ debug(D_PORT,"mapped I/O port: port=%#x count=%d\n", port, count); } #endif + +int +get_all_regs(struct vmctx *ctx, int vcpu, regcontext_t *regs) +{ + int error = 0; + + if ((error = vm_get_register(ctx, vcpu, VM_REG_GUEST_GS, ®s->r.gs.r_rx)) != 0) + goto done; + + if ((error = vm_get_register(ctx, vcpu, VM_REG_GUEST_FS, ®s->r.fs.r_rx)) != 0) + goto done; + + if ((error = vm_get_register(ctx, vcpu, VM_REG_GUEST_ES, ®s->r.es.r_rx)) != 0) + goto done; + + if ((error = vm_get_register(ctx, vcpu, VM_REG_GUEST_DS, ®s->r.es.r_rx)) != 0) + goto done; + + if ((error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RDI, ®s->r.edi.r_rx)) != 0) + goto done; + + if ((error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RSI, ®s->r.esi.r_rx)) != 0) + goto done; + + if ((error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RBP, ®s->r.ebp.r_rx)) != 0) + goto done; + + if ((error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RBX, ®s->r.ebx.r_rx)) != 0) + goto done; + + if ((error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RDX, ®s->r.edx.r_rx)) != 0) + goto done; + + if ((error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RCX, ®s->r.ecx.r_rx)) != 0) + goto done; + + if ((error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RAX, ®s->r.eax.r_rx)) != 0) + goto done; + + if ((error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RIP, ®s->r.eip.r_rx)) != 0) + goto done; + + if ((error = vm_get_register(ctx, vcpu, VM_REG_GUEST_CS, ®s->r.cs.r_rx)) != 0) + goto done; + + if ((error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RFLAGS, ®s->r.efl.r_rx)) != 0) + goto done; + + if ((error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RSP, ®s->r.esp.r_rx)) != 0) + goto done; + + if ((error = vm_get_register(ctx, vcpu, VM_REG_GUEST_SS, ®s->r.ss.r_rx)) != 0) + goto done; +done: + return (error); +} + +int +set_modified_regs(struct vmctx *ctx, int vcpu, regcontext_t *orig, regcontext_t *modified) +{ + int error = 0; + + if ((orig->r.gs.r_rx != modified->r.gs.r_rx) && + (error = vm_set_register(ctx, vcpu, VM_REG_GUEST_GS, modified->r.gs.r_rx)) != 0) + goto done; + + if ((orig->r.fs.r_rx != modified->r.fs.r_rx) && + (error = vm_get_register(ctx, vcpu, VM_REG_GUEST_FS, &modified->r.fs.r_rx)) != 0) + goto done; + + if ((orig->r.es.r_rx != modified->r.es.r_rx) && + (error = vm_get_register(ctx, vcpu, VM_REG_GUEST_ES, &modified->r.es.r_rx)) != 0) + goto done; + + if ((orig->r.ds.r_rx != modified->r.ds.r_rx) && + (error = vm_get_register(ctx, vcpu, VM_REG_GUEST_DS, &modified->r.es.r_rx)) != 0) + goto done; + + if ((orig->r.edi.r_rx != modified->r.edi.r_rx) && + (error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RDI, &modified->r.edi.r_rx)) != 0) + goto done; + + if ((orig->r.esi.r_rx != modified->r.esi.r_rx) && + (error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RSI, &modified->r.esi.r_rx)) != 0) + goto done; + + if ((orig->r.ebp.r_rx != modified->r.ebp.r_rx) && + (error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RBP, &modified->r.ebp.r_rx)) != 0) + goto done; + + if ((orig->r.ebx.r_rx != modified->r.ebx.r_rx) && + (error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RBX, &modified->r.ebx.r_rx)) != 0) + goto done; + + if ((orig->r.edx.r_rx != modified->r.edx.r_rx) && + (error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RDX, &modified->r.edx.r_rx)) != 0) + goto done; + + if ((orig->r.ecx.r_rx != modified->r.ecx.r_rx) && + (error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RCX, &modified->r.ecx.r_rx)) != 0) + goto done; + + if ((orig->r.eax.r_rx != modified->r.eax.r_rx) && + (error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RAX, &modified->r.eax.r_rx)) != 0) + goto done; + + if ((orig->r.eip.r_rx != modified->r.eip.r_rx) && + (error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RIP, &modified->r.eip.r_rx)) != 0) + goto done; + + if ((orig->r.cs.r_rx != modified->r.cs.r_rx) && + (error = vm_get_register(ctx, vcpu, VM_REG_GUEST_CS, &modified->r.cs.r_rx)) != 0) + goto done; + + if ((orig->r.efl.r_rx != modified->r.efl.r_rx) && + (error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RFLAGS, &modified->r.efl.r_rx)) != 0) + goto done; + + if ((orig->r.esp.r_rx != modified->r.esp.r_rx) && + (error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RSP, &modified->r.esp.r_rx)) != 0) + goto done; + + if ((orig->r.ss.r_rx != modified->r.ss.r_rx) && + (error = vm_get_register(ctx, vcpu, VM_REG_GUEST_SS, &modified->r.ss.r_rx)) != 0) + goto done; +done: + + return (error); +} + +extern void int13(regcontext_t *REGS); + +int +biosemul_call(struct vmctx *ctx, int vcpu, int intno) +{ + int ret = 0; + regcontext_t orig, modified; + + get_all_regs(ctx, vcpu, &orig); + modified = orig; + printf("%s RAX=%lx EAX=%x AX=%x AH=%x AL=%x\n", + __func__, + orig.r.eax.r_rx, + orig.r.eax.r_dw.r_ex, + orig.r.eax.r_w.r_x, + orig.r.eax.r_b.r_l, + orig.r.eax.r_b.r_h); + printf("%s RBX=%lx EBX=%x BX=%x BH=%x BL=%x\n", + __func__, + orig.r.ebx.r_rx, + orig.r.ebx.r_dw.r_ex, + orig.r.ebx.r_w.r_x, + orig.r.ebx.r_b.r_l, + orig.r.ebx.r_b.r_h); + + switch (intno) { + case 0x13: + int13(&modified); + break; + default: + ret = -1; + } + set_modified_regs(ctx, vcpu, &orig, &modified); + + return (ret); +} + Modified: soc2012/syuu/bhyve-bios/lib/libbiosemul/biosemul.h ============================================================================== --- soc2012/syuu/bhyve-bios/lib/libbiosemul/biosemul.h Sun Jul 29 09:23:32 2012 (r239889) +++ soc2012/syuu/bhyve-bios/lib/libbiosemul/biosemul.h Sun Jul 29 10:38:35 2012 (r239890) @@ -0,0 +1,11 @@ + +#ifndef _BIOSEMUL_H_ +#define _BIOSEMUL_H_ + +#include +#include + +void biosemul_init(char *lomem); +int biosemul_call(struct vmctx *ctx, int vcpu, int intno); +#endif + Modified: soc2012/syuu/bhyve-bios/lib/libbiosemul/doscmd.h ============================================================================== --- soc2012/syuu/bhyve-bios/lib/libbiosemul/doscmd.h Sun Jul 29 09:23:32 2012 (r239889) +++ soc2012/syuu/bhyve-bios/lib/libbiosemul/doscmd.h Sun Jul 29 10:38:35 2012 (r239890) @@ -88,7 +88,7 @@ #define IntState vconnect_area.int_state /* bios.c */ -#define BIOSDATA ((u_char *)(0x400 + lomem_addr)) +#define BIOSDATA ((u_char *)(lomem_addr + 0x400)) extern u_int32_t rom_config; extern int nfloppies; extern int ndisks; Modified: soc2012/syuu/bhyve-bios/lib/libbiosemul/int13.c ============================================================================== --- soc2012/syuu/bhyve-bios/lib/libbiosemul/int13.c Sun Jul 29 09:23:32 2012 (r239889) +++ soc2012/syuu/bhyve-bios/lib/libbiosemul/int13.c Sun Jul 29 10:38:35 2012 (r239890) @@ -94,8 +94,8 @@ int changed:1; /* Set if we change format */ }; -#define hd_status (*(u_char *)0x474) -#define fd_status (*(u_char *)0x441) +#define hd_status (*(u_char *)(lomem_addr + 0x474)) +#define fd_status (*(u_char *)(lomem_addr + 0x441)) static __inline int disize(struct diskinfo *di) Modified: soc2012/syuu/bhyve-bios/lib/libbiosemul/register.h ============================================================================== --- soc2012/syuu/bhyve-bios/lib/libbiosemul/register.h Sun Jul 29 09:23:32 2012 (r239889) +++ soc2012/syuu/bhyve-bios/lib/libbiosemul/register.h Sun Jul 29 10:38:35 2012 (r239890) @@ -36,17 +36,24 @@ /* standard register representation */ typedef union { - u_int32_t r_ex; + u_int64_t r_rx; + struct + { + u_int32_t r_ex; + u_int32_t :32; + } r_dw; struct { u_short r_x; u_short :16; + u_int32_t :32; } r_w; struct { u_char r_l; u_char r_h; u_short :16; + u_int32_t :32; } r_b; } reg86_t; @@ -91,46 +98,46 @@ */ /* register shorthands */ -#define R_ESP (REGS->r.esp.r_ex) +#define R_ESP (REGS->r.esp.r_dw.r_ex) #define R_SP (REGS->r.esp.r_w.r_x) -#define R_EBP (REGS->r.ebp.r_ex) +#define R_EBP (REGS->r.ebp.r_dw.r_ex) #define R_BP (REGS->r.ebp.r_w.r_x) -#define R_ISP (REGS->r.isp.r_ex) -#define R_EIP (REGS->r.eip.r_ex) +#define R_ISP (REGS->r.isp.r_dw.r_ex) +#define R_EIP (REGS->r.eip.r_dw.r_ex) #define R_IP (REGS->r.eip.r_w.r_x) -#define R_EFLAGS (REGS->r.efl.r_ex) +#define R_EFLAGS (REGS->r.efl.r_dw.r_ex) #define R_FLAGS (REGS->r.efl.r_w.r_x) -#define R_EES (REGS->r.es.r_ex) +#define R_EES (REGS->r.es.r_dw.r_ex) #define R_ES (REGS->r.es.r_w.r_x) -#define R_EDS (REGS->r.ds.r_ex) +#define R_EDS (REGS->r.ds.r_dw.r_ex) #define R_DS (REGS->r.ds.r_w.r_x) -#define R_ECS (REGS->r.cs.r_ex) +#define R_ECS (REGS->r.cs.r_dw.r_ex) #define R_CS (REGS->r.cs.r_w.r_x) -#define R_ESS (REGS->r.ss.r_ex) +#define R_ESS (REGS->r.ss.r_dw.r_ex) #define R_SS (REGS->r.ss.r_w.r_x) -#define R_EDI (REGS->r.edi.r_ex) +#define R_EDI (REGS->r.edi.r_dw.r_ex) #define R_DI (REGS->r.edi.r_w.r_x) -#define R_ESI (REGS->r.esi.r_ex) +#define R_ESI (REGS->r.esi.r_dw.r_ex) #define R_SI (REGS->r.esi.r_w.r_x) -#define R_EBX (REGS->r.ebx.r_ex) +#define R_EBX (REGS->r.ebx.r_dw.r_ex) #define R_BX (REGS->r.ebx.r_w.r_x) #define R_BL (REGS->r.ebx.r_b.r_l) #define R_BH (REGS->r.ebx.r_b.r_h) -#define R_EDX (REGS->r.edx.r_ex) +#define R_EDX (REGS->r.edx.r_dw.r_ex) #define R_DX (REGS->r.edx.r_w.r_x) #define R_DL (REGS->r.edx.r_b.r_l) #define R_DH (REGS->r.edx.r_b.r_h) -#define R_ECX (REGS->r.ecx.r_ex) +#define R_ECX (REGS->r.ecx.r_dw.r_ex) #define R_CX (REGS->r.ecx.r_w.r_x) #define R_CL (REGS->r.ecx.r_b.r_l) #define R_CH (REGS->r.ecx.r_b.r_h) -#define R_EAX (REGS->r.eax.r_ex) +#define R_EAX (REGS->r.eax.r_dw.r_ex) #define R_AX (REGS->r.eax.r_w.r_x) #define R_AL (REGS->r.eax.r_b.r_l) #define R_AH (REGS->r.eax.r_b.r_h) -#define R_EGS (REGS->r.gs.r_ex) +#define R_EGS (REGS->r.gs.r_dw.r_ex) #define R_GS (REGS->r.gs.r_w.r_x) -#define R_EFS (REGS->r.fs.r_ex) +#define R_EFS (REGS->r.fs.r_dw.r_ex) #define R_FS (REGS->r.fs.r_w.r_x) #endif Modified: soc2012/syuu/bhyve-bios/usr.sbin/bhyve/Makefile ============================================================================== --- soc2012/syuu/bhyve-bios/usr.sbin/bhyve/Makefile Sun Jul 29 09:23:32 2012 (r239889) +++ soc2012/syuu/bhyve-bios/usr.sbin/bhyve/Makefile Sun Jul 29 10:38:35 2012 (r239890) @@ -8,7 +8,8 @@ SRCS+= instruction_emul.c mevent.c SRCS+= pci_emul.c pci_hostbridge.c pci_passthru.c pci_virtio_block.c SRCS+= pci_virtio_net.c pci_uart.c pit_8254.c post.c rtc.c uart.c xmsr.c -SRCS+= bios_call.c bios_int10.c bios_int13.c bios_int16.c bios_int18.c +#SRCS+= bios_call.c bios_int10.c bios_int13.c bios_int16.c bios_int18.c +SRCS+= bios_call.c bios_int10.c bios_int16.c bios_int18.c NO_MAN= @@ -17,6 +18,6 @@ WARNS?= 2 -CFLAGS+= -I${.CURDIR}/../../sys +CFLAGS+= -I${.CURDIR}/../../sys -g .include Modified: soc2012/syuu/bhyve-bios/usr.sbin/bhyve/bios_call.c ============================================================================== --- soc2012/syuu/bhyve-bios/usr.sbin/bhyve/bios_call.c Sun Jul 29 09:23:32 2012 (r239889) +++ soc2012/syuu/bhyve-bios/usr.sbin/bhyve/bios_call.c Sun Jul 29 10:38:35 2012 (r239890) @@ -35,6 +35,8 @@ #include #include +#include + #include "bios_call.h" SET_DECLARE(bios_call_set, struct bios_call); Modified: soc2012/syuu/bhyve-bios/usr.sbin/bhyve/fbsdrun.c ============================================================================== --- soc2012/syuu/bhyve-bios/usr.sbin/bhyve/fbsdrun.c Sun Jul 29 09:23:32 2012 (r239889) +++ soc2012/syuu/bhyve-bios/usr.sbin/bhyve/fbsdrun.c Sun Jul 29 10:38:35 2012 (r239890) @@ -47,6 +47,8 @@ #include #include +#include + #include "fbsdrun.h" #include "inout.h" #include "dbgport.h" @@ -443,11 +445,19 @@ vmexit->rip); return (VMEXIT_ABORT); } - - if (emulate_bios_call(ctx, *pvcpu, intno) != 0) { - fprintf(stderr, "Failed to emulate INT %x at 0x%lx\n", - intno, vmexit->rip); - return (VMEXIT_ABORT); + if (intno == 0x13) { + if (biosemul_call(ctx, *pvcpu, intno) != 0) { + fprintf(stderr, "Failed to emulate INT %x at 0x%lx\n", + intno, vmexit->rip); + return (VMEXIT_ABORT); + } + } else + { + if (emulate_bios_call(ctx, *pvcpu, intno) != 0) { + fprintf(stderr, "Failed to emulate INT %x at 0x%lx\n", + intno, vmexit->rip); + return (VMEXIT_ABORT); + } } return (VMEXIT_CONTINUE); @@ -675,6 +685,7 @@ if (bios_mode != 0) { vm_set_capability(ctx, BSP, VM_CAP_UNRESTRICTED_GUEST, 1); init_bios_call(); + biosemul_init(lomem_addr); } init_inout(); From owner-svn-soc-all@FreeBSD.ORG Sun Jul 29 14:00:30 2012 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id 74B631065670 for ; Sun, 29 Jul 2012 14:00:28 +0000 (UTC) (envelope-from aleek@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Sun, 29 Jul 2012 14:00:28 +0000 Date: Sun, 29 Jul 2012 14:00:28 +0000 From: aleek@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20120729140028.74B631065670@hub.freebsd.org> Cc: Subject: socsvn commit: r239892 - soc2012/aleek/beaglexm-armv6/sys/arm/include X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 29 Jul 2012 14:00:30 -0000 Author: aleek Date: Sun Jul 29 14:00:27 2012 New Revision: 239892 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=239892 Log: workaround for 'external non linefetch abort' - modyfication of include/atomic.h Modified: soc2012/aleek/beaglexm-armv6/sys/arm/include/atomic.h Modified: soc2012/aleek/beaglexm-armv6/sys/arm/include/atomic.h ============================================================================== --- soc2012/aleek/beaglexm-armv6/sys/arm/include/atomic.h Sun Jul 29 11:51:48 2012 (r239891) +++ soc2012/aleek/beaglexm-armv6/sys/arm/include/atomic.h Sun Jul 29 14:00:27 2012 (r239892) @@ -59,7 +59,8 @@ #endif /* XXX: Rethink for userland later as those won't be defined */ -#if ARM_ARCH_6 || ARM_ARCH_7A +//#if ARM_ARCH_6 || ARM_ARCH_7A +#if 0 static __inline void __do_dmb(void) From owner-svn-soc-all@FreeBSD.ORG Mon Jul 30 10:59:56 2012 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id 887511065672 for ; Mon, 30 Jul 2012 10:59:55 +0000 (UTC) (envelope-from tzabal@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Mon, 30 Jul 2012 10:59:55 +0000 Date: Mon, 30 Jul 2012 10:59:55 +0000 From: tzabal@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20120730105955.887511065672@hub.freebsd.org> Cc: Subject: socsvn commit: r239905 - soc2012/tzabal/client-side/akcrs-head/usr.sbin/crashreport X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 30 Jul 2012 10:59:56 -0000 Author: tzabal Date: Mon Jul 30 10:59:54 2012 New Revision: 239905 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=239905 Log: Changes in the formation of the report. Modified: soc2012/tzabal/client-side/akcrs-head/usr.sbin/crashreport/crashreport.sh Modified: soc2012/tzabal/client-side/akcrs-head/usr.sbin/crashreport/crashreport.sh ============================================================================== --- soc2012/tzabal/client-side/akcrs-head/usr.sbin/crashreport/crashreport.sh Mon Jul 30 08:56:56 2012 (r239904) +++ soc2012/tzabal/client-side/akcrs-head/usr.sbin/crashreport/crashreport.sh Mon Jul 30 10:59:54 2012 (r239905) @@ -160,7 +160,7 @@ ## Form the report data=`mktemp /tmp/crashreport.XXXXXX` -commands1="date/3;hostname/5;ostype/6;osrelease/7;version/8;machine/9" +commands1="crashdate/3;hostname/5;ostype/6;osrelease/7;version/8;machine/9" commands2="ps -axl;vmstat -s;vmstat -m;vmstat -z;vmstat -i;pstat -T;pstat -s;\ iostat;ipcs -a;ipcs -T;nfsstat;netstat -s;netstat -m;netstat -id;netstat -anr;\ netstat -anA;netstat -aL;fstat;dmesg;kernel config;ddb capture buffer" @@ -179,7 +179,14 @@ echo "${_email}" >> ${data} echo "" >> ${data} -echo "" >> ${data} +echo "" >> ${data} +echo "" >> ${data} + +echo "" >> ${data} +echo "" >> ${data} +echo "crashtype" >> ${data} +echo "" >> ${data} +echo "" >> ${data} output=`file "${_dumpdir}/${_file}"` if echo "${output}" | grep 'POSIX tar archive' > /dev/null; then type='textdump' @@ -190,10 +197,8 @@ exit 1 fi echo "${type}" >> ${data} -echo "" >> ${data} - -echo "" >> ${data} -echo "" >> ${data} +echo "" >> ${data} +echo "" >> ${data} if [ "${type}" == 'vmcore' ]; then # A temporary-auxiliary file for the extraction From owner-svn-soc-all@FreeBSD.ORG Mon Jul 30 12:57:05 2012 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id 77204106566B for ; Mon, 30 Jul 2012 12:57:03 +0000 (UTC) (envelope-from jhagewood@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Mon, 30 Jul 2012 12:57:03 +0000 Date: Mon, 30 Jul 2012 12:57:03 +0000 From: jhagewood@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20120730125703.77204106566B@hub.freebsd.org> Cc: Subject: socsvn commit: r239913 - in soc2012/jhagewood/sdiff: . sdiff X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 30 Jul 2012 12:57:05 -0000 Author: jhagewood Date: Mon Jul 30 12:57:02 2012 New Revision: 239913 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=239913 Log: Fixed compiler warnings in sdiff. Modified: soc2012/jhagewood/sdiff/hagewood-sdiff.patch soc2012/jhagewood/sdiff/sdiff/sdiff.c Modified: soc2012/jhagewood/sdiff/hagewood-sdiff.patch ============================================================================== --- soc2012/jhagewood/sdiff/hagewood-sdiff.patch Mon Jul 30 11:29:05 2012 (r239912) +++ soc2012/jhagewood/sdiff/hagewood-sdiff.patch Mon Jul 30 12:57:02 2012 (r239913) @@ -173,7 +173,7 @@ + diff -rupN sdiff-orig/sdiff.c sdiff/sdiff.c --- sdiff-orig/sdiff.c 2012-07-26 03:11:02.000000000 -0400 -+++ sdiff/sdiff.c 2012-07-27 04:03:20.000000000 -0400 ++++ sdiff/sdiff.c 2012-07-30 12:54:48.000000000 -0400 @@ -5,6 +5,14 @@ * Public domain. */ @@ -204,7 +204,7 @@ static void enqueue(char *, char, char *); static char *mktmpcpy(const char *); +static int istextfile(FILE *); -+static void binexec(char *, char *, char *); __dead2; ++static void binexec(char *, char *, char *) __dead2; static void freediff(struct diffline *); static void int_usage(void); static int parsecmd(FILE *, FILE *, FILE *); @@ -380,7 +380,7 @@ if ((ofd = mkstemp(target_file)) == -1) { warn("error opening %s", target_file); - goto FAIL; -+ fail(*target_file); ++ fail(target_file); } while ((rcount = read(ifd, buf, sizeof(buf))) != -1 && rcount != 0) { @@ -389,13 +389,13 @@ if (-1 == wcount || rcount != wcount) { warn("error writing to %s", target_file); - goto FAIL; -+ fail(*target_file); ++ fail(target_file); } } if (rcount == -1) { warn("error reading from %s", source_file); - goto FAIL; -+ fail(*target_file); ++ fail(target_file); } close(ifd); @@ -741,7 +741,7 @@ processq(); } -@@ -1103,24 +1160,35 @@ printd(FILE *file1, size_t file1end) +@@ -1103,24 +1160,36 @@ printd(FILE *file1, size_t file1end) static void int_usage(void) { @@ -753,8 +753,10 @@ - "r | 2:\tchoose right diff\n" - "s:\tsilent mode--don't print identical lines\n" - "v:\tverbose mode--print identical lines\n" +- "q:\tquit"); + -+ printf("%s", "e:\tedit blank diff\n", ++ printf("%s", ++ "e:\tedit blank diff\n", + "eb:\tedit both diffs concatenated\n", + "el:\tedit left diff\n", + "er:\tedit right diff\n", @@ -762,7 +764,7 @@ + "r | 2:\tchoose right diff\n", + "s:\tsilent mode--don't print identical lines\n", + "v:\tverbose mode--print identical lines\n", - "q:\tquit"); ++ "q:\tquit\n"); } static void Modified: soc2012/jhagewood/sdiff/sdiff/sdiff.c ============================================================================== --- soc2012/jhagewood/sdiff/sdiff/sdiff.c Mon Jul 30 11:29:05 2012 (r239912) +++ soc2012/jhagewood/sdiff/sdiff/sdiff.c Mon Jul 30 12:57:02 2012 (r239913) @@ -64,7 +64,7 @@ static void enqueue(char *, char, char *); static char *mktmpcpy(const char *); static int istextfile(FILE *); -static void binexec(char *, char *, char *); __dead2; +static void binexec(char *, char *, char *) __dead2; static void freediff(struct diffline *); static void int_usage(void); static int parsecmd(FILE *, FILE *, FILE *); @@ -215,7 +215,7 @@ err(2, "asprintf"); if ((ofd = mkstemp(target_file)) == -1) { warn("error opening %s", target_file); - fail(*target_file); + fail(target_file); } while ((rcount = read(ifd, buf, sizeof(buf))) != -1 && rcount != 0) { @@ -224,12 +224,12 @@ wcount = write(ofd, buf, (size_t)rcount); if (-1 == wcount || rcount != wcount) { warn("error writing to %s", target_file); - fail(*target_file); + fail(target_file); } } if (rcount == -1) { warn("error reading from %s", source_file); - fail(*target_file); + fail(target_file); } close(ifd); @@ -1161,7 +1161,8 @@ int_usage(void) { - printf("%s", "e:\tedit blank diff\n", + printf("%s", + "e:\tedit blank diff\n", "eb:\tedit both diffs concatenated\n", "el:\tedit left diff\n", "er:\tedit right diff\n", @@ -1169,7 +1170,7 @@ "r | 2:\tchoose right diff\n", "s:\tsilent mode--don't print identical lines\n", "v:\tverbose mode--print identical lines\n", - "q:\tquit"); + "q:\tquit\n"); } static void From owner-svn-soc-all@FreeBSD.ORG Mon Jul 30 13:20:45 2012 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id 8F460106564A for ; Mon, 30 Jul 2012 13:20:43 +0000 (UTC) (envelope-from jhagewood@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Mon, 30 Jul 2012 13:20:43 +0000 Date: Mon, 30 Jul 2012 13:20:43 +0000 From: jhagewood@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20120730132043.8F460106564A@hub.freebsd.org> Cc: Subject: socsvn commit: r239915 - in soc2012/jhagewood: diff diff/diff sdiff sdiff/sdiff X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 30 Jul 2012 13:20:45 -0000 Author: jhagewood Date: Mon Jul 30 13:20:42 2012 New Revision: 239915 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=239915 Log: Modified: soc2012/jhagewood/diff/diff/diffreg.c soc2012/jhagewood/diff/hagewood-diff.patch soc2012/jhagewood/sdiff/hagewood-sdiff.patch soc2012/jhagewood/sdiff/sdiff/sdiff.c Modified: soc2012/jhagewood/diff/diff/diffreg.c ============================================================================== --- soc2012/jhagewood/diff/diff/diffreg.c Mon Jul 30 12:25:20 2012 (r239914) +++ soc2012/jhagewood/diff/diff/diffreg.c Mon Jul 30 13:20:42 2012 (r239915) @@ -344,8 +344,9 @@ if (filebehave == FILE_NORMAL) f1 = fopen(file1, "r"); if (filebehave == FILE_GZIP) { - gz1 = gzdopen(file1, "r"); - gzdread(gz1, buf, MAX_INT); + if (gz1 = gzopen(file1, "r") == Z_NULL) + err(1, "Could not open compressed file %s.", file1); + gzread(gz1, buf, MAX_INT); f1 = fdopen(buf, "r"); } } @@ -372,8 +373,9 @@ if (filebehave == FILE_NORMAL) f2 = fopen(file2, "r"); if (filebehave == FILE_GZIP) - gz2 = gzdopen(file2, "r"); - gzdread(gz2, buf, MAX_INT); + if(gz2 = gzopen(file2, "r") == Z_NULL) + err(1, "Could not open compressed file %s.", file2); + gzread(gz2, buf, MAX_INT); f2 = fdopen(buf, "r"); } } Modified: soc2012/jhagewood/diff/hagewood-diff.patch ============================================================================== --- soc2012/jhagewood/diff/hagewood-diff.patch Mon Jul 30 12:25:20 2012 (r239914) +++ soc2012/jhagewood/diff/hagewood-diff.patch Mon Jul 30 13:20:42 2012 (r239915) @@ -1,6 +1,18 @@ +diff -rupN diff-orig/Makefile diff/Makefile +--- diff-orig/Makefile 2012-07-26 03:11:00.000000000 -0400 ++++ diff/Makefile 2012-07-26 03:11:00.000000000 -0400 +@@ -3,7 +3,7 @@ + + DEBUG_FLAGS+= -g + +-PROG= diff ++PROG= diff xdiff + SRCS= diff.c diffdir.c diffreg.c + CFLAGS+= -std=c99 -Wall -pedantic + diff -rupN diff-orig/diff.c diff/diff.c ---- diff-orig/diff.c 2012-07-25 11:37:23.299991134 -0400 -+++ diff/diff.c 2012-07-25 11:37:23.727991128 -0400 +--- diff-orig/diff.c 2012-07-26 03:11:00.000000000 -0400 ++++ diff/diff.c 2012-07-26 03:11:00.000000000 -0400 @@ -1,4 +1,4 @@ -/*- +/* @@ -57,7 +69,7 @@ /* Options which exceed manageable alphanumeric assignments */ -@@ -69,107 +68,163 @@ enum +@@ -69,107 +68,163 @@ enum OPT_STRIPCR, OPT_NORMAL, OPT_LEFTC, @@ -639,9 +651,47 @@ - exit(2); + exit(1); } +diff -rupN diff-orig/diff.h diff/diff.h +--- diff-orig/diff.h 2012-07-26 03:11:00.000000000 -0400 ++++ diff/diff.h 2012-07-26 03:11:00.000000000 -0400 +@@ -48,6 +48,8 @@ + #define D_NREVERSE 5 /* Reverse ed script with numbered + lines and no trailing . */ + #define D_BRIEF 6 /* Say if the files differ */ ++#define D_GF 7 /* Group format */ ++#define D_LF 8 /* Line format */ + + /* + * Output flags +@@ -70,15 +72,22 @@ + #define D_SKIPPED1 8 /* path1 was a special file */ + #define D_SKIPPED2 9 /* path2 was a special file */ + ++/* ++ * File input types ++ */ ++#define FILE_NORMAL 0 ++#define FILE_GZIP 1 ++ + struct excludes { + char *pattern; + struct excludes *next; + }; + +-extern int aflag, bflag, dflag, iflag, lflag, Nflag, Pflag, pflag, rflag, +- sflag, tflag, Tflag, wflag; +-extern int Bflag, strip_cr, tabsize; ++extern int aflag, bflag, cflag, dflag, Eflag, Fromflag, iflag, lflag, Nflag, Pflag, pflag, rflag, ++ sflag, tflag, Tflag, Toflag, wflag; ++extern int Bflag, strip_cr, suppress_cl, tabsize; + extern int format, context, status; ++extern int filebehave; + extern char ignore_file_case; + extern char *start, *ifdefname, *diffargs, *label[2], *ignore_pats; + extern struct stat stb1, stb2; diff -rupN diff-orig/diffdir.c diff/diffdir.c ---- diff-orig/diffdir.c 2012-07-25 11:37:23.299991134 -0400 -+++ diff/diffdir.c 2012-07-25 11:37:23.726991126 -0400 +--- diff-orig/diffdir.c 2012-07-26 03:11:00.000000000 -0400 ++++ diff/diffdir.c 2012-07-26 03:11:00.000000000 -0400 @@ -20,13 +20,13 @@ #include @@ -748,47 +798,9 @@ strlcpy(path1 + plen1, dp->d_name, MAXPATHLEN - plen1); if (stat(path1, &stb1) != 0) { -diff -rupN diff-orig/diff.h diff/diff.h ---- diff-orig/diff.h 2012-07-25 11:37:23.300991134 -0400 -+++ diff/diff.h 2012-07-25 11:37:23.728991128 -0400 -@@ -48,6 +48,8 @@ - #define D_NREVERSE 5 /* Reverse ed script with numbered - lines and no trailing . */ - #define D_BRIEF 6 /* Say if the files differ */ -+#define D_GF 7 /* Group format */ -+#define D_LF 8 /* Line format */ - - /* - * Output flags -@@ -70,15 +72,22 @@ - #define D_SKIPPED1 8 /* path1 was a special file */ - #define D_SKIPPED2 9 /* path2 was a special file */ - -+/* -+ * File input types -+ */ -+#define FILE_NORMAL 0 -+#define FILE_GZIP 1 -+ - struct excludes { - char *pattern; - struct excludes *next; - }; - --extern int aflag, bflag, dflag, iflag, lflag, Nflag, Pflag, pflag, rflag, -- sflag, tflag, Tflag, wflag; --extern int Bflag, strip_cr, tabsize; -+extern int aflag, bflag, cflag, dflag, Eflag, Fromflag, iflag, lflag, Nflag, Pflag, pflag, rflag, -+ sflag, tflag, Tflag, Toflag, wflag; -+extern int Bflag, strip_cr, suppress_cl, tabsize; - extern int format, context, status; -+extern int filebehave; - extern char ignore_file_case; - extern char *start, *ifdefname, *diffargs, *label[2], *ignore_pats; - extern struct stat stb1, stb2; diff -rupN diff-orig/diffreg.c diff/diffreg.c ---- diff-orig/diffreg.c 2012-07-25 11:37:23.298991134 -0400 -+++ diff/diffreg.c 2012-07-25 12:07:51.966957049 -0400 +--- diff-orig/diffreg.c 2012-07-26 03:11:00.000000000 -0400 ++++ diff/diffreg.c 2012-07-30 13:11:25.000000000 -0400 @@ -62,15 +62,13 @@ * @(#)diffreg.c 8.1 (Berkeley) 6/6/93 */ @@ -809,14 +821,7 @@ #include #include -@@ -80,16 +78,30 @@ __FBSDID("$FreeBSD"); - #include - #include - #include -+#include - #include - #include - #include +@@ -86,10 +84,24 @@ __FBSDID("$FreeBSD"); #include #include #include @@ -835,6 +840,7 @@ +# define TIMESPEC_NS(timespec) 0 +#endif + ++#define MAX_INT 2147483647 +#define MAX_CHECK 768 /* 3 kilobytes of chars. */ + /* @@ -948,7 +954,7 @@ anychange = 0; lastline = 0; -@@ -310,7 +326,7 @@ diffreg(char *ofile1, char *ofile2, int +@@ -310,7 +326,7 @@ diffreg(char *ofile1, char *ofile2, int if (S_ISDIR(stb1.st_mode) != S_ISDIR(stb2.st_mode)) return (S_ISDIR(stb1.st_mode) ? D_MISMATCH1 : D_MISMATCH2); if (strcmp(file1, "-") == 0 && strcmp(file2, "-") == 0) @@ -957,7 +963,7 @@ if (flags & D_EMPTY1) f1 = fopen(_PATH_DEVNULL, "r"); -@@ -320,17 +336,24 @@ diffreg(char *ofile1, char *ofile2, int +@@ -320,17 +336,25 @@ diffreg(char *ofile1, char *ofile2, int fstat(fileno(f1), &stb1) < 0) { warn("%s", file1); status |= 2; @@ -972,7 +978,8 @@ + if (filebehave == FILE_NORMAL) + f1 = fopen(file1, "r"); + if (filebehave == FILE_GZIP) { -+ gz1 = gzopen(file1, "r"); ++ if (gz1 = gzopen(file1, "r") == Z_NULL) ++ err(1, "Could not open compressed file %s.", file1); + gzread(gz1, buf, MAX_INT); + f1 = fdopen(buf, "r"); + } @@ -986,7 +993,7 @@ } if (flags & D_EMPTY2) -@@ -341,34 +364,39 @@ diffreg(char *ofile1, char *ofile2, int +@@ -341,34 +365,40 @@ diffreg(char *ofile1, char *ofile2, int fstat(fileno(f2), &stb2) < 0) { warn("%s", file2); status |= 2; @@ -1001,7 +1008,8 @@ + if (filebehave == FILE_NORMAL) + f2 = fopen(file2, "r"); + if (filebehave == FILE_GZIP) -+ gz2 = gzopen(file2, "r"); ++ if(gz2 = gzopen(file2, "r") == Z_NULL) ++ err(1, "Could not open compressed file %s.", file2); + gzread(gz2, buf, MAX_INT); + f2 = fdopen(buf, "r"); + } @@ -1035,7 +1043,7 @@ } if (lflag) { /* redirect stdout to pr */ -@@ -452,7 +480,11 @@ diffreg(char *ofile1, char *ofile2, int +@@ -452,7 +482,11 @@ diffreg(char *ofile1, char *ofile2, int } waitpid(pid, &wstatus, 0); } @@ -1048,7 +1056,7 @@ if (anychange) { status |= 1; if (rval == D_SAME) -@@ -477,8 +509,8 @@ closem: +@@ -477,8 +511,8 @@ closem: static int files_differ(FILE *f1, FILE *f2, int flags) { @@ -1059,7 +1067,7 @@ if ((flags & (D_EMPTY1|D_EMPTY2)) || stb1.st_size != stb2.st_size || (stb1.st_mode & S_IFMT) != (stb2.st_mode & S_IFMT)) -@@ -503,9 +535,9 @@ files_differ(FILE *f1, FILE *f2, int fla +@@ -503,9 +537,9 @@ files_differ(FILE *f1, FILE *f2, int fla static FILE * opentemp(const char *file) { @@ -1072,7 +1080,7 @@ if (strcmp(file, "-") == 0) ifd = STDIN_FILENO; -@@ -541,7 +573,7 @@ opentemp(const char *file) +@@ -541,7 +575,7 @@ opentemp(const char *file) char * splice(char *dir, char *file) { @@ -1081,7 +1089,7 @@ if ((tail = strrchr(file, '/')) == NULL) tail = file; -@@ -555,8 +587,8 @@ static void +@@ -555,8 +589,8 @@ static void prepare(int i, FILE *fd, off_t filesize) { struct line *p; @@ -1092,7 +1100,7 @@ rewind(fd); -@@ -579,7 +611,7 @@ prepare(int i, FILE *fd, off_t filesize) +@@ -579,7 +613,7 @@ prepare(int i, FILE *fd, off_t filesize) static void prune(void) { @@ -1101,7 +1109,7 @@ for (pref = 0; pref < len[0] && pref < len[1] && file[0][pref + 1].value == file[1][pref + 1].value; -@@ -600,7 +632,7 @@ prune(void) +@@ -600,7 +634,7 @@ prune(void) static void equiv(struct line *a, int n, struct line *b, int m, int *c) { @@ -1110,7 +1118,7 @@ i = j = 1; while (i <= n && j <= m) { -@@ -629,7 +661,7 @@ equiv(struct line *a, int n, struct line +@@ -629,7 +663,7 @@ equiv(struct line *a, int n, struct line static int isqrt(int n) { @@ -1119,7 +1127,7 @@ if (n == 0) return (0); -@@ -647,9 +679,9 @@ isqrt(int n) +@@ -647,9 +681,9 @@ isqrt(int n) static int stone(int *a, int n, int *b, int *c) { @@ -1132,7 +1140,7 @@ const u_int bound = dflag ? UINT_MAX : MAX(256, isqrt(n)); k = 0; -@@ -705,7 +737,7 @@ newcand(int x, int y, int pred) +@@ -705,7 +739,7 @@ newcand(int x, int y, int pred) static int search(int *c, int k, int y) { @@ -1141,7 +1149,7 @@ if (clist[c[k]].y < y) /* quick look for typical case */ return (k + 1); -@@ -730,7 +762,7 @@ static void +@@ -730,7 +764,7 @@ static void unravel(int p) { struct cand *q; @@ -1150,7 +1158,7 @@ for (i = 0; i <= len[0]; i++) J[i] = i <= pref ? i : -@@ -748,9 +780,10 @@ unravel(int p) +@@ -748,9 +782,10 @@ unravel(int p) static void check(char *file1, FILE *f1, char *file2, FILE *f2) { @@ -1164,7 +1172,7 @@ rewind(f1); rewind(f2); j = 1; -@@ -766,7 +799,7 @@ check(char *file1, FILE *f1, char *file2 +@@ -766,7 +801,7 @@ check(char *file1, FILE *f1, char *file2 ixnew[j] = ctnew += skipline(f2); j++; } @@ -1173,7 +1181,7 @@ for (;;) { c = getc(f1); d = getc(f2); -@@ -781,6 +814,7 @@ check(char *file1, FILE *f1, char *file2 +@@ -781,6 +816,7 @@ check(char *file1, FILE *f1, char *file2 } ctold++; ctnew++; @@ -1181,7 +1189,7 @@ if (bflag && isspace(c) && isspace(d)) { do { if (c == '\n') -@@ -792,6 +826,7 @@ check(char *file1, FILE *f1, char *file2 +@@ -792,6 +828,7 @@ check(char *file1, FILE *f1, char *file2 break; ctnew++; } while (isspace(d = getc(f2))); @@ -1189,7 +1197,7 @@ } else if (wflag) { while (isspace(c) && c != '\n') { c = getc(f1); -@@ -801,31 +836,55 @@ check(char *file1, FILE *f1, char *file2 +@@ -801,31 +838,55 @@ check(char *file1, FILE *f1, char *file2 d = getc(f2); ctnew++; } @@ -1266,7 +1274,7 @@ if (chrtran[c] != chrtran[d]) { jackpot++; J[i] = 0; -@@ -872,7 +931,7 @@ static void +@@ -872,7 +933,7 @@ static void sort(struct line *a, int n) { struct line *ai, *aim, w; @@ -1275,7 +1283,7 @@ if (n == 0) return; -@@ -916,7 +975,7 @@ unsort(struct line *f, int l, int *b) +@@ -916,7 +977,7 @@ unsort(struct line *f, int l, int *b) static int skipline(FILE *f) { @@ -1284,7 +1292,7 @@ for (i = 1; (c = getc(f)) != '\n' && c != EOF; i++) continue; -@@ -926,7 +985,7 @@ skipline(FILE *f) +@@ -926,7 +987,7 @@ skipline(FILE *f) static void output(char *file1, FILE *f1, char *file2, FILE *f2, int flags) { @@ -1293,7 +1301,7 @@ rewind(f1); rewind(f2); -@@ -965,7 +1024,7 @@ output(char *file1, FILE *f1, char *file +@@ -965,7 +1026,7 @@ output(char *file1, FILE *f1, char *file #define c i0 if ((c = getc(f1)) == EOF) return; @@ -1302,7 +1310,7 @@ } #undef c } -@@ -980,6 +1039,7 @@ output(char *file1, FILE *f1, char *file +@@ -980,6 +1041,7 @@ output(char *file1, FILE *f1, char *file static void range(int a, int b, char *separator) { @@ -1310,7 +1318,7 @@ printf("%d", a > b ? b : a); if (a < b) printf("%s%d", separator, b); -@@ -988,6 +1048,7 @@ range(int a, int b, char *separator) +@@ -988,6 +1050,7 @@ range(int a, int b, char *separator) static void uni_range(int a, int b) { @@ -1318,7 +1326,7 @@ if (a < b) printf("%d,%d", a, b - a + 1); else if (a == b) -@@ -999,22 +1060,22 @@ uni_range(int a, int b) +@@ -999,22 +1062,22 @@ uni_range(int a, int b) static char * preadline(int fd, size_t len, off_t off) { @@ -1345,7 +1353,7 @@ ret = regexec(&ignore_re, line, 0, NULL, 0); free(line); -@@ -1032,10 +1093,10 @@ static void +@@ -1032,10 +1095,10 @@ static void change(char *file1, FILE *f1, char *file2, FILE *f2, int a, int b, int c, int d, int *pflags) { @@ -1359,7 +1367,7 @@ if (format != D_IFDEF && a > b && c > d) return; if (ignore_pats != NULL) { -@@ -1050,7 +1111,7 @@ restart: +@@ -1050,7 +1113,7 @@ restart: line = preadline(fileno(f1), ixold[i] - ixold[i - 1], ixold[i - 1]); if (!ignoreline(line)) @@ -1368,7 +1376,7 @@ } } if (a > b || c <= d) { /* Changes and inserts. */ -@@ -1058,12 +1119,12 @@ restart: +@@ -1058,12 +1121,12 @@ restart: line = preadline(fileno(f2), ixnew[i] - ixnew[i - 1], ixnew[i - 1]); if (!ignoreline(line)) @@ -1383,7 +1391,7 @@ if (*pflags & D_HEADER) { printf("%s %s %s\n", diffargs, file1, file2); *pflags &= ~D_HEADER; -@@ -1113,15 +1174,15 @@ proceed: +@@ -1113,15 +1176,15 @@ proceed: case D_NORMAL: case D_EDIT: range(a, b, ","); @@ -1403,7 +1411,7 @@ break; case D_NREVERSE: if (a > b) -@@ -1137,7 +1198,7 @@ proceed: +@@ -1137,7 +1200,7 @@ proceed: if (format == D_NORMAL || format == D_IFDEF) { fetch(ixold, a, b, f1, '<', 1); if (a <= b && c <= d && format == D_NORMAL) @@ -1412,7 +1420,7 @@ } i = fetch(ixnew, c, d, f2, format == D_NORMAL ? '>' : '\0', 0); if (i != 0 && format == D_EDIT) { -@@ -1148,14 +1209,14 @@ proceed: +@@ -1148,14 +1211,14 @@ proceed: * it. We have to add a substitute command to change this * back and restart where we left off. */ @@ -1430,7 +1438,7 @@ if (inifdef) { printf("#endif /* %s */\n", ifdefname); inifdef = 0; -@@ -1165,8 +1226,8 @@ proceed: +@@ -1165,8 +1228,8 @@ proceed: static int fetch(long *f, int a, int b, FILE *lb, int ch, int oldfile) { @@ -1441,7 +1449,7 @@ /* * When doing #ifdef's, copy down to current line -@@ -1177,7 +1238,7 @@ fetch(long *f, int a, int b, FILE *lb, i +@@ -1177,7 +1240,7 @@ fetch(long *f, int a, int b, FILE *lb, i /* print through if append (a>b), else to (nb: 0 vs 1 orig) */ nc = f[a > b ? b : a - 1] - curpos; for (i = 0; i < nc; i++) @@ -1450,7 +1458,7 @@ } if (a > b) return (0); -@@ -1197,12 +1258,12 @@ fetch(long *f, int a, int b, FILE *lb, i +@@ -1197,12 +1260,12 @@ fetch(long *f, int a, int b, FILE *lb, i fseek(lb, f[i - 1], SEEK_SET); nc = f[i] - f[i - 1]; if (format != D_IFDEF && ch != '\0') { @@ -1466,7 +1474,7 @@ } col = 0; for (j = 0, lastc = '\0'; j < nc; j++, lastc = c) { -@@ -1211,13 +1272,13 @@ fetch(long *f, int a, int b, FILE *lb, i +@@ -1211,13 +1274,13 @@ fetch(long *f, int a, int b, FILE *lb, i format == D_NREVERSE) warnx("No newline at end of file"); else @@ -1482,7 +1490,7 @@ } while (++col < newcol); } else { if (format == D_EDIT && j == 1 && c == '\n' -@@ -1229,10 +1290,10 @@ fetch(long *f, int a, int b, FILE *lb, i +@@ -1229,10 +1292,10 @@ fetch(long *f, int a, int b, FILE *lb, i * giving the caller an offset * from which to restart. */ @@ -1495,7 +1503,7 @@ col++; } } -@@ -1246,8 +1307,8 @@ fetch(long *f, int a, int b, FILE *lb, i +@@ -1246,8 +1309,8 @@ fetch(long *f, int a, int b, FILE *lb, i static int readhash(FILE *f) { @@ -1506,7 +1514,7 @@ sum = 1; space = 0; -@@ -1305,20 +1366,28 @@ readhash(FILE *f) +@@ -1305,20 +1368,28 @@ readhash(FILE *f) return (sum == 0 ? 1 : sum); } @@ -1542,7 +1550,7 @@ return (1); } -@@ -1327,10 +1396,10 @@ asciifile(FILE *f) +@@ -1327,10 +1398,10 @@ asciifile(FILE *f) static char * match_function(const long *f, int pos, FILE *file) { @@ -1557,7 +1565,7 @@ lastline = pos; while (pos > last) { -@@ -1342,7 +1411,6 @@ match_function(const long *f, int pos, F +@@ -1342,7 +1413,6 @@ match_function(const long *f, int pos, F if (nc > 0) { buf[nc] = '\0'; buf[strcspn(buf, "\n")] = '\0'; @@ -1565,7 +1573,7 @@ if (isalpha(buf[0]) || buf[0] == '_' || buf[0] == '$') { if (begins_with(buf, "private:")) { if (!state) -@@ -1373,9 +1441,9 @@ static void +@@ -1373,9 +1443,9 @@ static void dump_context_vec(FILE *f1, FILE *f2) { struct context_vec *cvp = context_vec_start; @@ -1578,7 +1586,7 @@ if (context_vec_start > context_vec_ptr) return; -@@ -1390,8 +1458,8 @@ dump_context_vec(FILE *f1, FILE *f2) +@@ -1390,8 +1460,8 @@ dump_context_vec(FILE *f1, FILE *f2) if (pflag) { f = match_function(ixold, lowa-1, f1); if (f != NULL) { @@ -1589,7 +1597,7 @@ } } printf("\n*** "); -@@ -1478,9 +1546,9 @@ static void +@@ -1478,9 +1548,9 @@ static void dump_unified_vec(FILE *f1, FILE *f2) { struct context_vec *cvp = context_vec_start; @@ -1602,7 +1610,7 @@ if (context_vec_start > context_vec_ptr) return; -@@ -1491,19 +1559,19 @@ dump_unified_vec(FILE *f1, FILE *f2) +@@ -1491,19 +1561,19 @@ dump_unified_vec(FILE *f1, FILE *f2) lowc = MAX(1, cvp->c - context); upd = MIN(len[1], context_vec_ptr->d + context); @@ -1628,7 +1636,7 @@ /* * Output changes in "unified" diff format--the old and new lines -@@ -1551,16 +1619,43 @@ dump_unified_vec(FILE *f1, FILE *f2) +@@ -1551,16 +1621,43 @@ dump_unified_vec(FILE *f1, FILE *f2) static void print_header(const char *file1, const char *file2) { @@ -1678,15 +1686,3 @@ + printf("%s %s\t%s\n", format == D_CONTEXT ? "---" : "+++", + file2, buf2); } -diff -rupN diff-orig/Makefile diff/Makefile ---- diff-orig/Makefile 2012-07-25 11:37:23.300991134 -0400 -+++ diff/Makefile 2012-07-25 11:40:31.643987623 -0400 -@@ -3,7 +3,7 @@ - - DEBUG_FLAGS+= -g - --PROG= diff -+PROG= diff xdiff - SRCS= diff.c diffdir.c diffreg.c - CFLAGS+= -std=c99 -Wall -pedantic - Modified: soc2012/jhagewood/sdiff/hagewood-sdiff.patch ============================================================================== --- soc2012/jhagewood/sdiff/hagewood-sdiff.patch Mon Jul 30 12:25:20 2012 (r239914) +++ soc2012/jhagewood/sdiff/hagewood-sdiff.patch Mon Jul 30 13:20:42 2012 (r239915) @@ -173,7 +173,7 @@ + diff -rupN sdiff-orig/sdiff.c sdiff/sdiff.c --- sdiff-orig/sdiff.c 2012-07-26 03:11:02.000000000 -0400 -+++ sdiff/sdiff.c 2012-07-30 12:54:48.000000000 -0400 ++++ sdiff/sdiff.c 2012-07-30 13:14:21.000000000 -0400 @@ -5,6 +5,14 @@ * Public domain. */ @@ -531,16 +531,21 @@ execvp(diffprog, diffargv); err(2, "could not execute diff: %s", diffprog); break; -@@ -406,6 +436,16 @@ main(int argc, char **argv) +@@ -406,6 +436,21 @@ main(int argc, char **argv) if ((file2 = fopen(filename2, "r")) == NULL) err(2, "could not open %s", filename2); + if (!istextfile(file1) || !istextfile(file2)) { ++ /* Close open files and pipe, delete temps */ + fclose(file1); + fclose(file2); + fclose(diffpipe); -+ unlink(tmp1); -+ unlink(tmp2); ++ if (tmp1) ++ if (unlink(tmp1)) ++ warn("Error deleting %s.", tmp1); ++ if (tmp2) ++ if (unlink(tmp2)) ++ warn("Error deleting %s.", tmp2); + free(tmp1); + free(tmp2); + binexec(diffprog, filename1, filename2); @@ -548,7 +553,26 @@ /* Line numbers start at one. */ file1ln = file2ln = 1; -@@ -452,6 +492,39 @@ main(int argc, char **argv) +@@ -417,15 +462,15 @@ main(int argc, char **argv) + /* Wait for diff to exit. */ + if (waitpid(pid, &status, 0) == -1 || !WIFEXITED(status) || + WEXITSTATUS(status) >= 2) +- err(2, "diff exited abnormally"); ++ err(2, "diff exited abnormally."); + + /* Delete and free unneeded temporary files. */ + if (tmp1) + if (unlink(tmp1)) +- warn("error deleting %s", tmp1); ++ warn("Error deleting %s.", tmp1); + if (tmp2) + if (unlink(tmp2)) +- warn("error deleting %s", tmp2); ++ warn("Error deleting %s.", tmp2); + free(tmp1); + free(tmp2); + filename1 = filename2 = tmp1 = tmp2 = NULL; +@@ -452,6 +497,40 @@ main(int argc, char **argv) return (WEXITSTATUS(status)); } @@ -559,7 +583,8 @@ + char *args[] = {diffprog, f1, f2, (char *) 0}; + + execv(diffprog, args); -+ printf("Could not execute diff process.\n"); ++ /* If execv() fails, this program's execution will continue. */ ++ sprintf(stderr, "Could not execute diff process.\n"); + exit(1); +} +/* @@ -588,7 +613,7 @@ /* * Prints an individual column (left or right), taking into account * that tabs are variable-width. Takes a string, the current column -@@ -461,6 +534,7 @@ main(int argc, char **argv) +@@ -461,6 +540,7 @@ main(int argc, char **argv) static void printcol(const char *s, size_t *col, const size_t col_max) { @@ -596,7 +621,7 @@ for (; *s && *col < col_max; ++s) { size_t new_col; -@@ -484,11 +558,9 @@ printcol(const char *s, size_t *col, con +@@ -484,11 +564,9 @@ printcol(const char *s, size_t *col, con return; *col = new_col; break; @@ -608,7 +633,7 @@ putchar(*s); } } -@@ -512,56 +584,47 @@ prompt(const char *s1, const char *s2) +@@ -512,56 +590,47 @@ prompt(const char *s1, const char *s2) /* Skip leading whitespace. */ for (p = cmd; isspace(*p); ++p) ; @@ -674,7 +699,7 @@ free(cmd); return; } -@@ -570,7 +633,7 @@ PROMPT: +@@ -570,7 +639,7 @@ PROMPT: * If there was no error, we received an EOF from stdin, so we * should quit. */ @@ -683,7 +708,7 @@ fclose(outfp); exit(0); } -@@ -678,7 +741,6 @@ parsecmd(FILE *diffpipe, FILE *file1, FI +@@ -678,7 +747,6 @@ parsecmd(FILE *diffpipe, FILE *file1, FI /* A range is specified for file1. */ if (c == ',') { @@ -691,7 +716,7 @@ q = p; /* Go to character after file2end. */ while (isdigit(*p)) -@@ -690,7 +752,6 @@ parsecmd(FILE *diffpipe, FILE *file1, FI +@@ -690,7 +758,6 @@ parsecmd(FILE *diffpipe, FILE *file1, FI errx(2, "file1 end is %s: %s", errstr, line); if (file1start > file1end) errx(2, "invalid line range in file1: %s", line); @@ -699,7 +724,7 @@ } else file1end = file1start; -@@ -809,17 +870,14 @@ parsecmd(FILE *diffpipe, FILE *file1, FI +@@ -809,17 +876,14 @@ parsecmd(FILE *diffpipe, FILE *file1, FI printa(file2, file2end); n = file2end - file2start + 1; break; @@ -717,7 +742,7 @@ default: errx(2, "invalid diff command: %c: %s", cmd, line); } -@@ -854,6 +912,7 @@ enqueue(char *left, char div, char *righ +@@ -854,6 +918,7 @@ enqueue(char *left, char div, char *righ static void freediff(struct diffline *diffp) { @@ -725,7 +750,7 @@ free(diffp->left); free(diffp->right); free(diffp); -@@ -876,7 +935,6 @@ astrcat(char **s, const char *append) +@@ -876,7 +941,6 @@ astrcat(char **s, const char *append) static const char *oldstr = NULL; char *newstr; @@ -733,7 +758,7 @@ /* * First string is NULL, so just copy append. */ -@@ -1002,7 +1060,6 @@ printa(FILE *file, size_t line2) +@@ -1002,7 +1066,6 @@ printa(FILE *file, size_t line2) errx(2, "append ended early"); enqueue(NULL, '>', line); } @@ -741,7 +766,7 @@ processq(); } -@@ -1103,24 +1160,36 @@ printd(FILE *file1, size_t file1end) +@@ -1103,24 +1166,36 @@ printd(FILE *file1, size_t file1end) static void int_usage(void) { Modified: soc2012/jhagewood/sdiff/sdiff/sdiff.c ============================================================================== --- soc2012/jhagewood/sdiff/sdiff/sdiff.c Mon Jul 30 12:25:20 2012 (r239914) +++ soc2012/jhagewood/sdiff/sdiff/sdiff.c Mon Jul 30 13:20:42 2012 (r239915) @@ -437,11 +437,16 @@ err(2, "could not open %s", filename2); if (!istextfile(file1) || !istextfile(file2)) { + /* Close open files and pipe, delete temps */ fclose(file1); fclose(file2); fclose(diffpipe); - unlink(tmp1); - unlink(tmp2); + if (tmp1) + if (unlink(tmp1)) + warn("Error deleting %s.", tmp1); + if (tmp2) + if (unlink(tmp2)) + warn("Error deleting %s.", tmp2); free(tmp1); free(tmp2); binexec(diffprog, filename1, filename2); @@ -457,15 +462,15 @@ /* Wait for diff to exit. */ if (waitpid(pid, &status, 0) == -1 || !WIFEXITED(status) || WEXITSTATUS(status) >= 2) - err(2, "diff exited abnormally"); + err(2, "diff exited abnormally."); /* Delete and free unneeded temporary files. */ if (tmp1) if (unlink(tmp1)) - warn("error deleting %s", tmp1); + warn("Error deleting %s.", tmp1); if (tmp2) if (unlink(tmp2)) - warn("error deleting %s", tmp2); + warn("Error deleting %s.", tmp2); free(tmp1); free(tmp2); filename1 = filename2 = tmp1 = tmp2 = NULL; @@ -499,7 +504,8 @@ char *args[] = {diffprog, f1, f2, (char *) 0}; execv(diffprog, args); - printf("Could not execute diff process.\n"); + /* If execv() fails, this program's execution will continue. */ + sprintf(stderr, "Could not execute diff process.\n"); exit(1); } /* From owner-svn-soc-all@FreeBSD.ORG Tue Jul 31 15:47:53 2012 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id 2CD85106564A for ; Tue, 31 Jul 2012 15:47:51 +0000 (UTC) (envelope-from aleek@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Tue, 31 Jul 2012 15:47:51 +0000 Date: Tue, 31 Jul 2012 15:47:51 +0000 From: aleek@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20120731154751.2CD85106564A@hub.freebsd.org> Cc: Subject: socsvn commit: r239956 - in soc2012/aleek/beaglexm-armv6/sys: arm/conf arm/ti arm/ti/am37x arm/ti/usb boot/fdt/dts X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 31 Jul 2012 15:47:53 -0000 Author: aleek Date: Tue Jul 31 15:47:50 2012 New Revision: 239956 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=239956 Log: cleanup of ti_gpio and ti_ehci driver. Added i2c to the board Modified: soc2012/aleek/beaglexm-armv6/sys/arm/conf/BEAGLEBOARD-XM soc2012/aleek/beaglexm-armv6/sys/arm/ti/am37x/am37x_prcm.c soc2012/aleek/beaglexm-armv6/sys/arm/ti/am37x/am37x_scm_padconf.c soc2012/aleek/beaglexm-armv6/sys/arm/ti/ti_gpio.c soc2012/aleek/beaglexm-armv6/sys/arm/ti/ti_i2c.c soc2012/aleek/beaglexm-armv6/sys/arm/ti/ti_machdep.c soc2012/aleek/beaglexm-armv6/sys/arm/ti/usb/omap_ehci.c soc2012/aleek/beaglexm-armv6/sys/boot/fdt/dts/beagleboardxm.dts Modified: soc2012/aleek/beaglexm-armv6/sys/arm/conf/BEAGLEBOARD-XM ============================================================================== --- soc2012/aleek/beaglexm-armv6/sys/arm/conf/BEAGLEBOARD-XM Tue Jul 31 13:11:20 2012 (r239955) +++ soc2012/aleek/beaglexm-armv6/sys/arm/conf/BEAGLEBOARD-XM Tue Jul 31 15:47:50 2012 (r239956) @@ -48,19 +48,19 @@ options PREEMPTION # Debugging -#makeoptions DEBUG=-g #Build kernel with gdb(1) debug symbols +makeoptions DEBUG=-g #Build kernel with gdb(1) debug symbols #makeoptions WERROR="-Werror" #makeoptions WERROR="" options BREAK_TO_DEBUGGER -#options VERBOSE_SYSINIT #Enable verbose sysinit messages +#options VERBOSE_SYSINIT #Enable verbose sysinit messages options KDB options DDB #Enable the kernel debugger -options INVARIANTS #Enable calls of extra sanity checking -options INVARIANT_SUPPORT #Extra sanity checks of internal structures, required by INVARIANTS -#options WITNESS #Enable checks to detect deadlocks and cycles -#options WITNESS_SKIPSPIN #Don't run witness on spinlocks for speed -options DIAGNOSTIC -options DEBUG +#options INVARIANTS #Enable calls of extra sanity checking +#options INVARIANT_SUPPORT #Extra sanity checks of internal structures, required by INVARIANTS +#options WITNESS #Enable checks to detect deadlocks and cycles +#options WITNESS_SKIPSPIN #Don't run witness on spinlocks for speed +#options DIAGNOSTIC +#options DEBUG # NFS support @@ -94,9 +94,9 @@ device random # Entropy device # I2C support -#device iicbus -#device iic -#device ti_i2c +device iicbus +device iic +device ti_i2c #device am37x_pmic # AM335x Power Management IC (TPC65217) # GPIO @@ -115,14 +115,13 @@ # Ethernet device loop -#device ether -#device mii -#device smcphy +device ether +device mii +device smcphy # USB ethernet support, requires miibus -#device miibus -#device cpsw -#device axe # ASIX Electronics USB Ethernet +device miibus +device smsc # Flattened Device Tree options FDT Modified: soc2012/aleek/beaglexm-armv6/sys/arm/ti/am37x/am37x_prcm.c ============================================================================== --- soc2012/aleek/beaglexm-armv6/sys/arm/ti/am37x/am37x_prcm.c Tue Jul 31 13:11:20 2012 (r239955) +++ soc2012/aleek/beaglexm-armv6/sys/arm/ti/am37x/am37x_prcm.c Tue Jul 31 15:47:50 2012 (r239956) @@ -312,13 +312,12 @@ OMAP3_GENERIC_CLOCK_DEV(GPIO4_CLK), OMAP3_GENERIC_CLOCK_DEV(GPIO5_CLK), OMAP3_GENERIC_CLOCK_DEV(GPIO6_CLK), -#if 0 + /* I2C */ OMAP3_GENERIC_CLOCK_DEV(I2C1_CLK), OMAP3_GENERIC_CLOCK_DEV(I2C2_CLK), OMAP3_GENERIC_CLOCK_DEV(I2C3_CLK), -#endif /* sDMA */ OMAP3_ALWAYSON_CLOCK_DEV(SDMA_CLK), { INVALID_CLK_IDENT, NULL, NULL, NULL, NULL } @@ -409,7 +408,6 @@ OMAP3_GENERIC_CLOCK_DETAILS(USBHSHOST_CLK, -1, USBHOST_CM_OFFSET, 0x00, 0x10, 0x20, 1), -#if 0 /* GPIO modules */ OMAP3_GENERIC_CLOCK_DETAILS(GPIO1_CLK, -1, WKUP_CM_OFFSET, 0x00, 0x10, 0x20, 3), @@ -431,7 +429,7 @@ 0x00, 0x10, 0x20, 16), OMAP3_GENERIC_CLOCK_DETAILS(I2C3_CLK, -1, CORE_CM_OFFSET, 0x00, 0x10, 0x20, 17), -#endif + { INVALID_CLK_IDENT, 0, 0, 0, 0 }, }; Modified: soc2012/aleek/beaglexm-armv6/sys/arm/ti/am37x/am37x_scm_padconf.c ============================================================================== --- soc2012/aleek/beaglexm-armv6/sys/arm/ti/am37x/am37x_scm_padconf.c Tue Jul 31 13:11:20 2012 (r239955) +++ soc2012/aleek/beaglexm-armv6/sys/arm/ti/am37x/am37x_scm_padconf.c Tue Jul 31 15:47:50 2012 (r239956) @@ -193,14 +193,19 @@ _PIN(0x01b8, "v26", 191, 4, "hsusb0_data7", NULL, NULL, NULL, "gpio_191", NULL, NULL, "safe_mode"), _PIN(0x01a6, "r28", 122, 4, "hsusb0_dir", NULL, NULL, NULL, "gpio_122", NULL, NULL, "safe_mode"), _PIN(0x01a8, "t26", 124, 4, "hsusb0_nxt", NULL, NULL, NULL, "gpio_124", NULL, NULL, "safe_mode"), - _PIN(0x01a4, "t25", 121, 4, "hsusb0_stp", NULL, NULL, NULL, "gpio_121", NULL, NULL, "safe_mode"), - _PIN(0x01be, "af15", 168, 4, "i2c2_scl", NULL, NULL, NULL, "gpio_168", NULL, NULL, "safe_mode"), - _PIN(0x01c0, "ae15", 183, 4, "i2c2_sda", NULL, NULL, NULL, "gpio_183", NULL, NULL, "safe_mode"), - _PIN(0x01c2, "af14", 184, 4, "i2c3_scl", NULL, NULL, NULL, "gpio_184", NULL, NULL, "safe_mode"), - _PIN(0x01c4, "ag14", 185, 4, "i2c3_sda", NULL, NULL, NULL, "gpio_185", NULL, NULL, "safe_mode"), - _PIN(0x0a00, "ad26", 0, 0, "i2c4_scl", "sys_nvmode1", NULL, NULL, NULL, NULL, NULL, "safe_mode"), - _PIN(0x0a02, "ae26", 0, 0, "i2c4_sda", "sys_nvmode2", NULL, NULL, NULL, NULL, NULL, "safe_mode"), - _PIN(0x0a24, "aa11", 11, 4, "jtag_emu0", NULL, NULL, NULL, "gpio_11", NULL, NULL, "safe_mode"), + + /* yes, this beautiful tabbing was because I am a little bit pedantic :D aleek */ + _PIN(0x01a4, "t25", 121, 4, "hsusb0_stp", NULL, NULL, NULL, "gpio_121", NULL, NULL, "safe_mode"), + _PIN(0x01ba, "ic11", 191, 4, "i2c1_scl", NULL, NULL, NULL, NULL, NULL, NULL, NULL ), + _PIN(0x01bc, "ic12", 191, 4, "i2c1_sda", NULL, NULL, NULL, NULL, NULL, NULL, NULL ), + _PIN(0x01be, "af15", 168, 4, "i2c2_scl", NULL, NULL, NULL, "gpio_168", NULL, NULL, "safe_mode"), + _PIN(0x01c0, "ae15", 183, 4, "i2c2_sda", NULL, NULL, NULL, "gpio_183", NULL, NULL, "safe_mode"), + _PIN(0x01c2, "af14", 184, 4, "i2c3_scl", NULL, NULL, NULL, "gpio_184", NULL, NULL, "safe_mode"), + _PIN(0x01c4, "ag14", 185, 4, "i2c3_sda", NULL, NULL, NULL, "gpio_185", NULL, NULL, "safe_mode"), + _PIN(0x0a00, "ad26", 0, 0, "i2c4_scl", "sys_nvmode1", NULL, NULL, NULL, NULL, NULL, "safe_mode"), + _PIN(0x0a02, "ae26", 0, 0, "i2c4_sda", "sys_nvmode2", NULL, NULL, NULL, NULL, NULL, "safe_mode"), + _PIN(0x0a24, "aa11", 11, 4, "jtag_emu0", NULL, NULL, NULL, "gpio_11", NULL, NULL, "safe_mode"), + _PIN(0x0a26, "aa10", 31, 4, "jtag_emu1", NULL, NULL, NULL, "gpio_31", NULL, NULL, "safe_mode"), _PIN(0x018c, "y21", 156, 4, "mcbsp1_clkr", "mcspi4_clk", NULL, NULL, "gpio_156", NULL, NULL, "safe_mode"), _PIN(0x0198, "w21", 162, 4, "mcbsp1_clkx", NULL, "mcbsp3_clkx", NULL, "gpio_162", NULL, NULL, "safe_mode"), Modified: soc2012/aleek/beaglexm-armv6/sys/arm/ti/ti_gpio.c ============================================================================== --- soc2012/aleek/beaglexm-armv6/sys/arm/ti/ti_gpio.c Tue Jul 31 13:11:20 2012 (r239955) +++ soc2012/aleek/beaglexm-armv6/sys/arm/ti/ti_gpio.c Tue Jul 31 15:47:50 2012 (r239956) @@ -448,10 +448,7 @@ return (EINVAL); - device_printf( sc->sc_dev, "locking mutex\n" ); - device_printf( sc->sc_dev, "adres mutexa: %p\n", &sc->sc_mtx ); TI_GPIO_LOCK(sc); - device_printf( sc->sc_dev, "mutex locked!!\n" ); /* Sanity check the pin number is valid */ if ((bank > MAX_GPIO_BANKS) || (sc->sc_mem_res[bank] == NULL)) { @@ -668,10 +665,8 @@ sc->sc_dev = dev; - device_printf(dev, "Inicjalizacja mutexa gpio\n"); TI_GPIO_LOCK_INIT(sc); - device_printf( dev, "Address do softc struct: %p\n", sc ); /* There are up to 6 different GPIO register sets located in different Modified: soc2012/aleek/beaglexm-armv6/sys/arm/ti/ti_i2c.c ============================================================================== --- soc2012/aleek/beaglexm-armv6/sys/arm/ti/ti_i2c.c Tue Jul 31 13:11:20 2012 (r239955) +++ soc2012/aleek/beaglexm-armv6/sys/arm/ti/ti_i2c.c Tue Jul 31 15:47:50 2012 (r239956) @@ -116,6 +116,10 @@ { IIC_SLOW, 100000, 3, 53, 55, 0, 0}, { IIC_FAST, 400000, 3, 8, 10, 0, 0}, { IIC_FASTEST, 400000, 3, 8, 10, 0, 0}, /* This might be higher */ +#elif defined(SOC_OMAP3) || defined(SOC_TI_AM37X) + { IIC_SLOW, 100000, 23, 13, 15, 0, 0}, + { IIC_FAST, 400000, 9, 5, 7, 0, 0}, + { IIC_FASTEST, 3400000, 4, 113, 115, 7, 10}, #else #error "TI I2C driver is not supported on this SoC" #endif Modified: soc2012/aleek/beaglexm-armv6/sys/arm/ti/ti_machdep.c ============================================================================== --- soc2012/aleek/beaglexm-armv6/sys/arm/ti/ti_machdep.c Tue Jul 31 13:11:20 2012 (r239955) +++ soc2012/aleek/beaglexm-armv6/sys/arm/ti/ti_machdep.c Tue Jul 31 15:47:50 2012 (r239956) @@ -527,8 +527,8 @@ DOMAIN_CLIENT); pmap_pa = kernel_l1pt.pv_pa; - arm_early_puts( "Dumping memory layout!\n" ); - dump_l1pagetable( kernel_l1pt.pv_pa ); + //arm_early_puts( "Dumping memory layout!\n" ); + //dump_l1pagetable( kernel_l1pt.pv_pa ); setttb(kernel_l1pt.pv_pa); cpu_tlb_flushID(); Modified: soc2012/aleek/beaglexm-armv6/sys/arm/ti/usb/omap_ehci.c ============================================================================== --- soc2012/aleek/beaglexm-armv6/sys/arm/ti/usb/omap_ehci.c Tue Jul 31 13:11:20 2012 (r239955) +++ soc2012/aleek/beaglexm-armv6/sys/arm/ti/usb/omap_ehci.c Tue Jul 31 15:47:50 2012 (r239956) @@ -125,7 +125,6 @@ int port_mode[3]; int phy_reset[3]; int reset_gpio_pin[3]; - struct mtx mtx; }; static device_attach_t omap_ehci_attach; @@ -350,36 +349,28 @@ int i; device_printf(isc->sc_dev, "Starting TI EHCI USB Controller\n"); - device_printf( isc->sc_dev, "%s:%d\n", __FUNCTION__, __LINE__ ); /* Enable Clocks for high speed USBHOST */ ti_prcm_clk_enable(USBHSHOST_CLK); - device_printf( isc->sc_dev, "%s:%d\n", __FUNCTION__, __LINE__ ); /* Hold the PHY in reset while configuring */ for (int i = 0; i < 3; i++) { if (isc->phy_reset[i]) { - device_printf( isc->sc_dev, "%s:%d\n", __FUNCTION__, __LINE__ ); /* Configure the GPIO to drive low (hold in reset) */ if ((isc->reset_gpio_pin[i] != -1) && (isc->sc_gpio_dev != NULL)) { - device_printf( isc->sc_dev, "%s:%d\n", __FUNCTION__, __LINE__ ); GPIO_PIN_SETFLAGS(isc->sc_gpio_dev, isc->reset_gpio_pin[i], GPIO_PIN_OUTPUT); - device_printf( isc->sc_dev, "%s:%d\n", __FUNCTION__, __LINE__ ); GPIO_PIN_SET(isc->sc_gpio_dev, isc->reset_gpio_pin[i], GPIO_PIN_LOW); - device_printf( isc->sc_dev, "%s:%d\n", __FUNCTION__, __LINE__ ); reset_performed = 1; } } } - device_printf( isc->sc_dev, "%s:%d\n", __FUNCTION__, __LINE__ ); /* Hold the PHY in RESET for enough time till DIR is high */ if (reset_performed) DELAY(10); - device_printf( isc->sc_dev, "%s:%d\n", __FUNCTION__, __LINE__ ); /* Read the UHH revision */ isc->ehci_rev = omap_uhh_read_4(isc, OMAP_USBHOST_UHH_REVISION); @@ -788,13 +779,6 @@ int len, tuple_size; int i; - memset( &isc->mtx, 0, sizeof( struct mtx) ); - - device_printf( dev, "%s:%d\n", __FUNCTION__, __LINE__ ); - - mtx_init(&isc->mtx, "habababa", "ti_ehci_testowy", MTX_DEF); - device_printf( dev, "%s:%d\n", __FUNCTION__, __LINE__ ); - /* initialise some bus fields */ sc->sc_bus.parent = dev; sc->sc_bus.devices = sc->sc_devices; @@ -803,17 +787,11 @@ /* save the device */ isc->sc_dev = dev; - device_printf( dev, "%s:%d\n", __FUNCTION__, __LINE__ ); /* get all DMA memory */ if (usb_bus_mem_alloc_all(&sc->sc_bus, USB_GET_DMA_TAG(dev), &ehci_iterate_hw_softc)) { return (ENOMEM); } - device_printf( dev, "%s:%d\n", __FUNCTION__, __LINE__ ); - mtx_lock( &isc->mtx ); - device_printf( dev, "%s:%d\n", __FUNCTION__, __LINE__ ); - mtx_unlock( &isc->mtx ); - device_printf( dev, "%s:%d\n", __FUNCTION__, __LINE__ ); /* When the EHCI driver is added to the tree it is expected that 3 * memory resources and 1 interrupt resource is assigned. The memory * resources should be: @@ -824,7 +802,6 @@ * The interrupt resource is just the single interupt for the controller. */ - device_printf( dev, "%s:%d\n", __FUNCTION__, __LINE__ ); /* Allocate resource for the EHCI register set */ rid = 0; sc->sc_io_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE); @@ -832,7 +809,6 @@ device_printf(dev, "Error: Could not map EHCI memory\n"); goto error; } - device_printf( dev, "%s:%d\n", __FUNCTION__, __LINE__ ); /* Request an interrupt resource */ rid = 0; sc->sc_irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE); @@ -840,7 +816,6 @@ device_printf(dev, "Error: could not allocate irq\n"); goto error; } - device_printf( dev, "%s:%d\n", __FUNCTION__, __LINE__ ); /* Allocate resource for the UHH register set */ rid = 1; @@ -849,7 +824,6 @@ device_printf(dev, "Error: Could not map UHH memory\n"); goto error; } - device_printf( dev, "%s:%d\n", __FUNCTION__, __LINE__ ); /* Allocate resource for the TLL register set */ rid = 2; isc->tll_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE); @@ -857,7 +831,6 @@ device_printf(dev, "Error: Could not map TLL memory\n"); goto error; } - device_printf( dev, "%s:%d\n", __FUNCTION__, __LINE__ ); /* Add this device as a child of the USBus device */ sc->sc_bus.bdev = device_add_child(dev, "usbus", -1); @@ -865,7 +838,6 @@ device_printf(dev, "Error: could not add USB device\n"); goto error; } - device_printf( dev, "%s:%d\n", __FUNCTION__, __LINE__ ); device_set_ivars(sc->sc_bus.bdev, &sc->sc_bus); device_set_desc(sc->sc_bus.bdev, OMAP_EHCI_HC_DEVSTR); @@ -889,7 +861,6 @@ isc->reset_gpio_pin[i] = -1; } - device_printf( dev, "%s:%d\n", __FUNCTION__, __LINE__ ); tuple_size = sizeof(pcell_t) * 3; node = ofw_bus_get_node(dev); @@ -910,7 +881,6 @@ } } - device_printf( dev, "%s:%d\n", __FUNCTION__, __LINE__ ); /* Initialise the ECHI registers */ err = omap_ehci_init(isc); if (err) { @@ -919,14 +889,12 @@ } - device_printf( dev, "%s:%d\n", __FUNCTION__, __LINE__ ); /* Set the tag and size of the register set in the EHCI context */ sc->sc_io_hdl = rman_get_bushandle(sc->sc_io_res); sc->sc_io_tag = rman_get_bustag(sc->sc_io_res); sc->sc_io_size = rman_get_size(sc->sc_io_res); - device_printf( dev, "%s:%d\n", __FUNCTION__, __LINE__ ); /* Setup the interrupt */ err = bus_setup_intr(dev, sc->sc_irq_res, INTR_TYPE_BIO | INTR_MPSAFE, NULL, (driver_intr_t *)ehci_interrupt, sc, &sc->sc_intr_hdl); @@ -936,11 +904,9 @@ goto error; } - device_printf( dev, "%s:%d\n", __FUNCTION__, __LINE__ ); /* Finally we are ready to kick off the ECHI host controller */ err = ehci_init(sc); - device_printf( dev, "%s:%d\n", __FUNCTION__, __LINE__ ); if (err == 0) { err = device_probe_and_attach(sc->sc_bus.bdev); } Modified: soc2012/aleek/beaglexm-armv6/sys/boot/fdt/dts/beagleboardxm.dts ============================================================================== --- soc2012/aleek/beaglexm-armv6/sys/boot/fdt/dts/beagleboardxm.dts Tue Jul 31 13:11:20 2012 (r239955) +++ soc2012/aleek/beaglexm-armv6/sys/boot/fdt/dts/beagleboardxm.dts Tue Jul 31 15:47:50 2012 (r239956) @@ -94,7 +94,11 @@ "ad25", "gpio_147", "output", "ae7", "hsusb2_clk", "output", - "r8", "gpio_56", "output"; + "r8", "gpio_56", "output", + + /* i2c */ + "ic11", "i2c1_scl", "output", + "ic12", "i2c1_sda", "output"; }; @@ -173,7 +177,7 @@ interrupts = < 12 13 14 15 >; interrupt-parent = <&AINTC>; }; -/* + mmchs@4809c000 { compatible = "ti,mmchs"; reg =<0x4809c000 0x1000 >; @@ -181,20 +185,20 @@ interrupt-parent = <&AINTC>; mmchs-device-id = <1>; }; -*/ - i2c0: i2c@48070000 { + + i2c1: i2c@48070000 { #address-cells = <1>; #size-cells = <0>; compatible = "ti,i2c"; reg =< 0x48070000 0x1000 >; interrupts = <56>; interrupt-parent = <&AINTC>; - i2c-device-id = <0>; - pmic@24 { + i2c-device-id = <1>; + /*pmic@24 { compatible = "ti,am37x-pmic"; reg = <0x24>; - }; + };*/ }; ehci@48064800 { @@ -211,7 +215,7 @@ * gpio_pin - GPIO pin that is used to perform reset */ phy-config = < 1 0 0 - 1 1 56 + 1 1 147 0 0 0>; reg = < 0x48064800 0x400 /* EHCI */ 0x48064000 0x400 /* UHH */ From owner-svn-soc-all@FreeBSD.ORG Tue Jul 31 16:20:08 2012 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id D84F2106566B for ; Tue, 31 Jul 2012 16:20:05 +0000 (UTC) (envelope-from exxo@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Tue, 31 Jul 2012 16:20:05 +0000 Date: Tue, 31 Jul 2012 16:20:05 +0000 From: exxo@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20120731162005.D84F2106566B@hub.freebsd.org> Cc: Subject: socsvn commit: r239957 - in soc2012/exxo/freebsd-head: include/rpcsvc lib/libc/yp usr.sbin/ypbind X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 31 Jul 2012 16:20:08 -0000 Author: exxo Date: Tue Jul 31 16:20:04 2012 New Revision: 239957 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=239957 Log: Updating ypbind Modified: soc2012/exxo/freebsd-head/include/rpcsvc/yp.x soc2012/exxo/freebsd-head/include/rpcsvc/yp_prot.h soc2012/exxo/freebsd-head/lib/libc/yp/yplib.c soc2012/exxo/freebsd-head/usr.sbin/ypbind/yp_ping.c soc2012/exxo/freebsd-head/usr.sbin/ypbind/yp_ping.h soc2012/exxo/freebsd-head/usr.sbin/ypbind/ypbind.c Modified: soc2012/exxo/freebsd-head/include/rpcsvc/yp.x ============================================================================== --- soc2012/exxo/freebsd-head/include/rpcsvc/yp.x Tue Jul 31 15:47:50 2012 (r239956) +++ soc2012/exxo/freebsd-head/include/rpcsvc/yp.x Tue Jul 31 16:20:04 2012 (r239957) @@ -208,12 +208,12 @@ ypbind_binding ypbind_bindinfo; }; -/* Detailed failure reason codes for response field ypbind_error*/ +/* Detailed failure reason codes for response field ypbind_error */ const YPBIND_ERR_ERR = 1; /* Internal error */ const YPBIND_ERR_NOSERV = 2; /* No bound server for passed domain */ const YPBIND_ERR_RESC = 3; /* System resource allocation failure */ - +const YPBIND_ERR_FAMILY = 4; /* Unsupported family */ /* * Request data structure for ypbind "Set domain" procedure. @@ -223,6 +223,8 @@ ypbind_binding ypsetdom_binding; unsigned ypsetdom_vers; }; +%#define ypsetdom_addr ypsetdom_binding.ypbind_binding_addr +%#define ypsetdom_port ypsetdom_binding.ypbind_binding_port /* Backward compatibility for YPBIND protocol version 2 */ #ifdef YPBIND_COMPAT_V2 @@ -247,8 +249,17 @@ unsigned ypsetdom_vers; }; +%#define yprespv2_error ypbind_resp_v2_u.ypbind_error +%#define yprespv2_addr ypbind_resp_v2_u.ypbind_bindinfo.ypbind_binding_addr +%#define yprespv2_port ypbind_resp_v2_u.ypbind_bindinfo.ypbind_binding_port + #endif +%#define ypresp_error ypbind_resp_u.ypbind_error +%#define ypresp_family ypbind_resp_u.ypbind_bindinfo.ypbind_binding_family +%#define ypresp_addr ypbind_resp_u.ypbind_bindinfo.ypbind_binding_addr +%#define ypresp_port ypbind_resp_u.ypbind_bindinfo.ypbind_binding_port + /* * NIS v1 support for backwards compatibility */ Modified: soc2012/exxo/freebsd-head/include/rpcsvc/yp_prot.h ============================================================================== --- soc2012/exxo/freebsd-head/include/rpcsvc/yp_prot.h Tue Jul 31 15:47:50 2012 (r239956) +++ soc2012/exxo/freebsd-head/include/rpcsvc/yp_prot.h Tue Jul 31 16:20:04 2012 (r239957) @@ -261,6 +261,7 @@ #define YPBIND_ERR_ERR 1 /* internal error */ #define YPBIND_ERR_NOSERV 2 /* no bound server for passed domain */ #define YPBIND_ERR_RESC 3 /* system resource allocation failure */ +#define YPBIND_ERR_FAMILY 4 /* unsupported family */ /* * Request data structure for ypbind "Set domain" procedure. @@ -295,8 +296,17 @@ u_int ypsetdom_vers; }; +#define yprespv2_error ypbind_resp_v2_u.ypbind_error +#define yprespv2_addr ypbind_resp_v2_u.ypbind_bindinfo.ypbind_binding_addr +#define yprespv2_port ypbind_resp_v2_u.ypbind_bindinfo.ypbind_binding_port + #endif +#define ypresp_error ypbind_resp_u.ypbind_error +#define ypresp_family ypbind_resp_u.ypbind_bindinfo.ypbind_binding_family +#define ypresp_addr ypbind_resp_u.ypbind_bindinfo.ypbind_binding_addr +#define ypresp_port ypbind_resp_u.ypbind_bindinfo.ypbind_binding_port + /* * YPPUSH PROTOCOL: * Modified: soc2012/exxo/freebsd-head/lib/libc/yp/yplib.c ============================================================================== --- soc2012/exxo/freebsd-head/lib/libc/yp/yplib.c Tue Jul 31 15:47:50 2012 (r239956) +++ soc2012/exxo/freebsd-head/lib/libc/yp/yplib.c Tue Jul 31 16:20:04 2012 (r239957) @@ -278,6 +278,8 @@ return ("Domain not bound"); case YPBIND_ERR_RESC: return ("System resource allocation failure"); + case YPBIND_ERR_FAMILY: + return ("Unsupported family"); } sprintf(err, "Unknown ypbind error: #%d\n", incode); return (err); Modified: soc2012/exxo/freebsd-head/usr.sbin/ypbind/yp_ping.c ============================================================================== --- soc2012/exxo/freebsd-head/usr.sbin/ypbind/yp_ping.c Tue Jul 31 15:47:50 2012 (r239956) +++ soc2012/exxo/freebsd-head/usr.sbin/ypbind/yp_ping.c Tue Jul 31 16:20:04 2012 (r239957) @@ -229,25 +229,20 @@ # define TSP_LEN (V4 + 1) #endif -static u_short -__yp_getport(const struct sockaddr_storage *host, const char *netid) +u_short +__rpcb_getport(const char *hostname, const char *netid, + const rpcprog_t prognum, const rpcvers_t versnum) { struct sockaddr_storage sst; struct netconfig *nconf; struct netbuf svcaddr; u_short port; - char str[ADDRSTRLEN]; - int family; - char *ptr; svcaddr.len = 0; svcaddr.maxlen = sizeof(sst); svcaddr.buf = &sst; - if (ss_extract(host, &family, &ptr, 0)) - return (0); - inet_ntop(family, ptr, str, ADDRSTRLEN); if ((nconf = getnetconfigent(netid)) == NULL || - !rpcb_getaddr(YPPROG, YPVERS, nconf, &svcaddr, str)) + !rpcb_getaddr(prognum, versnum, nconf, &svcaddr, hostname)) return (0); switch (svcaddr.len) { case sizeof(struct sockaddr_in) : @@ -264,6 +259,19 @@ return (port); /* Network byte order */ } +static u_short +__yp_getport(const struct sockaddr_storage *host, const char *netid) +{ + char str[ADDRSTRLEN]; + int family; + char *ptr; + + if (ss_extract(host, &family, &ptr, 0)) + return (0); + inet_ntop(family, ptr, str, ADDRSTRLEN); + return (__rpcb_getport(str, netid, YPPROG, YPVERS)); +} + static int rpc_init(struct transport *tsp) { @@ -278,13 +286,13 @@ continue; #ifdef INET6 if (i == V6) { - tsp[i]->sock = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP); + tsp[i]->sock = socket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP); tsp[i]->addr.len = sizeof(struct sockaddr_in6); } else /* V4 */ #endif { - tsp[i]->sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); + tsp[i]->sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); tsp[i]->addr.len = sizeof(struct sockaddr_in); } if (tsp[i]->sock < 0) @@ -322,7 +330,7 @@ } int -__yp_ping(struct sockaddr_storage *restricted_addrs, int cnt, char *dom, short *port) +__yp_ping(struct sockaddr_storage *restricted_addrs, int cnt, char *dom, u_short *port) { struct ping_req **reqs; unsigned long i; @@ -345,7 +353,7 @@ xid_seed = time(NULL) ^ getpid(); for (i = 0; i < cnt; i++) { - yp_port = __yp_getport(&restricted_addrs[i], "udp"); + yp_port = __yp_getport(&restricted_addrs[i], CONNLESS_TSP); if (yp_port == 0) continue; reqs[i] = calloc(1, sizeof(struct ping_req)); Modified: soc2012/exxo/freebsd-head/usr.sbin/ypbind/yp_ping.h ============================================================================== --- soc2012/exxo/freebsd-head/usr.sbin/ypbind/yp_ping.h Tue Jul 31 15:47:50 2012 (r239956) +++ soc2012/exxo/freebsd-head/usr.sbin/ypbind/yp_ping.h Tue Jul 31 16:20:04 2012 (r239957) @@ -2,6 +2,9 @@ * $FreeBSD$ */ +#define CONNFULL_TSP "tcp" +#define CONNLESS_TSP "udp" + #ifdef INET6 # define ADDRSTRLEN INET6_ADDRSTRLEN #else @@ -22,13 +25,13 @@ case AF_INET: *addr = ss_to_sinaddr(ss); if (len) - *len = sizeof(struct sockaddr_in); + *len = sizeof(struct in_addr); break; #ifdef INET6 case AF_INET6: *addr = ss_to_sin6addr(ss); if (len) - *len = sizeof(struct sockaddr_in6); + *len = sizeof(struct in6_addr); break; #endif default: @@ -37,4 +40,17 @@ return (0); } -extern int __yp_ping(struct sockaddr_storage *, int, char *, short *); +static inline u_short * +ss_getport(const struct sockaddr_storage *ss) +{ +#ifdef INET6 + if (ss_family(ss) == AF_INET6) + return (&ss_to_sin6port(ss)); + else +#endif + return (&ss_to_sinport(ss)); +} + +extern int __yp_ping(struct sockaddr_storage *, int, char *, u_short *); +extern u_short __rpcb_getport(const char *hostname, const char *netid, + const rpcprog_t prognum, const rpcvers_t versnum); Modified: soc2012/exxo/freebsd-head/usr.sbin/ypbind/ypbind.c ============================================================================== --- soc2012/exxo/freebsd-head/usr.sbin/ypbind/ypbind.c Tue Jul 31 15:47:50 2012 (r239956) +++ soc2012/exxo/freebsd-head/usr.sbin/ypbind/ypbind.c Tue Jul 31 16:20:04 2012 (r239957) @@ -69,6 +69,10 @@ #define BINDINGDIR "/var/yp/binding" #endif +#if !defined(BINDINGDIR_V2) && defined(YPBIND_COMPAT_V2) +#define BINDINGDIR_V2 "/var/yp/binding.2" +#endif + #ifndef YPBINDLOCK #define YPBINDLOCK "/var/run/ypbind.lock" #endif @@ -79,6 +83,9 @@ struct sockaddr_storage dom_server_addr; /* TODO */ long int dom_vers; int dom_lockfd; +#ifdef YPBIND_COMPAT_V2 + int dom_lockfd_v2; +#endif int dom_alive; int dom_broadcast_pid; int dom_pipe_fds[2]; @@ -148,6 +155,9 @@ #define MAX_RETRIES 30 #endif +#define CLOSE_LKS 1 +#define FREE_DOMB 2 + int retries = 0; int children = 0; int domains = 0; @@ -168,7 +178,6 @@ { static struct ypbind_resp res; struct _dom_binding *ypdb; - char path[MAXPATHLEN]; bzero(&res, sizeof res); res.ypbind_status = YPBIND_FAIL_VAL; @@ -209,9 +218,10 @@ ypdb->dom_alive = 0; ypdb->dom_default = 0; ypdb->dom_lockfd = -1; - sprintf(path, "%s/%s.%ld", BINDINGDIR, - ypdb->dom_domain, ypdb->dom_vers); - unlink(path); +#ifdef YPBIND_COMPAT_V2 + ypdb->dom_lockfd_v2 = -1; +#endif + unregister_domb(ypdb, 0); ypdb->dom_pnext = ypbindlist; ypbindlist = ypdb; domains++; @@ -355,18 +365,14 @@ terminate(int sig) { struct _dom_binding *ypdb; - char path[MAXPATHLEN]; if (ppid != getpid()) exit(0); for (ypdb = ypbindlist; ypdb; ypdb = ypdb->dom_pnext) { - close(ypdb->dom_lockfd); if (ypdb->dom_broadcast_pid) kill(ypdb->dom_broadcast_pid, SIGINT); - sprintf(path, "%s/%s.%ld", BINDINGDIR, - ypdb->dom_domain, ypdb->dom_vers); - unlink(path); + unregister_domb(ypdb, CLOSE_LKS); } close(yplockfd); unlink(YPBINDLOCK); @@ -396,6 +402,136 @@ va_end(args); } +static int +create_domb_file(const struct _dom_binding *ypdb, const char *binding_dir) +{ + char path[MAXPATHLEN]; + int fd; + + sprintf(path, "%s/%s.%ld", binding_dir, + ypdb->dom_domain, ypdb->dom_vers); +#ifdef O_SHLOCK + if ((fd = open(path, O_CREAT|O_SHLOCK|O_RDWR|O_TRUNC, 0644)) == -1) { + (void)mkdir(binding_dir, 0755); + if ((fd = open(path, O_CREAT|O_SHLOCK|O_RDWR|O_TRUNC, 0644)) == -1) + return (-1); + } +#else + if ((fd = open(path, O_CREAT|O_RDWR|O_TRUNC, 0644)) == -1) { + (void)mkdir(binding_dir, 0755); + if ((fd = open(path, O_CREAT|O_RDWR|O_TRUNC, 0644)) == -1) + return (-1); + } + flock(fd, LOCK_SH); +#endif + return (fd); +} + +static void +register_domb(struct _dom_binding *ypdb, const struct sockaddr_storage *addr) +{ + struct iovec iov[2]; + struct ypbind_resp ybr; + int family; + u_short port; + + if (ypdb->dom_lockfd != -1) + close(ypdb->dom_lockfd); + + ypdb->dom_lockfd = create_domb_file(ypdb, BINDINGDIR); + if (ypdb->dom_lockfd == -1) + return; + + port = __rpcb_getport("127.0.0.1", CONNLESS_TSP, YPBINDPROG, YPBINDVERS); + iov[0].iov_base = (char *)&port + iov[0].iov_len = sizeof(port); + iov[1].iov_base = (char *)&ybr; + iov[1].iov_len = sizeof(ybr); + + family = ss_family(addr); + bzero(&ybr, sizeof(ybr)); + ybr.ypbind_status = YPBIND_SUCC_VAL; + ybr.ypresp_family = family; + *(u_short *)&ybr.ypresp_port = *ss_getport(addr); +#ifdef INET6 + if (family == AF_INET6) + bcopy(ss_to_sin6addr(addr), (char *) ybr.ypresp_addr, sizeof(struct in6_addr)); + else +#endif + bcopy(ss_to_sinaddr(addr), (char *) ybr.ypresp_addr, sizeof(struct in_addr)); + + if (writev(ypdb->dom_lockfd, iov, 2) != iov[0].iov_len + iov[1].iov_len) { + syslog(LOG_WARNING, "write: %m"); + close(ypdb->dom_lockfd); + ypdb->dom_lockfd = -1; + } +} + +#ifdef YPBIND_COMPAT_V2 +static void +register_domb_v2(struct _dom_binding *ypdb, const struct sockaddr_storage *addr) +{ + struct iovec iov[2]; + struct ypbind_resp_v2 ybr; + int family; + u_short port; + + if (ypdb->dom_lockfd_v2 != -1) + close(ypdb->dom_lockfd_v2); + + ypdb->dom_lockfd_v2 = create_domb_file(ypdb, BINDINGDIR_V2); + if (ypdb->dom_lockfd_v2 == -1) + return; + + port = __rpcb_getport("127.0.0.1", CONNLESS_TSP, YPBINDPROG, YPBINDVERS_2); + iov[0].iov_base = (char *)&port + iov[0].iov_len = sizeof(port); + iov[1].iov_base = (char *)&ybr; + iov[1].iov_len = sizeof(ybr); + + family = ss_family(addr); + bzero(&ybr, sizeof(ybr)); + if (family != AF_INET) { /* AF_INET6 is not supported in version 2 */ + ybr2.ypbind_status = YPBIND_FAIL_VAL; + ybr2.yprespv2_error = YPBIND_ERR_FAMILY; + } + else { + ybr2.ypbind_status = YPBIND_SUCC_VAL; + bcopy(ss_to_sinaddr(addr), (char *) ybr2.yprespv2_addr, sizeof(struct in_addr)); + *(u_short *)&ybr2.yprespv2_port = ss_to_sinport(addr) + } + + if (writev(ypdb->dom_lockfd_v2, iov, 2) != iov[0].iov_len + iov[1].iov_len) { + syslog(LOG_WARNING, "write: %m"); + close(ypdb->dom_lockfd_v2); + ypdb->dom_lockfd_v2 = -1; + } +} +#endif + +static void +unregister_domb(const struct _dom_binding *ypdb, unsigned char mode) +{ + char path[MAXPATHLEN]; + + sprintf(path, "%s/%s.%ld", BINDINGDIR, + ypdb->dom_domain, YPVERS); + if ( (mode & CLOSE_LKS)) + close(ypdb->dom_lockfd); + unlink(path); +#ifdef YPBIND_COMPAT_V2 + sprintf(path, "%s/%s.%ld", BINDINGDIR_V2, + ypdb->dom_domain, YPVERS); + if ( (mode & CLOSE_LKS)) + close(ypdb->dom_lockfd_v2); + unlink(path); +#endif + if ( (mode & FREE_DOMB)) { + free(ypdb); + domains--; + } +} + int main(int argc, char *argv[]) { @@ -404,6 +540,7 @@ DIR *dird; struct dirent *dirp; struct _dom_binding *ypdb, *next; + char path[MAXPATHLEN]; /* Check that another ypbind isn't already running. */ if ((yplockfd = (open(YPBINDLOCK, O_RDONLY|O_CREAT, 0444))) == -1) @@ -432,10 +569,9 @@ errx(1, "unknown option: %s", argv[i]); } - /* blow away everything in BINDINGDIR (if it exists) */ + /* blow away everything in BINDINGDIR/BINDINGDIR_V2 (if they exist) */ if ((dird = opendir(BINDINGDIR)) != NULL) { - char path[MAXPATHLEN]; while ((dirp = readdir(dird)) != NULL) if (strcmp(dirp->d_name, ".") && strcmp(dirp->d_name, "..")) { @@ -444,6 +580,17 @@ } closedir(dird); } +#ifdef YPBIND_COMPAT_V2 + if ((dird = opendir(BINDINGDIR_V2)) != NULL) { + while ((dirp = readdir(dird)) != NULL) + if (strcmp(dirp->d_name, ".") && + strcmp(dirp->d_name, "..")) { + sprintf(path,"%s/%s",BINDINGDIR_V2,dirp->d_name); + unlink(path); + } + closedir(dird); + } +#endif #ifdef DAEMON if (daemon(0,0)) @@ -454,15 +601,15 @@ #ifdef YPBIND_COMPAT_V2 rpcb_unset(YPBINDPROG, YPBINDVERS_2, NULL); #endif - if (!svc_create(ypbindprog_2, YPBINDPROG, YPBINDVERS, "udp")) /* TODO see how to retrieve xp_port */ - errx(1, "cannot create udp service"); - if (!svc_create(ypbindprog_2, YPBINDPROG, YPBINDVERS, "tcp")) - errx(1, "cannot create tcp service"); -#ifdef YPBIND_COMPAT_V2 - if (!svc_create(ypbindprog_2, YPBINDPROG, YPBINDVERS_2, "udp")) - errx(1, "cannot create udp service"); - if (!svc_create(ypbindprog_2, YPBINDPROG, YPBINDVERS_2, "tcp")) - errx(1, "cannot create tcp service"); + if (!svc_create(ypbindprog_2, YPBINDPROG, YPBINDVERS, CONNLESS_TSP)) /* TODO see how to retrieve xp_port */ + errx(1, "cannot create %s service", CONNLESS_TSP); + if (!svc_create(ypbindprog_2, YPBINDPROG, YPBINDVERS, CONNFULL_TSP)) + errx(1, "cannot create %s service", CONNFULL_TSP); +#ifdef YPBIND_COMPAT_V2 + if (!svc_create(ypbindprog_2, YPBINDPROG, YPBINDVERS_2, CONNLESS_TSP)) + errx(1, "cannot create %s service", CONNLESS_TSP); + if (!svc_create(ypbindprog_2, YPBINDPROG, YPBINDVERS_2, CONNFULL_TSP)) + errx(1, "cannot create %s service", CONNFULL_TSP); #endif /* build initial domain binding, make it "unsuccessful" */ @@ -474,6 +621,9 @@ ypbindlist->dom_vers = YPVERS; ypbindlist->dom_alive = 0; ypbindlist->dom_lockfd = -1; +#ifdef YPBIND_COMPAT_V2 + ypbindlist->dom_lockfd_v2 = -1; +#endif ypbindlist->dom_default = 1; domains++; @@ -547,15 +697,14 @@ handle_children(struct _dom_binding *ypdb) { char buf[YPMAXDOMAIN + 1]; - struct sockaddr_in addr; + struct sockaddr_storage addr; int d = 0, a = 0; struct _dom_binding *y, *prev = NULL; - char path[MAXPATHLEN]; if ((d = read(READFD, &buf, sizeof(buf))) <= 0) syslog(LOG_WARNING, "could not read from child: %m"); - if ((a = read(READFD, &addr, sizeof(struct sockaddr_in))) < 0) + if ((a = read(READFD, &addr, sizeof(addr))) < 0) syslog(LOG_WARNING, "could not read from child: %m"); close(READFD); @@ -576,12 +725,7 @@ ypbindlist = y->dom_pnext; else prev->dom_pnext = y->dom_pnext; - sprintf(path, "%s/%s.%ld", BINDINGDIR, - ypdb->dom_domain, YPVERS); - close(ypdb->dom_lockfd); - unlink(path); - free(ypdb); - domains--; + unregister_domb(ypdb, CLOSE_LKS | FREE_DOMB); return; case 1: ypdb->dom_broadcast_pid = 0; @@ -600,7 +744,7 @@ * Send our dying words back to our parent before we perish. */ int -tell_parent(char *dom, struct sockaddr_in *addr) +tell_parent(char *dom, struct sockaddr_storage *addr) { char buf[YPMAXDOMAIN + 1]; struct timeval timeout; @@ -623,7 +767,7 @@ if (select(FD_SETSIZE, NULL, &fds, NULL, &timeout) == -1) return(1); if (FD_ISSET(BROADFD, &fds)) { - if (write(BROADFD, addr, sizeof(struct sockaddr_in)) < 0) + if (write(BROADFD, addr, sizeof(*addr)) < 0) return(1); } else { return(1); @@ -633,23 +777,28 @@ return (0); } -bool_t broadcast_result(out, addr) -bool_t *out; -struct sockaddr_in *addr; +bool_t +broadcast_result(bool_t *out, const struct netbuf *addr, + const struct netconfig * netconf) { + struct sockaddr_storage sst; + + if (addr->len > sizeof(sst) || strcmp(netconf->nc_netid, CONNLESS_TSP)) + return (FALSE); + bzero((char*) &sst, sizeof(sst)); if (retries >= MAX_RETRIES) { - bzero(addr, sizeof(struct sockaddr_in)); - if (tell_parent(broad_domain->dom_domain, addr)) + if (tell_parent(broad_domain->dom_domain, &sst)) syslog(LOG_WARNING, "lost connection to parent"); return (TRUE); } - - if (yp_restricted && verify(addr->sin_addr)) { + bcpy(addr.buf, (char *) &sst, addr.len); + if (yp_restricted && verify(&sst)) { retries++; - syslog(LOG_NOTICE, "NIS server at %s not in restricted mode access list -- rejecting.\n",inet_ntoa(addr->sin_addr)); + logwaddr(LOG_NOTICE, &sst, "NIS server at %%s not in restricted mode access list -- rejecting.\n"); return (FALSE); - } else { - if (tell_parent(broad_domain->dom_domain, addr)) + } + else { + if (tell_parent(broad_domain->dom_domain, &sst)) syslog(LOG_WARNING, "lost connection to parent"); return (TRUE); } @@ -692,6 +841,9 @@ broad_domain = ypdb; flock(ypdb->dom_lockfd, LOCK_UN); +#ifdef YPBIND_COMPAT_V2 + flock(ypdb->dom_lockfd_v2, LOCK_UN); +#endif switch ((ypdb->dom_broadcast_pid = fork())) { case 0: @@ -714,6 +866,9 @@ /* Release all locks before doing anything else. */ while (ypbindlist) { close(ypbindlist->dom_lockfd); +#ifdef YPBIND_COMPAT_V2 + close(ypbindlist->dom_lockfd_v2); +#endif ypbindlist = ypbindlist->dom_pnext; } close(yplockfd); @@ -727,27 +882,20 @@ * operation: we transmit uni-cast datagrams only. */ if (yp_restricted && yp_manycast) { - short port; + u_short port; int i; - struct sockaddr_in sin; + struct sockaddr_storage sst; - i = __yp_ping(restricted_addrs, yp_restricted, - ypdb->dom_domain, &port); + i = __yp_ping(restricted_addrs, yp_restricted, ypdb->dom_domain, &port); if (i == -1) { - bzero(&ypdb->dom_server_addr, - sizeof(struct sockaddr_in)); - if (tell_parent(ypdb->dom_domain, - &ypdb->dom_server_addr)) + bzero(&ypdb->dom_server_addr, sizeof(struct sockaddr_storage)); + if (tell_parent(ypdb->dom_domain, &ypdb->dom_server_addr)) syslog(LOG_WARNING, "lost connection to parent"); } else { - bzero(&sin, sizeof(struct sockaddr_in)); - bcopy(&restricted_addrs[i], - &sin.sin_addr, sizeof(struct in_addr)); - sin.sin_family = AF_INET; - sin.sin_port = port; - if (tell_parent(broad_domain->dom_domain, &sin)) - syslog(LOG_WARNING, - "lost connection to parent"); + bcopy(&restricted_addrs[i], &sst, sizeof(sst)); + *ss_getport(&sst) = port; + if (tell_parent(broad_domain->dom_domain, &sst)) + syslog(LOG_WARNING, "lost connection to parent"); } _exit(0); } @@ -758,15 +906,14 @@ char *ptr; ptr = ypdb->dom_domain; - stat = clnt_broadcast(YPPROG, YPVERS, YPPROC_DOMAIN_NONACK, + stat = rpc_broadcast(YPPROG, YPVERS, YPPROC_DOMAIN_NONACK, (xdrproc_t)xdr_domainname, &ptr, (xdrproc_t)xdr_bool, &out, - (resultproc_t)broadcast_result); + (resultproc_t)broadcast_result, CONNLESS_TSP); } if (stat != RPC_SUCCESS) { - bzero(&ypdb->dom_server_addr, - sizeof(struct sockaddr_in)); + bzero(&ypdb->dom_server_addr, sizeof(struct sockaddr_storage)); if (tell_parent(ypdb->dom_domain, &ypdb->dom_server_addr)) syslog(LOG_WARNING, "lost connection to parent"); } @@ -774,6 +921,40 @@ _exit(0); } +static CLIENT * +yp_udpclient(struct sockaddr_storage *sst, int *sock) +{ + int family; + int s = -1; + CLIENT *client = NULL; + struct netbuf addr; + struct timeval interval; + + interval.tv_sec = FAIL_THRESHOLD; + interval.tv_usec = 0; + + family = ss_family(sst); + if (family == AF_INET) + addr.len = sizeof(struct sockaddr_sin); + else /* AF_INET6 */ +#ifdef INET6 + addr.len = sizeof(struct sockaddr_sin6); +#else + goto err; +#endif + addr.buf = sst; + if ((s = socket(family, SOCK_DGRAM, IPPROTO_UDP)) < 0) + goto err; + client = clnt_dg_create(s, &addr, YPPROG, YPVERS, + RPCSMALLMSGSIZE, RPCSMALLMSGSIZE); + clnt_control(client, CLSET_RETRY_TIMEOUT, &interval); +err: + if (!client) + close(s); + *sock = s; + return (client); +} + /* * The right way to check if a server is alive. * Attempt to get a client handle pointing to the server and send a @@ -790,61 +971,50 @@ ping(struct _dom_binding *ypdb) { bool_t out; - struct timeval interval, timeout; + struct timeval timeout; enum clnt_stat stat; - int rpcsock = RPC_ANYSOCK; - CLIENT *client_handle; + int rpcsock, err = 0; + CLIENT *client; - interval.tv_sec = FAIL_THRESHOLD; - interval.tv_usec = 0; timeout.tv_sec = FAIL_THRESHOLD; timeout.tv_usec = 0; if (ypdb->dom_broadcast_pid) return(1); - if ((client_handle = clntudp_bufcreate(&ypdb->dom_server_addr, - YPPROG, YPVERS, interval, &rpcsock, RPCSMALLMSGSIZE, - RPCSMALLMSGSIZE)) == (CLIENT *)NULL) { + if ((client = yp_udpclient(&ypdb->dom_server_addr, &rpcsock)) == NULL) { /* Can't get a handle: we're dead. */ - ypdb->dom_alive = 0; - ypdb->dom_vers = -1; - broadcast(ypdb); - return(1); + err = 1; + goto err; } { - char *ptr; - - ptr = ypdb->dom_domain; + char *ptr = ypdb->dom_domain; - stat = clnt_call(client_handle, YPPROC_DOMAIN, + stat = clnt_call(client, YPPROC_DOMAIN, (xdrproc_t)xdr_domainname, &ptr, (xdrproc_t)xdr_bool, &out, timeout); - if (stat != RPC_SUCCESS || out == FALSE) { - ypdb->dom_alive = 0; - ypdb->dom_vers = -1; - clnt_destroy(client_handle); - broadcast(ypdb); - return(1); - } + if (stat != RPC_SUCCESS || out == FALSE) + err = 1; } - - clnt_destroy(client_handle); - return(0); +err: + if (err) { + ypdb->dom_alive = 0; + ypdb->dom_vers = -1; + broadcast(ypdb); + } + if (client) { + close(rpcsock); + clnt_destroy(client); + } + return(err); } void -rpc_received(char *dom, struct sockaddr_in *raddrp, int force) +rpc_received(char *dom, struct sockaddr_storage *raddrp, int force) { + static struct sockaddr_storage null_addr; struct _dom_binding *ypdb, *prev = NULL; - struct iovec iov[2]; - struct ypbind_resp ybr; - char path[MAXPATHLEN]; - int fd; - - /*printf("returned from %s/%d about %s\n", inet_ntoa(raddrp->sin_addr), - ntohs(raddrp->sin_port), dom);*/ if (dom == NULL) return; @@ -865,11 +1035,10 @@ } } + port = ntohs(*ss_getport(raddrp)); /* if in secure mode, check originating port number */ - if ((ypsecuremode && (ntohs(raddrp->sin_port) >= IPPORT_RESERVED))) { - syslog(LOG_WARNING, "Rejected NIS server on [%s/%d] for domain %s.", - inet_ntoa(raddrp->sin_addr), ntohs(raddrp->sin_port), - dom); + if ((ypsecuremode && port >= IPPORT_RESERVED))) { + logwaddr(LOG_WARNING, raddrp, "Rejected NIS server on [%%s/%d] for domain %s.", port, dom); if (ypdb != NULL) { ypdb->dom_broadcast_pid = 0; ypdb->dom_alive = 0; @@ -877,19 +1046,16 @@ return; } - if (raddrp->sin_addr.s_addr == (long)0) { + /* bcmp should be safe here due to the earlier raddrp memset which + * prevents us from alignement issues */ + if (!bcmp((char *) raddrp, (char *) null_addr, sizeof(null_addr))) { switch (ypdb->dom_default) { case 0: if (prev == NULL) ypbindlist = ypdb->dom_pnext; else prev->dom_pnext = ypdb->dom_pnext; - sprintf(path, "%s/%s.%ld", BINDINGDIR, - ypdb->dom_domain, YPVERS); - close(ypdb->dom_lockfd); - unlink(path); - free(ypdb); - domains--; + unregister_domb(ypdb, CLOSE_LKS | FREE_DOMB); return; case 1: ypdb->dom_broadcast_pid = 0; @@ -912,17 +1078,20 @@ bzero(ypdb, sizeof *ypdb); strncpy(ypdb->dom_domain, dom, sizeof ypdb->dom_domain); ypdb->dom_lockfd = -1; +#ifdef YPBIND_COMPAT_V2 + ypdb->dom_lockfd_v2 = -1; +#endif ypdb->dom_default = 0; ypdb->dom_pnext = ypbindlist; ypbindlist = ypdb; } /* We've recovered from a crash: inform the world. */ - if (ypdb->dom_vers == -1 && ypdb->dom_server_addr.sin_addr.s_addr) { + if (ypdb->dom_vers == -1 && bcmp(&ypdb->dom_server_addr, &null_addr, sizeof(null_addr))) { if (not_responding_count >= NOT_RESPONDING_HYSTERESIS) { not_responding_count = 0; - syslog(LOG_WARNING, "NIS server [%s] for domain \"%s\" OK", - inet_ntoa(raddrp->sin_addr), ypdb->dom_domain); + logwaddr(LOG_WARNING, raddrp, "NIS server [%%s] for domain \"%s\" OK", + ypdb->dom_domain); } } @@ -933,48 +1102,10 @@ ypdb->dom_alive = 1; ypdb->dom_broadcast_pid = 0; - if (ypdb->dom_lockfd != -1) - close(ypdb->dom_lockfd); - - sprintf(path, "%s/%s.%ld", BINDINGDIR, - ypdb->dom_domain, ypdb->dom_vers); -#ifdef O_SHLOCK - if ((fd = open(path, O_CREAT|O_SHLOCK|O_RDWR|O_TRUNC, 0644)) == -1) { - (void)mkdir(BINDINGDIR, 0755); - if ((fd = open(path, O_CREAT|O_SHLOCK|O_RDWR|O_TRUNC, 0644)) == -1) - return; - } -#else - if ((fd = open(path, O_CREAT|O_RDWR|O_TRUNC, 0644)) == -1) { - (void)mkdir(BINDINGDIR, 0755); - if ((fd = open(path, O_CREAT|O_RDWR|O_TRUNC, 0644)) == -1) - return; - } - flock(fd, LOCK_SH); + register_domb(ypdb, raddrp); +#ifdef YPBIND_COMPAT_V2 + register_domb_v2(ypdb, raddrp); #endif - - /* - * ok, if BINDINGDIR exists, and we can create the binding file, - * then write to it.. - */ - ypdb->dom_lockfd = fd; - - iov[0].iov_base = (char *)&(udptransp->xp_port); - iov[0].iov_len = sizeof udptransp->xp_port; - iov[1].iov_base = (char *)&ybr; - iov[1].iov_len = sizeof ybr; - - bzero(&ybr, sizeof ybr); - ybr.ypbind_status = YPBIND_SUCC_VAL; - *(u_int32_t *)&ybr.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_addr = raddrp->sin_addr.s_addr; - *(u_short *)&ybr.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_port = raddrp->sin_port; - - if (writev(ypdb->dom_lockfd, iov, 2) != iov[0].iov_len + iov[1].iov_len) { - syslog(LOG_WARNING, "write: %m"); - close(ypdb->dom_lockfd); - ypdb->dom_lockfd = -1; - return; - } } /* @@ -982,14 +1113,20 @@ * 1 if not matched. */ int -verify(struct in_addr addr) +verify(struct sockaddr_storage *addr) { + int restrict_family, addr_family; + char *restrict_ptr, *addr_ptr; + size_t restrict_len, addr_len; int i; - for (i = 0; i < RESTRICTED_SERVERS; i++) - if (!bcmp(&addr, &restricted_addrs[i], sizeof(struct in_addr))) - return(0); - + for (i = 0; i < RESTRICTED_SERVERS; i++) { + if (ss_extract(&restricted_addrs[i], &restrict_family, &restrict_ptr, &restrict_len) + || ss_extract(addr, &addr_family, &addr_ptr, &addr_len)) + return (1); + if (restrict_family == addr_family && !bcmp(addr_ptr, restrict_ptr, addr_len)) + return (0); + } return(1); } @@ -1000,7 +1137,7 @@ void yp_restricted_mode(char *args) { - struct hostent *h; + struct addrinfo hint, *res; int i = 0; char *s; @@ -1009,12 +1146,19 @@ return; domain_name = s; + bzero(&hint, sizeof(hint)); /* Get the addresses of the servers. */ while ((s = strsep(&args, ",")) != NULL && i < RESTRICTED_SERVERS) { - if ((h = gethostbyname(s)) == NULL) + hint.ai_flags = AI_ADDRCONFIG; +#ifdef INET6 + hint.ai_family = PF_UNSPEC; +#else + hint.ai_family = PF_INET; +#endif + if (getaddrinfo(s, 0, &hint, &res)) return; - bcopy (h->h_addr_list[0], &restricted_addrs[i], - sizeof(struct in_addr)); + bcopy ((char *) res->ai_addr, (char *) &restricted_addrs[i], res->ai_addrlen); + freeaddrinfo(res); i++; } From owner-svn-soc-all@FreeBSD.ORG Tue Jul 31 18:57:10 2012 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id 13CF9106566C for ; Tue, 31 Jul 2012 18:57:09 +0000 (UTC) (envelope-from rudot@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Tue, 31 Jul 2012 18:57:09 +0000 Date: Tue, 31 Jul 2012 18:57:09 +0000 From: rudot@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20120731185709.13CF9106566C@hub.freebsd.org> Cc: Subject: socsvn commit: r239963 - soc2012/rudot/sys/kern X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 31 Jul 2012 18:57:10 -0000 Author: rudot Date: Tue Jul 31 18:57:08 2012 New Revision: 239963 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=239963 Log: use special way to calculate %cpu for short-lived processes. Work in progress. Modified: soc2012/rudot/sys/kern/kern_racct.c Modified: soc2012/rudot/sys/kern/kern_racct.c ============================================================================== --- soc2012/rudot/sys/kern/kern_racct.c Tue Jul 31 17:32:28 2012 (r239962) +++ soc2012/rudot/sys/kern/kern_racct.c Tue Jul 31 18:57:08 2012 (r239963) @@ -282,7 +282,7 @@ * work. */ static u_int -racct_getpcpu(struct proc *p) +racct_getpcpu(struct proc *p, u_int pcpu) { u_int swtime; #ifdef SCHED_4BSD @@ -298,6 +298,14 @@ swtime = (ticks - p->p_swtick) / hz; if ((swtime == 0) || ((p->p_flag & P_INMEM) == 0)) return (0); + if (swtime < 20) { + /* + * For short-lived processes, the sched_pctcpu() returns small + * values even for cpu intensive processes. Therefore we use + * our own estimate in this case. + */ + return (pcpu); + } p_pctcpu = 0; FOREACH_THREAD_IN_PROC(p, td) { @@ -1002,7 +1010,7 @@ struct proc *p; struct timeval wallclock; uint64_t runtime; - u_int pct; + u_int pct, pct_estimate; int over_limits; for (;;) { @@ -1036,7 +1044,10 @@ runtime = p->p_prev_runtime; #endif p->p_prev_runtime = runtime; - pct = racct_getpcpu(p); + pct_estimate = (runtime * 100) / + ((uint64_t)wallclock.tv_sec * 1000000 + + wallclock.tv_usec); + pct = racct_getpcpu(p, pct_estimate); mtx_lock(&racct_lock); over_limits = racct_set_check_locked(p, RACCT_PCTCPU, pct); if (over_limits) { From owner-svn-soc-all@FreeBSD.ORG Tue Jul 31 19:17:28 2012 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id 0D74C106566B for ; Tue, 31 Jul 2012 19:17:26 +0000 (UTC) (envelope-from jhagewood@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Tue, 31 Jul 2012 19:17:26 +0000 Date: Tue, 31 Jul 2012 19:17:26 +0000 From: jhagewood@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20120731191726.0D74C106566B@hub.freebsd.org> Cc: Subject: socsvn commit: r239967 - in soc2012/jhagewood/diff: . diff X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 31 Jul 2012 19:17:28 -0000 Author: jhagewood Date: Tue Jul 31 19:17:25 2012 New Revision: 239967 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=239967 Log: Added -lz to CFLAGS in diff Makefile. Modified: soc2012/jhagewood/diff/diff/Makefile soc2012/jhagewood/diff/diff/diffreg.c soc2012/jhagewood/diff/hagewood-diff.patch Modified: soc2012/jhagewood/diff/diff/Makefile ============================================================================== --- soc2012/jhagewood/diff/diff/Makefile Tue Jul 31 18:47:17 2012 (r239966) +++ soc2012/jhagewood/diff/diff/Makefile Tue Jul 31 19:17:25 2012 (r239967) @@ -3,8 +3,8 @@ DEBUG_FLAGS+= -g -PROG= diff xdiff +PROG= diff zdiff SRCS= diff.c diffdir.c diffreg.c -CFLAGS+= -std=c99 -Wall -pedantic +CFLAGS+= -std=c99 -Wall -pedantic -lz .include Modified: soc2012/jhagewood/diff/diff/diffreg.c ============================================================================== --- soc2012/jhagewood/diff/diff/diffreg.c Tue Jul 31 18:47:17 2012 (r239966) +++ soc2012/jhagewood/diff/diff/diffreg.c Tue Jul 31 19:17:25 2012 (r239967) @@ -306,7 +306,7 @@ int diffreg(char *ofile1, char *ofile2, int flags) { - char *buf; + char *buf = ""; char *file1 = ofile1; char *file2 = ofile2; FILE *f1 = NULL; Modified: soc2012/jhagewood/diff/hagewood-diff.patch ============================================================================== --- soc2012/jhagewood/diff/hagewood-diff.patch Tue Jul 31 18:47:17 2012 (r239966) +++ soc2012/jhagewood/diff/hagewood-diff.patch Tue Jul 31 19:17:25 2012 (r239967) @@ -1,15 +1,17 @@ diff -rupN diff-orig/Makefile diff/Makefile --- diff-orig/Makefile 2012-07-26 03:11:00.000000000 -0400 -+++ diff/Makefile 2012-07-26 03:11:00.000000000 -0400 -@@ -3,7 +3,7 @@ ++++ diff/Makefile 2012-07-31 19:16:23.000000000 -0400 +@@ -3,8 +3,8 @@ DEBUG_FLAGS+= -g -PROG= diff -+PROG= diff xdiff ++PROG= diff zdiff SRCS= diff.c diffdir.c diffreg.c - CFLAGS+= -std=c99 -Wall -pedantic +-CFLAGS+= -std=c99 -Wall -pedantic ++CFLAGS+= -std=c99 -Wall -pedantic -lz + .include diff -rupN diff-orig/diff.c diff/diff.c --- diff-orig/diff.c 2012-07-26 03:11:00.000000000 -0400 +++ diff/diff.c 2012-07-26 03:11:00.000000000 -0400 @@ -800,7 +802,7 @@ if (stat(path1, &stb1) != 0) { diff -rupN diff-orig/diffreg.c diff/diffreg.c --- diff-orig/diffreg.c 2012-07-26 03:11:00.000000000 -0400 -+++ diff/diffreg.c 2012-07-30 13:11:25.000000000 -0400 ++++ diff/diffreg.c 2012-07-31 19:11:25.000000000 -0400 @@ -62,15 +62,13 @@ * @(#)diffreg.c 8.1 (Berkeley) 6/6/93 */ @@ -940,7 +942,7 @@ - int rval = D_SAME; - int i, ostdout = -1; - pid_t pid = -1; -+ char *buf; ++ char *buf = ""; + char *file1 = ofile1; + char *file2 = ofile2; + FILE *f1 = NULL; From owner-svn-soc-all@FreeBSD.ORG Tue Jul 31 19:55:19 2012 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id BD4F4106564A for ; Tue, 31 Jul 2012 19:55:17 +0000 (UTC) (envelope-from gmiller@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Tue, 31 Jul 2012 19:55:17 +0000 Date: Tue, 31 Jul 2012 19:55:17 +0000 From: gmiller@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20120731195517.BD4F4106564A@hub.freebsd.org> Cc: Subject: socsvn commit: r239968 - in soc2012/gmiller/locking-head: . include lib/libwitness X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 31 Jul 2012 19:55:19 -0000 Author: gmiller Date: Tue Jul 31 19:55:16 2012 New Revision: 239968 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=239968 Log: r240024@FreeBSD-dev: root | 2012-07-24 08:43:51 -0500 Add child and sibling information to pthread_lockorder_np structure. Modified: soc2012/gmiller/locking-head/ (props changed) soc2012/gmiller/locking-head/include/pthread_np.h soc2012/gmiller/locking-head/lib/libwitness/lockinfo.c Modified: soc2012/gmiller/locking-head/include/pthread_np.h ============================================================================== --- soc2012/gmiller/locking-head/include/pthread_np.h Tue Jul 31 19:17:25 2012 (r239967) +++ soc2012/gmiller/locking-head/include/pthread_np.h Tue Jul 31 19:55:16 2012 (r239968) @@ -73,6 +73,8 @@ struct pthread_lockorder_np { struct _pthread_lockorder_private *_pvt; void *lock; + void *child; + void *sibling; }; typedef void (*pthread_switch_routine_t)(pthread_t, pthread_t); Modified: soc2012/gmiller/locking-head/lib/libwitness/lockinfo.c ============================================================================== --- soc2012/gmiller/locking-head/lib/libwitness/lockinfo.c Tue Jul 31 19:17:25 2012 (r239967) +++ soc2012/gmiller/locking-head/lib/libwitness/lockinfo.c Tue Jul 31 19:55:16 2012 (r239968) @@ -184,6 +184,18 @@ if (node->_pvt->last_record != NULL) { node->lock = node->_pvt->last_record->lock; + if (node->_pvt->last_record->child != NULL) { + node->child = + node->_pvt->last_record->child->lock; + } else { + node->child = NULL; + } + if (node->_pvt->last_record->sibling != NULL) { + node->sibling = + node->_pvt->last_record->sibling->lock; + } else { + node->sibling = NULL; + } return (1); } From owner-svn-soc-all@FreeBSD.ORG Wed Aug 1 08:12:59 2012 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id 497B610656AD for ; Wed, 1 Aug 2012 08:12:57 +0000 (UTC) (envelope-from gmiller@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Wed, 01 Aug 2012 08:12:57 +0000 Date: Wed, 01 Aug 2012 08:12:57 +0000 From: gmiller@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20120801081257.497B610656AD@hub.freebsd.org> Cc: Subject: socsvn commit: r239981 - in soc2012/gmiller/locking-head: . lib/libwitness X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 01 Aug 2012 08:12:59 -0000 Author: gmiller Date: Wed Aug 1 08:12:56 2012 New Revision: 239981 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=239981 Log: r240026@FreeBSD-dev: root | 2012-07-24 09:15:58 -0500 Reverse the parent->child order in the lock order graph in order to make it more intuitive. Modified: soc2012/gmiller/locking-head/ (props changed) soc2012/gmiller/locking-head/lib/libwitness/lists.c soc2012/gmiller/locking-head/lib/libwitness/wrappers.c Modified: soc2012/gmiller/locking-head/lib/libwitness/lists.c ============================================================================== --- soc2012/gmiller/locking-head/lib/libwitness/lists.c Wed Aug 1 05:53:20 2012 (r239980) +++ soc2012/gmiller/locking-head/lib/libwitness/lists.c Wed Aug 1 08:12:56 2012 (r239981) @@ -73,7 +73,7 @@ SLIST_INSERT_HEAD(&lock_head, entry, lock_next); - if (next != NULL && insert_lock(entry->lock, next->lock) < 0) { + if (next != NULL && insert_lock(next->lock, entry->lock) < 0) { log_reversal(entry->lock, next->lock); } } Modified: soc2012/gmiller/locking-head/lib/libwitness/wrappers.c ============================================================================== --- soc2012/gmiller/locking-head/lib/libwitness/wrappers.c Wed Aug 1 05:53:20 2012 (r239980) +++ soc2012/gmiller/locking-head/lib/libwitness/wrappers.c Wed Aug 1 08:12:56 2012 (r239981) @@ -384,7 +384,7 @@ _pthread_mutex_lock(&witness_mtx); - if (insert_lock(lookup_lock(second), lookup_lock(first)) < 0) { + if (insert_lock(lookup_lock(first), lookup_lock(second)) < 0) { ret = EINVAL; } From owner-svn-soc-all@FreeBSD.ORG Wed Aug 1 08:14:01 2012 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id 4A3BE1065670 for ; Wed, 1 Aug 2012 08:13:59 +0000 (UTC) (envelope-from gmiller@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Wed, 01 Aug 2012 08:13:59 +0000 Date: Wed, 01 Aug 2012 08:13:59 +0000 From: gmiller@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20120801081359.4A3BE1065670@hub.freebsd.org> Cc: Subject: socsvn commit: r239982 - in soc2012/gmiller/locking-head: . lib/libwitness X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 01 Aug 2012 08:14:01 -0000 Author: gmiller Date: Wed Aug 1 08:13:59 2012 New Revision: 239982 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=239982 Log: r240027@FreeBSD-dev: root | 2012-07-24 11:56:51 -0500 Fix crashes and graph generation errors that produced infinite loops and more crashes. Modified: soc2012/gmiller/locking-head/ (props changed) soc2012/gmiller/locking-head/lib/libwitness/graph.c Modified: soc2012/gmiller/locking-head/lib/libwitness/graph.c ============================================================================== --- soc2012/gmiller/locking-head/lib/libwitness/graph.c Wed Aug 1 08:12:56 2012 (r239981) +++ soc2012/gmiller/locking-head/lib/libwitness/graph.c Wed Aug 1 08:13:59 2012 (r239982) @@ -34,6 +34,7 @@ scan_graph(struct lock_info *graph, struct lock_info *lock) { int ret; + struct lock_info *child; if (graph == NULL) { return (0); @@ -43,9 +44,11 @@ return (1); } - ret = scan_graph(graph->child, lock); - if (!ret) { - ret = scan_graph(graph->sibling, lock); + ret = 0; + child = graph->child; + while (ret == 0 && child != NULL) { + ret = scan_graph(child, lock); + child = child->sibling; } return (ret); @@ -74,28 +77,21 @@ child->sibling = from->child; from->child = child; } + + break; } + previous = child; child = next; } } -static void -optimize_links(struct lock_info *to) -{ - struct lock_info *from; - - SLIST_FOREACH(from, &graph_roots, root_next) { - if (scan_graph(from, to)) { - optimize_path(from, to); - } - } -} - int insert_lock(struct lock_info *from, struct lock_info *to) { struct lock_info *child; + struct lock_info *node; + struct lock_info *node_temp; if (from == to || from == NULL || to == NULL) { return (0); @@ -105,19 +101,29 @@ return (-1); } - SLIST_REMOVE(&graph_roots, from, lock_info, root_next); + if (SLIST_FIRST(&graph_roots) == to) { + SLIST_REMOVE_HEAD(&graph_roots, root_next); + } else { + SLIST_FOREACH_SAFE(node, &graph_roots, root_next, node_temp) { + if (SLIST_NEXT(node, root_next) == to) { + SLIST_REMOVE_AFTER(node, root_next); + } + } + } - to->sibling = from->child; - from->child = to; + if (to != from->child) { + to->sibling = from->child; + from->child = to; + } child = to->sibling; while (child != NULL) { - optimize_links(child); + optimize_path(from, child); child = child->sibling; } - optimize_links(to); + optimize_path(from, to); return (0); } From owner-svn-soc-all@FreeBSD.ORG Wed Aug 1 08:14:25 2012 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id 455BF106566C for ; Wed, 1 Aug 2012 08:14:23 +0000 (UTC) (envelope-from gmiller@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Wed, 01 Aug 2012 08:14:23 +0000 Date: Wed, 01 Aug 2012 08:14:23 +0000 From: gmiller@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20120801081423.455BF106566C@hub.freebsd.org> Cc: Subject: socsvn commit: r239983 - in soc2012/gmiller/locking-head: . tools/regression/lib/libwitness X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 01 Aug 2012 08:14:25 -0000 Author: gmiller Date: Wed Aug 1 08:14:22 2012 New Revision: 239983 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=239983 Log: r240028@FreeBSD-dev: root | 2012-07-24 12:09:57 -0500 Add additional tests to verify correct, optimal lock order graphs for the harder cases. Added: soc2012/gmiller/locking-head/tools/regression/lib/libwitness/graph.c soc2012/gmiller/locking-head/tools/regression/lib/libwitness/graph.t - copied unchanged from r239709, soc2012/gmiller/locking-head/tools/regression/lib/libwitness/setorder.t Modified: soc2012/gmiller/locking-head/ (props changed) soc2012/gmiller/locking-head/tools/regression/lib/libwitness/Makefile Modified: soc2012/gmiller/locking-head/tools/regression/lib/libwitness/Makefile ============================================================================== --- soc2012/gmiller/locking-head/tools/regression/lib/libwitness/Makefile Wed Aug 1 08:13:59 2012 (r239982) +++ soc2012/gmiller/locking-head/tools/regression/lib/libwitness/Makefile Wed Aug 1 08:14:22 2012 (r239983) @@ -1,7 +1,7 @@ # $FreeBSD$ -TESTS= lor-basic setorder bless setname -CFLAGS+= -g -Wall -Wextra -Werror -lwitness +TESTS= lor-basic setorder bless setname graph +CFLAGS+= -g -Wall -Wextra -Werror -lwitness -lpthread -static .PHONY: tests tests: ${TESTS} @@ -22,3 +22,6 @@ setname: setname.c check.c ${CC} -o setname setname.c check.c ${CFLAGS} + +graph: graph.c check.c + ${CC} -o graph graph.c check.c ${CFLAGS} Added: soc2012/gmiller/locking-head/tools/regression/lib/libwitness/graph.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2012/gmiller/locking-head/tools/regression/lib/libwitness/graph.c Wed Aug 1 08:14:22 2012 (r239983) @@ -0,0 +1,118 @@ +/*- + * Copyright (c) 2012 Greg Miller .. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ + +#include +#include +#include + +#include "check.h" + +void +check_graph(pthread_mutex_t *lock_buffer, int lock_count) +{ + struct pthread_lockorder_np order; + int i; + + pthread_lockorder_begin_np(&order); + while (pthread_lockorder_next_np(&order)) { + i = (pthread_mutex_t *)order.lock - lock_buffer; + if (i >= 0 && i < lock_count) { + check((i < (lock_count - 1) && + (lock_buffer + i + 1) == order.child) || + (i == (lock_count - 1) && order.child == NULL)); + } + } + pthread_lockorder_end_np(&order); +} + +void +cycle_locks(pthread_mutex_t *lock_buffer, int *lock_set, int lock_set_size) +{ + int i = 0; + + while (i < lock_set_size) { + pthread_mutex_lock(&lock_buffer[lock_set[i++]]); + } + + while (--i >= 0) { + pthread_mutex_unlock(&lock_buffer[lock_set[i]]); + } +} + +void +graph_test(pthread_mutex_t *lock_buffer, int lock_count, int *lock_set, + int lock_set_size, int depth) +{ + if (depth == lock_count) { + cycle_locks(lock_buffer, lock_set, lock_set_size); + } else { + graph_test(lock_buffer, lock_count, lock_set, lock_set_size, + depth + 1); + + lock_set[lock_set_size++] = depth; + + graph_test(lock_buffer, lock_count, lock_set, lock_set_size, + depth + 1); + } +} + +void +all_tests(int lock_count) +{ + int i; + pthread_mutex_t *lock_buffer; + int *lock_set; + + pthread_lockorder_reset_np(); + + lock_buffer = malloc(sizeof(pthread_mutex_t) * lock_count); + lock_set = malloc(sizeof(int) * lock_count); + + for (i = 0; i < lock_count; i++) { + pthread_mutex_init(&lock_buffer[i], NULL); + } + + graph_test(lock_buffer, lock_count, lock_set, 0, 0); + check_graph(lock_buffer, lock_count); + + for (i = 0; i < lock_count; i++) { + pthread_mutex_destroy(&lock_buffer[i]); + } + + free(lock_set); + free(lock_buffer); +} + +int +main(void) +{ + all_tests(5); + + show_test_results(); + + return (0); +} Copied: soc2012/gmiller/locking-head/tools/regression/lib/libwitness/graph.t (from r239709, soc2012/gmiller/locking-head/tools/regression/lib/libwitness/setorder.t) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2012/gmiller/locking-head/tools/regression/lib/libwitness/graph.t Wed Aug 1 08:14:22 2012 (r239983, copy of r239709, soc2012/gmiller/locking-head/tools/regression/lib/libwitness/setorder.t) @@ -0,0 +1,10 @@ +#!/bin/sh +# $FreeBSD$ + +cd `dirname $0` + +executable=`basename $0 .t` + +make $executable 2>&1 > /dev/null + +exec ./$executable From owner-svn-soc-all@FreeBSD.ORG Wed Aug 1 08:14:49 2012 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id D05D11065672 for ; Wed, 1 Aug 2012 08:14:47 +0000 (UTC) (envelope-from gmiller@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Wed, 01 Aug 2012 08:14:47 +0000 Date: Wed, 01 Aug 2012 08:14:47 +0000 From: gmiller@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20120801081447.D05D11065672@hub.freebsd.org> Cc: Subject: socsvn commit: r239984 - in soc2012/gmiller/locking-head: . tools/regression/lib/libwitness X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 01 Aug 2012 08:14:50 -0000 Author: gmiller Date: Wed Aug 1 08:14:47 2012 New Revision: 239984 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=239984 Log: r240029@FreeBSD-dev: root | 2012-07-24 12:12:10 -0500 Add sibling checks to the graph.t tests. Modified: soc2012/gmiller/locking-head/ (props changed) soc2012/gmiller/locking-head/tools/regression/lib/libwitness/graph.c Modified: soc2012/gmiller/locking-head/tools/regression/lib/libwitness/graph.c ============================================================================== --- soc2012/gmiller/locking-head/tools/regression/lib/libwitness/graph.c Wed Aug 1 08:14:22 2012 (r239983) +++ soc2012/gmiller/locking-head/tools/regression/lib/libwitness/graph.c Wed Aug 1 08:14:47 2012 (r239984) @@ -44,6 +44,7 @@ check((i < (lock_count - 1) && (lock_buffer + i + 1) == order.child) || (i == (lock_count - 1) && order.child == NULL)); + check(order.sibling == NULL); } } pthread_lockorder_end_np(&order); From owner-svn-soc-all@FreeBSD.ORG Wed Aug 1 08:15:14 2012 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id 1E64A106566C for ; Wed, 1 Aug 2012 08:15:12 +0000 (UTC) (envelope-from gmiller@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Wed, 01 Aug 2012 08:15:12 +0000 Date: Wed, 01 Aug 2012 08:15:12 +0000 From: gmiller@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20120801081512.1E64A106566C@hub.freebsd.org> Cc: Subject: socsvn commit: r239985 - in soc2012/gmiller/locking-head: . lib/libwitness X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 01 Aug 2012 08:15:14 -0000 Author: gmiller Date: Wed Aug 1 08:15:11 2012 New Revision: 239985 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=239985 Log: r240030@FreeBSD-dev: root | 2012-07-24 12:16:39 -0500 Remove graph root code that's no longer needed. Modified: soc2012/gmiller/locking-head/ (props changed) soc2012/gmiller/locking-head/lib/libwitness/graph.c soc2012/gmiller/locking-head/lib/libwitness/lockinfo.c soc2012/gmiller/locking-head/lib/libwitness/witness.h soc2012/gmiller/locking-head/lib/libwitness/wrappers.c Modified: soc2012/gmiller/locking-head/lib/libwitness/graph.c ============================================================================== --- soc2012/gmiller/locking-head/lib/libwitness/graph.c Wed Aug 1 08:14:47 2012 (r239984) +++ soc2012/gmiller/locking-head/lib/libwitness/graph.c Wed Aug 1 08:15:11 2012 (r239985) @@ -27,9 +27,6 @@ #include "witness.h" -static SLIST_HEAD(graph_root_head, lock_info) graph_roots = - SLIST_HEAD_INITIALIZER(graph_roots); - static int scan_graph(struct lock_info *graph, struct lock_info *lock) { @@ -90,8 +87,6 @@ insert_lock(struct lock_info *from, struct lock_info *to) { struct lock_info *child; - struct lock_info *node; - struct lock_info *node_temp; if (from == to || from == NULL || to == NULL) { return (0); @@ -101,16 +96,6 @@ return (-1); } - if (SLIST_FIRST(&graph_roots) == to) { - SLIST_REMOVE_HEAD(&graph_roots, root_next); - } else { - SLIST_FOREACH_SAFE(node, &graph_roots, root_next, node_temp) { - if (SLIST_NEXT(node, root_next) == to) { - SLIST_REMOVE_AFTER(node, root_next); - } - } - } - if (to != from->child) { to->sibling = from->child; from->child = to; @@ -127,15 +112,3 @@ return (0); } - -void -add_root(struct lock_info *root) -{ - SLIST_INSERT_HEAD(&graph_roots, root, root_next); -} - -void -reset_graph(void) -{ - SLIST_INIT(&graph_roots); -} Modified: soc2012/gmiller/locking-head/lib/libwitness/lockinfo.c ============================================================================== --- soc2012/gmiller/locking-head/lib/libwitness/lockinfo.c Wed Aug 1 08:14:47 2012 (r239984) +++ soc2012/gmiller/locking-head/lib/libwitness/lockinfo.c Wed Aug 1 08:15:11 2012 (r239985) @@ -58,7 +58,6 @@ SLIST_INIT(&info->bless_head); SLIST_INSERT_HEAD(&lock_info_head, info, lock_info_next); - add_root(info); } } Modified: soc2012/gmiller/locking-head/lib/libwitness/witness.h ============================================================================== --- soc2012/gmiller/locking-head/lib/libwitness/witness.h Wed Aug 1 08:14:47 2012 (r239984) +++ soc2012/gmiller/locking-head/lib/libwitness/witness.h Wed Aug 1 08:15:11 2012 (r239985) @@ -52,12 +52,10 @@ extern pthread_mutex_t witness_mtx; -void add_root(struct lock_info *root); void add_lock(struct lock_info *lock); void remove_lock(struct lock_info *lock); int insert_lock(struct lock_info *new_lock, struct lock_info *previous); -void reset_graph(void); void reset_lists(void); Modified: soc2012/gmiller/locking-head/lib/libwitness/wrappers.c ============================================================================== --- soc2012/gmiller/locking-head/lib/libwitness/wrappers.c Wed Aug 1 08:14:47 2012 (r239984) +++ soc2012/gmiller/locking-head/lib/libwitness/wrappers.c Wed Aug 1 08:15:11 2012 (r239985) @@ -445,7 +445,6 @@ _pthread_mutex_lock(&witness_mtx); reset_lists(); - reset_graph(); reset_lock_info(); _pthread_mutex_unlock(&witness_mtx); From owner-svn-soc-all@FreeBSD.ORG Wed Aug 1 19:41:26 2012 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id 8DDB5106566C for ; Wed, 1 Aug 2012 19:41:25 +0000 (UTC) (envelope-from jhagewood@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Wed, 01 Aug 2012 19:41:25 +0000 Date: Wed, 01 Aug 2012 19:41:25 +0000 From: jhagewood@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20120801194125.8DDB5106566C@hub.freebsd.org> Cc: Subject: socsvn commit: r239998 - soc2012/jhagewood/sdiff X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 01 Aug 2012 19:41:26 -0000 Author: jhagewood Date: Wed Aug 1 19:41:24 2012 New Revision: 239998 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=239998 Log: sdiff benchmarks Added: soc2012/jhagewood/sdiff/benchmarks Added: soc2012/jhagewood/sdiff/benchmarks ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2012/jhagewood/sdiff/benchmarks Wed Aug 1 19:41:24 2012 (r239998) @@ -0,0 +1,10 @@ +Command - sdiff 1.txt 2.txt +________________________________ + +-- GNU sdiff -- + +Minor pagefaults - 181 + +-- BSD sdiff -- + +Minor pagefaults - 232 From owner-svn-soc-all@FreeBSD.ORG Wed Aug 1 21:32:55 2012 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id 4B31A106566B for ; Wed, 1 Aug 2012 21:32:53 +0000 (UTC) (envelope-from tzabal@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Wed, 01 Aug 2012 21:32:53 +0000 Date: Wed, 01 Aug 2012 21:32:53 +0000 From: tzabal@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20120801213253.4B31A106566B@hub.freebsd.org> Cc: Subject: socsvn commit: r240000 - soc2012/tzabal/server-side/akcrs-release/9.0.0/usr.sbin/crashreportd X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 01 Aug 2012 21:32:55 -0000 Author: tzabal Date: Wed Aug 1 21:32:52 2012 New Revision: 240000 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=240000 Log: The phases receive-check-store are complete. A basic testing and debugging has occured for these phases. A clean up of the code will take place in the near future. Modified: soc2012/tzabal/server-side/akcrs-release/9.0.0/usr.sbin/crashreportd/crashreportd.py Modified: soc2012/tzabal/server-side/akcrs-release/9.0.0/usr.sbin/crashreportd/crashreportd.py ============================================================================== --- soc2012/tzabal/server-side/akcrs-release/9.0.0/usr.sbin/crashreportd/crashreportd.py Wed Aug 1 19:27:12 2012 (r239999) +++ soc2012/tzabal/server-side/akcrs-release/9.0.0/usr.sbin/crashreportd/crashreportd.py Wed Aug 1 21:32:52 2012 (r240000) @@ -1,123 +1,385 @@ #!/usr/local/bin/python -tt +"""This module is the software that implements the server side part of the +Automated Kernel Crash Reporting System. +""" +import argparse +import hashlib +import logging import os +import random import re +import smtplib +import string +from StringIO import StringIO import time import tarfile -import argparse -import logging +from lxml import etree +import psycopg2 +from email.mime.text import MIMEText # Module Variables _interval_time = 10 _pid_file = '/var/run/crashreportd.pid' _crashreports_dir = '/var/spool/crashreports' -_logging_file = '' +_auxiliary_dir = '/tmp/crashreports' +_logging_file = '/home/tzabal/crashreportd.log' +_conn = '' +_curs = '' -def valid_report_name(report): - """Checks if the filename matches the pattern of a valid crash report name.""" - filename = os.path.basename(report) - match_obj = re.match('^crashreport\.[A-Za-z0-9]{6}\.tar\.gz$', filename) +class CrashReport(object): + """This class represents a crash report.""" - if not match_obj: - logging.info('Invalid crash report name: %s' % filename) - return + valid_name = re.compile('^crashreport\.[A-Za-z0-9]{6}\.tar\.gz$') - return True + + def __init__(self, path): + name = os.path.basename(path) + + self.path = path + self.name = name + self.data = CrashData(name) + + + def has_valid_name(self): + """Returns True is the report's name matches the name of a valid crash + report. Otherwise it returns implicit False.""" + match = re.match(self.__class__.valid_name, self.name) + + if not match: + return + + return True + + + def has_valid_type(self): + """Returns True if the report's file type matches the file type of a + valid crash report. Otherwise it returns implicit False.""" + if not tarfile.is_tarfile(self.path): + return + + try: + tarfileobj = tarfile.open(self.path, 'r:gz') + except tarfile.ReadError: + return + except tarfile.CompressionError: + return + finally: + tarfileobj.close() + + return True + + + def has_valid_contents_number(self): + """Returns True is the report contains the same number of files that a + valid crash report has. Othewise it returns implicit False.""" + try: + tarfileobj = tarfile.open(self.path, 'r:gz') + except tarfile.ReadError: + return + except tarfile.CompressionError: + return + else: + contents_list = tarfileobj.getnames() + if not len(contents_list) == 1: + return + finally: + tarfileobj.close() + + return True + + +class CrashData(object): + """This class represents the crash data that a crash report contains.""" + + valid_name = re.compile('^crashreport\.[A-Za-z0-9]{6}\.xml$') + + + def __init__(self, reportname): + name = re.sub('tar.gz', 'xml', reportname) + + self.path = _auxiliary_dir + '/' + name + self.name = name + self.info = {} + self.commands = {} + + + def has_valid_name(self): + """Returns True if the report's crash data name matches the name of a + valid crash data. Otherwise it returns implicit False.""" + if not os.path.isfile(self.path): + return + + self.name = os.path.basename(self.path) + + match = re.match(self.__class__.valid_name, self.name) + + if not match: + return + + return True + + def has_valid_crashdata(self): + """Returns True if the crash data is a well formed and valid XML file. + Otherwise implicit False.""" + dtdfile = StringIO(""" + + + + + + """) + + try: + elemtree = etree.parse(self.path) + except: + logging.info('%s is not a well formed crash report data.' % + (self.path)) + return + else: + dtd = etree.DTD(dtdfile) + if not dtd.validate(elemtree): + logging.info('%s is not a valid crash report data.' % + (self.path)) + return + + return True -def valid_report_type(report): - """Check if the report's file type matches the file type of a valid crash report.""" - if not tarfile.is_tarfile(report): - logging.info('Report %s is not a tar file.' % report) - return + +def send_confirmation_email(report): + sender = 'Automated Kernel Crash Reporting System ' + #receiver = report.data.info['email'] + receiver = 'invalid@it.teithe.gr' + subject = 'Kernel Crash Report Confirmation' + text = 'Confirm your kernel crash report by clicking here.' + smtpserver = 'smtp.hol.gr' + + message = MIMEText(text) + message['From'] = sender + message['To'] = receiver + message['Subject'] = subject + + #print message try: - tarfile_obj = tarfile.open(report, 'r:gz') - except ReadError: - logging.info('ReadError exception.') - return - except CompressionError: - logging.info('CompressionError exception') + smtpconn = smtplib.SMTP(smtpserver) + smtpconn.sendmail(sender, receiver, message.as_string()) + except smtplib.SMTPException, err: + logging.info(err) return finally: - tarfile_obj.close() + smtpconn.quit() + + return True + + +def parse_crashdata(report): + """Parses the crash data XML file of the given report and store the data in + variable instances of the report.""" + validnames = ['crashtype', 'crashdate', 'hostname', 'ostype', 'osrelease', + 'version', 'machine', 'panic', 'backtrace', 'ps_axl', + 'vmstat_s', 'vmstat_m', 'vmstat_z', 'vmstat_i', 'pstat_T', + 'pstat_s', 'iostat', 'ipcs_a', 'ipcs_T', 'nfsstat', + 'netstat_s', 'netstat_m', 'netstat_id', 'netstat_anr', + 'netstat_anA', 'netstat_aL', 'fstat', 'dmesg', 'kernelconfig', + 'ddbcapturebuffer'] + + elemtree = etree.parse(report.data.path) + root = elemtree.getroot() + + report.data.info['email'] = re.sub(r'\s', '', root[0][0].text) + + for elem in elemtree.iter(): + if elem.tag == 'command': + children = list(elem) + #print 'children[0].text: %s' % (children[0].text) + name = re.sub(r'\s', '', children[0].text) + result = children[1].text + if name in validnames: + #print 'name: %s' % (name) + report.data.commands[name] = result return True -def valid_contents_number(report): - """Checks if the report contains the same number of files as a valid report.""" +def generate_password(): + """Generates and returns a random password. + + Password is 8 characters in length and it may contain digits, lowercase and + uppercase letters. + """ + size = 8 + chars = string.letters + string.digits + return ''.join(random.choice(chars) for ch in range(size)) + + +def store_report(report): + query = """SELECT id FROM Submitters WHERE email = %s""" + values = (report.data.info['email'], ) + try: - tarfile_obj = tarfile.open(report, 'r:gz') - except ReadError: - logging.info('ReadError exception.') - return - except CompressionError: - logging.info('CompressionError exception') - return + _curs.execute(query, values) + except Exception, err: + logging.info(err) + + if _curs.rowcount: + submitter_id = _curs.fetchone() + print 'Submitter_id: %s' % (submitter_id) else: - contents_list = tarfile_obj.getnames() - if not len(contents_list) == 1: - logging.info('Invalid number of files inside the crash report.') - return - finally: - tarfile_obj.close() + password = generate_password() + print 'password: %s' % (password) + hashobj = hashlib.sha256() + hashobj.update(password) + hashpass = hashobj.hexdigest() + + query = """INSERT INTO Submitters (email, password) + VALUES (%s, %s) RETURNING id;""" + values = (report.data.info['email'], hashpass) + + try: + _curs.execute(query, values) + except Exception, err: + logging.info(err) + else: + submitter_id = _curs.fetchone() + _conn.commit() + + # -1 declares that the report has not analyzed yet for similarities + # with previously logged reports + bug_id = -1 + + query = """INSERT INTO Reports (bug_id, submitter_id, crashtype, crashdate, + hostname, ostype, osrelease, version, machine, panic, backtrace, ps_axl, + vmstat_s, vmstat_m, vmstat_z, vmstat_i, pstat_T, pstat_s, iostat, ipcs_a, + ipcs_T, nfsstat, netstat_s, netstat_m, netstat_id, netstat_anr, + netstat_anA, netstat_aL, fstat, dmesg, kernelconfig, ddbcapturebuffer) + VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, + %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)""" + + values = (bug_id, + submitter_id, + report.data.commands['crashtype'], + report.data.commands['crashdate'], + report.data.commands['hostname'], + report.data.commands['ostype'], + report.data.commands['osrelease'], + report.data.commands['version'], + report.data.commands['machine'], + report.data.commands['panic'], + report.data.commands['backtrace'], + report.data.commands['ps_axl'], + report.data.commands['vmstat_s'], + report.data.commands['vmstat_m'], + report.data.commands['vmstat_z'], + report.data.commands['vmstat_i'], + report.data.commands['pstat_T'], + report.data.commands['pstat_s'], + report.data.commands['iostat'], + report.data.commands['ipcs_a'], + report.data.commands['ipcs_T'], + report.data.commands['nfsstat'], + report.data.commands['netstat_s'], + report.data.commands['netstat_m'], + report.data.commands['netstat_id'], + report.data.commands['netstat_anr'], + report.data.commands['netstat_anA'], + report.data.commands['netstat_aL'], + report.data.commands['fstat'], + report.data.commands['dmesg'], + report.data.commands['kernelconfig'], + report.data.commands['ddbcapturebuffer']) + + try: + _curs.execute(query, values) + except Exception, err: + logging.info(err) + logging.info('Query failed.') + else: + _conn.commit() return True -def valid_data_name(report): - """Checks if the filename matches the pattern of a valid crash data name.""" +def extract_report(report): + """Extracts the given report to the auxiliary directory.""" + if not os.path.isdir(_auxiliary_dir): + logging.info('Auxiliary directory does not exist') + return + try: - tarfile_obj = tarfile.open(report, 'r:gz') - except ReadError: - logging.info('ReadError exception.') + tarfileobj = tarfile.open(report, 'r:gz') + tarfileobj.extractall(_auxiliary_dir) + except tarfile.ReadError: return - except CompressionError: - logging.info('CompressionError exception') + except tarfile.CompressionError: return - else: - contents_list = tarfile_obj.getnames() - match_obj = re.match('^crashreport\.[A-Za-z0-9]{6}\.xml$', contents_list[0]) finally: - tarfile_obj.close() - - if not match_obj: - logging.info('Invalid crash data name: %s' % contents_list[0]) - return + tarfileobj.close() return True def discard_report(report): - """Discard a crash report from the system.""" - os.remove(report) + """Discards a crash report from the system.""" + os.remove(report.path) def check_report(report): - """Container function that calls all the functions related to validity.""" - if not valid_report_name(report): - discard_report(report) + """Checks a crash report for validity and security. + + It is a function that calls all the methods provided by the CrashReport and + the CrashData objects that are related with the validity of a report. The + methods are called with a stict order because some methods assign values + to the instance variables of the given object and some other methods depend + on them. This is done in order to avoid execution of the same code multiple + times and distinguish the checks easily. + """ + if not report.has_valid_name(): + logging.info('Invalid crash report name: %s' % report.path) return - if not valid_report_type(report): - discard_report(report) + if not report.has_valid_type(): + logging.info('Invalid crash report type: %s' % report.path) return - if not valid_contents_number(report): - discard_report(report) + if not report.has_valid_contents_number(): + logging.info('Invalid number of contents in crash report %s' % + report.path) return - if not valid_data_name(report): - discard_report(report) + if not extract_report(report.path): + logging.info('Error occured while extract the report %s' % report.path) + return + + if not report.data.has_valid_name(): + logging.info('Invalid crash data name: %s' % report.data.path) + return + + if not report.data.has_valid_crashdata(): + logging.info('Invalid crash data XML file: %s' % report.data.path) + return + + if not parse_crashdata(report): return return True +def connect_database(): + global _conn, _curs + + try: + _conn = psycopg2.connect(database='akcrsdb', user='akcrs', password='freebsd') + except: + logging.error('Could not connect to the database') + else: + _curs = _conn.cursor() + + def create_pid_file(): """Creates the Process ID file that contains the PID of crashreportd. @@ -125,29 +387,50 @@ """ pid = os.getpid() try: - file_obj = open(_pid_file, 'w') - file_obj.write(str(pid)) - file_obj.close() + pidfile = open(_pid_file, 'w') + pidfile.write(str(pid)) + pidfile.close() except IOError: return finally: - file_obj.close() + pidfile.close() return True +def log(): + """Turns on or off the logging facility.""" + global _logging_file + if _logging_file: + logging.basicConfig(level=logging.DEBUG, filename=_logging_file, + format='%(asctime)s in %(funcName)s() at ' + '%(lineno)s %(levelname)s: %(message)s', + datefmt='%Y-%m-%d %H:%M:%S') + + def parse_arguments(): - """Parse the command line arguments provided.""" + """Parses the command line arguments.""" parser = argparse.ArgumentParser() - parser.add_argument('-d', help='the directory where crash reports arrive in the system', dest='crashreports_dir') - parser.add_argument('-p', help='the file that stores the process id of crashreportd', dest='pid_file') - parser.add_argument('-t', type=int, help='the minimum delay between two checks of the crash reports directory', dest='interval_time') - parser.add_argument('-l', help='the file that various log messages will be stored (enables logging)', dest='logging_file') + parser.add_argument('-d', help='the directory where crash reports arrive ' + 'in the system', dest='crashreports_dir') + parser.add_argument('-a', help='an auxiliary directory used for various ' + 'actions', dest='auxiliary_dir') + parser.add_argument('-p', help='the file that stores the process id of ' + 'this program', dest='pid_file') + parser.add_argument('-t', type=int, help='the minimum delay between two ' + 'checks of the crash reports directory', + dest='interval_time') + parser.add_argument('-l', help='the file that various log messages will be ' + 'stored (implicitly enables logging)', + dest='logging_file') args = parser.parse_args() if args.crashreports_dir: global _crashreports_dir _crashreports_dir = args.crashreports_dir + if args.auxiliary_dir: + global _auxiliary_dir + _auxiliary_dir = args.auxiliary_dir if args.pid_file: global _pid_file _pid_file = args.pid_file @@ -159,57 +442,28 @@ _logging_file = args.logging_file -def log(): - """Turns on or off the logging facility.""" - global _logging_file - if _logging_file: - logging.basicConfig(level=logging.DEBUG, filename=_logging_file, - format='%(asctime)s %(funcName)s() %(levelname)s: %(message)s', - datefmt='%Y-%m-%d %H:%M:%S') - - def main(): - """The infinite loop of the daemon. - - It is the starting point of the program when it is invoked directly. Here - lives the infinite loop that checks the directory that crash reports arrive - in the server. For every new crash report, a number of actions are executed. - """ parse_arguments() log() create_pid_file() + connect_database() + logging.info('========================') while True: dirlist = os.listdir(_crashreports_dir) for filename in dirlist: - report = _crashreports_dir + '/' + filename - check_report(report) - time.sleep(_interval_time) + path = _crashreports_dir + '/' + filename + report = CrashReport(path) + if not check_report(report): + print 'Failed in check report' + #discard_report(report) + continue + if not store_report(report): + print 'Failed in store report' + if not send_confirmation_email(report): + print 'Failed in sending confirmation email' + #time.sleep(_interval_time) + break if __name__ == '__main__': main() - -#def extract_report(filename): -# if not os.path.isdir(extraction_dir): -# logging.debug() -# return False -# -# try: -# tarfile_obj = tarfile.open(report, 'r:gz') -# tarfile_obj.extractall(extraction_dir); -# except ReadError: -# logging.debug() -# return -# except CompressionError: -# logging.debug() -# return -# -# dirlist = os.listdir(extraction_dir) -# if not len(dirlist) == 1: -# logging.debug() -# return False -# -# data_name = dirlist[0] -# #print "data_name: ", data_name -# -# return True \ No newline at end of file From owner-svn-soc-all@FreeBSD.ORG Wed Aug 1 21:47:55 2012 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id D6109106564A for ; Wed, 1 Aug 2012 21:47:52 +0000 (UTC) (envelope-from tzabal@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Wed, 01 Aug 2012 21:47:52 +0000 Date: Wed, 01 Aug 2012 21:47:52 +0000 From: tzabal@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20120801214752.D6109106564A@hub.freebsd.org> Cc: Subject: socsvn commit: r240001 - soc2012/tzabal/server-side/akcrs-setup X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 01 Aug 2012 21:47:55 -0000 Author: tzabal Date: Wed Aug 1 21:47:52 2012 New Revision: 240001 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=240001 Log: Changes to the database schema and the installation guide. Modified: soc2012/tzabal/server-side/akcrs-setup/database.sql soc2012/tzabal/server-side/akcrs-setup/setup Modified: soc2012/tzabal/server-side/akcrs-setup/database.sql ============================================================================== --- soc2012/tzabal/server-side/akcrs-setup/database.sql Wed Aug 1 21:32:52 2012 (r240000) +++ soc2012/tzabal/server-side/akcrs-setup/database.sql Wed Aug 1 21:47:52 2012 (r240001) @@ -3,44 +3,47 @@ * for the PostgreSQL DBMS */ ---DROP TABLE Submitters; ---DROP TABLE Bugs; ---DROP TABLE Reports; +DROP TABLE Reports; +DROP TABLE Bugs; +DROP TABLE Submitters; CREATE TABLE Submitters ( - id SERIAL, + id serial NOT NULL, email varchar(254) NOT NULL, - passwd varchar(12) NOT NULL, + password varchar(64) NOT NULL, - PRIMARY KEY (id) + CONSTRAINT submitters_pkey PRIMARY KEY (id) ); CREATE TABLE Bugs ( - id SERIAL, + id serial NOT NULL, state varchar(10) NOT NULL, reported integer NOT NULL, - PRIMARY KEY (id) + CONSTRAINT bugs_pkey PRIMARY KEY (id) ); CREATE TABLE Reports ( - id SERIAL, + id serial NOT NULL, bug_id integer NOT NULL, submitter_id integer NOT NULL, received_date date DEFAULT CURRENT_DATE, - crash_type text, - crash_date date, + confirmed boolean DEFAULT false, + crashtype text, + crashdate text, hostname text, ostype text, osrelease text, version text, machine text, + panic text, + backtrace text, ps_axl text, vmstat_s text, vmstat_m text, @@ -63,7 +66,9 @@ kernelconfig text, ddbcapturebuffer text, - PRIMARY KEY (id), - FOREIGN KEY (bug_id) REFERENCES Bugs(id), - FOREIGN KEY (submitter_id) REFERENCES Reports(id) + CONSTRAINT reports_pkey PRIMARY KEY (id), + CONSTRAINT reports_bug_id_fkey FOREIGN KEY (bug_id) REFERENCES Bugs (id), + CONSTRAINT reports_submitter_id_fkey FOREIGN KEY (submitter_id) REFERENCES Submitters (id) ); + +INSERT INTO Bugs (id, state, reported) VALUES (-1, 'Unknown', 0); Modified: soc2012/tzabal/server-side/akcrs-setup/setup ============================================================================== --- soc2012/tzabal/server-side/akcrs-setup/setup Wed Aug 1 21:32:52 2012 (r240000) +++ soc2012/tzabal/server-side/akcrs-setup/setup Wed Aug 1 21:47:52 2012 (r240001) @@ -26,6 +26,9 @@ # Give ownership of the directory to reporter chown reporter:reporter /var/spool/crashreports +# Create an auxiliary directory used for various actions +mkdir /tmp/crashreports + # Make sure that the OpenSSH daemon is enabled cat /etc/rc.conf | grep 'sshd_enable="YES"' @@ -84,14 +87,23 @@ # Start the database server /usr/local/etc/rc.d/postgresql start -# Swith to the (system) user that owns the PostgreSQL Server (or remain as root) +# Swith to the (system) user that owns the PostgreSQL Server (or stay as root) su pgsql # Create a new PostgreSQL user (role) that will NOT be superuser, create databases and create roles createuser -P akcrs # Create a Unicode database that our PostgreSQL user will has access to -/usr/local/bin/createdb akcrs_db -O akcrs --encoding=UNICODE +/usr/local/bin/createdb akcrsdb -O akcrs --encoding=UNICODE + +# Using psql connect to the database as the user that owns it +psql -d akcrsdb -U akcrs + +# Execute the SQL script that creates the database schema +\i /home/tzabal/akcrs/server-side/akcrs-setup/database.sql + +# Exit psql +\q ########################################################### From owner-svn-soc-all@FreeBSD.ORG Thu Aug 2 01:21:01 2012 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id F0AEE106564A for ; Thu, 2 Aug 2012 01:20:58 +0000 (UTC) (envelope-from exxo@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Thu, 02 Aug 2012 01:20:58 +0000 Date: Thu, 02 Aug 2012 01:20:58 +0000 From: exxo@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20120802012058.F0AEE106564A@hub.freebsd.org> Cc: Subject: socsvn commit: r240004 - in soc2012/exxo/freebsd-head: include/rpcsvc usr.bin/ypwhich usr.sbin/ypbind X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 02 Aug 2012 01:21:01 -0000 Author: exxo Date: Thu Aug 2 01:20:58 2012 New Revision: 240004 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=240004 Log: ypbind/ypwhich updated, adding yp_utils Added: soc2012/exxo/freebsd-head/include/rpcsvc/yp_utils.h Modified: soc2012/exxo/freebsd-head/include/rpcsvc/yp.x soc2012/exxo/freebsd-head/include/rpcsvc/yp_prot.h soc2012/exxo/freebsd-head/usr.bin/ypwhich/Makefile soc2012/exxo/freebsd-head/usr.bin/ypwhich/ypwhich.c soc2012/exxo/freebsd-head/usr.sbin/ypbind/Makefile soc2012/exxo/freebsd-head/usr.sbin/ypbind/yp_ping.c soc2012/exxo/freebsd-head/usr.sbin/ypbind/yp_ping.h soc2012/exxo/freebsd-head/usr.sbin/ypbind/ypbind.c Modified: soc2012/exxo/freebsd-head/include/rpcsvc/yp.x ============================================================================== --- soc2012/exxo/freebsd-head/include/rpcsvc/yp.x Thu Aug 2 00:00:34 2012 (r240003) +++ soc2012/exxo/freebsd-head/include/rpcsvc/yp.x Thu Aug 2 01:20:58 2012 (r240004) @@ -223,8 +223,6 @@ ypbind_binding ypsetdom_binding; unsigned ypsetdom_vers; }; -%#define ypsetdom_addr ypsetdom_binding.ypbind_binding_addr -%#define ypsetdom_port ypsetdom_binding.ypbind_binding_port /* Backward compatibility for YPBIND protocol version 2 */ #ifdef YPBIND_COMPAT_V2 @@ -249,17 +247,8 @@ unsigned ypsetdom_vers; }; -%#define yprespv2_error ypbind_resp_v2_u.ypbind_error -%#define yprespv2_addr ypbind_resp_v2_u.ypbind_bindinfo.ypbind_binding_addr -%#define yprespv2_port ypbind_resp_v2_u.ypbind_bindinfo.ypbind_binding_port - #endif -%#define ypresp_error ypbind_resp_u.ypbind_error -%#define ypresp_family ypbind_resp_u.ypbind_bindinfo.ypbind_binding_family -%#define ypresp_addr ypbind_resp_u.ypbind_bindinfo.ypbind_binding_addr -%#define ypresp_port ypbind_resp_u.ypbind_bindinfo.ypbind_binding_port - /* * NIS v1 support for backwards compatibility */ Modified: soc2012/exxo/freebsd-head/include/rpcsvc/yp_prot.h ============================================================================== --- soc2012/exxo/freebsd-head/include/rpcsvc/yp_prot.h Thu Aug 2 00:00:34 2012 (r240003) +++ soc2012/exxo/freebsd-head/include/rpcsvc/yp_prot.h Thu Aug 2 01:20:58 2012 (r240004) @@ -296,17 +296,8 @@ u_int ypsetdom_vers; }; -#define yprespv2_error ypbind_resp_v2_u.ypbind_error -#define yprespv2_addr ypbind_resp_v2_u.ypbind_bindinfo.ypbind_binding_addr -#define yprespv2_port ypbind_resp_v2_u.ypbind_bindinfo.ypbind_binding_port - #endif -#define ypresp_error ypbind_resp_u.ypbind_error -#define ypresp_family ypbind_resp_u.ypbind_bindinfo.ypbind_binding_family -#define ypresp_addr ypbind_resp_u.ypbind_bindinfo.ypbind_binding_addr -#define ypresp_port ypbind_resp_u.ypbind_bindinfo.ypbind_binding_port - /* * YPPUSH PROTOCOL: * Added: soc2012/exxo/freebsd-head/include/rpcsvc/yp_utils.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2012/exxo/freebsd-head/include/rpcsvc/yp_utils.h Thu Aug 2 01:20:58 2012 (r240004) @@ -0,0 +1,109 @@ +/* + * Copyright (c) TODO + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD: soc2012/exxo/freebsd-head/include/rpcsvc/yp_prot.h 239957 2012-07-31 16:20:04Z exxo $ + */ + +#ifndef _RPCSVC_YP_UTILS_H_ +#define _RPCSVC_YP_UTILS_H_ + +/* YPBIND facilities + * + * This file should be included after or + * It provides facilities to deal with YPBIND protocols + */ + +#define ypresp_status ypbind_status +#define ypsetdom_family ypsetdom_binding.ypbind_binding_family + +#ifdef _RPCSVC_YP_PROT_H_ /* if used with yp_prot.h */ + +# define ypresp_family ypbind_respbody.ypbind_bindinfo.ypbind_binding_family +# define ypresp_error ypbind_respbody.ypbind_error +# define ypresp_addr ypbind_respbody.ypbind_bindinfo.ypbind_binding_addr +# define ypresp_port ypbind_respbody.ypbind_bindinfo.ypbind_binding_port + +#elif defined(_YP_H_RPCGEN) /* if used with yp.h */ + +# define ypsetdom_addr ypsetdom_binding.ypbind_binding_addr +# define ypsetdom_port ypsetdom_binding.ypbind_binding_port + +# define ypresp_family ypbind_resp_u.ypbind_bindinfo.ypbind_binding_family +# define ypresp_error ypbind_resp_u.ypbind_error +# define ypresp_addr ypbind_resp_u.ypbind_bindinfo.ypbind_binding_addr +# define ypresp_port ypbind_resp_u.ypbind_bindinfo.ypbind_binding_port +# define ypresp_error_v2 ypbind_resp_v2_u.ypbind_error +# define ypresp_addr_v2 ypbind_resp_v2_u.ypbind_bindinfo.ypbind_binding_addr +# define ypresp_port_v2 ypbind_resp_v2_u.ypbind_bindinfo.ypbind_binding_port + +#endif + +union ypbf_resp { + struct { + enum ypbind_resptype status; + u_int error; + } header; + struct ypbind_resp resp; +#ifdef YPBIND_COMPAT_V2 + struct ypbind_resp_v2 resp2; +#endif +}; +#define ypbf_rstatus header.status +#define ypbf_rerror header.error +#define ypbf_rfamily resp.ypresp_family +#define ypbf_raddr resp.ypresp_addr +#define ypbf_rport resp.ypresp_port +#ifdef YPBIND_COMPAT_V2 +# ifdef _RPCSVC_YP_PROT_H_ /* yp_prot.h */ +# define ypbf_raddr_v2 resp2.ypresp_addr +# define ypbf_rport_v2 resp2.ypresp_port +# elif defined(_YP_H_RPCGEN) /* yp.h */ +# define ypbf_raddr_v2 resp2.ypresp_addr_v2 +# define ypbf_rport_v2 resp2.ypresp_port_v2 +# endif +#endif + +union ypbf_setdom { + char ypsetdom_domain[YPMAXDOMAIN + 1]; + struct ypbind_setdom setdom; +#ifdef YPBIND_COMPAT_V2 + struct ypbind_setdom_v2 setdom2; +#endif +}; +#define ypbf_sdomain ypsetdom_domain +#define ypbf_sfamily setdom.ypsetdom_family +#define ypbf_saddr setdom.ypsetdom_addr +#define ypbf_sport setdom.ypsetdom_port +#define ypbf_svers setdom.ypsetdom_vers +#ifdef YPBIND_COMPAT_V2 +# define ypbf_saddr_v2 setdom2.ypsetdom_addr +# define ypbf_sport_v2 setdom2.ypsetdom_port +# define ypbf_svers_v2 setdom2.ypsetdom_vers +#endif + +#endif /* _RPCSVC_YP_UTILS_H_ */ Modified: soc2012/exxo/freebsd-head/usr.bin/ypwhich/Makefile ============================================================================== --- soc2012/exxo/freebsd-head/usr.bin/ypwhich/Makefile Thu Aug 2 00:00:34 2012 (r240003) +++ soc2012/exxo/freebsd-head/usr.bin/ypwhich/Makefile Thu Aug 2 01:20:58 2012 (r240004) @@ -7,8 +7,9 @@ WARNS?= 2 +CFLAGS += -DYPBIND_COMPAT_V2 .if ${MK_INET6_SUPPORT} != "no" -CFLAGS+= -DINET6 -DYPBIND_COMPAT_V2 +CFLAGS += -DINET6 .endif .include Modified: soc2012/exxo/freebsd-head/usr.bin/ypwhich/ypwhich.c ============================================================================== --- soc2012/exxo/freebsd-head/usr.bin/ypwhich/ypwhich.c Thu Aug 2 00:00:34 2012 (r240003) +++ soc2012/exxo/freebsd-head/usr.bin/ypwhich/ypwhich.c Thu Aug 2 01:20:58 2012 (r240004) @@ -37,6 +37,7 @@ #include #include #include +#include #include #include @@ -83,24 +84,6 @@ exit(ERR_USAGE); } -union ypb_resp { - struct { - enum ypbind_resptype status; - u_int error; - } header; - struct ypbind_resp resp; -#ifdef YPBIND_COMPAT_V2 - struct ypbind_resp_v2 resp2; -#endif -}; -#define ypb_status header.status -#define ypb_error header.error -#define ypb_family resp.ypbind_respbody.ypbind_bindinfo.ypbind_binding_family -#define ypb_addr resp.ypbind_respbody.ypbind_bindinfo.ypbind_binding_addr -#ifdef YPBIND_COMPAT_V2 -# define ypb_addr_v2 resp2.ypbind_respbody.ypbind_bindinfo.ypbind_binding_addr -#endif - #ifdef INET6 # define ADDRSTRLEN INET6_ADDRSTRLEN #else @@ -108,7 +91,7 @@ #endif static void -print_addr(const union ypb_resp *ypbr, int version) +print_addr(const union ypbf_resp *ypbr, int version) { struct hostent *hent = NULL; char str[ADDRSTRLEN]; @@ -125,19 +108,19 @@ if (version == YPBINDVERS_2) { family = AF_INET; len = sizeof(ss_addr.in); - bcopy(&ypbr->ypb_addr_v2, &ss_addr, len); + bcopy(&ypbr->ypbf_raddr_v2, &ss_addr, len); } else /* YPBINDVERS */ #endif { - family = ypbr->ypb_family; + family = ypbr->ypbf_rfamily; #ifdef INET6 if (family == AF_INET6) len = sizeof(ss_addr.in6); else /* AF_INET */ #endif len = sizeof(ss_addr.in); - bcopy(&ypbr->ypb_addr, &ss_addr, len); + bcopy(&ypbr->ypbf_raddr, &ss_addr, len); } hent = gethostbyaddr((char *)&ss_addr, len, family); if (hent) @@ -152,7 +135,7 @@ static int bind_host(char *dom, const char *host) { - union ypb_resp ypbr; + union ypbf_resp ypbr; struct timeval tv; CLIENT *client; int r; @@ -186,9 +169,9 @@ clnt_destroy(client); return (YPERR_YPBIND); } else { - if (ypbr.ypb_status != YPBIND_SUCC_VAL) { + if (ypbr.ypbf_rstatus != YPBIND_SUCC_VAL) { warnx("can't yp_bind: reason: %s", - ypbinderr_string(ypbr.ypb_error)); + ypbinderr_string(ypbr.ypbf_rerror)); clnt_destroy(client); return (r); } Modified: soc2012/exxo/freebsd-head/usr.sbin/ypbind/Makefile ============================================================================== --- soc2012/exxo/freebsd-head/usr.sbin/ypbind/Makefile Thu Aug 2 00:00:34 2012 (r240003) +++ soc2012/exxo/freebsd-head/usr.sbin/ypbind/Makefile Thu Aug 2 01:20:58 2012 (r240004) @@ -1,11 +1,16 @@ # from: @(#)Makefile 5.8 (Berkeley) 7/28/90 # $FreeBSD$ +.include + PROG= ypbind MAN= ypbind.8 SRCS= ypbind.c yp_ping.c -CFLAGS+= -DDAEMON +CFLAGS += -DDAEMON -DYPBIND_COMPAT_V2 +.if ${MK_INET6_SUPPORT} != "no" +CFLAGS += -DINET6 +.endif WARNS?= 2 Modified: soc2012/exxo/freebsd-head/usr.sbin/ypbind/yp_ping.c ============================================================================== --- soc2012/exxo/freebsd-head/usr.sbin/ypbind/yp_ping.c Thu Aug 2 00:00:34 2012 (r240003) +++ soc2012/exxo/freebsd-head/usr.sbin/ypbind/yp_ping.c Thu Aug 2 01:20:58 2012 (r240004) @@ -275,36 +275,36 @@ static int rpc_init(struct transport *tsp) { - static timeval timenull; + static struct timeval timenull; int async = TRUE; int dontblock = 1; int validtransp = 0; int i; for (i = 0; i < TSP_LEN; ++i) { - if (tsp[i]->any == NULL) + if (tsp[i].any == NULL) continue; #ifdef INET6 if (i == V6) { - tsp[i]->sock = socket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP); - tsp[i]->addr.len = sizeof(struct sockaddr_in6); + tsp[i].sock = socket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP); + tsp[i].addr.len = sizeof(struct sockaddr_in6); } else /* V4 */ #endif { - tsp[i]->sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); - tsp[i]->addr.len = sizeof(struct sockaddr_in); + tsp[i].sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); + tsp[i].addr.len = sizeof(struct sockaddr_in); } - if (tsp[i]->sock < 0) + if (tsp[i].sock < 0) return (1); - tsp[i]->addr.buf = tsp[i]->any; - tsp[i]->clnt = clnt_dg_create(tsp[i]->sock, &tsp[i]->addr, YPPROG, YPVERS, 0, 0); - if (tsp[i]->clnt == NULL) + tsp[i].addr.buf = tsp[i].any; + tsp[i].clnt = clnt_dg_create(tsp[i].sock, &tsp[i].addr, YPPROG, YPVERS, 0, 0); + if (tsp[i].clnt == NULL) return (1); - tsp[i]->clnt->cl_auth = authsys_create_default(); - clnt_control(tsp[i]->clnt, CLSET_TIMEOUT, (char *)&timenull); - clnt_control(tsp[i]->clnt, CLSET_ASYNC, (char *)&async); - ioctl(tsp[i]->sock, FIONBIO, &dontblock); + tsp[i].clnt->cl_auth = authsys_create_default(); + clnt_control(tsp[i].clnt, CLSET_TIMEOUT, (char *)&timenull); + clnt_control(tsp[i].clnt, CLSET_ASYNC, (char *)&async); + ioctl(tsp[i].sock, FIONBIO, &dontblock); ++validtransp; } return (!validtransp); @@ -316,16 +316,16 @@ int i; for (i = 0; i < TSP_LEN; ++i) { - if (tsp[i]->clnt) { - auth_destroy(tsp[i]->clnt->cl_auth); - clnt_destroy(tsp[i]->clnt); - tsp[i]->clnt = NULL; - } - tsp[i]->xid_lookup = 0; - tsp[i]->any = NULL; - close(tsp[i]->sock); - tsp[i]->sock = -1; - tsp[i]->addr.buf = NULL; + if (tsp[i].clnt) { + auth_destroy(tsp[i].clnt->cl_auth); + clnt_destroy(tsp[i].clnt); + tsp[i].clnt = NULL; + } + tsp[i].xid_lookup = 0; + tsp[i].any = NULL; + close(tsp[i].sock); + tsp[i].sock = -1; + tsp[i].addr.buf = NULL; } } Modified: soc2012/exxo/freebsd-head/usr.sbin/ypbind/yp_ping.h ============================================================================== --- soc2012/exxo/freebsd-head/usr.sbin/ypbind/yp_ping.h Thu Aug 2 00:00:34 2012 (r240003) +++ soc2012/exxo/freebsd-head/usr.sbin/ypbind/yp_ping.h Thu Aug 2 01:20:58 2012 (r240004) @@ -14,8 +14,8 @@ #define ss_family(x) (((struct sockaddr *) x)->sa_family) #define ss_to_sinaddr(x) ((char *) &((struct sockaddr_in *) x)->sin_addr) #define ss_to_sin6addr(x) ((char *) &((struct sockaddr_in6 *) x)->sin6_addr) -#define ss_to_sinport(x) ((u_short) ((struct sockaddr_in *) x)->sin_port) -#define ss_to_sin6port(x) ((u_short) ((struct sockaddr_in6 *) x)->sin6_port) +#define ss_to_sinport(x) (((struct sockaddr_in *) x)->sin_port) +#define ss_to_sin6port(x) (((struct sockaddr_in6 *) x)->sin6_port) static inline int ss_extract(const struct sockaddr_storage *ss, int *family, char **addr, size_t *len) Modified: soc2012/exxo/freebsd-head/usr.sbin/ypbind/ypbind.c ============================================================================== --- soc2012/exxo/freebsd-head/usr.sbin/ypbind/ypbind.c Thu Aug 2 00:00:34 2012 (r240003) +++ soc2012/exxo/freebsd-head/usr.sbin/ypbind/ypbind.c Thu Aug 2 01:20:58 2012 (r240004) @@ -57,11 +57,13 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include "yp_ping.h" @@ -80,7 +82,7 @@ struct _dom_binding { struct _dom_binding *dom_pnext; char dom_domain[YPMAXDOMAIN + 1]; - struct sockaddr_storage dom_server_addr; /* TODO */ + struct sockaddr_storage dom_server_addr; long int dom_vers; int dom_lockfd; #ifdef YPBIND_COMPAT_V2 @@ -96,22 +98,26 @@ #define WRITEFD ypdb->dom_pipe_fds[1] #define BROADFD broad_domain->dom_pipe_fds[1] -extern bool_t xdr_domainname(), xdr_ypbind_resp(); +extern bool_t xdr_domainname(); extern bool_t xdr_ypreq_key(), xdr_ypresp_val(); -extern bool_t xdr_ypbind_setdom(); +extern bool_t xdr_ypbind_setdom(), xdr_ypbind_setdom_v2(); +extern bool_t xdr_ypbind_resp(), xdr_ypbind_resp_v2(); +void *ypbindproc_null(SVCXPRT *, void *, const rpcvers_t); +void *ypbindproc_setdom(SVCXPRT *, const union ypbf_setdom *, const rpcvers_t); +char *ypbindproc_domain(SVCXPRT *, domainname *, const rpcvers_t); +void ypbindprog(struct svc_req *, register SVCXPRT *); +void reaper(int); +void terminate(int); void checkwork(void); -void *ypbindproc_null_2_yp(SVCXPRT *, void *, CLIENT *); -void *ypbindproc_setdom_2_yp(SVCXPRT *, struct ypbind_setdom *, CLIENT *); -void rpc_received(char *, struct sockaddr_in *, int); +void handle_children(struct _dom_binding *); +int tell_parent(char *, const struct sockaddr_storage *); +bool_t broadcast_result(bool_t *, const struct netbuf *, const struct netconfig *); void broadcast(struct _dom_binding *); int ping(struct _dom_binding *); -int tell_parent(char *, struct sockaddr_in *); -void handle_children(struct _dom_binding *); -void reaper(int); -void terminate(int); +void rpc_received(char *, const struct sockaddr_storage *, int); +int verify(const struct sockaddr_storage *); void yp_restricted_mode(char *); -int verify(struct in_addr); char *domain_name; struct _dom_binding *ypbindlist; @@ -155,38 +161,166 @@ #define MAX_RETRIES 30 #endif -#define CLOSE_LKS 1 -#define FREE_DOMB 2 - int retries = 0; int children = 0; int domains = 0; int yplockfd; fd_set fdsr; +#define CLOSE_LKS 1 +#define FREE_DOMB 2 + +static int +create_domb_file(const struct _dom_binding *ypdb, const char *binding_dir) +{ + char path[MAXPATHLEN]; + int fd; + + sprintf(path, "%s/%s.%ld", binding_dir, + ypdb->dom_domain, ypdb->dom_vers); +#ifdef O_SHLOCK + if ((fd = open(path, O_CREAT|O_SHLOCK|O_RDWR|O_TRUNC, 0644)) == -1) { + (void)mkdir(binding_dir, 0755); + if ((fd = open(path, O_CREAT|O_SHLOCK|O_RDWR|O_TRUNC, 0644)) == -1) + return (-1); + } +#else + if ((fd = open(path, O_CREAT|O_RDWR|O_TRUNC, 0644)) == -1) { + (void)mkdir(binding_dir, 0755); + if ((fd = open(path, O_CREAT|O_RDWR|O_TRUNC, 0644)) == -1) + return (-1); + } + flock(fd, LOCK_SH); +#endif + return (fd); +} + +static void +register_domb(struct _dom_binding *ypdb, const struct sockaddr_storage *addr) +{ + struct iovec iov[2]; + struct ypbind_resp ybr; + int family; + u_short port; + + if (ypdb->dom_lockfd != -1) + close(ypdb->dom_lockfd); + + ypdb->dom_lockfd = create_domb_file(ypdb, BINDINGDIR); + if (ypdb->dom_lockfd == -1) + return; + + port = __rpcb_getport("127.0.0.1", CONNLESS_TSP, YPBINDPROG, YPBINDVERS); + iov[0].iov_base = (char *)&port; + iov[0].iov_len = sizeof(port); + iov[1].iov_base = (char *)&ybr; + iov[1].iov_len = sizeof(ybr); + + family = ss_family(addr); + bzero(&ybr, sizeof(ybr)); + ybr.ypresp_status = YPBIND_SUCC_VAL; + ybr.ypresp_family = family; + *(u_short *)&ybr.ypresp_port = *ss_getport(addr); +#ifdef INET6 + if (family == AF_INET6) + bcopy(ss_to_sin6addr(addr), (char *) ybr.ypresp_addr, sizeof(struct in6_addr)); + else +#endif + bcopy(ss_to_sinaddr(addr), (char *) ybr.ypresp_addr, sizeof(struct in_addr)); + + if (writev(ypdb->dom_lockfd, iov, 2) != iov[0].iov_len + iov[1].iov_len) { + syslog(LOG_WARNING, "write: %m"); + close(ypdb->dom_lockfd); + ypdb->dom_lockfd = -1; + } +} + +#ifdef YPBIND_COMPAT_V2 +static void +register_domb_v2(struct _dom_binding *ypdb, const struct sockaddr_storage *addr) +{ + struct iovec iov[2]; + struct ypbind_resp_v2 ybr; + int family; + u_short port; + + if (ypdb->dom_lockfd_v2 != -1) + close(ypdb->dom_lockfd_v2); + + ypdb->dom_lockfd_v2 = create_domb_file(ypdb, BINDINGDIR_V2); + if (ypdb->dom_lockfd_v2 == -1) + return; + + port = __rpcb_getport("127.0.0.1", CONNLESS_TSP, YPBINDPROG, YPBINDVERS_2); + iov[0].iov_base = (char *)&port; + iov[0].iov_len = sizeof(port); + iov[1].iov_base = (char *)&ybr; + iov[1].iov_len = sizeof(ybr); + + family = ss_family(addr); + bzero(&ybr, sizeof(ybr)); + if (family != AF_INET) { /* AF_INET6 is not supported in version 2 */ + ybr.ypresp_status = YPBIND_FAIL_VAL; + ybr.ypresp_error_v2 = YPBIND_ERR_FAMILY; + } + else { + ybr.ypresp_status = YPBIND_SUCC_VAL; + bcopy(ss_to_sinaddr(addr), (char *) ybr.ypresp_addr_v2, sizeof(struct in_addr)); + *(u_short *)&ybr.ypresp_port_v2 = ss_to_sinport(addr); + } + + if (writev(ypdb->dom_lockfd_v2, iov, 2) != iov[0].iov_len + iov[1].iov_len) { + syslog(LOG_WARNING, "write: %m"); + close(ypdb->dom_lockfd_v2); + ypdb->dom_lockfd_v2 = -1; + } +} +#endif + +static void +unregister_domb(struct _dom_binding *ypdb, unsigned char mode) +{ + char path[MAXPATHLEN]; + + sprintf(path, "%s/%s.%ld", BINDINGDIR, + ypdb->dom_domain, YPVERS); + if ( (mode & CLOSE_LKS)) + close(ypdb->dom_lockfd); + unlink(path); +#ifdef YPBIND_COMPAT_V2 + sprintf(path, "%s/%s.%ld", BINDINGDIR_V2, + ypdb->dom_domain, YPVERS); + if ( (mode & CLOSE_LKS)) + close(ypdb->dom_lockfd_v2); + unlink(path); +#endif + if ( (mode & FREE_DOMB)) { + free(ypdb); + domains--; + } +} + void * -ypbindproc_null_2_yp(SVCXPRT *transp, void *argp, CLIENT *clnt) +ypbindproc_null(SVCXPRT *transp, void *argp, const rpcvers_t version) { - static char res; + static const char res; - bzero(&res, sizeof(res)); - return &res; + return ((void *) &res); } -struct ypbind_resp * -ypbindproc_domain_2_yp(SVCXPRT *transp, domainname *argp, CLIENT *clnt) +char * +ypbindproc_domain(SVCXPRT *transp, domainname *argp, const rpcvers_t version) { - static struct ypbind_resp res; + static union ypbf_resp res; struct _dom_binding *ypdb; + int family; - bzero(&res, sizeof res); - res.ypbind_status = YPBIND_FAIL_VAL; - res.ypbind_resp_u.ypbind_error = YPBIND_ERR_NOSERV; + res.ypbf_rstatus = YPBIND_FAIL_VAL; + res.ypbf_rerror = YPBIND_ERR_NOSERV; if (strchr(*argp, '/')) { - syslog(LOG_WARNING, "Domain name '%s' has embedded slash -- \ -rejecting.", *argp); - return(&res); + syslog(LOG_WARNING, "Domain name '%s' has embedded slash -- rejecting.", *argp); + return((char *) &res); } for (ypdb = ypbindlist; ypdb; ypdb = ypdb->dom_pnext) { @@ -197,20 +331,19 @@ if (ypdb == NULL) { if (yp_restricted) { syslog(LOG_NOTICE, "Running in restricted mode -- request to bind domain \"%s\" rejected.\n", *argp); - return (&res); + return ((char *) &res); } if (domains >= MAX_DOMAINS) { - syslog(LOG_WARNING, "domain limit (%d) exceeded", - MAX_DOMAINS); - res.ypbind_resp_u.ypbind_error = YPBIND_ERR_RESC; - return (&res); + syslog(LOG_WARNING, "domain limit (%d) exceeded", MAX_DOMAINS); + res.ypbf_rerror = YPBIND_ERR_RESC; + return ((char *) &res); } ypdb = (struct _dom_binding *)malloc(sizeof *ypdb); if (ypdb == NULL) { syslog(LOG_WARNING, "malloc: %m"); - res.ypbind_resp_u.ypbind_error = YPBIND_ERR_RESC; - return (&res); + res.ypbf_rerror = YPBIND_ERR_RESC; + return ((char *) &res); } bzero(ypdb, sizeof *ypdb); strncpy(ypdb->dom_domain, *argp, sizeof ypdb->dom_domain); @@ -227,111 +360,186 @@ domains++; } - if (ping(ypdb)) { - return (&res); - } + if (ping(ypdb)) + return ((char *) &res); - res.ypbind_status = YPBIND_SUCC_VAL; - res.ypbind_resp_u.ypbind_error = 0; /* Success */ - *(u_int32_t *)&res.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_addr = - ypdb->dom_server_addr.sin_addr.s_addr; - *(u_short *)&res.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_port = - ypdb->dom_server_addr.sin_port; - /*printf("domain %s at %s/%d\n", ypdb->dom_domain, - inet_ntoa(ypdb->dom_server_addr.sin_addr), - ntohs(ypdb->dom_server_addr.sin_port));*/ - return (&res); + res.ypbf_rstatus = YPBIND_SUCC_VAL; + res.ypbf_rerror = 0; /* Success */ + family = ss_family(&ypdb->dom_server_addr); +#ifdef YPBIND_COMPAT_V2 + if (version == YPBINDVERS_2) { + if (family != AF_INET) { /* AF_INET6 is not supported in version 2 */ + res.ypbf_rstatus = YPBIND_FAIL_VAL; + res.ypbf_rerror = YPBIND_ERR_FAMILY; + } + else { + bcopy(ss_to_sinaddr(&ypdb->dom_server_addr), (char *) res.ypbf_raddr_v2, sizeof(struct in_addr)); + *(u_short *)&res.ypbf_rport_v2 = ss_to_sinport(&ypdb->dom_server_addr); + } + } + else +#endif + { + res.ypbf_rfamily = family; + *(u_short *)&res.ypbf_rport = *ss_getport(&ypdb->dom_server_addr); +#ifdef INET6 + if (family == AF_INET6) + bcopy(ss_to_sin6addr(&ypdb->dom_server_addr), (char *) res.ypbf_raddr, sizeof(struct in6_addr)); + else +#endif + bcopy(ss_to_sinaddr(&ypdb->dom_server_addr), (char *) res.ypbf_raddr, sizeof(struct in_addr)); + } + return ((char *) &res); } -void * -ypbindproc_setdom_2_yp(SVCXPRT *transp, ypbind_setdom *argp, CLIENT *clnt) +static int +is_loopback(const char *buf, size_t len) { - struct sockaddr_in *fromsin, bindsin; - static char *result = NULL; + int ret = 0; - if (strchr(argp->ypsetdom_domain, '/')) { - syslog(LOG_WARNING, "Domain name '%s' has embedded slash -- \ -rejecting.", argp->ypsetdom_domain); - return(NULL); - } - fromsin = svc_getcaller(transp); - - switch (ypsetmode) { - case YPSET_LOCAL: - if (fromsin->sin_addr.s_addr != htonl(INADDR_LOOPBACK)) { - svcerr_noprog(transp); - return(NULL); - } + switch (len) { + case sizeof(struct sockaddr_in) : + if (((struct sockaddr_in *) buf)->sin_addr.s_addr == htonl(INADDR_LOOPBACK)) + ret = 1; break; - case YPSET_ALL: +#ifdef INET6 + case sizeof(struct sockaddr_in6) : + if (IN6_IS_ADDR_LOOPBACK(&((struct sockaddr_in6 *) buf)->sin6_addr)) + ret = 1; break; - case YPSET_NO: - default: - svcerr_noprog(transp); - return(NULL); +#endif + default : + ret = -1; } + return (ret); +} - if (ntohs(fromsin->sin_port) >= IPPORT_RESERVED) { - svcerr_noprog(transp); - return(NULL); - } +void * +ypbindproc_setdom(SVCXPRT *transp, const union ypbf_setdom *argp, const rpcvers_t version) +{ + struct sockaddr_storage bindaddr; + static char *result = NULL; + struct netbuf *addr; + int r; - if (argp->ypsetdom_vers != YPVERS) { - svcerr_noprog(transp); - return(NULL); + struct sockaddr_in * const sin = (struct sockaddr_in *) &bindaddr; +#ifdef INET6 + struct sockaddr_in6 * const sin6 = (struct sockaddr_in6 *) &bindaddr; +#endif + + if (strchr(argp->ypbf_sdomain, '/')) { + syslog(LOG_WARNING, "Domain name '%s' has embedded slash -- rejecting.", argp->ypbf_sdomain); + return (NULL); + } + addr = svc_getrpccaller(transp); + r = is_loopback(addr->buf, addr->len); + if (r < 0) { + syslog(LOG_WARNING, "Query from an unsupported address -- rejecting."); + return (NULL); } + if ((ypsetmode == YPSET_LOCAL && r == 0) || ypsetmode != YPSET_ALL) + goto err; + + /* It's ok to consider addr.buf as a sockaddr_storage structure + * ss_* macros never deal with its real representation */ + if (ntohs(*ss_getport(addr->buf)) >= IPPORT_RESERVED) + goto err; - bzero(&bindsin, sizeof bindsin); - bindsin.sin_family = AF_INET; - bindsin.sin_addr.s_addr = *(u_int32_t *)argp->ypsetdom_binding.ypbind_binding_addr; - bindsin.sin_port = *(u_short *)argp->ypsetdom_binding.ypbind_binding_port; - rpc_received(argp->ypsetdom_domain, &bindsin, 1); + bzero(&bindaddr, sizeof(bindaddr)); +#ifdef YPBIND_COMPAT_V2 + if (version == YPBINDVERS_2) { + if (argp->ypbf_svers_v2 != YPVERS) + goto err; + + sin->sin_family = AF_INET; + sin->sin_len = sizeof(struct sockaddr_in); + bcopy(argp->ypbf_saddr_v2, &sin->sin_addr, sizeof(struct in_addr)); + sin->sin_port = *(u_short *)&argp->ypbf_sport_v2; + } + else +#endif + { + if (argp->ypbf_svers != YPVERS) + goto err; + + switch (argp->ypbf_sfamily) { + case AF_INET : + sin->sin_family = AF_INET; + sin->sin_len = sizeof(struct sockaddr_in); + bcopy(argp->ypbf_saddr, &sin->sin_addr, sizeof(struct in_addr)); + sin->sin_port = *(u_short *)&argp->ypbf_sport; + break; +#ifdef INET6 + case AF_INET6 : + sin6->sin6_family = AF_INET6; + sin6->sin6_len = sizeof(struct sockaddr_in6); + bcopy(argp->ypbf_saddr, &sin6->sin6_addr, sizeof(struct in6_addr)); + sin6->sin6_port = *(u_short *)&argp->ypbf_sport; + break; +#endif + default : + syslog(LOG_WARNING, "Request an unsupported family -- rejecting."); + return (NULL); + } + } + rpc_received((char *) argp->ypbf_sdomain, &bindaddr, 1); return((void *) &result); + +err: + svcerr_noprog(transp); + return (NULL); } void -ypbindprog_2(struct svc_req *rqstp, register SVCXPRT *transp) +ypbindprog(struct svc_req *rqstp, register SVCXPRT *transp) { + typedef char *(*funcptr)(); union { - domainname ypbindproc_domain_2_arg; - struct ypbind_setdom ypbindproc_setdom_2_arg; + domainname domain; + union ypbf_setdom setdom_arg; } argument; - struct authunix_parms *creds; + struct authsys_parms *creds; char *result; + const rpcvers_t version = rqstp->rq_vers; bool_t (*xdr_argument)(), (*xdr_result)(); - char *(*local)(); + funcptr local; switch (rqstp->rq_proc) { case YPBINDPROC_NULL: xdr_argument = xdr_void; xdr_result = xdr_void; - local = (char *(*)()) ypbindproc_null_2_yp; + local = (funcptr) ypbindproc_null; break; case YPBINDPROC_DOMAIN: xdr_argument = xdr_domainname; - xdr_result = xdr_ypbind_resp; - local = (char *(*)()) ypbindproc_domain_2_yp; + if (version == YPBINDVERS_2) + xdr_result = xdr_ypbind_resp_v2; + else + xdr_result = xdr_ypbind_resp; + local = (funcptr) ypbindproc_domain; break; case YPBINDPROC_SETDOM: switch (rqstp->rq_cred.oa_flavor) { - case AUTH_UNIX: - creds = (struct authunix_parms *)rqstp->rq_clntcred; + case AUTH_SYS: + creds = (struct authsys_parms *) rqstp->rq_clntcred; if (creds->aup_uid != 0) { svcerr_auth(transp, AUTH_BADCRED); return; } break; default: - svcerr_auth(transp, AUTH_TOOWEAK); + svcerr_weakauth(transp); return; } - - xdr_argument = xdr_ypbind_setdom; + if (version == YPBINDVERS_2) + xdr_argument = xdr_ypbind_setdom_v2; + else + xdr_argument = xdr_ypbind_setdom; xdr_result = xdr_void; - local = (char *(*)()) ypbindproc_setdom_2_yp; + local = (funcptr) ypbindproc_setdom; break; default: @@ -343,7 +551,7 @@ svcerr_decode(transp); return; } - result = (*local)(transp, &argument, rqstp); + result = (*local)(transp, &argument, version); if (result != NULL && !svc_sendreply(transp, (xdrproc_t)xdr_result, result)) { svcerr_systemerr(transp); @@ -402,136 +610,6 @@ va_end(args); } -static int -create_domb_file(const struct _dom_binding *ypdb, const char *binding_dir) -{ - char path[MAXPATHLEN]; - int fd; - - sprintf(path, "%s/%s.%ld", binding_dir, - ypdb->dom_domain, ypdb->dom_vers); -#ifdef O_SHLOCK - if ((fd = open(path, O_CREAT|O_SHLOCK|O_RDWR|O_TRUNC, 0644)) == -1) { - (void)mkdir(binding_dir, 0755); - if ((fd = open(path, O_CREAT|O_SHLOCK|O_RDWR|O_TRUNC, 0644)) == -1) - return (-1); - } -#else - if ((fd = open(path, O_CREAT|O_RDWR|O_TRUNC, 0644)) == -1) { - (void)mkdir(binding_dir, 0755); - if ((fd = open(path, O_CREAT|O_RDWR|O_TRUNC, 0644)) == -1) - return (-1); - } - flock(fd, LOCK_SH); -#endif - return (fd); -} - -static void -register_domb(struct _dom_binding *ypdb, const struct sockaddr_storage *addr) -{ - struct iovec iov[2]; - struct ypbind_resp ybr; - int family; - u_short port; - - if (ypdb->dom_lockfd != -1) - close(ypdb->dom_lockfd); - - ypdb->dom_lockfd = create_domb_file(ypdb, BINDINGDIR); - if (ypdb->dom_lockfd == -1) - return; - - port = __rpcb_getport("127.0.0.1", CONNLESS_TSP, YPBINDPROG, YPBINDVERS); - iov[0].iov_base = (char *)&port - iov[0].iov_len = sizeof(port); - iov[1].iov_base = (char *)&ybr; - iov[1].iov_len = sizeof(ybr); - - family = ss_family(addr); - bzero(&ybr, sizeof(ybr)); - ybr.ypbind_status = YPBIND_SUCC_VAL; - ybr.ypresp_family = family; - *(u_short *)&ybr.ypresp_port = *ss_getport(addr); -#ifdef INET6 - if (family == AF_INET6) - bcopy(ss_to_sin6addr(addr), (char *) ybr.ypresp_addr, sizeof(struct in6_addr)); - else -#endif - bcopy(ss_to_sinaddr(addr), (char *) ybr.ypresp_addr, sizeof(struct in_addr)); - - if (writev(ypdb->dom_lockfd, iov, 2) != iov[0].iov_len + iov[1].iov_len) { - syslog(LOG_WARNING, "write: %m"); - close(ypdb->dom_lockfd); - ypdb->dom_lockfd = -1; - } -} - -#ifdef YPBIND_COMPAT_V2 -static void -register_domb_v2(struct _dom_binding *ypdb, const struct sockaddr_storage *addr) -{ - struct iovec iov[2]; - struct ypbind_resp_v2 ybr; - int family; - u_short port; - - if (ypdb->dom_lockfd_v2 != -1) - close(ypdb->dom_lockfd_v2); - - ypdb->dom_lockfd_v2 = create_domb_file(ypdb, BINDINGDIR_V2); - if (ypdb->dom_lockfd_v2 == -1) - return; - - port = __rpcb_getport("127.0.0.1", CONNLESS_TSP, YPBINDPROG, YPBINDVERS_2); - iov[0].iov_base = (char *)&port - iov[0].iov_len = sizeof(port); - iov[1].iov_base = (char *)&ybr; - iov[1].iov_len = sizeof(ybr); - - family = ss_family(addr); - bzero(&ybr, sizeof(ybr)); - if (family != AF_INET) { /* AF_INET6 is not supported in version 2 */ - ybr2.ypbind_status = YPBIND_FAIL_VAL; - ybr2.yprespv2_error = YPBIND_ERR_FAMILY; *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** From owner-svn-soc-all@FreeBSD.ORG Thu Aug 2 01:38:16 2012 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id 8537F106566C for ; Thu, 2 Aug 2012 01:38:14 +0000 (UTC) (envelope-from exxo@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Thu, 02 Aug 2012 01:38:14 +0000 Date: Thu, 02 Aug 2012 01:38:14 +0000 From: exxo@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20120802013814.8537F106566C@hub.freebsd.org> Cc: Subject: socsvn commit: r240005 - in soc2012/exxo: . patches X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 02 Aug 2012 01:38:16 -0000 Author: exxo Date: Thu Aug 2 01:38:14 2012 New Revision: 240005 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=240005 Log: Add yp patch and update softnotes Added: soc2012/exxo/patches/yp.patch Modified: soc2012/exxo/softnotes.txt Added: soc2012/exxo/patches/yp.patch ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2012/exxo/patches/yp.patch Thu Aug 2 01:38:14 2012 (r240005) @@ -0,0 +1,2073 @@ +Index: freebsd-head/usr.bin/ypwhich/ypwhich.c +=================================================================== +--- freebsd-head/usr.bin/ypwhich/ypwhich.c (revision 239326) ++++ freebsd-head/usr.bin/ypwhich/ypwhich.c (working copy) +@@ -37,6 +37,7 @@ __FBSDID("$FreeBSD$"); + #include + #include + #include ++#include + #include + + #include +@@ -83,26 +84,68 @@ usage(void) + exit(ERR_USAGE); + } + ++#ifdef INET6 ++# define ADDRSTRLEN INET6_ADDRSTRLEN ++#else ++# define ADDRSTRLEN INET_ADDRSTRLEN ++#endif ++ ++static void ++print_addr(const union ypbf_resp *ypbr, int version) ++{ ++ struct hostent *hent = NULL; ++ char str[ADDRSTRLEN]; ++ int family; ++ size_t len; ++ union { ++ struct in_addr in; ++#ifdef INET6 ++ struct in6_addr in6; ++#endif ++ } ss_addr; ++ ++#ifdef YPBIND_COMPAT_V2 ++ if (version == YPBINDVERS_2) { ++ family = AF_INET; ++ len = sizeof(ss_addr.in); ++ bcopy(&ypbr->ypbf_raddr_v2, &ss_addr, len); ++ } ++ else /* YPBINDVERS */ ++#endif ++ { ++ family = ypbr->ypbf_rfamily; ++#ifdef INET6 ++ if (family == AF_INET6) ++ len = sizeof(ss_addr.in6); ++ else /* AF_INET */ ++#endif ++ len = sizeof(ss_addr.in); ++ bcopy(&ypbr->ypbf_raddr, &ss_addr, len); ++ } ++ hent = gethostbyaddr((char *)&ss_addr, len, family); ++ if (hent) ++ printf("%s\n", hent->h_name); ++ else ++ printf("%s\n", inet_ntop(family, &ss_addr, str, ADDRSTRLEN)); ++} + + /* + * Like yp_bind except can query a specific host + */ + static int +-bind_host(char *dom, struct sockaddr_in *lsin) ++bind_host(char *dom, const char *host) + { +- struct hostent *hent = NULL; +- struct ypbind_resp ypbr; ++ union ypbf_resp ypbr; + struct timeval tv; + CLIENT *client; +- int sock, r; +- struct in_addr ss_addr; ++ int r; ++ int version = YPBINDVERS; + +- sock = RPC_ANYSOCK; + tv.tv_sec = 15; + tv.tv_usec = 0; +- client = clntudp_create(lsin, YPBINDPROG, YPBINDVERS, tv, &sock); ++ client = clnt_create_timed(host, YPBINDPROG, version, "udp", &tv); + if (client == NULL) { +- warnx("can't clntudp_create: %s", yperr_string(YPERR_YPBIND)); ++ warnx("can't clnt_create_timed: %s", yperr_string(YPERR_YPBIND)); + return (YPERR_YPBIND); + } + +@@ -110,28 +153,31 @@ bind_host(char *dom, struct sockaddr_in + tv.tv_usec = 0; + r = clnt_call(client, YPBINDPROC_DOMAIN, + (xdrproc_t)xdr_domainname, &dom, +- (xdrproc_t)xdr_ypbind_resp, &ypbr, tv); ++ (xdrproc_t)xdr_ypbind_resp, &ypbr.resp, tv); ++#ifdef YPBIND_COMPAT_V2 ++ if (r == RPC_PROGVERSMISMATCH) { ++ fprintf(stderr, "Warning: %s, fallback in V2 compatibility mode\n", clnt_sperrno(r)); ++ version = YPBINDVERS_2; ++ if (clnt_control(client, CLSET_VERS, &version) == TRUE) ++ r = clnt_call(client, YPBINDPROC_DOMAIN, ++ (xdrproc_t)xdr_domainname, &dom, ++ (xdrproc_t)xdr_ypbind_resp_v2, &ypbr.resp2, tv); /* TODO libc must define YPBIND_COMPAT_V2 */ ++ } ++#endif + if (r != RPC_SUCCESS) { + warnx("can't clnt_call: %s", yperr_string(YPERR_YPBIND)); + clnt_destroy(client); + return (YPERR_YPBIND); + } else { +- if (ypbr.ypbind_status != YPBIND_SUCC_VAL) { ++ if (ypbr.ypbf_rstatus != YPBIND_SUCC_VAL) { + warnx("can't yp_bind: reason: %s", +- ypbinderr_string(ypbr.ypbind_respbody.ypbind_error)); ++ ypbinderr_string(ypbr.ypbf_rerror)); + clnt_destroy(client); + return (r); + } + } + clnt_destroy(client); +- +- ss_addr = ypbr.ypbind_respbody.ypbind_bindinfo.ypbind_binding_addr; +- /*printf("%08x\n", ss_addr);*/ +- hent = gethostbyaddr((char *)&ss_addr, sizeof(ss_addr), AF_INET); +- if (hent) +- printf("%s\n", hent->h_name); +- else +- printf("%s\n", inet_ntoa(ss_addr)); ++ print_addr(&ypbr, version); + return (0); + } + +@@ -141,8 +187,7 @@ main(int argc, char *argv[]) + char *domnam = NULL, *master; + char *map = NULL; + struct ypmaplist *ypml, *y; +- struct hostent *hent; +- struct sockaddr_in lsin; ++ char *host; + int notrans, mode; + int c, r; + u_int i; +@@ -166,38 +211,20 @@ main(int argc, char *argv[]) + mode++; + break; + default: +- usage(); ++ usage(); + } + + if (!domnam) + yp_get_default_domain(&domnam); + + if (mode == 0) { +- switch (argc-optind) { +- case 0: +- bzero(&lsin, sizeof lsin); +- lsin.sin_family = AF_INET; +- lsin.sin_addr.s_addr = htonl(INADDR_LOOPBACK); +- +- if (bind_host(domnam, &lsin)) +- exit(ERR_NOBINDING); +- break; +- case 1: +- bzero(&lsin, sizeof lsin); +- lsin.sin_family = AF_INET; +- if ((lsin.sin_addr.s_addr = inet_addr(argv[optind])) == INADDR_NONE) { +- hent = gethostbyname(argv[optind]); +- if (!hent) +- errx(ERR_NOSUCHHOST, "host %s unknown", argv[optind]); +- bcopy((char *)hent->h_addr_list[0], +- (char *)&lsin.sin_addr, sizeof lsin.sin_addr); +- } +- if (bind_host(domnam, &lsin)) ++ if (argc-optind == 0 || argc-optind == 1) { ++ host = argc-optind ? argv[optind] : "127.0.0.1"; ++ if (bind_host(domnam, host)) + exit(ERR_NOBINDING); +- break; +- default: +- usage(); + } ++ else ++ usage(); + exit(0); + } + +Index: freebsd-head/usr.bin/ypwhich/Makefile +=================================================================== +--- freebsd-head/usr.bin/ypwhich/Makefile (revision 239326) ++++ freebsd-head/usr.bin/ypwhich/Makefile (working copy) +@@ -1,8 +1,15 @@ + # from: @(#)Makefile 5.8 (Berkeley) 7/28/90 + # $FreeBSD$ + ++.include ++ + PROG= ypwhich + + WARNS?= 2 + ++CFLAGS += -DYPBIND_COMPAT_V2 ++.if ${MK_INET6_SUPPORT} != "no" ++CFLAGS += -DINET6 ++.endif ++ + .include +Index: freebsd-head/include/rpcsvc/yp_utils.h +=================================================================== +--- freebsd-head/include/rpcsvc/yp_utils.h (revision 0) ++++ freebsd-head/include/rpcsvc/yp_utils.h (revision 240004) +@@ -0,0 +1,109 @@ ++/* ++ * Copyright (c) TODO ++ * All rights reserved. ++ * ++ * Redistribution and use in source and binary forms, with or without ++ * modification, are permitted provided that the following conditions ++ * are met: ++ * 1. Redistributions of source code must retain the above copyright ++ * notice, this list of conditions and the following disclaimer. ++ * 2. Redistributions in binary form must reproduce the above copyright ++ * notice, this list of conditions and the following disclaimer in the ++ * documentation and/or other materials provided with the distribution. ++ * 3. The name of the author may not be used to endorse or promote ++ * products derived from this software without specific prior written ++ * permission. ++ * ++ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS ++ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ++ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ++ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY ++ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ++ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS ++ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ++ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT ++ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY ++ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ++ * SUCH DAMAGE. ++ * ++ * $FreeBSD: soc2012/exxo/freebsd-head/include/rpcsvc/yp_prot.h 239957 2012-07-31 16:20:04Z exxo $ ++ */ ++ ++#ifndef _RPCSVC_YP_UTILS_H_ ++#define _RPCSVC_YP_UTILS_H_ ++ ++/* YPBIND facilities ++ * ++ * This file should be included after or ++ * It provides facilities to deal with YPBIND protocols ++ */ ++ ++#define ypresp_status ypbind_status ++#define ypsetdom_family ypsetdom_binding.ypbind_binding_family ++ ++#ifdef _RPCSVC_YP_PROT_H_ /* if used with yp_prot.h */ ++ ++# define ypresp_family ypbind_respbody.ypbind_bindinfo.ypbind_binding_family ++# define ypresp_error ypbind_respbody.ypbind_error ++# define ypresp_addr ypbind_respbody.ypbind_bindinfo.ypbind_binding_addr ++# define ypresp_port ypbind_respbody.ypbind_bindinfo.ypbind_binding_port ++ ++#elif defined(_YP_H_RPCGEN) /* if used with yp.h */ ++ ++# define ypsetdom_addr ypsetdom_binding.ypbind_binding_addr ++# define ypsetdom_port ypsetdom_binding.ypbind_binding_port ++ ++# define ypresp_family ypbind_resp_u.ypbind_bindinfo.ypbind_binding_family ++# define ypresp_error ypbind_resp_u.ypbind_error ++# define ypresp_addr ypbind_resp_u.ypbind_bindinfo.ypbind_binding_addr ++# define ypresp_port ypbind_resp_u.ypbind_bindinfo.ypbind_binding_port ++# define ypresp_error_v2 ypbind_resp_v2_u.ypbind_error ++# define ypresp_addr_v2 ypbind_resp_v2_u.ypbind_bindinfo.ypbind_binding_addr ++# define ypresp_port_v2 ypbind_resp_v2_u.ypbind_bindinfo.ypbind_binding_port ++ ++#endif ++ ++union ypbf_resp { ++ struct { ++ enum ypbind_resptype status; ++ u_int error; ++ } header; ++ struct ypbind_resp resp; ++#ifdef YPBIND_COMPAT_V2 ++ struct ypbind_resp_v2 resp2; ++#endif ++}; ++#define ypbf_rstatus header.status ++#define ypbf_rerror header.error ++#define ypbf_rfamily resp.ypresp_family ++#define ypbf_raddr resp.ypresp_addr ++#define ypbf_rport resp.ypresp_port ++#ifdef YPBIND_COMPAT_V2 ++# ifdef _RPCSVC_YP_PROT_H_ /* yp_prot.h */ ++# define ypbf_raddr_v2 resp2.ypresp_addr ++# define ypbf_rport_v2 resp2.ypresp_port ++# elif defined(_YP_H_RPCGEN) /* yp.h */ ++# define ypbf_raddr_v2 resp2.ypresp_addr_v2 ++# define ypbf_rport_v2 resp2.ypresp_port_v2 ++# endif ++#endif ++ ++union ypbf_setdom { ++ char ypsetdom_domain[YPMAXDOMAIN + 1]; ++ struct ypbind_setdom setdom; ++#ifdef YPBIND_COMPAT_V2 ++ struct ypbind_setdom_v2 setdom2; ++#endif ++}; ++#define ypbf_sdomain ypsetdom_domain ++#define ypbf_sfamily setdom.ypsetdom_family ++#define ypbf_saddr setdom.ypsetdom_addr ++#define ypbf_sport setdom.ypsetdom_port ++#define ypbf_svers setdom.ypsetdom_vers ++#ifdef YPBIND_COMPAT_V2 ++# define ypbf_saddr_v2 setdom2.ypsetdom_addr ++# define ypbf_sport_v2 setdom2.ypsetdom_port ++# define ypbf_svers_v2 setdom2.ypsetdom_vers ++#endif ++ ++#endif /* _RPCSVC_YP_UTILS_H_ */ +Index: freebsd-head/include/rpcsvc/yp_prot.h +=================================================================== +--- freebsd-head/include/rpcsvc/yp_prot.h (revision 239326) ++++ freebsd-head/include/rpcsvc/yp_prot.h (working copy) +@@ -199,7 +199,7 @@ struct ypresp_maplist { + struct dom_binding { + struct dom_binding *dom_pnext; + char dom_domain[YPMAXDOMAIN + 1]; +- struct sockaddr_in dom_server_addr; ++ struct sockaddr_storage dom_server_addr; /* TODO impact of changing this ? */ + u_short dom_server_port; + int dom_socket; + CLIENT *dom_client; +@@ -222,7 +222,8 @@ struct dom_binding { + */ + + #define YPBINDPROG ((u_long)100007) +-#define YPBINDVERS ((u_long)2) ++#define YPBINDVERS ((u_long)3) ++#define YPBINDVERS_2 ((u_long)2) + #define YPBINDVERS_ORIG ((u_long)1) + + /* ypbind procedure numbers */ +@@ -238,7 +239,13 @@ enum ypbind_resptype { + + /* network order, of course */ + struct ypbind_binding { +- struct in_addr ypbind_binding_addr; ++ sa_family_t ypbind_binding_family; ++ union { ++ struct in_addr in; ++#ifdef INET6 ++ struct in6_addr in6; ++#endif ++ } ypbind_binding_addr; + u_short ypbind_binding_port; + }; + +@@ -254,6 +261,7 @@ struct ypbind_resp { + #define YPBIND_ERR_ERR 1 /* internal error */ + #define YPBIND_ERR_NOSERV 2 /* no bound server for passed domain */ + #define YPBIND_ERR_RESC 3 /* system resource allocation failure */ ++#define YPBIND_ERR_FAMILY 4 /* unsupported family */ + + /* + * Request data structure for ypbind "Set domain" procedure. +@@ -266,6 +274,30 @@ struct ypbind_setdom { + #define ypsetdom_addr ypsetdom_binding.ypbind_binding_addr + #define ypsetdom_port ypsetdom_binding.ypbind_binding_port + ++/* Backward compatibility for YPBIND protocol version 2 */ ++#ifdef YPBIND_COMPAT_V2 ++ ++struct ypbind_binding_v2 { ++ struct in_addr ypbind_binding_addr; ++ u_short ypbind_binding_port; ++}; ++ ++struct ypbind_resp_v2 { ++ enum ypbind_resptype ypbind_status; ++ union { ++ u_int ypbind_error; ++ struct ypbind_binding_v2 ypbind_bindinfo; ++ } ypbind_respbody; ++}; ++ ++struct ypbind_setdom_v2 { ++ char ypsetdom_domain[YPMAXDOMAIN + 1]; ++ struct ypbind_binding_v2 ypsetdom_binding; ++ u_int ypsetdom_vers; ++}; ++ ++#endif ++ + /* + * YPPUSH PROTOCOL: + * +@@ -317,6 +349,7 @@ bool_t xdr_ypreq_xfr(XDR *, struct ypreq + bool_t xdr_ypresp_val(XDR *, struct ypresp_val *); + bool_t xdr_ypresp_key_val(XDR *, struct ypresp_key_val *); + bool_t xdr_ypbind_resp(XDR *, struct ypbind_resp *); ++bool_t xdr_ypbind_resp_v2(XDR *, struct ypbind_resp_v2 *); + bool_t xdr_ypbind_setdom(XDR *, struct ypbind_setdom *); + bool_t xdr_yp_inaddr(XDR *, struct inaddr *); + bool_t xdr_ypmap_parms(XDR *, struct ypmap_parms *); +Index: freebsd-head/include/rpcsvc/yp.x +=================================================================== +--- freebsd-head/include/rpcsvc/yp.x (revision 239326) ++++ freebsd-head/include/rpcsvc/yp.x (working copy) +@@ -196,7 +196,8 @@ enum ypbind_resptype { + }; + + struct ypbind_binding { +- opaque ypbind_binding_addr[4]; /* In network order */ ++ unsigned char ypbind_binding_family; ++ opaque ypbind_binding_addr[16]; /* In network order */ + opaque ypbind_binding_port[2]; /* In network order */ + }; + +@@ -207,12 +208,12 @@ case YPBIND_SUCC_VAL: + ypbind_binding ypbind_bindinfo; + }; + +-/* Detailed failure reason codes for response field ypbind_error*/ ++/* Detailed failure reason codes for response field ypbind_error */ + + const YPBIND_ERR_ERR = 1; /* Internal error */ + const YPBIND_ERR_NOSERV = 2; /* No bound server for passed domain */ + const YPBIND_ERR_RESC = 3; /* System resource allocation failure */ +- ++const YPBIND_ERR_FAMILY = 4; /* Unsupported family */ + + /* + * Request data structure for ypbind "Set domain" procedure. +@@ -223,6 +224,30 @@ struct ypbind_setdom { + unsigned ypsetdom_vers; + }; + ++/* Backward compatibility for YPBIND protocol version 2 */ ++#ifdef YPBIND_COMPAT_V2 ++ ++const YPBINDVERS_2 = 2; ++ ++struct ypbind_binding_v2 { ++ opaque ypbind_binding_addr[4]; /* In network order */ ++ opaque ypbind_binding_port[2]; /* In network order */ ++}; ++ ++union ypbind_resp_v2 switch (ypbind_resptype ypbind_status) { ++case YPBIND_FAIL_VAL: ++ unsigned ypbind_error; ++case YPBIND_SUCC_VAL: ++ ypbind_binding_v2 ypbind_bindinfo; ++}; ++ ++struct ypbind_setdom_v2 { ++ domainname ypsetdom_domain; ++ ypbind_binding_v2 ypsetdom_binding; ++ unsigned ypsetdom_vers; ++}; ++ ++#endif + + /* + * NIS v1 support for backwards compatibility +@@ -371,7 +396,7 @@ program YPBINDPROG { + + void + YPBINDPROC_SETDOM(ypbind_setdom) = 2; +- } = 2; ++ } = 3; + } = 100007; + + #endif +Index: freebsd-head/usr.sbin/ypbind/yp_ping.c +=================================================================== +--- freebsd-head/usr.sbin/ypbind/yp_ping.c (revision 239326) ++++ freebsd-head/usr.sbin/ypbind/yp_ping.c (working copy) +@@ -103,6 +103,8 @@ __FBSDID("$FreeBSD$"); + */ + + ++#if 0 /* TODO : Does __yp_getport achieve the same result ? */ ++ + static struct timeval timeout = { 1, 0 }; + static struct timeval tottimeout = { 1, 0 }; + +@@ -145,6 +147,7 @@ __pmap_getport(struct sockaddr_in *addre + address->sin_port = 0; + return (port); + } ++#endif + + /* + * Transmit to YPPROC_DOMAIN_NONACK, return immediately. +@@ -207,104 +210,230 @@ ypproc_domain_nonack_2_recv(domainname * + */ + + struct ping_req { +- struct sockaddr_in sin; ++ struct sockaddr_storage sst; + u_int32_t xid; + }; + ++struct transport { ++ CLIENT *clnt; ++ u_int32_t xid_lookup; ++ struct sockaddr_storage *any; ++ int sock; ++ struct netbuf addr; ++}; ++#define V4 0 ++#define V6 1 ++#ifdef INET6 ++# define TSP_LEN (V6 + 1) ++#else ++# define TSP_LEN (V4 + 1) ++#endif ++ ++u_short ++__rpcb_getport(const char *hostname, const char *netid, ++ const rpcprog_t prognum, const rpcvers_t versnum) ++{ ++ struct sockaddr_storage sst; ++ struct netconfig *nconf; ++ struct netbuf svcaddr; ++ u_short port; ++ ++ svcaddr.len = 0; ++ svcaddr.maxlen = sizeof(sst); ++ svcaddr.buf = &sst; ++ if ((nconf = getnetconfigent(netid)) == NULL || ++ !rpcb_getaddr(prognum, versnum, nconf, &svcaddr, hostname)) ++ return (0); ++ switch (svcaddr.len) { ++ case sizeof(struct sockaddr_in) : ++ port = ss_to_sinport(svcaddr.buf); ++ break; ++#ifdef INET6 ++ case sizeof(struct sockaddr_in6) : ++ port = ss_to_sin6port(svcaddr.buf); ++ break; ++#endif ++ default : ++ port = 0; ++ } ++ return (port); /* Network byte order */ ++} ++ ++static u_short ++__yp_getport(const struct sockaddr_storage *host, const char *netid) ++{ ++ char str[ADDRSTRLEN]; ++ int family; ++ char *ptr; ++ ++ if (ss_extract(host, &family, &ptr, 0)) ++ return (0); ++ inet_ntop(family, ptr, str, ADDRSTRLEN); ++ return (__rpcb_getport(str, netid, YPPROG, YPVERS)); ++} ++ ++static int ++rpc_init(struct transport *tsp) ++{ ++ static struct timeval timenull; ++ int async = TRUE; ++ int dontblock = 1; ++ int validtransp = 0; ++ int i; ++ ++ for (i = 0; i < TSP_LEN; ++i) { ++ if (tsp[i].any == NULL) ++ continue; ++#ifdef INET6 ++ if (i == V6) { ++ tsp[i].sock = socket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP); ++ tsp[i].addr.len = sizeof(struct sockaddr_in6); ++ } ++ else /* V4 */ ++#endif ++ { ++ tsp[i].sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); ++ tsp[i].addr.len = sizeof(struct sockaddr_in); ++ } ++ if (tsp[i].sock < 0) ++ return (1); ++ tsp[i].addr.buf = tsp[i].any; ++ tsp[i].clnt = clnt_dg_create(tsp[i].sock, &tsp[i].addr, YPPROG, YPVERS, 0, 0); ++ if (tsp[i].clnt == NULL) ++ return (1); ++ tsp[i].clnt->cl_auth = authsys_create_default(); ++ clnt_control(tsp[i].clnt, CLSET_TIMEOUT, (char *)&timenull); ++ clnt_control(tsp[i].clnt, CLSET_ASYNC, (char *)&async); ++ ioctl(tsp[i].sock, FIONBIO, &dontblock); ++ ++validtransp; ++ } ++ return (!validtransp); ++} ++ ++static void ++rpc_destroy(struct transport *tsp) ++{ ++ int i; ++ ++ for (i = 0; i < TSP_LEN; ++i) { ++ if (tsp[i].clnt) { ++ auth_destroy(tsp[i].clnt->cl_auth); ++ clnt_destroy(tsp[i].clnt); ++ tsp[i].clnt = NULL; ++ } ++ tsp[i].xid_lookup = 0; ++ tsp[i].any = NULL; ++ close(tsp[i].sock); ++ tsp[i].sock = -1; ++ tsp[i].addr.buf = NULL; ++ } ++} ++ + int +-__yp_ping(struct in_addr *restricted_addrs, int cnt, char *dom, short *port) ++__yp_ping(struct sockaddr_storage *restricted_addrs, int cnt, char *dom, u_short *port) + { +- struct timeval tv = { 5, 0 }; + struct ping_req **reqs; + unsigned long i; +- int async; +- struct sockaddr_in sin, *any = NULL; +- struct netbuf addr; ++ int n; ++ struct sockaddr_storage *req_addr; + int winner = -1; +- u_int32_t xid_seed, xid_lookup; +- int sock, dontblock = 1; +- CLIENT *clnt; ++ u_int32_t xid_seed; + char *foo = dom; + int validsrvs = 0; ++ u_short yp_port; ++ struct transport tsp[TSP_LEN] = { ++#ifdef INET6 ++ {NULL, 0, NULL, -1}, ++#endif ++ {NULL, 0, NULL, -1} ++ }; + + /* Set up handles. */ + reqs = calloc(1, sizeof(struct ping_req *) * cnt); + xid_seed = time(NULL) ^ getpid(); + + for (i = 0; i < cnt; i++) { +- bzero((char *)&sin, sizeof(sin)); +- sin.sin_family = AF_INET; +- bcopy((char *)&restricted_addrs[i], +- (char *)&sin.sin_addr, sizeof(struct in_addr)); +- sin.sin_port = htons(__pmap_getport(&sin, YPPROG, +- YPVERS, IPPROTO_UDP)); +- if (sin.sin_port == 0) ++ yp_port = __yp_getport(&restricted_addrs[i], CONNLESS_TSP); ++ if (yp_port == 0) + continue; + reqs[i] = calloc(1, sizeof(struct ping_req)); +- bcopy((char *)&sin, (char *)&reqs[i]->sin, sizeof(sin)); +- any = &reqs[i]->sin; ++ req_addr = &reqs[i]->sst; ++ bcopy((char *)&restricted_addrs[i], (char *)req_addr, sizeof(*req_addr)); ++#ifdef INET6 ++ if (ss_family(req_addr) == AF_INET6) { ++ ss_to_sin6port(req_addr) = yp_port; ++ tsp[V6].any = req_addr; ++ } ++ else /* AF_INET */ ++#endif ++ { ++ ss_to_sinport(req_addr) = yp_port; ++ tsp[V4].any = req_addr; ++ } + reqs[i]->xid = xid_seed; + xid_seed++; + validsrvs++; + } + + /* Make sure at least one server was assigned */ +- if (!validsrvs) { +- free(reqs); +- return(-1); +- } ++ if (!validsrvs) ++ goto err; + +- /* Create RPC handle */ +- sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); +- clnt = clntudp_create(any, YPPROG, YPVERS, tv, &sock); +- if (clnt == NULL) { +- close(sock); +- for (i = 0; i < cnt; i++) +- if (reqs[i] != NULL) +- free(reqs[i]); +- free(reqs); +- return(-1); +- } +- clnt->cl_auth = authunix_create_default(); +- tv.tv_sec = 0; +- +- clnt_control(clnt, CLSET_TIMEOUT, (char *)&tv); +- async = TRUE; +- clnt_control(clnt, CLSET_ASYNC, (char *)&async); +- ioctl(sock, FIONBIO, &dontblock); ++ /* Create RPC transports ++ * an inet4 transport for any V4 address existing in `reqs' ++ * an inet6 transport for any V6 address existing in `reqs' ++ * otherwise, shutdown ++ * */ ++ if (rpc_init(tsp)) ++ goto err; + + /* Transmit */ +- for (i = 0; i < cnt; i++) { ++ for (i = 0; i < cnt; i++) + if (reqs[i] != NULL) { +- clnt_control(clnt, CLSET_XID, (char *)&reqs[i]->xid); +- addr.len = sizeof(reqs[i]->sin); +- addr.buf = (char *) &reqs[i]->sin; +- clnt_control(clnt, CLSET_SVC_ADDR, &addr); +- ypproc_domain_nonack_2_send(&foo, clnt); ++ req_addr = &reqs[i]->sst; ++ n = (ss_family(req_addr) == AF_INET ? V4 : V6); ++ clnt_control(tsp[n].clnt, CLSET_XID, (char *)&reqs[i]->xid); ++ tsp[n].addr.buf = (char *) req_addr; ++ clnt_control(tsp[n].clnt, CLSET_SVC_ADDR, &tsp[n].addr); ++ ypproc_domain_nonack_2_send(&foo, tsp[n].clnt); + } +- } + + /* Receive reply */ +- ypproc_domain_nonack_2_recv(&foo, clnt); ++ for (i = 0; i < TSP_LEN; ++i) ++ if (tsp[i].clnt) ++ ypproc_domain_nonack_2_recv(&foo, tsp[i].clnt); ++ ++ /* Get the winner */ ++ for (i = 0; i < TSP_LEN; ++i) ++ if (tsp[i].clnt) ++ clnt_control(tsp[i].clnt, CLGET_XID, (char *)&tsp[i].xid_lookup); + +- /* Got a winner -- look him up. */ +- clnt_control(clnt, CLGET_XID, (char *)&xid_lookup); +- for (i = 0; i < cnt; i++) { +- if (reqs[i] != NULL && reqs[i]->xid == xid_lookup) { +- winner = i; +- *port = reqs[i]->sin.sin_port; ++ /* Look him up */ ++ for (i = 0; i < cnt; i++) ++ if (reqs[i] != NULL) { ++ for (n = 0; n < TSP_LEN; ++n) ++ if (reqs[i]->xid == tsp[n].xid_lookup) { ++#ifdef INET6 ++ if (n == V6) ++ *port = ss_to_sin6port(&reqs[i]->sst); /* Network byte order */ ++ else /* V4 */ ++#endif ++ *port = ss_to_sinport(&reqs[i]->sst); ++ winner = i; ++ break; ++ } ++ if (winner > 0) ++ break; + } +- } +- ++ + /* Shut everything down */ +- auth_destroy(clnt->cl_auth); +- clnt_destroy(clnt); +- close(sock); +- +- for (i = 0; i < cnt; i++) +- if (reqs[i] != NULL) +- free(reqs[i]); ++err: ++ rpc_destroy(tsp); ++ if (validsrvs) { ++ for (i = 0; i < cnt; i++) ++ if (reqs[i] != NULL) ++ free(reqs[i]); ++ } + free(reqs); +- + return(winner); + } +Index: freebsd-head/usr.sbin/ypbind/ypbind.c +=================================================================== +--- freebsd-head/usr.sbin/ypbind/ypbind.c (revision 239326) ++++ freebsd-head/usr.sbin/ypbind/ypbind.c (working copy) +@@ -57,11 +57,13 @@ __FBSDID("$FreeBSD$"); + #include + #include + #include ++#include + #include + #include + #include + #include + #include ++#include + #include + #include "yp_ping.h" + +@@ -69,6 +71,10 @@ __FBSDID("$FreeBSD$"); + #define BINDINGDIR "/var/yp/binding" + #endif + ++#if !defined(BINDINGDIR_V2) && defined(YPBIND_COMPAT_V2) ++#define BINDINGDIR_V2 "/var/yp/binding.2" ++#endif ++ + #ifndef YPBINDLOCK + #define YPBINDLOCK "/var/run/ypbind.lock" + #endif +@@ -76,9 +82,12 @@ __FBSDID("$FreeBSD$"); + struct _dom_binding { + struct _dom_binding *dom_pnext; + char dom_domain[YPMAXDOMAIN + 1]; +- struct sockaddr_in dom_server_addr; ++ struct sockaddr_storage dom_server_addr; + long int dom_vers; + int dom_lockfd; ++#ifdef YPBIND_COMPAT_V2 ++ int dom_lockfd_v2; ++#endif + int dom_alive; + int dom_broadcast_pid; + int dom_pipe_fds[2]; +@@ -89,22 +98,26 @@ struct _dom_binding { + #define WRITEFD ypdb->dom_pipe_fds[1] + #define BROADFD broad_domain->dom_pipe_fds[1] + +-extern bool_t xdr_domainname(), xdr_ypbind_resp(); ++extern bool_t xdr_domainname(); + extern bool_t xdr_ypreq_key(), xdr_ypresp_val(); +-extern bool_t xdr_ypbind_setdom(); ++extern bool_t xdr_ypbind_setdom(), xdr_ypbind_setdom_v2(); ++extern bool_t xdr_ypbind_resp(), xdr_ypbind_resp_v2(); + ++void *ypbindproc_null(SVCXPRT *, void *, const rpcvers_t); ++void *ypbindproc_setdom(SVCXPRT *, const union ypbf_setdom *, const rpcvers_t); ++char *ypbindproc_domain(SVCXPRT *, domainname *, const rpcvers_t); ++void ypbindprog(struct svc_req *, register SVCXPRT *); ++void reaper(int); ++void terminate(int); + void checkwork(void); +-void *ypbindproc_null_2_yp(SVCXPRT *, void *, CLIENT *); +-void *ypbindproc_setdom_2_yp(SVCXPRT *, struct ypbind_setdom *, CLIENT *); +-void rpc_received(char *, struct sockaddr_in *, int); ++void handle_children(struct _dom_binding *); ++int tell_parent(char *, const struct sockaddr_storage *); ++bool_t broadcast_result(bool_t *, const struct netbuf *, const struct netconfig *); + void broadcast(struct _dom_binding *); + int ping(struct _dom_binding *); +-int tell_parent(char *, struct sockaddr_in *); +-void handle_children(struct _dom_binding *); +-void reaper(int); +-void terminate(int); ++void rpc_received(char *, const struct sockaddr_storage *, int); ++int verify(const struct sockaddr_storage *); + void yp_restricted_mode(char *); +-int verify(struct in_addr); + + char *domain_name; + struct _dom_binding *ypbindlist; +@@ -128,7 +141,7 @@ static int not_responding_count = 0; + #define RESTRICTED_SERVERS 10 + int yp_restricted = 0; + int yp_manycast = 0; +-struct in_addr restricted_addrs[RESTRICTED_SERVERS]; ++struct sockaddr_storage restricted_addrs[RESTRICTED_SERVERS]; + + /* No more than MAX_CHILDREN child broadcasters at a time. */ + #ifndef MAX_CHILDREN +@@ -154,32 +167,160 @@ int domains = 0; + int yplockfd; + fd_set fdsr; + +-SVCXPRT *udptransp, *tcptransp; ++#define CLOSE_LKS 1 ++#define FREE_DOMB 2 ++ ++static int ++create_domb_file(const struct _dom_binding *ypdb, const char *binding_dir) ++{ ++ char path[MAXPATHLEN]; ++ int fd; ++ ++ sprintf(path, "%s/%s.%ld", binding_dir, ++ ypdb->dom_domain, ypdb->dom_vers); ++#ifdef O_SHLOCK ++ if ((fd = open(path, O_CREAT|O_SHLOCK|O_RDWR|O_TRUNC, 0644)) == -1) { ++ (void)mkdir(binding_dir, 0755); ++ if ((fd = open(path, O_CREAT|O_SHLOCK|O_RDWR|O_TRUNC, 0644)) == -1) ++ return (-1); ++ } ++#else ++ if ((fd = open(path, O_CREAT|O_RDWR|O_TRUNC, 0644)) == -1) { ++ (void)mkdir(binding_dir, 0755); ++ if ((fd = open(path, O_CREAT|O_RDWR|O_TRUNC, 0644)) == -1) ++ return (-1); ++ } ++ flock(fd, LOCK_SH); ++#endif ++ return (fd); ++} ++ ++static void ++register_domb(struct _dom_binding *ypdb, const struct sockaddr_storage *addr) ++{ ++ struct iovec iov[2]; ++ struct ypbind_resp ybr; ++ int family; ++ u_short port; ++ ++ if (ypdb->dom_lockfd != -1) ++ close(ypdb->dom_lockfd); ++ ++ ypdb->dom_lockfd = create_domb_file(ypdb, BINDINGDIR); ++ if (ypdb->dom_lockfd == -1) ++ return; ++ ++ port = __rpcb_getport("127.0.0.1", CONNLESS_TSP, YPBINDPROG, YPBINDVERS); ++ iov[0].iov_base = (char *)&port; ++ iov[0].iov_len = sizeof(port); ++ iov[1].iov_base = (char *)&ybr; ++ iov[1].iov_len = sizeof(ybr); ++ ++ family = ss_family(addr); ++ bzero(&ybr, sizeof(ybr)); ++ ybr.ypresp_status = YPBIND_SUCC_VAL; ++ ybr.ypresp_family = family; ++ *(u_short *)&ybr.ypresp_port = *ss_getport(addr); ++#ifdef INET6 ++ if (family == AF_INET6) ++ bcopy(ss_to_sin6addr(addr), (char *) ybr.ypresp_addr, sizeof(struct in6_addr)); ++ else ++#endif ++ bcopy(ss_to_sinaddr(addr), (char *) ybr.ypresp_addr, sizeof(struct in_addr)); ++ ++ if (writev(ypdb->dom_lockfd, iov, 2) != iov[0].iov_len + iov[1].iov_len) { ++ syslog(LOG_WARNING, "write: %m"); ++ close(ypdb->dom_lockfd); ++ ypdb->dom_lockfd = -1; ++ } ++} ++ ++#ifdef YPBIND_COMPAT_V2 ++static void ++register_domb_v2(struct _dom_binding *ypdb, const struct sockaddr_storage *addr) ++{ ++ struct iovec iov[2]; ++ struct ypbind_resp_v2 ybr; ++ int family; ++ u_short port; ++ ++ if (ypdb->dom_lockfd_v2 != -1) ++ close(ypdb->dom_lockfd_v2); ++ ++ ypdb->dom_lockfd_v2 = create_domb_file(ypdb, BINDINGDIR_V2); ++ if (ypdb->dom_lockfd_v2 == -1) ++ return; ++ ++ port = __rpcb_getport("127.0.0.1", CONNLESS_TSP, YPBINDPROG, YPBINDVERS_2); ++ iov[0].iov_base = (char *)&port; ++ iov[0].iov_len = sizeof(port); ++ iov[1].iov_base = (char *)&ybr; ++ iov[1].iov_len = sizeof(ybr); ++ ++ family = ss_family(addr); ++ bzero(&ybr, sizeof(ybr)); ++ if (family != AF_INET) { /* AF_INET6 is not supported in version 2 */ ++ ybr.ypresp_status = YPBIND_FAIL_VAL; ++ ybr.ypresp_error_v2 = YPBIND_ERR_FAMILY; ++ } ++ else { ++ ybr.ypresp_status = YPBIND_SUCC_VAL; ++ bcopy(ss_to_sinaddr(addr), (char *) ybr.ypresp_addr_v2, sizeof(struct in_addr)); ++ *(u_short *)&ybr.ypresp_port_v2 = ss_to_sinport(addr); ++ } ++ ++ if (writev(ypdb->dom_lockfd_v2, iov, 2) != iov[0].iov_len + iov[1].iov_len) { ++ syslog(LOG_WARNING, "write: %m"); ++ close(ypdb->dom_lockfd_v2); ++ ypdb->dom_lockfd_v2 = -1; ++ } ++} ++#endif ++ ++static void ++unregister_domb(struct _dom_binding *ypdb, unsigned char mode) *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** From owner-svn-soc-all@FreeBSD.ORG Thu Aug 2 01:46:14 2012 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id 165F9106564A for ; Thu, 2 Aug 2012 01:46:12 +0000 (UTC) (envelope-from exxo@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Thu, 02 Aug 2012 01:46:12 +0000 Date: Thu, 02 Aug 2012 01:46:12 +0000 From: exxo@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20120802014612.165F9106564A@hub.freebsd.org> Cc: Subject: socsvn commit: r240006 - in soc2012/exxo: . patches X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 02 Aug 2012 01:46:14 -0000 Author: exxo Date: Thu Aug 2 01:46:11 2012 New Revision: 240006 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=240006 Log: Minor cleanup Deleted: soc2012/exxo/patches/ypwhich.patch Modified: soc2012/exxo/softnotes.txt Modified: soc2012/exxo/softnotes.txt ============================================================================== --- soc2012/exxo/softnotes.txt Thu Aug 2 01:38:14 2012 (r240005) +++ soc2012/exxo/softnotes.txt Thu Aug 2 01:46:11 2012 (r240006) @@ -1,4 +1,4 @@ -openssl-1.0.1c FIXED (patch provided. Be aware of some TODO parts, Bio connect is not concerned by this patch) +openssl-1.0.1c FIXED (patch provided. Bio connect is not concerned by this patch) contrib/cvs FIXED (patch updated) usr.bin/who OK (software dependant, utmpx fixed it) usr.bin/systat FIXED (patch provided. systat now supports IPv6 when using ignore/display/show netstat commands) From owner-svn-soc-all@FreeBSD.ORG Thu Aug 2 15:35:15 2012 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id 79DF61065705 for ; Thu, 2 Aug 2012 15:35:14 +0000 (UTC) (envelope-from rudot@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Thu, 02 Aug 2012 15:35:14 +0000 Date: Thu, 02 Aug 2012 15:35:14 +0000 From: rudot@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20120802153514.79DF61065705@hub.freebsd.org> Cc: Subject: socsvn commit: r240016 - soc2012/rudot/sys/kern X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 02 Aug 2012 15:35:15 -0000 Author: rudot Date: Thu Aug 2 15:35:13 2012 New Revision: 240016 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=240016 Log: init process cpu time Modified: soc2012/rudot/sys/kern/kern_racct.c Modified: soc2012/rudot/sys/kern/kern_racct.c ============================================================================== --- soc2012/rudot/sys/kern/kern_racct.c Thu Aug 2 13:57:49 2012 (r240015) +++ soc2012/rudot/sys/kern/kern_racct.c Thu Aug 2 15:35:13 2012 (r240016) @@ -803,6 +803,9 @@ goto out; #endif + /* Init process cpu time */ + child->p_prev_runtime = 0; + /* * Inherit resource usage. */ From owner-svn-soc-all@FreeBSD.ORG Thu Aug 2 19:56:45 2012 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id E3F55106566B for ; Thu, 2 Aug 2012 19:56:43 +0000 (UTC) (envelope-from gmiller@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Thu, 02 Aug 2012 19:56:43 +0000 Date: Thu, 02 Aug 2012 19:56:43 +0000 From: gmiller@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20120802195643.E3F55106566B@hub.freebsd.org> Cc: Subject: socsvn commit: r240019 - in soc2012/gmiller/locking-head: . tools/regression/lib/libthr/lockprof X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 02 Aug 2012 19:56:45 -0000 Author: gmiller Date: Thu Aug 2 19:56:43 2012 New Revision: 240019 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=240019 Log: r240081@FreeBSD-dev: root | 2012-07-24 13:15:39 -0500 Minor test case fix. Modified: soc2012/gmiller/locking-head/ (props changed) soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/lock-cycle.c Modified: soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/lock-cycle.c ============================================================================== --- soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/lock-cycle.c Thu Aug 2 15:13:12 2012 (r240018) +++ soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/lock-cycle.c Thu Aug 2 19:56:43 2012 (r240019) @@ -95,7 +95,7 @@ check(record_count == 1); check(strcmp(stats.file, "lock-cycle.c") == 0); - check(stats.line == 17); + check(stats.line == 43); check(stats.wait_max.tv_sec == 0 && stats.wait_max.tv_nsec == 0); @@ -129,7 +129,7 @@ check(record_count == 1); check(strcmp(stats.file, "lock-cycle.c") == 0); - check(stats.line == 17); + check(stats.line == 43); tm = stats.hold_max.tv_sec * 1000000L + stats.hold_max.tv_nsec / 1000; check(tm >= 30); From owner-svn-soc-all@FreeBSD.ORG Fri Aug 3 14:34:56 2012 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id 7A33510656AC for ; Fri, 3 Aug 2012 14:34:54 +0000 (UTC) (envelope-from aleek@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Fri, 03 Aug 2012 14:34:54 +0000 Date: Fri, 03 Aug 2012 14:34:54 +0000 From: aleek@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20120803143454.7A33510656AC@hub.freebsd.org> Cc: Subject: socsvn commit: r240036 - in soc2012/aleek/beaglexm-armv6/sys: arm/conf arm/ti/am37x arm/ti/twl arm/ti/usb boot/fdt/dts X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 03 Aug 2012 14:34:56 -0000 Author: aleek Date: Fri Aug 3 14:34:53 2012 New Revision: 240036 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=240036 Log: initial twl/tps (Power Management Unit) support for bb-xm Modified: soc2012/aleek/beaglexm-armv6/sys/arm/conf/BEAGLEBOARD-XM soc2012/aleek/beaglexm-armv6/sys/arm/ti/am37x/am37x_pmic.c soc2012/aleek/beaglexm-armv6/sys/arm/ti/am37x/files.beagleboardxm soc2012/aleek/beaglexm-armv6/sys/arm/ti/twl/twl.c soc2012/aleek/beaglexm-armv6/sys/arm/ti/twl/twl_clks.c soc2012/aleek/beaglexm-armv6/sys/arm/ti/usb/omap_ehci.c soc2012/aleek/beaglexm-armv6/sys/boot/fdt/dts/beagleboardxm.dts Modified: soc2012/aleek/beaglexm-armv6/sys/arm/conf/BEAGLEBOARD-XM ============================================================================== --- soc2012/aleek/beaglexm-armv6/sys/arm/conf/BEAGLEBOARD-XM Fri Aug 3 13:50:29 2012 (r240035) +++ soc2012/aleek/beaglexm-armv6/sys/arm/conf/BEAGLEBOARD-XM Fri Aug 3 14:34:53 2012 (r240036) @@ -60,7 +60,7 @@ #options WITNESS #Enable checks to detect deadlocks and cycles #options WITNESS_SKIPSPIN #Don't run witness on spinlocks for speed #options DIAGNOSTIC -#options DEBUG +options DEBUG # NFS support @@ -97,7 +97,7 @@ device iicbus device iic device ti_i2c -#device am37x_pmic # AM335x Power Management IC (TPC65217) +device twl # GPIO device gpio Modified: soc2012/aleek/beaglexm-armv6/sys/arm/ti/am37x/am37x_pmic.c ============================================================================== --- soc2012/aleek/beaglexm-armv6/sys/arm/ti/am37x/am37x_pmic.c Fri Aug 3 13:50:29 2012 (r240035) +++ soc2012/aleek/beaglexm-armv6/sys/arm/ti/am37x/am37x_pmic.c Fri Aug 3 14:34:53 2012 (r240036) @@ -100,7 +100,7 @@ { struct am335x_pmic_softc *sc; - if (!ofw_bus_is_compatible(dev, "ti,am335x-pmic")) + if (!ofw_bus_is_compatible(dev, "ti,am37x-pmic")) return (ENXIO); sc = device_get_softc(dev); @@ -164,7 +164,7 @@ }; static driver_t am335x_pmic_driver = { - "am335x_pmic", + "am37x_pmic", am335x_pmic_methods, sizeof(struct am335x_pmic_softc), }; Modified: soc2012/aleek/beaglexm-armv6/sys/arm/ti/am37x/files.beagleboardxm ============================================================================== --- soc2012/aleek/beaglexm-armv6/sys/arm/ti/am37x/files.beagleboardxm Fri Aug 3 13:50:29 2012 (r240035) +++ soc2012/aleek/beaglexm-armv6/sys/arm/ti/am37x/files.beagleboardxm Fri Aug 3 14:34:53 2012 (r240036) @@ -1,3 +1,6 @@ #$FreeBSD$ -arm/ti/am37x/am37x_pmic.c optional am37x_pmic +#arm/ti/am37x/am37x_pmic.c optional am37x_pmic +arm/ti/twl/twl.c optional twl +arm/ti/twl/twl_vreg.c optional twl #twl_vreg +arm/ti/twl/twl_clks.c optional twl #twl_clks Modified: soc2012/aleek/beaglexm-armv6/sys/arm/ti/twl/twl.c ============================================================================== --- soc2012/aleek/beaglexm-armv6/sys/arm/ti/twl/twl.c Fri Aug 3 13:50:29 2012 (r240035) +++ soc2012/aleek/beaglexm-armv6/sys/arm/ti/twl/twl.c Fri Aug 3 14:34:53 2012 (r240036) @@ -419,6 +419,7 @@ return (ENOMEM); /* FIXME: should be in DTS file */ + device_printf( dev, "habababa\n" ); if ((sc->sc_vreg = device_add_child(dev, "twl_vreg", -1)) == NULL) device_printf(dev, "could not allocate twl_vreg instance\n"); if ((sc->sc_clks = device_add_child(dev, "twl_clks", -1)) == NULL) Modified: soc2012/aleek/beaglexm-armv6/sys/arm/ti/twl/twl_clks.c ============================================================================== --- soc2012/aleek/beaglexm-armv6/sys/arm/ti/twl/twl_clks.c Fri Aug 3 13:50:29 2012 (r240035) +++ soc2012/aleek/beaglexm-armv6/sys/arm/ti/twl/twl_clks.c Fri Aug 3 14:34:53 2012 (r240036) @@ -75,7 +75,7 @@ #include "twl_clks.h" -static int twl_clks_debug = 1; +static int twl_clks_debug = 1; //@todo XXX make it #if DEBUG /* Modified: soc2012/aleek/beaglexm-armv6/sys/arm/ti/usb/omap_ehci.c ============================================================================== --- soc2012/aleek/beaglexm-armv6/sys/arm/ti/usb/omap_ehci.c Fri Aug 3 13:50:29 2012 (r240035) +++ soc2012/aleek/beaglexm-armv6/sys/arm/ti/usb/omap_ehci.c Fri Aug 3 14:34:53 2012 (r240036) @@ -1023,3 +1023,4 @@ static devclass_t ehci_devclass; DRIVER_MODULE(ehci, simplebus, ehci_driver, ehci_devclass, 0, 0); +MODULE_DEPEND(ehci, twl_vreg, 1, 1, 1); Modified: soc2012/aleek/beaglexm-armv6/sys/boot/fdt/dts/beagleboardxm.dts ============================================================================== --- soc2012/aleek/beaglexm-armv6/sys/boot/fdt/dts/beagleboardxm.dts Fri Aug 3 13:50:29 2012 (r240035) +++ soc2012/aleek/beaglexm-armv6/sys/boot/fdt/dts/beagleboardxm.dts Fri Aug 3 14:34:53 2012 (r240036) @@ -195,10 +195,10 @@ interrupts = <56>; interrupt-parent = <&AINTC>; i2c-device-id = <1>; - /*pmic@24 { - compatible = "ti,am37x-pmic"; + pmic@24 { + compatible = "ti,twl4030"; reg = <0x24>; - };*/ + }; }; ehci@48064800 { From owner-svn-soc-all@FreeBSD.ORG Fri Aug 3 16:43:37 2012 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id 8DBEA106566B for ; Fri, 3 Aug 2012 16:43:35 +0000 (UTC) (envelope-from jhagewood@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Fri, 03 Aug 2012 16:43:35 +0000 Date: Fri, 03 Aug 2012 16:43:35 +0000 From: jhagewood@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20120803164335.8DBEA106566B@hub.freebsd.org> Cc: Subject: socsvn commit: r240045 - in soc2012/jhagewood/diff: . diff X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 03 Aug 2012 16:43:37 -0000 Author: jhagewood Date: Fri Aug 3 16:43:34 2012 New Revision: 240045 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=240045 Log: Modified: soc2012/jhagewood/diff/diff/diff.c soc2012/jhagewood/diff/diff/diff.h soc2012/jhagewood/diff/diff/diffreg.c soc2012/jhagewood/diff/hagewood-diff.patch Modified: soc2012/jhagewood/diff/diff/diff.c ============================================================================== --- soc2012/jhagewood/diff/diff/diff.c Fri Aug 3 15:58:05 2012 (r240044) +++ soc2012/jhagewood/diff/diff/diff.c Fri Aug 3 16:43:34 2012 (r240045) @@ -210,15 +210,13 @@ int ch, lastch, gotstdin, prevoptind, newarg; int oargc; + filebehave = FILE_NORMAL; /* Check what is the program name of the binary. In this way we can have all the funcionalities in one binary without the need of scripting and using ugly hacks. */ pn = getprogname(); if (pn[0] == 'z') { filebehave = FILE_GZIP; - pn += 1; - } else { - filebehave = FILE_NORMAL; } oargv = argv; @@ -700,14 +698,14 @@ { (void)fprintf(stderr, - "usage: diff [-abdilpqTtw] [-I pattern] [-c | -e | -f | -n | -u]\n" + "usage: %s [-abdilpqTtw] [-I pattern] [-c | -e | -f | -n | -u]\n" " [-L label] file1 file2\n" - " diff [-abdilpqTtw] [-I pattern] [-L label] -C number file1 file2\n" - " diff [-abdilqtw] [-I pattern] -D string file1 file2\n" - " diff [-abdilpqTtw] [-I pattern] [-L label] -U number file1 file2\n" - " diff [-abdilNPpqrsTtw] [-I pattern] [-c | -e | -f | -n | -u]\n" + " [-abdilpqTtw] [-I pattern] [-L label] -C number file1 file2\n" + " [-abdilqtw] [-I pattern] -D string file1 file2\n" + " [-abdilpqTtw] [-I pattern] [-L label] -U number file1 file2\n" + " [-abdilNPpqrsTtw] [-I pattern] [-c | -e | -f | -n | -u]\n" " [-L label] [-S name] [-X file] [-x pattern] dir1 dir2\n" - " diff [-v]\n"); + " [-v]\n", getprogname()); exit(1); } Modified: soc2012/jhagewood/diff/diff/diff.h ============================================================================== --- soc2012/jhagewood/diff/diff/diff.h Fri Aug 3 15:58:05 2012 (r240044) +++ soc2012/jhagewood/diff/diff/diff.h Fri Aug 3 16:43:34 2012 (r240045) @@ -102,3 +102,5 @@ void diffdir(char *, char *); void print_only(const char *, size_t, const char *); void print_status(int, char *, char *, char *); + +FILE *decompressfile(char *, char *); Modified: soc2012/jhagewood/diff/diff/diffreg.c ============================================================================== --- soc2012/jhagewood/diff/diff/diffreg.c Fri Aug 3 15:58:05 2012 (r240044) +++ soc2012/jhagewood/diff/diff/diffreg.c Fri Aug 3 16:43:34 2012 (r240045) @@ -99,7 +99,6 @@ # define TIMESPEC_NS(timespec) 0 #endif -#define MAX_INT 2147483647 #define MAX_CHECK 768 /* 3 kilobytes of chars. */ /* @@ -306,14 +305,10 @@ int diffreg(char *ofile1, char *ofile2, int flags) { - char *buf = ""; char *file1 = ofile1; char *file2 = ofile2; FILE *f1 = NULL; FILE *f2 = NULL; - gzFile *gz1 = NULL; - gzFile *gz2 = NULL; - int bytesread; int rval = D_SAME; int i, ostdout = -1; pid_t pid = -1; @@ -344,10 +339,7 @@ if (filebehave == FILE_NORMAL) f1 = fopen(file1, "r"); if (filebehave == FILE_GZIP) { - if (gz1 = gzopen(file1, "r") == Z_NULL) - err(1, "Could not open compressed file %s.", file1); - gzread(gz1, buf, MAX_INT); - f1 = fdopen(buf, "r"); + f1 = decompressfile(file1, "r"); } } } @@ -373,10 +365,7 @@ if (filebehave == FILE_NORMAL) f2 = fopen(file2, "r"); if (filebehave == FILE_GZIP) - if(gz2 = gzopen(file2, "r") == Z_NULL) - err(1, "Could not open compressed file %s.", file2); - gzread(gz2, buf, MAX_INT); - f2 = fdopen(buf, "r"); + f2 = decompressfile(file2, "r"); } } if (f2 == NULL) { Modified: soc2012/jhagewood/diff/hagewood-diff.patch ============================================================================== --- soc2012/jhagewood/diff/hagewood-diff.patch Fri Aug 3 15:58:05 2012 (r240044) +++ soc2012/jhagewood/diff/hagewood-diff.patch Fri Aug 3 16:43:34 2012 (r240045) @@ -12,9 +12,87 @@ +CFLAGS+= -std=c99 -Wall -pedantic -lz .include +diff -rupN diff-orig/decompress.c diff/decompress.c +--- diff-orig/decompress.c 1969-12-31 19:00:00.000000000 -0500 ++++ diff/decompress.c 2012-08-03 04:53:21.000000000 -0400 +@@ -0,0 +1,74 @@ ++/* ++ * Copyright (c) 2012 Jesse Hagewood ++ * All rights reserved. ++ * ++ * Redistribution and use in source and binary forms, with or without ++ * modification, are permitted provided that the following conditions ++ * are met: ++ * 1. Redistributions of source code must retain the above copyright ++ * notice, this list of conditions and the following disclaimer. ++ * 2. Redistributions in binary form must reproduce the above copyright ++ * notice, this list of conditions and the following disclaimer in the ++ * documentation and/or other materials provided with the distribution. ++ * ++ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ++ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ++ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ++ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE ++ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ++ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS ++ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ++ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT ++ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY ++ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ++ * SUCH DAMAGE. ++ */ ++ ++#if 0 ++#ifndef lint ++static char sccsid[] = "@(#)decompress.c 6/6/93"; ++#endif ++#endif /* not lint */ ++#include ++__FBSDID("$FreeBSD$"); ++ ++#include ++#include ++#include ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#ifndef WITHOUT_BZIP2 ++#include ++#endif ++ ++#include "diff.h" ++#include "pathnames.h" ++ ++#define MAXBUFSIZE (32 * 1024) ++ ++/* Decompresses a gzip file and returns a regular FILE. */ ++FILE * ++decompressfile(char *filename, char *mode) { ++ ++ FILE *file; ++ char *buf; ++ gzFile comprfile; ++ ++ if (comprfile = gzopen(filename, mode) == Z_NULL) ++ err(1, "Could not open compressed file %s.", filename); ++ gzread(comprfile, buf, MAXBUFSIZE); ++ file = fdopen(buf, mode); ++ ++ return file; ++} diff -rupN diff-orig/diff.c diff/diff.c --- diff-orig/diff.c 2012-07-26 03:11:00.000000000 -0400 -+++ diff/diff.c 2012-07-26 03:11:00.000000000 -0400 ++++ diff/diff.c 2012-08-03 04:03:45.000000000 -0400 @@ -1,4 +1,4 @@ -/*- +/* @@ -71,7 +149,7 @@ /* Options which exceed manageable alphanumeric assignments */ -@@ -69,107 +68,163 @@ enum +@@ -69,107 +68,161 @@ enum OPT_STRIPCR, OPT_NORMAL, OPT_LEFTC, @@ -281,15 +359,13 @@ + int ch, lastch, gotstdin, prevoptind, newarg; + int oargc; + ++ filebehave = FILE_NORMAL; + /* Check what is the program name of the binary. In this + way we can have all the funcionalities in one binary + without the need of scripting and using ugly hacks. */ + pn = getprogname(); + if (pn[0] == 'z') { + filebehave = FILE_GZIP; -+ pn += 1; -+ } else { -+ filebehave = FILE_NORMAL; + } + oargv = argv; @@ -299,7 +375,7 @@ lastch = '\0'; prevoptind = 1; -@@ -197,6 +252,7 @@ main(int argc, char **argv) +@@ -197,6 +250,7 @@ main(int argc, char **argv) break; case 'C': case 'c': @@ -307,7 +383,7 @@ format = D_CONTEXT; if (optarg != NULL) { l = strtol(optarg, &ep, 10); -@@ -213,6 +269,9 @@ main(int argc, char **argv) +@@ -213,6 +267,9 @@ main(int argc, char **argv) case 'd': dflag = 1; break; @@ -317,7 +393,7 @@ case 'e': format = D_EDIT; break; -@@ -284,7 +343,7 @@ main(int argc, char **argv) +@@ -284,7 +341,7 @@ main(int argc, char **argv) case 'v': printf("FreeBSD diff 2.8.7\n"); exit(0); @@ -326,7 +402,7 @@ wflag = 1; break; case 'X': -@@ -296,15 +355,48 @@ main(int argc, char **argv) +@@ -296,15 +353,48 @@ main(int argc, char **argv) case 'y': yflag = 1; break; @@ -383,7 +459,7 @@ case OPT_STRIPCR: strip_cr=1; break; -@@ -315,11 +407,10 @@ main(int argc, char **argv) +@@ -315,11 +405,10 @@ main(int argc, char **argv) ignore_file_case = 0; break; case OPT_HELP: @@ -397,7 +473,7 @@ break; default: usage(); -@@ -328,22 +419,22 @@ main(int argc, char **argv) +@@ -328,22 +417,22 @@ main(int argc, char **argv) lastch = ch; newarg = optind != prevoptind; prevoptind = optind; @@ -426,7 +502,7 @@ } /* -@@ -380,7 +471,10 @@ main(int argc, char **argv) +@@ -380,7 +469,10 @@ main(int argc, char **argv) set_argstr(oargv, argv); if (S_ISDIR(stb1.st_mode) && S_ISDIR(stb2.st_mode)) { if (format == D_IFDEF) @@ -438,7 +514,7 @@ diffdir(argv[0], argv[1]); } else { if (S_ISDIR(stb1.st_mode)) { -@@ -393,8 +487,26 @@ main(int argc, char **argv) +@@ -393,8 +485,26 @@ main(int argc, char **argv) if (stat(argv[1], &stb2) < 0) err(2, "%s", argv[1]); } @@ -467,7 +543,7 @@ } exit(status); } -@@ -402,11 +514,10 @@ main(int argc, char **argv) +@@ -402,11 +512,10 @@ main(int argc, char **argv) void * emalloc(size_t n) { @@ -480,7 +556,7 @@ if ((p = malloc(n)) == NULL) errx(2, NULL); return (p); -@@ -415,7 +526,7 @@ emalloc(size_t n) +@@ -415,7 +524,7 @@ emalloc(size_t n) void * erealloc(void *p, size_t n) { @@ -489,7 +565,7 @@ if (n == 0) errx(2, NULL); -@@ -431,13 +542,12 @@ erealloc(void *p, size_t n) +@@ -431,13 +540,12 @@ erealloc(void *p, size_t n) int easprintf(char **ret, const char *fmt, ...) { @@ -505,7 +581,7 @@ if (len < 0 || *ret == NULL) errx(2, NULL); return (len); -@@ -446,20 +556,21 @@ easprintf(char **ret, const char *fmt, . +@@ -446,20 +554,21 @@ easprintf(char **ret, const char *fmt, . char * estrdup(const char *str) { @@ -532,7 +608,7 @@ argsize = 4 + *ave - *av + 1; diffargs = emalloc(argsize); -@@ -475,12 +586,12 @@ set_argstr(char **av, char **ave) +@@ -475,12 +584,12 @@ set_argstr(char **av, char **ave) /* * Read in an excludes file and push each line. */ @@ -549,7 +625,7 @@ if (strcmp(file, "-") == 0) fp = stdin; -@@ -501,7 +612,7 @@ read_excludes_file(char *file) +@@ -501,7 +610,7 @@ read_excludes_file(char *file) /* * Push a pattern onto the excludes list. */ @@ -558,7 +634,7 @@ push_excludes(char *pattern) { struct excludes *entry; -@@ -512,10 +623,10 @@ push_excludes(char *pattern) +@@ -512,10 +621,10 @@ push_excludes(char *pattern) excludes_list = entry; } @@ -571,7 +647,7 @@ if (ignore_pats == NULL) ignore_pats = estrdup(pattern); -@@ -531,6 +642,7 @@ push_ignore_pats(char *pattern) +@@ -531,6 +640,7 @@ push_ignore_pats(char *pattern) void print_only(const char *path, size_t dirlen, const char *entry) { @@ -579,7 +655,7 @@ if (dirlen > 1) dirlen--; printf("Only in %.*s: %s\n", (int)dirlen, path, entry); -@@ -539,52 +651,54 @@ print_only(const char *path, size_t dirl +@@ -539,61 +649,63 @@ print_only(const char *path, size_t dirl void print_status(int val, char *path1, char *path2, char *entry) { @@ -644,18 +720,27 @@ { + (void)fprintf(stderr, - "usage: diff [-abdilpqTtw] [-I pattern] [-c | -e | -f | -n | -u]\n" +- "usage: diff [-abdilpqTtw] [-I pattern] [-c | -e | -f | -n | -u]\n" ++ "usage: %s [-abdilpqTtw] [-I pattern] [-c | -e | -f | -n | -u]\n" " [-L label] file1 file2\n" -@@ -595,5 +709,5 @@ usage(void) +- " diff [-abdilpqTtw] [-I pattern] [-L label] -C number file1 file2\n" +- " diff [-abdilqtw] [-I pattern] -D string file1 file2\n" +- " diff [-abdilpqTtw] [-I pattern] [-L label] -U number file1 file2\n" +- " diff [-abdilNPpqrsTtw] [-I pattern] [-c | -e | -f | -n | -u]\n" ++ " [-abdilpqTtw] [-I pattern] [-L label] -C number file1 file2\n" ++ " [-abdilqtw] [-I pattern] -D string file1 file2\n" ++ " [-abdilpqTtw] [-I pattern] [-L label] -U number file1 file2\n" ++ " [-abdilNPpqrsTtw] [-I pattern] [-c | -e | -f | -n | -u]\n" " [-L label] [-S name] [-X file] [-x pattern] dir1 dir2\n" - " diff [-v]\n"); +- " diff [-v]\n"); ++ " [-v]\n", getprogname()); - exit(2); + exit(1); } diff -rupN diff-orig/diff.h diff/diff.h --- diff-orig/diff.h 2012-07-26 03:11:00.000000000 -0400 -+++ diff/diff.h 2012-07-26 03:11:00.000000000 -0400 ++++ diff/diff.h 2012-08-03 04:51:29.000000000 -0400 @@ -48,6 +48,8 @@ #define D_NREVERSE 5 /* Reverse ed script with numbered lines and no trailing . */ @@ -691,6 +776,12 @@ extern char ignore_file_case; extern char *start, *ifdefname, *diffargs, *label[2], *ignore_pats; extern struct stat stb1, stb2; +@@ -93,3 +102,5 @@ void *erealloc(void *, size_t); + void diffdir(char *, char *); + void print_only(const char *, size_t, const char *); + void print_status(int, char *, char *, char *); ++ ++FILE *decompressfile(char *, char *); diff -rupN diff-orig/diffdir.c diff/diffdir.c --- diff-orig/diffdir.c 2012-07-26 03:11:00.000000000 -0400 +++ diff/diffdir.c 2012-07-26 03:11:00.000000000 -0400 @@ -802,7 +893,7 @@ if (stat(path1, &stb1) != 0) { diff -rupN diff-orig/diffreg.c diff/diffreg.c --- diff-orig/diffreg.c 2012-07-26 03:11:00.000000000 -0400 -+++ diff/diffreg.c 2012-07-31 19:11:25.000000000 -0400 ++++ diff/diffreg.c 2012-08-03 05:01:28.000000000 -0400 @@ -62,15 +62,13 @@ * @(#)diffreg.c 8.1 (Berkeley) 6/6/93 */ @@ -823,7 +914,7 @@ #include #include -@@ -86,10 +84,24 @@ __FBSDID("$FreeBSD"); +@@ -86,10 +84,23 @@ __FBSDID("$FreeBSD"); #include #include #include @@ -842,13 +933,12 @@ +# define TIMESPEC_NS(timespec) 0 +#endif + -+#define MAX_INT 2147483647 +#define MAX_CHECK 768 /* 3 kilobytes of chars. */ + /* * diff - compare two files. */ -@@ -181,47 +193,47 @@ struct context_vec { +@@ -181,47 +192,47 @@ struct context_vec { }; static FILE *opentemp(const char *); @@ -931,7 +1021,7 @@ static struct line *sfile[2]; /* shortened by pruning common prefix/suffix */ static u_char *chrtran; /* translation table for case-folding */ static struct context_vec *context_vec_start; -@@ -294,13 +306,17 @@ u_char cup2low[256] = { +@@ -294,13 +305,13 @@ u_char cup2low[256] = { int diffreg(char *ofile1, char *ofile2, int flags) { @@ -942,21 +1032,17 @@ - int rval = D_SAME; - int i, ostdout = -1; - pid_t pid = -1; -+ char *buf = ""; + char *file1 = ofile1; + char *file2 = ofile2; + FILE *f1 = NULL; + FILE *f2 = NULL; -+ gzFile *gz1 = NULL; -+ gzFile *gz2 = NULL; -+ int bytesread; + int rval = D_SAME; + int i, ostdout = -1; + pid_t pid = -1; anychange = 0; lastline = 0; -@@ -310,7 +326,7 @@ diffreg(char *ofile1, char *ofile2, int +@@ -310,7 +321,7 @@ diffreg(char *ofile1, char *ofile2, int if (S_ISDIR(stb1.st_mode) != S_ISDIR(stb2.st_mode)) return (S_ISDIR(stb1.st_mode) ? D_MISMATCH1 : D_MISMATCH2); if (strcmp(file1, "-") == 0 && strcmp(file2, "-") == 0) @@ -965,7 +1051,7 @@ if (flags & D_EMPTY1) f1 = fopen(_PATH_DEVNULL, "r"); -@@ -320,17 +336,25 @@ diffreg(char *ofile1, char *ofile2, int +@@ -320,17 +331,22 @@ diffreg(char *ofile1, char *ofile2, int fstat(fileno(f1), &stb1) < 0) { warn("%s", file1); status |= 2; @@ -980,10 +1066,7 @@ + if (filebehave == FILE_NORMAL) + f1 = fopen(file1, "r"); + if (filebehave == FILE_GZIP) { -+ if (gz1 = gzopen(file1, "r") == Z_NULL) -+ err(1, "Could not open compressed file %s.", file1); -+ gzread(gz1, buf, MAX_INT); -+ f1 = fdopen(buf, "r"); ++ f1 = decompressfile(file1, "r"); + } + } } @@ -995,7 +1078,7 @@ } if (flags & D_EMPTY2) -@@ -341,34 +365,40 @@ diffreg(char *ofile1, char *ofile2, int +@@ -341,34 +357,37 @@ diffreg(char *ofile1, char *ofile2, int fstat(fileno(f2), &stb2) < 0) { warn("%s", file2); status |= 2; @@ -1010,10 +1093,7 @@ + if (filebehave == FILE_NORMAL) + f2 = fopen(file2, "r"); + if (filebehave == FILE_GZIP) -+ if(gz2 = gzopen(file2, "r") == Z_NULL) -+ err(1, "Could not open compressed file %s.", file2); -+ gzread(gz2, buf, MAX_INT); -+ f2 = fdopen(buf, "r"); ++ f2 = decompressfile(file2, "r"); + } } if (f2 == NULL) { @@ -1045,7 +1125,7 @@ } if (lflag) { /* redirect stdout to pr */ -@@ -452,7 +482,11 @@ diffreg(char *ofile1, char *ofile2, int +@@ -452,7 +471,11 @@ diffreg(char *ofile1, char *ofile2, int } waitpid(pid, &wstatus, 0); } @@ -1058,7 +1138,7 @@ if (anychange) { status |= 1; if (rval == D_SAME) -@@ -477,8 +511,8 @@ closem: +@@ -477,8 +500,8 @@ closem: static int files_differ(FILE *f1, FILE *f2, int flags) { @@ -1069,7 +1149,7 @@ if ((flags & (D_EMPTY1|D_EMPTY2)) || stb1.st_size != stb2.st_size || (stb1.st_mode & S_IFMT) != (stb2.st_mode & S_IFMT)) -@@ -503,9 +537,9 @@ files_differ(FILE *f1, FILE *f2, int fla +@@ -503,9 +526,9 @@ files_differ(FILE *f1, FILE *f2, int fla static FILE * opentemp(const char *file) { @@ -1082,7 +1162,7 @@ if (strcmp(file, "-") == 0) ifd = STDIN_FILENO; -@@ -541,7 +575,7 @@ opentemp(const char *file) +@@ -541,7 +564,7 @@ opentemp(const char *file) char * splice(char *dir, char *file) { @@ -1091,7 +1171,7 @@ if ((tail = strrchr(file, '/')) == NULL) tail = file; -@@ -555,8 +589,8 @@ static void +@@ -555,8 +578,8 @@ static void prepare(int i, FILE *fd, off_t filesize) { struct line *p; @@ -1102,7 +1182,7 @@ rewind(fd); -@@ -579,7 +613,7 @@ prepare(int i, FILE *fd, off_t filesize) +@@ -579,7 +602,7 @@ prepare(int i, FILE *fd, off_t filesize) static void prune(void) { @@ -1111,7 +1191,7 @@ for (pref = 0; pref < len[0] && pref < len[1] && file[0][pref + 1].value == file[1][pref + 1].value; -@@ -600,7 +634,7 @@ prune(void) +@@ -600,7 +623,7 @@ prune(void) static void equiv(struct line *a, int n, struct line *b, int m, int *c) { @@ -1120,7 +1200,7 @@ i = j = 1; while (i <= n && j <= m) { -@@ -629,7 +663,7 @@ equiv(struct line *a, int n, struct line +@@ -629,7 +652,7 @@ equiv(struct line *a, int n, struct line static int isqrt(int n) { @@ -1129,7 +1209,7 @@ if (n == 0) return (0); -@@ -647,9 +681,9 @@ isqrt(int n) +@@ -647,9 +670,9 @@ isqrt(int n) static int stone(int *a, int n, int *b, int *c) { @@ -1142,7 +1222,7 @@ const u_int bound = dflag ? UINT_MAX : MAX(256, isqrt(n)); k = 0; -@@ -705,7 +739,7 @@ newcand(int x, int y, int pred) +@@ -705,7 +728,7 @@ newcand(int x, int y, int pred) static int search(int *c, int k, int y) { @@ -1151,7 +1231,7 @@ if (clist[c[k]].y < y) /* quick look for typical case */ return (k + 1); -@@ -730,7 +764,7 @@ static void +@@ -730,7 +753,7 @@ static void unravel(int p) { struct cand *q; @@ -1160,7 +1240,7 @@ for (i = 0; i <= len[0]; i++) J[i] = i <= pref ? i : -@@ -748,9 +782,10 @@ unravel(int p) +@@ -748,9 +771,10 @@ unravel(int p) static void check(char *file1, FILE *f1, char *file2, FILE *f2) { @@ -1174,7 +1254,7 @@ rewind(f1); rewind(f2); j = 1; -@@ -766,7 +801,7 @@ check(char *file1, FILE *f1, char *file2 +@@ -766,7 +790,7 @@ check(char *file1, FILE *f1, char *file2 ixnew[j] = ctnew += skipline(f2); j++; } @@ -1183,7 +1263,7 @@ for (;;) { c = getc(f1); d = getc(f2); -@@ -781,6 +816,7 @@ check(char *file1, FILE *f1, char *file2 +@@ -781,6 +805,7 @@ check(char *file1, FILE *f1, char *file2 } ctold++; ctnew++; @@ -1191,7 +1271,7 @@ if (bflag && isspace(c) && isspace(d)) { do { if (c == '\n') -@@ -792,6 +828,7 @@ check(char *file1, FILE *f1, char *file2 +@@ -792,6 +817,7 @@ check(char *file1, FILE *f1, char *file2 break; ctnew++; } while (isspace(d = getc(f2))); @@ -1199,7 +1279,7 @@ } else if (wflag) { while (isspace(c) && c != '\n') { c = getc(f1); -@@ -801,31 +838,55 @@ check(char *file1, FILE *f1, char *file2 +@@ -801,31 +827,55 @@ check(char *file1, FILE *f1, char *file2 d = getc(f2); ctnew++; } @@ -1276,7 +1356,7 @@ if (chrtran[c] != chrtran[d]) { jackpot++; J[i] = 0; -@@ -872,7 +933,7 @@ static void +@@ -872,7 +922,7 @@ static void sort(struct line *a, int n) { struct line *ai, *aim, w; @@ -1285,7 +1365,7 @@ if (n == 0) return; -@@ -916,7 +977,7 @@ unsort(struct line *f, int l, int *b) +@@ -916,7 +966,7 @@ unsort(struct line *f, int l, int *b) static int skipline(FILE *f) { @@ -1294,7 +1374,7 @@ for (i = 1; (c = getc(f)) != '\n' && c != EOF; i++) continue; -@@ -926,7 +987,7 @@ skipline(FILE *f) +@@ -926,7 +976,7 @@ skipline(FILE *f) static void output(char *file1, FILE *f1, char *file2, FILE *f2, int flags) { @@ -1303,7 +1383,7 @@ rewind(f1); rewind(f2); -@@ -965,7 +1026,7 @@ output(char *file1, FILE *f1, char *file +@@ -965,7 +1015,7 @@ output(char *file1, FILE *f1, char *file #define c i0 if ((c = getc(f1)) == EOF) return; @@ -1312,7 +1392,7 @@ } #undef c } -@@ -980,6 +1041,7 @@ output(char *file1, FILE *f1, char *file +@@ -980,6 +1030,7 @@ output(char *file1, FILE *f1, char *file static void range(int a, int b, char *separator) { @@ -1320,7 +1400,7 @@ printf("%d", a > b ? b : a); if (a < b) printf("%s%d", separator, b); -@@ -988,6 +1050,7 @@ range(int a, int b, char *separator) +@@ -988,6 +1039,7 @@ range(int a, int b, char *separator) static void uni_range(int a, int b) { @@ -1328,7 +1408,7 @@ if (a < b) printf("%d,%d", a, b - a + 1); else if (a == b) -@@ -999,22 +1062,22 @@ uni_range(int a, int b) +@@ -999,22 +1051,22 @@ uni_range(int a, int b) static char * preadline(int fd, size_t len, off_t off) { @@ -1355,7 +1435,7 @@ ret = regexec(&ignore_re, line, 0, NULL, 0); free(line); -@@ -1032,10 +1095,10 @@ static void +@@ -1032,10 +1084,10 @@ static void change(char *file1, FILE *f1, char *file2, FILE *f2, int a, int b, int c, int d, int *pflags) { @@ -1369,7 +1449,7 @@ if (format != D_IFDEF && a > b && c > d) return; if (ignore_pats != NULL) { -@@ -1050,7 +1113,7 @@ restart: +@@ -1050,7 +1102,7 @@ restart: line = preadline(fileno(f1), ixold[i] - ixold[i - 1], ixold[i - 1]); if (!ignoreline(line)) @@ -1378,7 +1458,7 @@ } } if (a > b || c <= d) { /* Changes and inserts. */ -@@ -1058,12 +1121,12 @@ restart: +@@ -1058,12 +1110,12 @@ restart: line = preadline(fileno(f2), ixnew[i] - ixnew[i - 1], ixnew[i - 1]); if (!ignoreline(line)) @@ -1393,7 +1473,7 @@ if (*pflags & D_HEADER) { printf("%s %s %s\n", diffargs, file1, file2); *pflags &= ~D_HEADER; -@@ -1113,15 +1176,15 @@ proceed: +@@ -1113,15 +1165,15 @@ proceed: case D_NORMAL: case D_EDIT: range(a, b, ","); @@ -1413,7 +1493,7 @@ break; case D_NREVERSE: if (a > b) -@@ -1137,7 +1200,7 @@ proceed: +@@ -1137,7 +1189,7 @@ proceed: if (format == D_NORMAL || format == D_IFDEF) { fetch(ixold, a, b, f1, '<', 1); if (a <= b && c <= d && format == D_NORMAL) @@ -1422,7 +1502,7 @@ } i = fetch(ixnew, c, d, f2, format == D_NORMAL ? '>' : '\0', 0); if (i != 0 && format == D_EDIT) { -@@ -1148,14 +1211,14 @@ proceed: +@@ -1148,14 +1200,14 @@ proceed: * it. We have to add a substitute command to change this * back and restart where we left off. */ @@ -1440,7 +1520,7 @@ if (inifdef) { printf("#endif /* %s */\n", ifdefname); inifdef = 0; -@@ -1165,8 +1228,8 @@ proceed: +@@ -1165,8 +1217,8 @@ proceed: static int fetch(long *f, int a, int b, FILE *lb, int ch, int oldfile) { @@ -1451,7 +1531,7 @@ /* * When doing #ifdef's, copy down to current line -@@ -1177,7 +1240,7 @@ fetch(long *f, int a, int b, FILE *lb, i +@@ -1177,7 +1229,7 @@ fetch(long *f, int a, int b, FILE *lb, i /* print through if append (a>b), else to (nb: 0 vs 1 orig) */ nc = f[a > b ? b : a - 1] - curpos; for (i = 0; i < nc; i++) @@ -1460,7 +1540,7 @@ } if (a > b) return (0); -@@ -1197,12 +1260,12 @@ fetch(long *f, int a, int b, FILE *lb, i +@@ -1197,12 +1249,12 @@ fetch(long *f, int a, int b, FILE *lb, i fseek(lb, f[i - 1], SEEK_SET); nc = f[i] - f[i - 1]; if (format != D_IFDEF && ch != '\0') { @@ -1476,7 +1556,7 @@ } col = 0; for (j = 0, lastc = '\0'; j < nc; j++, lastc = c) { -@@ -1211,13 +1274,13 @@ fetch(long *f, int a, int b, FILE *lb, i +@@ -1211,13 +1263,13 @@ fetch(long *f, int a, int b, FILE *lb, i format == D_NREVERSE) warnx("No newline at end of file"); else @@ -1492,7 +1572,7 @@ } while (++col < newcol); } else { if (format == D_EDIT && j == 1 && c == '\n' -@@ -1229,10 +1292,10 @@ fetch(long *f, int a, int b, FILE *lb, i +@@ -1229,10 +1281,10 @@ fetch(long *f, int a, int b, FILE *lb, i * giving the caller an offset * from which to restart. */ @@ -1505,7 +1585,7 @@ col++; } } -@@ -1246,8 +1309,8 @@ fetch(long *f, int a, int b, FILE *lb, i +@@ -1246,8 +1298,8 @@ fetch(long *f, int a, int b, FILE *lb, i static int readhash(FILE *f) { @@ -1516,7 +1596,7 @@ sum = 1; space = 0; -@@ -1305,20 +1368,28 @@ readhash(FILE *f) +@@ -1305,20 +1357,28 @@ readhash(FILE *f) return (sum == 0 ? 1 : sum); } @@ -1552,7 +1632,7 @@ return (1); } -@@ -1327,10 +1398,10 @@ asciifile(FILE *f) +@@ -1327,10 +1387,10 @@ asciifile(FILE *f) static char * match_function(const long *f, int pos, FILE *file) { @@ -1567,7 +1647,7 @@ lastline = pos; while (pos > last) { -@@ -1342,7 +1413,6 @@ match_function(const long *f, int pos, F +@@ -1342,7 +1402,6 @@ match_function(const long *f, int pos, F if (nc > 0) { buf[nc] = '\0'; buf[strcspn(buf, "\n")] = '\0'; @@ -1575,7 +1655,7 @@ if (isalpha(buf[0]) || buf[0] == '_' || buf[0] == '$') { if (begins_with(buf, "private:")) { if (!state) -@@ -1373,9 +1443,9 @@ static void +@@ -1373,9 +1432,9 @@ static void dump_context_vec(FILE *f1, FILE *f2) { struct context_vec *cvp = context_vec_start; @@ -1588,7 +1668,7 @@ if (context_vec_start > context_vec_ptr) return; -@@ -1390,8 +1460,8 @@ dump_context_vec(FILE *f1, FILE *f2) +@@ -1390,8 +1449,8 @@ dump_context_vec(FILE *f1, FILE *f2) if (pflag) { f = match_function(ixold, lowa-1, f1); if (f != NULL) { @@ -1599,7 +1679,7 @@ } } printf("\n*** "); -@@ -1478,9 +1548,9 @@ static void +@@ -1478,9 +1537,9 @@ static void dump_unified_vec(FILE *f1, FILE *f2) { struct context_vec *cvp = context_vec_start; @@ -1612,7 +1692,7 @@ if (context_vec_start > context_vec_ptr) return; -@@ -1491,19 +1561,19 @@ dump_unified_vec(FILE *f1, FILE *f2) +@@ -1491,19 +1550,19 @@ dump_unified_vec(FILE *f1, FILE *f2) lowc = MAX(1, cvp->c - context); upd = MIN(len[1], context_vec_ptr->d + context); @@ -1638,7 +1718,7 @@ /* * Output changes in "unified" diff format--the old and new lines -@@ -1551,16 +1621,43 @@ dump_unified_vec(FILE *f1, FILE *f2) +@@ -1551,16 +1610,43 @@ dump_unified_vec(FILE *f1, FILE *f2) static void print_header(const char *file1, const char *file2) { From owner-svn-soc-all@FreeBSD.ORG Fri Aug 3 16:45:09 2012 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id C7CBD106566B for ; Fri, 3 Aug 2012 16:45:08 +0000 (UTC) (envelope-from jhagewood@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Fri, 03 Aug 2012 16:45:08 +0000 Date: Fri, 03 Aug 2012 16:45:08 +0000 From: jhagewood@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20120803164508.C7CBD106566B@hub.freebsd.org> Cc: Subject: socsvn commit: r240046 - soc2012/jhagewood/diff/diff X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 03 Aug 2012 16:45:09 -0000 Author: jhagewood Date: Fri Aug 3 16:45:08 2012 New Revision: 240046 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=240046 Log: functions for decompression Added: soc2012/jhagewood/diff/diff/decompress.c Added: soc2012/jhagewood/diff/diff/decompress.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2012/jhagewood/diff/diff/decompress.c Fri Aug 3 16:45:08 2012 (r240046) @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2012 Jesse Hagewood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#if 0 +#ifndef lint +static char sccsid[] = "@(#)decompress.c 6/6/93"; +#endif +#endif /* not lint */ +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifndef WITHOUT_BZIP2 +#include +#endif + +#include "diff.h" +#include "pathnames.h" + +#define MAXBUFSIZE (32 * 1024) + +/* Decompresses a gzip file and returns a regular FILE. */ +FILE * +decompressfile(char *filename, char *mode) { + + FILE *file; + char *buf; + gzFile comprfile; + + if (comprfile = gzopen(filename, mode) == Z_NULL) + err(1, "Could not open compressed file %s.", filename); + gzread(comprfile, buf, MAXBUFSIZE); + file = fdopen(buf, mode); + + return file; +} From owner-svn-soc-all@FreeBSD.ORG Fri Aug 3 18:12:52 2012 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id 2DD2B1065670 for ; Fri, 3 Aug 2012 18:12:50 +0000 (UTC) (envelope-from syuu@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Fri, 03 Aug 2012 18:12:50 +0000 Date: Fri, 03 Aug 2012 18:12:50 +0000 From: syuu@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20120803181250.2DD2B1065670@hub.freebsd.org> Cc: Subject: socsvn commit: r240050 - soc2012/syuu/bhyve-bios/lib/libbiosemul X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 03 Aug 2012 18:12:52 -0000 Author: syuu Date: Fri Aug 3 18:12:49 2012 New Revision: 240050 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=240050 Log: fix incorrect drive number, fix incorrect 'vm_set_register' to 'vm_get_register' Modified: soc2012/syuu/bhyve-bios/lib/libbiosemul/biosemul.c soc2012/syuu/bhyve-bios/lib/libbiosemul/debug.c soc2012/syuu/bhyve-bios/lib/libbiosemul/int13.c Modified: soc2012/syuu/bhyve-bios/lib/libbiosemul/biosemul.c ============================================================================== --- soc2012/syuu/bhyve-bios/lib/libbiosemul/biosemul.c Fri Aug 3 17:04:41 2012 (r240049) +++ soc2012/syuu/bhyve-bios/lib/libbiosemul/biosemul.c Fri Aug 3 18:12:49 2012 (r240050) @@ -109,7 +109,7 @@ static struct vm86_init_args kargs; #endif -#define HDISK_CYL 130 +#define HDISK_CYL 2610 #define HDISK_HEAD 255 #define HDISK_TRACK 63 #define HDISK_FILE "/home/syuu/test.img" @@ -121,16 +121,16 @@ ivec = (u_int32_t *)lomem_addr; debugf = stderr; -#if 0 - debug_set(0); /* debug any D_TRAPS without intnum */ + debug_set(0xfffffff); +#if 0 /* Call init functions */ if (raw_kbd) console_init(); init_io_port_handlers(); #endif bios_init(); - init_hdisk(3, HDISK_CYL, HDISK_HEAD, HDISK_TRACK, HDISK_FILE, NULL); + init_hdisk(2, HDISK_CYL, HDISK_HEAD, HDISK_TRACK, HDISK_FILE, NULL); #if 0 cpu_init(); kbd_init(); @@ -830,67 +830,83 @@ int error = 0; if ((orig->r.gs.r_rx != modified->r.gs.r_rx) && + printf("%s gs:%lx\n", __func__, modified->r.gs.r_rx) && (error = vm_set_register(ctx, vcpu, VM_REG_GUEST_GS, modified->r.gs.r_rx)) != 0) goto done; if ((orig->r.fs.r_rx != modified->r.fs.r_rx) && - (error = vm_get_register(ctx, vcpu, VM_REG_GUEST_FS, &modified->r.fs.r_rx)) != 0) + printf("%s fs:%lx\n", __func__, modified->r.fs.r_rx) && + (error = vm_set_register(ctx, vcpu, VM_REG_GUEST_FS, modified->r.fs.r_rx)) != 0) goto done; if ((orig->r.es.r_rx != modified->r.es.r_rx) && - (error = vm_get_register(ctx, vcpu, VM_REG_GUEST_ES, &modified->r.es.r_rx)) != 0) + printf("%s es:%lx\n", __func__, modified->r.es.r_rx) && + (error = vm_set_register(ctx, vcpu, VM_REG_GUEST_ES, modified->r.es.r_rx)) != 0) goto done; if ((orig->r.ds.r_rx != modified->r.ds.r_rx) && - (error = vm_get_register(ctx, vcpu, VM_REG_GUEST_DS, &modified->r.es.r_rx)) != 0) + printf("%s ds:%lx\n", __func__, modified->r.ds.r_rx) && + (error = vm_set_register(ctx, vcpu, VM_REG_GUEST_DS, modified->r.es.r_rx)) != 0) goto done; if ((orig->r.edi.r_rx != modified->r.edi.r_rx) && - (error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RDI, &modified->r.edi.r_rx)) != 0) + printf("%s edi:%lx\n", __func__, modified->r.edi.r_rx) && + (error = vm_set_register(ctx, vcpu, VM_REG_GUEST_RDI, modified->r.edi.r_rx)) != 0) goto done; if ((orig->r.esi.r_rx != modified->r.esi.r_rx) && - (error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RSI, &modified->r.esi.r_rx)) != 0) + printf("%s esi:%lx\n", __func__, modified->r.esi.r_rx) && + (error = vm_set_register(ctx, vcpu, VM_REG_GUEST_RSI, modified->r.esi.r_rx)) != 0) goto done; if ((orig->r.ebp.r_rx != modified->r.ebp.r_rx) && - (error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RBP, &modified->r.ebp.r_rx)) != 0) + printf("%s ebp:%lx\n", __func__, modified->r.ebp.r_rx) && + (error = vm_set_register(ctx, vcpu, VM_REG_GUEST_RBP, modified->r.ebp.r_rx)) != 0) goto done; if ((orig->r.ebx.r_rx != modified->r.ebx.r_rx) && - (error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RBX, &modified->r.ebx.r_rx)) != 0) + printf("%s ebx:%lx\n", __func__, modified->r.ebx.r_rx) && + (error = vm_set_register(ctx, vcpu, VM_REG_GUEST_RBX, modified->r.ebx.r_rx)) != 0) goto done; if ((orig->r.edx.r_rx != modified->r.edx.r_rx) && - (error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RDX, &modified->r.edx.r_rx)) != 0) + printf("%s edx:%lx\n", __func__, modified->r.edx.r_rx) && + (error = vm_set_register(ctx, vcpu, VM_REG_GUEST_RDX, modified->r.edx.r_rx)) != 0) goto done; if ((orig->r.ecx.r_rx != modified->r.ecx.r_rx) && - (error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RCX, &modified->r.ecx.r_rx)) != 0) + printf("%s ecx:%lx\n", __func__, modified->r.ecx.r_rx) && + (error = vm_set_register(ctx, vcpu, VM_REG_GUEST_RCX, modified->r.ecx.r_rx)) != 0) goto done; if ((orig->r.eax.r_rx != modified->r.eax.r_rx) && - (error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RAX, &modified->r.eax.r_rx)) != 0) + printf("%s eax:%lx\n", __func__, modified->r.eax.r_rx) && + (error = vm_set_register(ctx, vcpu, VM_REG_GUEST_RAX, modified->r.eax.r_rx)) != 0) goto done; if ((orig->r.eip.r_rx != modified->r.eip.r_rx) && - (error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RIP, &modified->r.eip.r_rx)) != 0) + printf("%s eip:%lx\n", __func__, modified->r.eip.r_rx) && + (error = vm_set_register(ctx, vcpu, VM_REG_GUEST_RIP, modified->r.eip.r_rx)) != 0) goto done; if ((orig->r.cs.r_rx != modified->r.cs.r_rx) && - (error = vm_get_register(ctx, vcpu, VM_REG_GUEST_CS, &modified->r.cs.r_rx)) != 0) + printf("%s cs:%lx\n", __func__, modified->r.cs.r_rx) && + (error = vm_set_register(ctx, vcpu, VM_REG_GUEST_CS, modified->r.cs.r_rx)) != 0) goto done; if ((orig->r.efl.r_rx != modified->r.efl.r_rx) && - (error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RFLAGS, &modified->r.efl.r_rx)) != 0) + printf("%s eflags:%lx\n", __func__, modified->r.efl.r_rx) && + (error = vm_set_register(ctx, vcpu, VM_REG_GUEST_RFLAGS, modified->r.efl.r_rx)) != 0) goto done; if ((orig->r.esp.r_rx != modified->r.esp.r_rx) && - (error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RSP, &modified->r.esp.r_rx)) != 0) + printf("%s esp:%lx\n", __func__, modified->r.esp.r_rx) && + (error = vm_set_register(ctx, vcpu, VM_REG_GUEST_RSP, modified->r.esp.r_rx)) != 0) goto done; if ((orig->r.ss.r_rx != modified->r.ss.r_rx) && - (error = vm_get_register(ctx, vcpu, VM_REG_GUEST_SS, &modified->r.ss.r_rx)) != 0) + printf("%s ss:%lx\n", __func__, modified->r.ss.r_rx) && + (error = vm_set_register(ctx, vcpu, VM_REG_GUEST_SS, modified->r.ss.r_rx)) != 0) goto done; done: @@ -907,23 +923,38 @@ get_all_regs(ctx, vcpu, &orig); modified = orig; - printf("%s RAX=%lx EAX=%x AX=%x AH=%x AL=%x\n", + printf("%s orig RAX=%lx EAX=%x AX=%x AL=%x AH=%x\n", __func__, orig.r.eax.r_rx, orig.r.eax.r_dw.r_ex, orig.r.eax.r_w.r_x, orig.r.eax.r_b.r_l, orig.r.eax.r_b.r_h); - printf("%s RBX=%lx EBX=%x BX=%x BH=%x BL=%x\n", + printf("%s orig RBX=%lx EBX=%x BX=%x BL=%x BH=%x\n", __func__, orig.r.ebx.r_rx, orig.r.ebx.r_dw.r_ex, orig.r.ebx.r_w.r_x, orig.r.ebx.r_b.r_l, orig.r.ebx.r_b.r_h); + printf("%s modified RAX=%lx EAX=%x AX=%x AL=%x AH=%x\n", + __func__, + modified.r.eax.r_rx, + modified.r.eax.r_dw.r_ex, + modified.r.eax.r_w.r_x, + modified.r.eax.r_b.r_l, + modified.r.eax.r_b.r_h); + printf("%s modified RBX=%lx EBX=%x BX=%x BL=%x BH=%x\n", + __func__, + modified.r.ebx.r_rx, + modified.r.ebx.r_dw.r_ex, + modified.r.ebx.r_w.r_x, + modified.r.ebx.r_b.r_l, + modified.r.ebx.r_b.r_h); switch (intno) { case 0x13: + printf("call int13\n"); int13(&modified); break; default: Modified: soc2012/syuu/bhyve-bios/lib/libbiosemul/debug.c ============================================================================== --- soc2012/syuu/bhyve-bios/lib/libbiosemul/debug.c Fri Aug 3 17:04:41 2012 (r240049) +++ soc2012/syuu/bhyve-bios/lib/libbiosemul/debug.c Fri Aug 3 18:12:49 2012 (r240050) @@ -88,15 +88,19 @@ { va_list args; +#if 0 if (flags & (debug_flags & ~0xff)) { if ((debug_flags & 0xff) == 0 && (flags & (D_ITRAPS | D_TRAPS)) && !debug_isset(flags & 0xff)) return; +#endif va_start (args, fmt); vfprintf (debugf, fmt, args); va_end (args); +#if 0 } +#endif } /* Modified: soc2012/syuu/bhyve-bios/lib/libbiosemul/int13.c ============================================================================== --- soc2012/syuu/bhyve-bios/lib/libbiosemul/int13.c Fri Aug 3 17:04:41 2012 (r240049) +++ soc2012/syuu/bhyve-bios/lib/libbiosemul/int13.c Fri Aug 3 18:12:49 2012 (r240050) @@ -595,6 +595,8 @@ R_FLAGS &= ~PSL_C; + printf("%s:%d AH:%x AL:%x FLAGS:%x\n", __func__, __LINE__, R_AH, R_AL, R_FLAGS); + drive = R_DL; if (R_AX != 0x01) { @@ -621,6 +623,8 @@ sectors = R_AL; side = R_DH; R_AL = 0; /* Start out with nothing read */ + fprintf(stderr, "%s read addr:%x sectors:%d side:%d drive:%x\n", + __func__, (R_ES << 4) + R_BX, sectors, side, drive); if (drive & 0x80) { cyl = R_CH | ((R_CL & 0xc0) << 2); @@ -639,6 +643,8 @@ start = cyl * di->sectors * di->sides + side * di->sectors + sector; + fprintf(stderr, "%s cyl:%d sector:%d di->sectors:%d di->sides:%d\n", + __func__, cyl, sector, di->sectors, di->sides); if (start >= disize(di)) { debug(D_DISK, "Read past end of disk\n"); @@ -668,6 +674,8 @@ if ((did = diread(di, REGS, start, addr, sectors)) >= 0) R_AL = did; + + fprintf(stderr, "%s did:%d\n", __func__, did); #if 0 callint(0x0d); callint(0x76); From owner-svn-soc-all@FreeBSD.ORG Sat Aug 4 13:03:35 2012 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id 7E7AD106566C for ; Sat, 4 Aug 2012 13:03:33 +0000 (UTC) (envelope-from aleek@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Sat, 04 Aug 2012 13:03:33 +0000 Date: Sat, 04 Aug 2012 13:03:33 +0000 From: aleek@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20120804130333.7E7AD106566C@hub.freebsd.org> Cc: Subject: socsvn commit: r240068 - in soc2012/aleek/beaglexm-armv6/sys: arm/conf arm/ti/am37x arm/ti/twl boot/fdt/dts X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 04 Aug 2012 13:03:35 -0000 Author: aleek Date: Sat Aug 4 13:03:32 2012 New Revision: 240068 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=240068 Log: added warm reset support (not yet working) Modified: soc2012/aleek/beaglexm-armv6/sys/arm/conf/BEAGLEBOARD-XM soc2012/aleek/beaglexm-armv6/sys/arm/ti/am37x/am37x_prcm.c soc2012/aleek/beaglexm-armv6/sys/arm/ti/am37x/files.beagleboardxm soc2012/aleek/beaglexm-armv6/sys/arm/ti/twl/twl_vreg.c soc2012/aleek/beaglexm-armv6/sys/boot/fdt/dts/beagleboardxm.dts Modified: soc2012/aleek/beaglexm-armv6/sys/arm/conf/BEAGLEBOARD-XM ============================================================================== --- soc2012/aleek/beaglexm-armv6/sys/arm/conf/BEAGLEBOARD-XM Sat Aug 4 08:06:37 2012 (r240067) +++ soc2012/aleek/beaglexm-armv6/sys/arm/conf/BEAGLEBOARD-XM Sat Aug 4 13:03:32 2012 (r240068) @@ -82,7 +82,7 @@ device mmcsd # mmc/sd flash cards # Boot device is 2nd slice on MMC/SD card -options ROOTDEVNAME=\"msdosfs:mmcsd0s2\" +options ROOTDEVNAME=\"msdosfs:mmcsd0s3\" # Console and misc @@ -98,6 +98,8 @@ device iic device ti_i2c device twl +device twl_vreg +device twl_clks # GPIO device gpio Modified: soc2012/aleek/beaglexm-armv6/sys/arm/ti/am37x/am37x_prcm.c ============================================================================== --- soc2012/aleek/beaglexm-armv6/sys/arm/ti/am37x/am37x_prcm.c Sat Aug 4 08:06:37 2012 (r240067) +++ soc2012/aleek/beaglexm-armv6/sys/arm/ti/am37x/am37x_prcm.c Sat Aug 4 13:03:32 2012 (r240068) @@ -1036,6 +1036,12 @@ #endif } +static void +omap3_prcm_reset(void) +{ + prm_write_4( CORE_PRM_OFFSET + 0x50, (1<<2)); +} + static int omap3_prcm_probe(device_t dev) { @@ -1067,6 +1073,8 @@ sc->prm_bsh = rman_get_bushandle(sc->res[1]); omap3_prcm_sc = sc; + ti_cpu_reset = omap3_prcm_reset; + return (0); } Modified: soc2012/aleek/beaglexm-armv6/sys/arm/ti/am37x/files.beagleboardxm ============================================================================== --- soc2012/aleek/beaglexm-armv6/sys/arm/ti/am37x/files.beagleboardxm Sat Aug 4 08:06:37 2012 (r240067) +++ soc2012/aleek/beaglexm-armv6/sys/arm/ti/am37x/files.beagleboardxm Sat Aug 4 13:03:32 2012 (r240068) @@ -2,5 +2,5 @@ #arm/ti/am37x/am37x_pmic.c optional am37x_pmic arm/ti/twl/twl.c optional twl -arm/ti/twl/twl_vreg.c optional twl #twl_vreg -arm/ti/twl/twl_clks.c optional twl #twl_clks +arm/ti/twl/twl_vreg.c optional twl twl_vreg +arm/ti/twl/twl_clks.c optional twl twl_clks Modified: soc2012/aleek/beaglexm-armv6/sys/arm/ti/twl/twl_vreg.c ============================================================================== --- soc2012/aleek/beaglexm-armv6/sys/arm/ti/twl/twl_vreg.c Sat Aug 4 08:06:37 2012 (r240067) +++ soc2012/aleek/beaglexm-armv6/sys/arm/ti/twl/twl_vreg.c Sat Aug 4 13:03:32 2012 (r240068) @@ -75,7 +75,7 @@ #include "twl.h" #include "twl_vreg.h" -static int twl_vreg_debug = 1; +static int twl_vreg_debug = 10; /* @@ -885,6 +885,7 @@ int len = 0, prop_len; + device_printf( sc->sc_dev, "%s:%d\n", __FUNCTION__, __LINE__ ); /* Add the regulators from the list */ walker = ®ulators[0]; while (walker->name != NULL) { @@ -899,12 +900,14 @@ walker++; } + device_printf( sc->sc_dev, "%s:%d\n", __FUNCTION__, __LINE__ ); /* Check if the FDT is telling us to set any voltages */ child = ofw_bus_get_node(sc->sc_pdev); if (child) { prop_len = OF_getprop(child, "voltage-regulators", rnames, sizeof(rnames)); + device_printf( sc->sc_dev, "prop_len: %d\n", prop_len ); while (len < prop_len) { name = rnames + len; len += strlen(name) + 1; @@ -956,6 +959,7 @@ struct twl_vreg_softc *sc; sc = device_get_softc((device_t)dev); + device_printf( sc->sc_dev, "%s:%d\n", __FUNCTION__, __LINE__ ); TWL_VREG_XLOCK(sc); @@ -999,6 +1003,7 @@ /* We have to wait until interrupts are enabled. I2C read and write * only works if the interrupts are available. */ + device_printf( sc->sc_dev, "%s:%d\n", __FUNCTION__, __LINE__ ); sc->sc_init_hook.ich_func = twl_vreg_init; sc->sc_init_hook.ich_arg = dev; Modified: soc2012/aleek/beaglexm-armv6/sys/boot/fdt/dts/beagleboardxm.dts ============================================================================== --- soc2012/aleek/beaglexm-armv6/sys/boot/fdt/dts/beagleboardxm.dts Sat Aug 4 08:06:37 2012 (r240067) +++ soc2012/aleek/beaglexm-armv6/sys/boot/fdt/dts/beagleboardxm.dts Sat Aug 4 13:03:32 2012 (r240068) @@ -195,9 +195,9 @@ interrupts = <56>; interrupt-parent = <&AINTC>; i2c-device-id = <1>; - pmic@24 { + pmic@48 { compatible = "ti,twl4030"; - reg = <0x24>; + reg = <0x48>; }; }; From owner-svn-soc-all@FreeBSD.ORG Sat Aug 4 13:52:45 2012 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id CDAB51065757 for ; Sat, 4 Aug 2012 13:52:43 +0000 (UTC) (envelope-from aleek@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Sat, 04 Aug 2012 13:52:43 +0000 Date: Sat, 04 Aug 2012 13:52:43 +0000 From: aleek@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20120804135243.CDAB51065757@hub.freebsd.org> Cc: Subject: socsvn commit: r240069 - soc2012/aleek/beaglexm-armv6/sys/arm/ti/am37x X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 04 Aug 2012 13:52:46 -0000 Author: aleek Date: Sat Aug 4 13:52:43 2012 New Revision: 240069 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=240069 Log: software warm reset for bb-xm is working Modified: soc2012/aleek/beaglexm-armv6/sys/arm/ti/am37x/am37x_prcm.c Modified: soc2012/aleek/beaglexm-armv6/sys/arm/ti/am37x/am37x_prcm.c ============================================================================== --- soc2012/aleek/beaglexm-armv6/sys/arm/ti/am37x/am37x_prcm.c Sat Aug 4 13:03:32 2012 (r240068) +++ soc2012/aleek/beaglexm-armv6/sys/arm/ti/am37x/am37x_prcm.c Sat Aug 4 13:52:43 2012 (r240069) @@ -1039,7 +1039,8 @@ static void omap3_prcm_reset(void) { - prm_write_4( CORE_PRM_OFFSET + 0x50, (1<<2)); + prm_write_4( GLOBAL_PRM_OFFSET + 0x50, (1<<2)); + prm_read_4( GLOBAL_PRM_OFFSET + 0x50 ); } static int From owner-svn-soc-all@FreeBSD.ORG Sat Aug 4 16:56:24 2012 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id C5CA3106564A for ; Sat, 4 Aug 2012 16:56:22 +0000 (UTC) (envelope-from gpf@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Sat, 04 Aug 2012 16:56:22 +0000 Date: Sat, 04 Aug 2012 16:56:22 +0000 From: gpf@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20120804165622.C5CA3106564A@hub.freebsd.org> Cc: Subject: socsvn commit: r240071 - in soc2012/gpf/pefs_kmod: sbin/pefs sys/fs/pefs X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 04 Aug 2012 16:56:24 -0000 Author: gpf Date: Sat Aug 4 16:56:22 2012 New Revision: 240071 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=240071 Log: store signature in the beginning of .pefs.checksum work in progress Modified: soc2012/gpf/pefs_kmod/sbin/pefs/pefs_checksum.c soc2012/gpf/pefs_kmod/sbin/pefs/pefs_ctl.c soc2012/gpf/pefs_kmod/sbin/pefs/pefs_ctl.h soc2012/gpf/pefs_kmod/sys/fs/pefs/pefs_checksum.c soc2012/gpf/pefs_kmod/sys/fs/pefs/pefs_checksum.h soc2012/gpf/pefs_kmod/sys/fs/pefs/pefs_vfsops.c Modified: soc2012/gpf/pefs_kmod/sbin/pefs/pefs_checksum.c ============================================================================== --- soc2012/gpf/pefs_kmod/sbin/pefs/pefs_checksum.c Sat Aug 4 15:11:36 2012 (r240070) +++ soc2012/gpf/pefs_kmod/sbin/pefs/pefs_checksum.c Sat Aug 4 16:56:22 2012 (r240071) @@ -72,6 +72,7 @@ #define PEFS_NOEXTEND 2 #define PEFS_REALLOC 3 +#define PEFS_SIGNATURE_MAX_LENGTH 512 #define PEFS_CHECKSUM_FILE_VERSION 0xDD #define PEFS_HASH_BYTE_ALIGNMENT 512 #define PEFS_EXTRA_TABLE_SIZE 15 @@ -1213,9 +1214,14 @@ static int pefs_write_checksum_file_header(int fdout, struct checksum_file_header *cfhp) { + int rval; uint32_t bytes, hash_table_size; - cfhp->offset_to_hash_table = PEFS_CFH_SIZE; + rval = lseek(fdout, PEFS_SIGNATURE_MAX_LENGTH, SEEK_SET); + if (rval == -1) { + warn("lseek error while writing to .pefs.checksum"); + return (PEFS_ERR_SYS); + } bytes = write(fdout, &(cfhp->version), sizeof(cfhp->version)); if (bytes != sizeof(cfhp->version)) { @@ -1371,7 +1377,7 @@ return (error); /* this points to where the buckets start */ - buckets_offset = cfhp->offset_to_hash_table; + buckets_offset = PEFS_SIGNATURE_MAX_LENGTH + cfhp->offset_to_hash_table; /* this points to where the buckets stop and the checksums start */ hashes_offset = buckets_offset; @@ -1429,6 +1435,7 @@ cfhp->hash_table_size = chtp->size; cfhp->version = PEFS_CHECKSUM_FILE_VERSION; strlcpy(cfhp->hash_algo, algo, sizeof(cfhp->hash_algo)); + cfhp->offset_to_hash_table = PEFS_CFH_SIZE; } /* generate dsa keys & write public key to a file */ @@ -1482,7 +1489,7 @@ /* Sign .pefs.checksum. Signature is placed in a different file. */ static int -pefs_sign_file(int fd, FILE *pkfp, FILE *signfp) +pefs_sign_file(int fd, FILE *pkfp) { unsigned char buf[PEFS_BUFISZE]; EVP_MD_CTX ctx; @@ -1508,9 +1515,9 @@ /* generate digital signature */ EVP_SignInit(&ctx, md); - error = lseek(fd, 0, SEEK_SET); - if (error != 0) { - warn("lseek:"); + error = lseek(fd, PEFS_SIGNATURE_MAX_LENGTH, SEEK_SET); + if (error == -1) { + warn("lseek error while signing file"); EVP_PKEY_free(pkey); return (PEFS_ERR_SYS); } @@ -1545,8 +1552,9 @@ return (PEFS_ERR_SYS); } - /* write digital signature to .pefs.signature */ - if (fwrite(sign, sizeof(char), sign_len, signfp) < sign_len) { + /* write digital signature to beginning of .pefs.checksum */ + bytes = pwrite(fd, sign, sign_len, 0); + if (bytes == -1) { pefs_warn("error writing signature"); free(sign); EVP_PKEY_free(pkey); @@ -1593,15 +1601,14 @@ /* verify digital signature of .pefs.checksum */ static int -pefs_verify_signature(int fd, FILE *pk_fp, FILE *sign_fp) +pefs_verify_signature(int fd, FILE *pk_fp) { unsigned char buf[PEFS_BUFISZE]; EVP_MD_CTX ctx; const EVP_MD *md; EVP_PKEY *pkey; unsigned char *sign; - unsigned int sign_len; - int bytes, error, rval; + int bytes, error, rval, sign_len; /* read public key from .pefs.pkey */ pkey = pefs_read_dsa(pk_fp); @@ -1615,10 +1622,10 @@ return (PEFS_ERR_SYS); } - /* read signature from .pefs.signature */ - sign_len = fread(sign, sizeof(char), EVP_PKEY_size(pkey), sign_fp); - if (ferror(sign_fp)) { - pefs_warn("error reading from signature file"); + /* read signature from .pefs.checksum */ + sign_len = pread(fd, sign, EVP_PKEY_size(pkey), 0); + if (sign_len == -1) { + warn("error reading signature"); free(sign); return (PEFS_ERR_IO); } @@ -1634,9 +1641,9 @@ /* process .pefs.checksum & verify the signature */ EVP_VerifyInit(&ctx, md); - error = lseek(fd, 0, SEEK_SET); - if (error != 0) { - warn("lseek:"); + error = lseek(fd, PEFS_SIGNATURE_MAX_LENGTH, SEEK_SET); + if (error == -1) { + warn("lseek error while verifying file"); free(sign); EVP_PKEY_free(pkey); return (PEFS_ERR_SYS); @@ -1688,15 +1695,14 @@ */ static int pefs_open_checksum_files(int *fdp, char *fsroot, char *csm_path, FILE **pkfpp, - char *pk_path, FILE **signfpp, char *sign_path) + char *pk_path) { struct statfs pefs_fs, checksum_fs; - FILE *pkfp, *signfp; + FILE *pkfp; int fd; *fdp = -1; *pkfpp = NULL; - *signfpp = NULL; /* create checksum file */ fd = open(csm_path, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR); @@ -1733,14 +1739,6 @@ *pkfpp = pkfp; - signfp = fopen(sign_path, "wx"); - if (signfp == NULL) { - warn("cannot open %s", sign_path); - return (PEFS_ERR_SYS); - } - - *signfpp = signfp; - return (0); } @@ -1754,12 +1752,12 @@ */ int pefs_create_checksum_file(FILE *fpin, char *fsroot, char *csm_path, - char *pk_path, char *sign_path, const char *algo, int flags) + char *pk_path, const char *algo, int flags) { struct cuckoo_hash_table checksum_hash_table; struct checksum_file_header cfh; const EVP_MD *md; - FILE *pkfp, *signfp; + FILE *pkfp; int error, fdout; uint8_t hash_len; @@ -1774,8 +1772,7 @@ pefs_init_hash_table(&checksum_hash_table); - error = pefs_open_checksum_files(&fdout, fsroot, csm_path, &pkfp, pk_path, - &signfp, sign_path); + error = pefs_open_checksum_files(&fdout, fsroot, csm_path, &pkfp, pk_path); if (error != 0) goto out; @@ -1790,7 +1787,7 @@ if (error != 0) goto out; - error = pefs_sign_file(fdout, pkfp, signfp); + error = pefs_sign_file(fdout, pkfp); out: if (fdout >= 0) { @@ -1803,11 +1800,6 @@ if (error != 0) unlink(pk_path); } - if (signfp != NULL) { - fclose(signfp); - if (error != 0) - unlink(sign_path); - } pefs_free_hash_table(&checksum_hash_table); return (error); @@ -1816,8 +1808,15 @@ static int pefs_read_checksum_file_header(int fdin, struct checksum_file_header *cfhp) { + int rval; uint32_t bytes, hash_table_size; + rval = lseek(fdin, PEFS_SIGNATURE_MAX_LENGTH, SEEK_SET); + if (rval == -1) { + warn("lseek error while reading checksum file header"); + return (PEFS_ERR_SYS); + } + bytes = read(fdin, &(cfhp->version), sizeof(cfhp->version)); if (bytes != sizeof(cfhp->version)) { warn("error reading from .pefs.checksum"); @@ -1970,7 +1969,7 @@ int error; /* this points to where the buckets start */ - buckets_offset = cfhp->offset_to_hash_table; + buckets_offset = PEFS_SIGNATURE_MAX_LENGTH + cfhp->offset_to_hash_table; for (i = 0; i < chtp->size; i++) { bp = &chtp->buckets1[i]; @@ -2264,8 +2263,7 @@ * E) verify .pefs.signature from public key found in .pefs.pkey */ int -pefs_verify_checksum(int fdin, FILE *pk_fp, FILE *sign_fp, - char *fsroot, int flags) +pefs_verify_checksum(int fdin, FILE *pk_fp, char *fsroot, int flags) { struct statfs fs; struct checksum_file_header cfh; @@ -2330,7 +2328,7 @@ if (error == 0 && checksum_error != 0) error = checksum_error; - error = pefs_verify_signature(fdin, pk_fp, sign_fp); + error = pefs_verify_signature(fdin, pk_fp); out: pefs_free_hash_table(&cht); Modified: soc2012/gpf/pefs_kmod/sbin/pefs/pefs_ctl.c ============================================================================== --- soc2012/gpf/pefs_kmod/sbin/pefs/pefs_ctl.c Sat Aug 4 15:11:36 2012 (r240070) +++ soc2012/gpf/pefs_kmod/sbin/pefs/pefs_ctl.c Sat Aug 4 16:56:22 2012 (r240071) @@ -1040,7 +1040,6 @@ { char fsroot[MAXPATHLEN + 1]; char csm_path[MAXPATHLEN + 1], pk_path[MAXPATHLEN + 1]; - char sign_path[MAXPATHLEN + 1]; struct stat sb; FILE *fpin; int error, flags, i, j; @@ -1053,7 +1052,6 @@ /* by default create checksum files under $PWD */ snprintf(csm_path, sizeof(csm_path), "./%s", PEFS_FILE_CHECKSUM); snprintf(pk_path, sizeof(pk_path), "./%s", PEFS_FILE_PKEY); - snprintf(sign_path, sizeof(sign_path), "./%s", PEFS_FILE_SIGNATURE); while ((i = getopt(argc, argv, "fa:i:p:")) != -1) switch(i) { @@ -1098,8 +1096,6 @@ PEFS_FILE_CHECKSUM); snprintf(pk_path, sizeof(pk_path), "%s/%s", optarg, PEFS_FILE_PKEY); - snprintf(sign_path, sizeof(sign_path), "%s/%s", optarg, - PEFS_FILE_SIGNATURE); break; default: if (fpin != NULL) @@ -1112,7 +1108,7 @@ initfsroot(argc, argv, 0, fsroot, sizeof(fsroot)); error = pefs_create_checksum_file(fpin, fsroot, csm_path, pk_path, - sign_path,algo, flags); + algo, flags); out: if (fpin != NULL) @@ -1157,16 +1153,14 @@ { struct stat sb; char fsroot[MAXPATHLEN + 1], pk_path[MAXPATHLEN + 1]; - char sign_path[MAXPATHLEN + 1]; char *dirnamep; - FILE *pk_fp, *sign_fp; + FILE *pk_fp; int error, fdin, flags, i; fdin = -1; flags = PEFS_VERIFY; pk_fp = NULL; - sign_fp = NULL; - while ((i = getopt(argc, argv, "k:ns:u")) != -1) + while ((i = getopt(argc, argv, "k:nu")) != -1) switch(i) { case 'k': pk_fp = fopen(optarg, "r"); @@ -1183,14 +1177,6 @@ return (PEFS_ERR_INVALID); } break; - case 's': - sign_fp = fopen(optarg, "r"); - if (sign_fp == NULL) { - warn("error opening signature file %s", optarg); - error = PEFS_ERR_SYS; - goto out; - } - break; case 'u': flags|= PEFS_UNMOUNTED; if ((flags & PEFS_NOKEY) != 0) { @@ -1228,16 +1214,6 @@ goto out; } } - if (sign_fp == NULL) { - snprintf(sign_path, sizeof(sign_path), "%s/%s", dirnamep, - PEFS_FILE_SIGNATURE); - sign_fp = fopen(sign_path, "r"); - if (sign_fp == NULL) { - warn("error opening signature file %s", sign_path); - error = PEFS_ERR_SYS; - goto out; - } - } argc -=1; argv +=1; @@ -1263,7 +1239,7 @@ } } - error = pefs_verify_checksum(fdin, pk_fp, sign_fp, fsroot, flags); + error = pefs_verify_checksum(fdin, pk_fp, fsroot, flags); if (error == 0) printf("integrity verification ok!\n"); else @@ -1274,8 +1250,6 @@ close(fdin); if (pk_fp != NULL) fclose(pk_fp); - if (sign_fp != NULL) - fclose(sign_fp); return (error); } @@ -1286,12 +1260,12 @@ * * $command prints out the identifier for an encrypted pefs filename where * pefs encrypted filename = XBase64(checksum || E(tweak || filename)). - * + * * The id is the name checksum, meaning VMAC(E(tweak || filename)). - * + * * This identifier is used as a primary key when a specific filename is handled * by pefs for integrity checking purposes. - * + * * Some warning messages produced by /sbin/pefs refer to files by their internal * ID and not their unencrypted fullpath; e.g. when verifying an unmounted pefs * filesystem. Therefore this command can be used to map fullpaths to internal @@ -1301,11 +1275,14 @@ * provided yet. * * -u flag should be used if filesystem is unmounted. - * + * * In both of these scenarios the "filepath" that is provided by the user should * be the encrypted filepath. * * flags -u and -n are mutually exclusive. + * + * filepath may refer to any kind of file that is encrypted by pefs filesystem, + * such as directories, regular files, symlinks, etc. */ static int pefs_nameid(int argc, char *argv[]) @@ -1343,7 +1320,7 @@ warnx("too many arguments"); pefs_usage(); } - + strlcpy(file_path, argv[0], sizeof(file_path)); error = pefs_filename_to_id(file_path, flags); Modified: soc2012/gpf/pefs_kmod/sbin/pefs/pefs_ctl.h ============================================================================== --- soc2012/gpf/pefs_kmod/sbin/pefs/pefs_ctl.h Sat Aug 4 15:11:36 2012 (r240070) +++ soc2012/gpf/pefs_kmod/sbin/pefs/pefs_ctl.h Sat Aug 4 16:56:22 2012 (r240071) @@ -104,9 +104,8 @@ const struct pefs_xkey *xk_parent); uintmax_t pefs_keyid_as_int(char *keyid); int pefs_create_checksum_file(FILE *fpin, char *fsroot, char *csm_path, - char *pk_path, char *sign_path, const char *algo, int flags); -int pefs_verify_checksum(int fdin, FILE *pk_fp, FILE *sign_fp, - char *fsroot, int flags); + char *pk_path, const char *algo, int flags); +int pefs_verify_checksum(int fdin, FILE *pk_fp, char *fsroot, int flags); int pefs_filename_to_id(char *file_path, int flags); int pefs_name_pton(char const *src, size_t srclen, u_char *target, Modified: soc2012/gpf/pefs_kmod/sys/fs/pefs/pefs_checksum.c ============================================================================== --- soc2012/gpf/pefs_kmod/sys/fs/pefs/pefs_checksum.c Sat Aug 4 15:11:36 2012 (r240070) +++ soc2012/gpf/pefs_kmod/sys/fs/pefs/pefs_checksum.c Sat Aug 4 16:56:22 2012 (r240071) @@ -406,7 +406,7 @@ long *p; int error; - dprintf(("integrity checking!\noffset %llu\n", offset)); + printf("integrity checking!\noffset %llu\n", offset); /* * XXXgpf: For the moment, this flag's only purpose is to deny read access Modified: soc2012/gpf/pefs_kmod/sys/fs/pefs/pefs_checksum.h ============================================================================== --- soc2012/gpf/pefs_kmod/sys/fs/pefs/pefs_checksum.h Sat Aug 4 15:11:36 2012 (r240070) +++ soc2012/gpf/pefs_kmod/sys/fs/pefs/pefs_checksum.h Sat Aug 4 16:56:22 2012 (r240071) @@ -31,6 +31,8 @@ #define PEFS_CFH_SIZE 16 /* file header of .pefs.checksum file */ #define PEFS_HT_CELL_SIZE 16 /* hash table cell(bucket) size */ +#define PEFS_SIGNATURE_MAX_LENGTH 512 + #define PEFS_CHECKSUM_SUPPORTED_DIGESTS 2 #define PEFS_SHA256 0 Modified: soc2012/gpf/pefs_kmod/sys/fs/pefs/pefs_vfsops.c ============================================================================== --- soc2012/gpf/pefs_kmod/sys/fs/pefs/pefs_vfsops.c Sat Aug 4 15:11:36 2012 (r240070) +++ soc2012/gpf/pefs_kmod/sys/fs/pefs/pefs_vfsops.c Sat Aug 4 16:56:22 2012 (r240071) @@ -174,7 +174,7 @@ /* read checksum file header info */ buflen = PEFS_CFH_SIZE; pefs_chunk_create(&pc, NULL, buflen); - puio = pefs_chunk_uio(&pc, 0, UIO_READ); + puio = pefs_chunk_uio(&pc, PEFS_SIGNATURE_MAX_LENGTH, UIO_READ); /* XXXgpf: gleb says I should use vn_rdwr instead of VOP_READ */ error = VOP_READ(checksumvp, puio, IO_UNIT, cred); @@ -213,7 +213,8 @@ /* load and keep the 2 hash tables in kernel heap */ buflen = pcs->pcs_hash_table_size * PEFS_HT_CELL_SIZE; pefs_chunk_create(&pc, NULL, buflen); - puio = pefs_chunk_uio(&pc, pcs->pcs_offset_to_hash_table, UIO_READ); + puio = pefs_chunk_uio(&pc, PEFS_SIGNATURE_MAX_LENGTH + + pcs->pcs_offset_to_hash_table, UIO_READ); error = VOP_READ(checksumvp, puio, IO_UNIT, cred); if (error != 0) { @@ -228,8 +229,8 @@ pefs_chunk_free(&pc, NULL); pefs_chunk_create(&pc, NULL, buflen); - puio = pefs_chunk_uio(&pc, pcs->pcs_offset_to_hash_table + - buflen, UIO_READ); + puio = pefs_chunk_uio(&pc, PEFS_SIGNATURE_MAX_LENGTH + + pcs->pcs_offset_to_hash_table + buflen, UIO_READ); error = VOP_READ(checksumvp, puio, IO_UNIT, cred); if (error != 0) { From owner-svn-soc-all@FreeBSD.ORG Sat Aug 4 17:40:12 2012 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id 719B7106566C for ; Sat, 4 Aug 2012 17:40:10 +0000 (UTC) (envelope-from gpf@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Sat, 04 Aug 2012 17:40:10 +0000 Date: Sat, 04 Aug 2012 17:40:10 +0000 From: gpf@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20120804174010.719B7106566C@hub.freebsd.org> Cc: Subject: socsvn commit: r240072 - in soc2012/gpf/pefs_kmod: sbin/pefs sys/fs/pefs X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 04 Aug 2012 17:40:12 -0000 Author: gpf Date: Sat Aug 4 17:40:09 2012 New Revision: 240072 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=240072 Log: instead of generating DSA keys, ask them from user instead Modified: soc2012/gpf/pefs_kmod/sbin/pefs/pefs_checksum.c soc2012/gpf/pefs_kmod/sbin/pefs/pefs_ctl.c soc2012/gpf/pefs_kmod/sbin/pefs/pefs_ctl.h soc2012/gpf/pefs_kmod/sys/fs/pefs/pefs_checksum.c Modified: soc2012/gpf/pefs_kmod/sbin/pefs/pefs_checksum.c ============================================================================== --- soc2012/gpf/pefs_kmod/sbin/pefs/pefs_checksum.c Sat Aug 4 16:56:22 2012 (r240071) +++ soc2012/gpf/pefs_kmod/sbin/pefs/pefs_checksum.c Sat Aug 4 17:40:09 2012 (r240072) @@ -1210,7 +1210,6 @@ return (error); } - static int pefs_write_checksum_file_header(int fdout, struct checksum_file_header *cfhp) { @@ -1438,27 +1437,17 @@ cfhp->offset_to_hash_table = PEFS_CFH_SIZE; } -/* generate dsa keys & write public key to a file */ +/* read dsa pubkey from file */ static EVP_PKEY * -pefs_generate_dsa(FILE *pkfp) +pefs_read_dsa_privkey(FILE *pk_fp) { - unsigned char seed[PEFS_SEED_LEN]; DSA *dsa; EVP_PKEY *pkey; int rval; - RAND_bytes(seed, sizeof(seed)); - dsa = DSA_generate_parameters(PEFS_PLEN, seed, sizeof(seed), NULL, - NULL, NULL, NULL); + dsa = PEM_read_DSAPrivateKey(pk_fp, NULL, NULL, NULL); if (dsa == NULL) { - pefs_warn("error generating dsa parameters"); - return (NULL); - } - - rval = DSA_generate_key(dsa); - if (rval != 1) { - pefs_warn("error generating dsa key"); - DSA_free(dsa); + pefs_warn("error reading dsa pubkey"); return (NULL); } @@ -1468,6 +1457,7 @@ DSA_free(dsa); return (NULL); } + rval = EVP_PKEY_assign_DSA(pkey, dsa); if (rval != 1) { pefs_warn("error assigning dsa key"); @@ -1476,14 +1466,6 @@ return (NULL); } - rval = PEM_write_DSA_PUBKEY(pkfp, dsa); - if (rval != 1) { - pefs_warn("error writing dsa pubkey"); - EVP_PKEY_free(pkey); - DSA_free(dsa); - return (NULL); - } - return (pkey); } @@ -1501,7 +1483,7 @@ /* XXXgpf: [TODO] offer option of DSA/RSA & appropriate digests */ /* generate keys */ - pkey = pefs_generate_dsa(pkfp); + pkey = pefs_read_dsa_privkey(pkfp); if (pkey == NULL) return (PEFS_ERR_SYS); @@ -1569,7 +1551,7 @@ /* read dsa pubkey from file */ static EVP_PKEY * -pefs_read_dsa(FILE *pk_fp) +pefs_read_dsa_pubkey(FILE *pk_fp) { DSA *dsa; EVP_PKEY *pkey; @@ -1611,7 +1593,7 @@ int bytes, error, rval, sign_len; /* read public key from .pefs.pkey */ - pkey = pefs_read_dsa(pk_fp); + pkey = pefs_read_dsa_pubkey(pk_fp); if (pkey == NULL) return (PEFS_ERR_SYS); @@ -1690,19 +1672,14 @@ * If .pefs.checksum is created inside pefs mounted fs, then it will obtain an * encrypted filename & encrypted data, which is unacceptable. User should * create checksum file outside of filesystem and then copy it by hand. - * Alongside with the checksum file, we will create two additional files as - * placeholders for the public key and the file's digital signature. */ static int -pefs_open_checksum_files(int *fdp, char *fsroot, char *csm_path, FILE **pkfpp, - char *pk_path) +pefs_open_checksum_file(int *fdp, char *fsroot, char *csm_path) { struct statfs pefs_fs, checksum_fs; - FILE *pkfp; int fd; *fdp = -1; - *pkfpp = NULL; /* create checksum file */ fd = open(csm_path, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR); @@ -1730,15 +1707,6 @@ return (PEFS_ERR_INVALID); } - /* create files for the public key and .pefs.checksum's signature */ - pkfp = fopen(pk_path, "wx"); - if (pkfp == NULL) { - warn("cannot open %s", pk_path); - return (PEFS_ERR_SYS); - } - - *pkfpp = pkfp; - return (0); } @@ -1752,12 +1720,11 @@ */ int pefs_create_checksum_file(FILE *fpin, char *fsroot, char *csm_path, - char *pk_path, const char *algo, int flags) + FILE *pk_fp, const char *algo, int flags) { struct cuckoo_hash_table checksum_hash_table; struct checksum_file_header cfh; const EVP_MD *md; - FILE *pkfp; int error, fdout; uint8_t hash_len; @@ -1772,7 +1739,7 @@ pefs_init_hash_table(&checksum_hash_table); - error = pefs_open_checksum_files(&fdout, fsroot, csm_path, &pkfp, pk_path); + error = pefs_open_checksum_file(&fdout, fsroot, csm_path); if (error != 0) goto out; @@ -1787,7 +1754,7 @@ if (error != 0) goto out; - error = pefs_sign_file(fdout, pkfp); + error = pefs_sign_file(fdout, pk_fp); out: if (fdout >= 0) { @@ -1795,11 +1762,6 @@ if (error != 0) unlink(csm_path); } - if (pkfp != NULL) { - fclose(pkfp); - if (error != 0) - unlink(pk_path); - } pefs_free_hash_table(&checksum_hash_table); return (error); @@ -2338,7 +2300,6 @@ return (error); } - /* retrieve and then print the name checksum ID for a given filename */ int pefs_filename_to_id(char *file_path, int flags) Modified: soc2012/gpf/pefs_kmod/sbin/pefs/pefs_ctl.c ============================================================================== --- soc2012/gpf/pefs_kmod/sbin/pefs/pefs_ctl.c Sat Aug 4 16:56:22 2012 (r240071) +++ soc2012/gpf/pefs_kmod/sbin/pefs/pefs_ctl.c Sat Aug 4 17:40:09 2012 (r240072) @@ -1041,19 +1041,20 @@ char fsroot[MAXPATHLEN + 1]; char csm_path[MAXPATHLEN + 1], pk_path[MAXPATHLEN + 1]; struct stat sb; - FILE *fpin; + FILE *fpin, *pk_fp; int error, flags, i, j; const char *algo; flags = 0; fpin = stdin; + pk_fp = NULL; /* by default use sha256 */ algo = supported_digests[0]; /* by default create checksum files under $PWD */ snprintf(csm_path, sizeof(csm_path), "./%s", PEFS_FILE_CHECKSUM); snprintf(pk_path, sizeof(pk_path), "./%s", PEFS_FILE_PKEY); - while ((i = getopt(argc, argv, "fa:i:p:")) != -1) + while ((i = getopt(argc, argv, "fa:i:k:p:")) != -1) switch(i) { case 'a': for (j=0; j < PEFS_SUPPORTED_DIGESTS; j++) @@ -1079,6 +1080,14 @@ goto out; } break; + case 'k': + pk_fp = fopen(optarg, "r"); + if (pk_fp == NULL) { + warn("error opening privkey file %s", optarg); + error = PEFS_ERR_SYS; + goto out; + } + break; case 'p': if (stat(optarg, &sb) != 0) { warn("cannot stat file %s", optarg); @@ -1105,14 +1114,21 @@ argc -= optind; argv += optind; + if (pk_fp == NULL) { + pefs_warn("user must provide a file containing the public key"); + return (PEFS_ERR_INVALID); + } + initfsroot(argc, argv, 0, fsroot, sizeof(fsroot)); - error = pefs_create_checksum_file(fpin, fsroot, csm_path, pk_path, + error = pefs_create_checksum_file(fpin, fsroot, csm_path, pk_fp, algo, flags); out: if (fpin != NULL) fclose(fpin); + if (pk_fp != NULL) + fclose(pk_fp); return (error); } @@ -1152,8 +1168,7 @@ pefs_verify(int argc, char *argv[]) { struct stat sb; - char fsroot[MAXPATHLEN + 1], pk_path[MAXPATHLEN + 1]; - char *dirnamep; + char fsroot[MAXPATHLEN + 1]; FILE *pk_fp; int error, fdin, flags, i; @@ -1165,7 +1180,7 @@ case 'k': pk_fp = fopen(optarg, "r"); if (pk_fp == NULL) { - warn("error opening pkey file %s", optarg); + warn("error opening pubkey file %s", optarg); error = PEFS_ERR_SYS; goto out; } @@ -1190,6 +1205,11 @@ argc -= optind; argv += optind; + if (pk_fp == NULL) { + pefs_warn("user must provide a file containing the public key"); + return (PEFS_ERR_INVALID); + } + if (argc != 2) { if (argc < 2) warnx("too few arguments"); @@ -1204,16 +1224,6 @@ error = PEFS_ERR_INVALID; goto out; } - dirnamep = dirname(argv[0]); - if (pk_fp == NULL) { - snprintf(pk_path, sizeof(pk_path), "%s/%s", dirnamep, PEFS_FILE_PKEY); - pk_fp = fopen(pk_path, "r"); - if (pk_fp == NULL) { - warn("error opening pkey file %s", pk_path); - error = PEFS_ERR_SYS; - goto out; - } - } argc -=1; argv +=1; Modified: soc2012/gpf/pefs_kmod/sbin/pefs/pefs_ctl.h ============================================================================== --- soc2012/gpf/pefs_kmod/sbin/pefs/pefs_ctl.h Sat Aug 4 16:56:22 2012 (r240071) +++ soc2012/gpf/pefs_kmod/sbin/pefs/pefs_ctl.h Sat Aug 4 17:40:09 2012 (r240072) @@ -104,7 +104,7 @@ const struct pefs_xkey *xk_parent); uintmax_t pefs_keyid_as_int(char *keyid); int pefs_create_checksum_file(FILE *fpin, char *fsroot, char *csm_path, - char *pk_path, const char *algo, int flags); + FILE *pk_fp, const char *algo, int flags); int pefs_verify_checksum(int fdin, FILE *pk_fp, char *fsroot, int flags); int pefs_filename_to_id(char *file_path, int flags); Modified: soc2012/gpf/pefs_kmod/sys/fs/pefs/pefs_checksum.c ============================================================================== --- soc2012/gpf/pefs_kmod/sys/fs/pefs/pefs_checksum.c Sat Aug 4 16:56:22 2012 (r240071) +++ soc2012/gpf/pefs_kmod/sys/fs/pefs/pefs_checksum.c Sat Aug 4 17:40:09 2012 (r240072) @@ -406,7 +406,7 @@ long *p; int error; - printf("integrity checking!\noffset %llu\n", offset); + dprintf(("integrity checking!\noffset %llu\n", offset)); /* * XXXgpf: For the moment, this flag's only purpose is to deny read access