Re: Zenbleed

2023-07-25 Thread Rafael Sadowski
I hit the same trap as Lucas with my HV (netcup.de).

bios0 at mainbus0: SMBIOS rev. 2.8 @ 0xf5900 (10 entries)
bios0: vendor netcup version "RS 1000 G9 Plus" date 12/17/2020
bios0: netcup KVM Server
acpi0 at bios0: ACPI 1.0
acpi0: sleep states S5
acpi0: tables DSDT FACP APIC
acpi0: wakeup devices
acpitimer0 at acpi0: 3579545 Hz, 24 bits
acpimadt0 at acpi0 addr 0xfee0: PC-AT compat
cpu0 at mainbus0: apid 0 (boot processor)
cpu0: AMD EPYC 7702P 64-Core Processor, 1996.52 MHz, 17-31-00
cpu0: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,MMX,FXSR,SSE,SSE2,HTT,SSE3,PCLMUL,SSSE3,FMA3,CX16,SSE4.1,SSE4.2,x2APIC,MOVBE,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,HV,NXE,MMXX,FFXSR,PAGE1GB,RDTSCP,LONG,LAHF,CMPLEG,AMCR8,ABM,SSE4A,MASSE,3DNOWP,OSVW,CPCTR,FSGSBASE,TSC_ADJUST,BMI1,AVX2,SMEP,BMI2,RDSEED,ADX,SMAP,CLFLUSHOPT,CLWB,SHA,UMIP,IBRS,IBPB,STIBP,SSBD,IBPB,IBRS,STIBP,SSBD,VIRTSSBD,XSAVEOPT,XSAVEC,XGETBV1,XSAVES
cpu0: 64KB 64b/line 2-way D-cache, 64KB 64b/line 2-way I-cache
cpu0: 512KB 64b/line 16-way L2 cache
cpu0: smt 0, core 0, package 0

https://ibb.co/gZPtLZb
https://ibb.co/sgnTsPb

Based on your diff below the following diff applies on -stable and works
for me.

Index: cpu.c
===
RCS file: /cvs/src/sys/arch/amd64/amd64/cpu.c,v
retrieving revision 1.165
diff -u -p -r1.165 cpu.c
--- cpu.c   9 Mar 2023 13:17:28 -   1.165
+++ cpu.c   25 Jul 2023 06:17:59 -
@@ -1181,7 +1181,8 @@ cpu_fix_msrs(struct cpu_info *ci)
 * This MSR is available on all AMD families >= 10h, except 11h
 * where LFENCE is always serializing.
 */
-   if (family >= 0x10 && family != 0x11) {
+   if (family >= 0x10 && family != 0x11 &&
+   (cpu_ecxfeature & CPUIDECX_HV) == 0) {
msr = rdmsr(MSR_DE_CFG);
if ((msr & DE_CFG_SERIALIZE_LFENCE) == 0) {
msr |= DE_CFG_SERIALIZE_LFENCE;

On Mon Jul 24, 2023 at 10:25:29PM -0600, Theo de Raadt wrote:
> Would like to know if this patch helps anyone with this type of
> problem.
> 
> Index: sys/arch/amd64/amd64/cpu.c
> ===
> RCS file: /cvs/src/sys/arch/amd64/amd64/cpu.c,v
> retrieving revision 1.172
> diff -u -p -u -r1.172 cpu.c
> --- sys/arch/amd64/amd64/cpu.c24 Jul 2023 14:53:58 -  1.172
> +++ sys/arch/amd64/amd64/cpu.c25 Jul 2023 03:28:35 -
> @@ -1216,7 +1216,8 @@ cpu_fix_msrs(struct cpu_info *ci)
>   if (msr != nmsr)
>   wrmsr(MSR_DE_CFG, nmsr);
>   }
> - if (family == 0x17 && ci->ci_model >= 0x31) {
> + if (family == 0x17 && ci->ci_model >= 0x31 &&
> + (cpu_ecxfeature & CPUIDECX_HV) == 0) {
>   nmsr = msr = rdmsr(MSR_DE_CFG);
>   nmsr |= DE_CFG_SERIALIZE_9;
>   if (msr != nmsr)
> Index: sys/arch/i386/i386/machdep.c
> ===
> RCS file: /cvs/src/sys/arch/i386/i386/machdep.c,v
> retrieving revision 1.664
> diff -u -p -u -r1.664 machdep.c
> --- sys/arch/i386/i386/machdep.c  24 Jul 2023 14:54:00 -  1.664
> +++ sys/arch/i386/i386/machdep.c  25 Jul 2023 03:28:29 -
> @@ -1993,7 +1993,8 @@ identifycpu(struct cpu_info *ci)
>   if (msr != nmsr)
>   wrmsr(MSR_DE_CFG, nmsr);
>   }
> - if (family == 0x17 && ci->ci_model >= 0x31) {
> + if (family == 0x17 && ci->ci_model >= 0x31 &&
> + (cpu_ecxfeature & CPUIDECX_HV) == 0) {
>   nmsr = msr = rdmsr(MSR_DE_CFG);
>   nmsr |= DE_CFG_SERIALIZE_9;
>   if (msr != nmsr)
> 



Re: qt.qpa.xcb: xcb_shm_attach() failed

2022-11-16 Thread Rafael Sadowski
On Sun Nov 13, 2022 at 08:37:55PM +0100, Rafael Sadowski wrote:
> I don't know if this has worked in the past, but when debugging some Qt
> applications I saw the following debug messages:
> 
> $ gwenview
> qt.qpa.xcb: Has MIT-SHM : true
> qt.qpa.xcb: Has MIT-SHM FD  : true
> qt.qpa.xcb: xcb_shm_attach() failed
> qt.qpa.xcb: failed to create System V shared memory segment (remote X11 
> connection?), disabling SHM
> qt.qpa.xcb: Using XInput version 2.2
> qt.qpa.screen: Output DP-1 is not connected
> qt.qpa.screen: Output HDMI-1 is not connected
> 
> The code that fails is here. xcb_shm_attach_checked and/or
> xcb_request_check failed with all my Qt applications.
> 
> pobj/qtbase-5.15.6/qtbase-everywhere-src-5.15.6/src/plugins/platforms/xcb/qxcbbackingstore.cpp
> 
> bool QXcbBackingStoreImage::createSystemVShmSegment(xcb_connection_t *c, 
> size_t segmentSize,
> xcb_shm_segment_info_t 
> *shmInfo)
> {
> const int id = shmget(IPC_PRIVATE, segmentSize, IPC_CREAT | 0x1C0);
> if (id == -1) {
> qCWarning(lcQpaXcb, "shmget() failed (%d: %s) for size %zu", errno, 
> strerror(errno), segmentSize);
> return false;
> }
> 
> void *addr = shmat(id, nullptr, 0);
> if (addr == (void *)-1) {
> qCWarning(lcQpaXcb, "shmat() failed (%d: %s) for id %d", errno, 
> strerror(errno), id);
> return false;
> }
> 
> if (shmctl(id, IPC_RMID, nullptr) == -1)
> qCWarning(lcQpaXcb, "Error while marking the shared memory segment to 
> be destroyed");
> 
> const auto seg = xcb_generate_id(c);
> auto cookie = xcb_shm_attach_checked(c, seg, id, false);
> auto *error = xcb_request_check(c, cookie);
> if (error) {
> qCWarning(lcQpaXcb(), "xcb_shm_attach() failed");
> free(error);
> if (shmdt(addr) == -1)
> qCWarning(lcQpaXcb, "shmdt() failed (%d: %s) for %p", errno, 
> strerror(errno), addr);
> return false;
> 
> 
> If you want to test it run any Qt application with
> QT_LOGGING_RULES="qt.qpa.xcb.debug=true" exported.
> 
> Should SHM with XCB generally work on OpenBSD?
> 
> Rafael
> 

Okay I tried to isolate that issue form Qt and unfortunately I can
reproduce the same issue.

The following code only works with "DISPLAY:0" and xcb_connect. Which is
wired, isn't?

- xcb_connect(3):
 - display_name = "DISPLAY:0" - works
 - display_name = ":0" fails with xcb_shm_attach_checked
 - display_name = NULL fails with  xcb_shm_attach_checked

- XOpenDisplay(3):
 - display_name = "DISPLAY:0" - segmentation fault
 - display_name = ":0" fails with xcb_shm_attach_checked
 - display_name = NULL fails with xcb_shm_attach_checked


Qt use XOpenDisplay(3) to connect to the XServer. Unfortunately, I can't
find a solution with XOpenDisplay(3) which works with SHM. Someone has
an idea or can confirm my issue?

Here is my "small" test case:

//  cc -O2 -pipe -std=c99 -I/usr/X11R6/include/xcb -I/usr/X11R6/include 
-L/usr/X11R6/lib \
//-lxcb-shm -lxcb -lX11-xcb -lX11 xcb_shm_attach.c
#include 
#include 
#include 
#include 
#include 

#include 
#include 
#include 

#include 
#include 
#include 
#include 

#include 
#include 
#include 
#include 



int main(int argc, char *argv[]) {

// create connection to X11 server

/**
 * displayname = "DISPLAY:0" work with xcb_shm_attach_checked

 * displayname = ":0" NOT work with xcb_shm_attach_checked
 * displayname = NULL NOT work with xcb_shm_attach_checked
 */
/*
int screen = 0;
xcb_connection_t* c = xcb_connect("DISPLAY:0", ); // is the only one 
that works with xcb_shm_attach_checked
if(c == NULL) {
printf("xcb_connect");
return -1;
}
*/

/**
 * displayname = "DISPLAY:0" segmentation fault

 * displayname = ":0" NOT work with xcb_shm_attach_checked
 * displayname = NULL NOT work with xcb_shm_attach_checked
 */
Display *dpy = XOpenDisplay(NULL);
xcb_connection_t* c = XGetXCBConnection(dpy);

struct xcb_shm_segment_info_t *shmInfo;
size_t segmentSize = 1800;
const int id = shmget(IPC_PRIVATE, segmentSize, IPC_CREAT | 0600);
if (id == -1) {
printf("shmget");
return -1;
}

void *addr = shmat(id, NULL, 0);
if (addr == (void *)-1) {
printf("shmat");
return -1;
}

if (shmctl(id, IPC_RMID, NULL) == -1) {
printf("shmctl");
return -1;
}

const uint32_t seg = xcb_generate_id(c);
xcb_void_cookie_t cookie = xcb_shm_attach_checked(c, seg, id, 1);
xcb_generic_error_t* error = xcb

Re: qt.qpa.xcb: xcb_shm_attach() failed

2022-11-13 Thread Rafael Sadowski
On Sun Nov 13, 2022 at 08:37:55PM +0100, Rafael Sadowski wrote:
> I don't know if this has worked in the past, but when debugging some Qt
> applications I saw the following debug messages:
> 
> $ gwenview
> qt.qpa.xcb: Has MIT-SHM : true
> qt.qpa.xcb: Has MIT-SHM FD  : true
> qt.qpa.xcb: xcb_shm_attach() failed
> qt.qpa.xcb: failed to create System V shared memory segment (remote X11 
> connection?), disabling SHM
> qt.qpa.xcb: Using XInput version 2.2
> qt.qpa.screen: Output DP-1 is not connected
> qt.qpa.screen: Output HDMI-1 is not connected
> 
> The code that fails is here. xcb_shm_attach_checked and/or
> xcb_request_check failed with all my Qt applications.
> 
> pobj/qtbase-5.15.6/qtbase-everywhere-src-5.15.6/src/plugins/platforms/xcb/qxcbbackingstore.cpp
> 
> bool QXcbBackingStoreImage::createSystemVShmSegment(xcb_connection_t *c, 
> size_t segmentSize,
> xcb_shm_segment_info_t 
> *shmInfo)
> {
> const int id = shmget(IPC_PRIVATE, segmentSize, IPC_CREAT | 0x1C0);
  ^
This is 0600 by default not 0x1C0. It was a test.



qt.qpa.xcb: xcb_shm_attach() failed

2022-11-13 Thread Rafael Sadowski
I don't know if this has worked in the past, but when debugging some Qt
applications I saw the following debug messages:

$ gwenview
qt.qpa.xcb: Has MIT-SHM : true
qt.qpa.xcb: Has MIT-SHM FD  : true
qt.qpa.xcb: xcb_shm_attach() failed
qt.qpa.xcb: failed to create System V shared memory segment (remote X11 
connection?), disabling SHM
qt.qpa.xcb: Using XInput version 2.2
qt.qpa.screen: Output DP-1 is not connected
qt.qpa.screen: Output HDMI-1 is not connected

The code that fails is here. xcb_shm_attach_checked and/or
xcb_request_check failed with all my Qt applications.

pobj/qtbase-5.15.6/qtbase-everywhere-src-5.15.6/src/plugins/platforms/xcb/qxcbbackingstore.cpp

bool QXcbBackingStoreImage::createSystemVShmSegment(xcb_connection_t *c, size_t 
segmentSize,
xcb_shm_segment_info_t 
*shmInfo)
{
const int id = shmget(IPC_PRIVATE, segmentSize, IPC_CREAT | 0x1C0);
if (id == -1) {
qCWarning(lcQpaXcb, "shmget() failed (%d: %s) for size %zu", errno, 
strerror(errno), segmentSize);
return false;
}

void *addr = shmat(id, nullptr, 0);
if (addr == (void *)-1) {
qCWarning(lcQpaXcb, "shmat() failed (%d: %s) for id %d", errno, 
strerror(errno), id);
return false;
}

if (shmctl(id, IPC_RMID, nullptr) == -1)
qCWarning(lcQpaXcb, "Error while marking the shared memory segment to 
be destroyed");

const auto seg = xcb_generate_id(c);
auto cookie = xcb_shm_attach_checked(c, seg, id, false);
auto *error = xcb_request_check(c, cookie);
if (error) {
qCWarning(lcQpaXcb(), "xcb_shm_attach() failed");
free(error);
if (shmdt(addr) == -1)
qCWarning(lcQpaXcb, "shmdt() failed (%d: %s) for %p", errno, 
strerror(errno), addr);
return false;


If you want to test it run any Qt application with
QT_LOGGING_RULES="qt.qpa.xcb.debug=true" exported.

Should SHM with XCB generally work on OpenBSD?

Rafael



Re: clang: compile static analyzer

2022-01-14 Thread Rafael Sadowski
On Fri Jan 14, 2022 at 03:17:21PM +0100, Tobias Heider wrote:
> Hi,
> 
> clang ships with a pretty useful static analyzer to find all kinds of bugs
> in C and C++ code:
> 
> https://clang-analyzer.llvm.org/
> 
> I use it regularly to check my own diffs and found plenty of bugs I could
> have missed otherwise.  While we have the code in base we don't actually
> build it into our libclang currently, so the only ways to use it are
> manually modifying the Makefiles or installing llvm from ports.
> 
> I was wondering if anyone else uses this and if there was any interest to
> have this in our base clang?

Please checkout devel/clang-tools-extra, if you missed something let me know.
CLANG_ENABLE_STATIC_ANALYZER=ON is enabled by default.

Rafael

> 
> diff --git gnu/usr.bin/clang/Makefile gnu/usr.bin/clang/Makefile
> index 6cf71d36cf8..b47abc02474 100644
> --- gnu/usr.bin/clang/Makefile
> +++ gnu/usr.bin/clang/Makefile
> @@ -39,6 +39,11 @@ SUBDIR+=libclangSerialization
>  SUBDIR+=libclangFrontend
>  SUBDIR+=libclangRewriteFrontend
>  SUBDIR+=libclangFrontendTool
> +SUBDIR+=libclangASTMatchers
> +SUBDIR+=libclangCrossTU
> +SUBDIR+=libclangStaticAnalyzer
> +SUBDIR+=libclangIndex
> +SUBDIR+=libclangTooling
>  
>  SUBDIR+=clang
>  
> diff --git gnu/usr.bin/clang/clang/Makefile gnu/usr.bin/clang/clang/Makefile
> index 76535ee8842..7d3847f883d 100644
> --- gnu/usr.bin/clang/clang/Makefile
> +++ gnu/usr.bin/clang/clang/Makefile
> @@ -43,6 +43,11 @@ LLVM_LIBDEPS=  LLVM \
>   clangEdit \
>   clangAST \
>   clangLex \
> - clangBasic
> + clangBasic \
> + clangStaticAnalyzer \
> + clangCrossTU \
> + clangASTMatchers \
> + clangIndex \
> + clangTooling \
>  
>  .include 
> diff --git gnu/usr.bin/clang/include/clang/Config/config.h 
> gnu/usr.bin/clang/include/clang/Config/config.h
> index 02a049bf2be..93494d6a0b1 100644
> --- gnu/usr.bin/clang/include/clang/Config/config.h
> +++ gnu/usr.bin/clang/include/clang/Config/config.h
> @@ -78,7 +78,7 @@
>  /* Enable each functionality of modules */
>  #define CLANG_ENABLE_ARCMT 0
>  #define CLANG_ENABLE_OBJC_REWRITER 0
> -#define CLANG_ENABLE_STATIC_ANALYZER 0
> +#define CLANG_ENABLE_STATIC_ANALYZER 1
>  
>  /* Spawn a new process clang.exe for the CC1 tool invocation, when necessary 
> */
>  #define CLANG_SPAWN_CC1 0
> diff --git gnu/usr.bin/clang/libclangASTMatchers/Makefile 
> gnu/usr.bin/clang/libclangASTMatchers/Makefile
> new file mode 100644
> index 000..76c79c738cb
> --- /dev/null
> +++ gnu/usr.bin/clang/libclangASTMatchers/Makefile
> @@ -0,0 +1,25 @@
> +LIB= clangASTMatchers
> +NOPIC=
> +NOPROFILE=
> +
> +CPPFLAGS+=${CLANG_INCLUDES}
> +
> +.include 
> +
> +# Core
> +SRCS+=   ASTMatchFinder.cpp \
> + ASTMatchersInternal.cpp \
> + GtestMatchers.cpp \
> + Diagnostics.cpp \
> + Marshallers.cpp \
> + Parser.cpp \
> + Registry.cpp \
> + VariantValue.cpp \
> +
> +.PATH:   ${.CURDIR}/../../../llvm/clang/lib/ASTMatchers
> +.PATH:   ${.CURDIR}/../../../llvm/clang/lib/ASTMatchers/Dynamic
> +
> +install:
> + @# Nothing here so far ...
> +
> +.include 
> diff --git gnu/usr.bin/clang/libclangAnalysis/Makefile 
> gnu/usr.bin/clang/libclangAnalysis/Makefile
> index 25669a34cc0..7be18f24685 100644
> --- gnu/usr.bin/clang/libclangAnalysis/Makefile
> +++ gnu/usr.bin/clang/libclangAnalysis/Makefile
> @@ -23,6 +23,7 @@ SRCS=   AnalysisDeclContext.cpp \
>   ExprMutationAnalyzer.cpp \
>   IssueHash.cpp \
>   LiveVariables.cpp \
> + MacroExpansionContext.cpp \
>   ObjCNoReturn.cpp \
>   PathDiagnostic.cpp \
>   PostOrderCFGView.cpp \
> diff --git gnu/usr.bin/clang/libclangCrossTU/Makefile 
> gnu/usr.bin/clang/libclangCrossTU/Makefile
> new file mode 100644
> index 000..59541bce012
> --- /dev/null
> +++ gnu/usr.bin/clang/libclangCrossTU/Makefile
> @@ -0,0 +1,17 @@
> +LIB= clangCrossTU
> +NOPIC=
> +NOPROFILE=
> +
> +CPPFLAGS+=   -I ${.CURDIR}/../../../llvm/clang/lib/CrossTU
> +CPPFLAGS+=${CLANG_INCLUDES}
> +
> +.include 
> +
> +SRCS+=   CrossTranslationUnit.cpp \
> +
> +.PATH:   ${.CURDIR}/../../../llvm/clang/lib/CrossTU/
> +
> +install:
> + @# Nothing here so far ...
> +
> +.include 
> diff --git gnu/usr.bin/clang/libclangIndex/Makefile 
> gnu/usr.bin/clang/libclangIndex/Makefile
> new file mode 100644
> index 000..b31d906a5ee
> --- /dev/null
> +++ gnu/usr.bin/clang/libclangIndex/Makefile
> @@ -0,0 +1,18 @@
> +LIB= clangIndex
> +NOPIC=
> +NOPROFILE=
> +
> +CPPFLAGS+=   -I ${.CURDIR}/../../../llvm/clang/lib/Index
> +CPPFLAGS+=${CLANG_INCLUDES}
> +
> +.include 
> +
> +SRCS+=   CommentToXML.cpp \
> + USRGeneration.cpp \
> +
> +.PATH:   ${.CURDIR}/../../../llvm/clang/lib/Index/
> +
> +install:
> + @# Nothing here so far ...
> +
> +.include 
> diff --git gnu/usr.bin/clang/libclangStaticAnalyzer/Makefile 
> 

waitid(2)

2021-12-07 Thread Rafael Sadowski
Our devel/boost uses waitid(2) but OpenBSD does not implement it yet.

In file included from /usr/local/include/boost/process.hpp:25:
In file included from /usr/local/include/boost/process/group.hpp:32:
/usr/local/include/boost/process/detail/posix/wait_group.hpp:38:17: error: no 
member named 'waitid' in the global namespace
 ret = ::waitid(P_PGID, p.grp, , WEXITED | WNOHANG);
   ~~^
/usr/local/include/boost/process/detail/posix/wait_group.hpp:38:24: error: use 
of undeclared identifier 'P_PGID'
 ret = ::waitid(P_PGID, p.grp, , WEXITED | WNOHANG);
^
/usr/local/include/boost/process/detail/posix/wait_group.hpp:38:48: error: use 
of undeclared identifier 'WEXITED'
 ret = ::waitid(P_PGID, p.grp, , WEXITED | WNOHANG);
^
/usr/local/include/boost/process/detail/posix/wait_group.hpp:74:17: error: no 
member named 'waitid' in the global namespace
 ret = ::waitid(P_PGID, p.grp, , WEXITED | WSTOPPED | WNOHANG);
   ~~^
/usr/local/include/boost/process/detail/posix/wait_group.hpp:74:24: error: use 
of undeclared identifier 'P_PGID'
 ret = ::waitid(P_PGID, p.grp, , WEXITED | WSTOPPED | WNOHANG);
^
/usr/local/include/boost/process/detail/posix/wait_group.hpp:74:49: error: use 
of undeclared identifier 'WEXITED'
 ret = ::waitid(P_PGID, p.grp, , WEXITED | WSTOPPED | WNOHANG);
 ^
/usr/local/include/boost/process/detail/posix/wait_group.hpp:74:59: error: use 
of undeclared identifier 'WSTOPPED'
 ret = ::waitid(P_PGID, p.grp, , WEXITED | WSTOPPED | WNOHANG);


Brad (boost co-maintainer) has found out the following, which I would
like to share here and ask for feedback:

waitid(2) is part of newer POSIX. Looks like waitid(2) was introduced
around Boost 1.69.

https://github.com/boostorg/process/commits/develop/include/boost/process/detail/posix/wait_group.hpp
https://github.com/boostorg/process/commit/eea73753b572ec5df69b2a624cbacf7569fde835

NetBSD imported it in 2016:
https://github.com/NetBSD/src/commit/1abafffcad6331f872b7d8e74ea533ed83e864b4

Is there anything against importing this into OpenBSD? Does anyone have
this in their diff stack already? I would love to test it with an port
witch depends on boot/process.hpp

Rafael



Re: sigwaitinfo(2) and sigtimedwait(2)

2021-10-04 Thread Rafael Sadowski
On Sun Sep 26, 2021 at 02:36:02PM +0200, Mark Kettenis wrote:
> > Date: Fri, 24 Sep 2021 19:36:21 +0200
> > From: Rafael Sadowski 
> > 
> > I'm trying to port the more KDE stuff so my question is from porter
> > perspective.
> > 
> > I need sigwaitinfo(2)/sigtimedwait(2) and I found both functions in
> > lib/libc/gen/sigwait.c with the comment "need kernel to fill in more
> > siginfo_t bits first". Is the comment still up to date? If no, is it
> > possible to unlock the functions?
> 
> Still true.  These functions are somewhat underspecified by POSIX so
> it isn't really obvious whatadditional bits need to be filled in.
> Having examples of code that use these interfaces from ports could
> help with that.
> 

One use-case from kscreenlocker-5.22.5/kcheckpass/kcheckpass.c

Full code:
https://github.com/KDE/kscreenlocker/blob/master/kcheckpass/kcheckpass.c

It tries to handle SIGUSR1 and SIGUSR2. I think this can be solved in
another way, so this is a bad example, isn't it?

/* signal_info for sigwaitinfo() */
siginfo_t signalInfo;

// now lets block on the fd
for (;;) {
conv_server(ConvPutReadyForAuthentication, 0);

keventData = kevent(keventQueue, NULL, 0, keventEvent, 1, NULL);
if (keventData == -1) {
/* Let's figure this out in the future, shall we */
message("kevent() failed with %d\n", errno);
return 1;
} else if (keventData == 0) {
/* Do we need to handle timeouts? */
message("kevent timeout\n");
continue;
}
// We know we got a SIGUSR1 or SIGUSR2, so fetch it via 
sigwaitinfo()
// (otherwise, we could have used sigtimedwait() )
int signalReturn = sigwaitinfo(, );
if (signalReturn < 0) {
if (errno == EINTR) {
message("sigawaitinfo() interrupted by unblocked caught 
signal");
continue;
} else if (errno == EAGAIN) {
/* This should not happen, as kevent notified us about such 
a signal */
message("no signal of type USR1 or USR2 pending.");
continue;
} else {
message("Unhandled error in sigwaitinfo()");
conv_server(ConvPutAuthError, 0);
return 1;
}
}
if (signalReturn == SIGUSR1) {
if (signalInfo.si_pid != parentPid) {
message("signal from wrong process\n");
continue;
}
/* Now do the fandango */
ret = Authenticate(method, username, conv_server);

if (ret == AuthBad) {
message("Authentication failure\n");
if (!nullpass) {
openlog("kcheckpass", LOG_PID, LOG_AUTH);
syslog(LOG_NOTICE, "Authentication failure for %s 
(invoked by uid %d)", username, uid);
}
}
switch (ret) {
case AuthOk:
conv_server(ConvPutAuthSucceeded, 0);
break;
case AuthBad:
conv_server(ConvPutAuthFailed, 0);
break;
case AuthError:
conv_server(ConvPutAuthError, 0);
break;
case AuthAbort:
conv_server(ConvPutAuthAbort, 0);
default:
break;
}
if (uid != geteuid()) {
// we don't support multiple auth for setuid kcheckpass
break;
}
} else if (signalReturn == SIGUSR2) {
if (signalInfo.si_pid != parentPid) {
message("signal from wrong process\n");
continue;
}
break;
}



Re: Missing include in sys/device.h

2021-09-28 Thread Rafael Sadowski
On Mon Sep 27, 2021 at 11:20:55PM -0600, Theo de Raadt wrote:
> Oh, like how about you try compiling a kernel after your proposed diff?
> 
> in userland -
>size_t comes from sys/types.h
>or a header file which pulls in sys/types.h, and there should be
>no further new iteration added
> 
> in kernel -
> size_t comes from either sys/param.h or sys/types.h, depending
> on which one a file includes
> 
> What you are suggesting is completely crazy.  It's akin to "all
> header files should include all other dependent header files, and
> hey maybe one day we can have a #include_all directive, eh?
> 
> Absolutely no way.
> 

Totally understandable! I have to get used with the userland/kernel src-
environment. Thanks for the explanation and sorry for the noise.



Missing include in sys/device.h

2021-09-27 Thread Rafael Sadowski
device.h misses a definition of size_t

/usr/include/sys/device.h:128:2: error: unknown type name 'size_t'

Index: device.h
===
RCS file: /cvs/src/sys/sys/device.h,v
retrieving revision 1.55
diff -u -p -r1.55 device.h
--- device.h10 Sep 2018 16:18:34 -  1.55
+++ device.h28 Sep 2021 05:04:57 -
@@ -44,6 +44,8 @@
 #ifndef _SYS_DEVICE_H_
 #define_SYS_DEVICE_H_
 
+#include 
+
 #include 
 
 /*



sigwaitinfo(2) and sigtimedwait(2)

2021-09-24 Thread Rafael Sadowski
I'm trying to port the more KDE stuff so my question is from porter
perspective.

I need sigwaitinfo(2)/sigtimedwait(2) and I found both functions in
lib/libc/gen/sigwait.c with the comment "need kernel to fill in more
siginfo_t bits first". Is the comment still up to date? If no, is it
possible to unlock the functions?

Thanks, Rafael



POSIX_C_SOURCE 200809L, XOPEN_SOURCE 700 and bsd_locale_fallbacks errors

2021-04-13 Thread Rafael Sadowski
Based on my cmake pull-request(1) to fix the cmake build on OpenBSD, the
following question has arisen which is worth analysing?

"It seems OpenBSD has a strange behavior because macro _POSIX_C_SOURCE is a
standard!  @sizeofvoid What are the errors raised if _POSIX_C_SOURCE or
_XOPEN_SOURCE are defined?" -- Marc Chevrier

[1]: https://gitlab.kitware.com/cmake/cmake/-/merge_requests/6000

The following code includes the if-defs from cmake with a simple sstream
include.

$ cat define_test.cxx
#if !defined(_WIN32) && !defined(__sun)
// POSIX APIs are needed
// NOLINTNEXTLINE(bugprone-reserved-identifier)
#  define _POSIX_C_SOURCE 200809L
#endif
#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__)
// For isascii
// NOLINTNEXTLINE(bugprone-reserved-identifier)
#  define _XOPEN_SOURCE 700
#endif

#include 
int main () { return 0; }

$ clang++ -std=c++17 define_test.cxx  # also with c++11/14
In file included from define_test.cxx:16:
In file included from /usr/include/c++/v1/sstream:173:
In file included from /usr/include/c++/v1/ostream:140:
In file included from /usr/include/c++/v1/locale:207:
/usr/include/c++/v1/__bsd_locale_fallbacks.h:122:17: error: use of undeclared 
identifier 'vasprintf'; did you mean 'vsprintf'?
int __res = vasprintf(__s, __format, __va);
^
/usr/include/c++/v1/cstdio:124:9: note: 'vsprintf' declared here
using ::vsprintf;
^
In file included from define_test.cxx:16:
In file included from /usr/include/c++/v1/sstream:173:
In file included from /usr/include/c++/v1/ostream:140:
In file included from /usr/include/c++/v1/locale:207:
/usr/include/c++/v1/__bsd_locale_fallbacks.h:122:27: error: cannot initialize a 
parameter of type 'char *' with an lvalue of type 'char **'
int __res = vasprintf(__s, __format, __va);
  ^~~
/usr/include/stdio.h:269:21: note: passing argument to parameter here
int  vsprintf(char *, const char *, __va_list);
^
2 errors generated

Looks like, if "_XOPEN_SOURCE 700" or "_POSIX_C_SOURCE 200809L" is defined we
run in this compile error. The question is, is that deliberate?



Re: Start point to learn OpenBSD programming

2020-03-16 Thread Rafael Sadowski
On Mon Mar 16, 2020 at 07:23:15AM +, Martin wrote:
> Hello list,
> 
> The best way for beginner to start with OpenbBSD programming?
> 
> Martin

http://www.grenadille.net/post/2019/10/21/10-projects-to-start-contributing-to-OpenBSD

Rafael



Re: Qt5's libtool link scripts are unusable

2019-06-20 Thread Rafael Sadowski
On Thu Jun 20, 2019 at 04:46:59PM +0100, Stuart Henderson wrote:
> Thanks for the report,
> 
> On 2019/06/20 17:30, Vadim Penzin wrote:
> > I admit that I am not familiar with the release process of pre-built binary
> > packages; I might be writing to a wrong mailing list and I apologize in
> > advance.
> 
> ports@ is the better list for this, I've CC'd and set reply-to.
> 
> > All libtool scripts from qt5 (/usr/local/lib/qt5/*.la) contain the following
> > on their third line:
> > 
> >   LIBQt5XXX_VERSION=5.9# The name that we can dlopen(3).
> > 
> > (XXX above stands for the name of a particular library, such as Core,
> > Network, etc.)
> > 
> > Since shell scripts (that libtool generates) source .la files, sh(1) fails
> > on unexpected '(' because someone, somewhere omitted a space before the
> > comment.
> > 
> > Patching /usr/local/lib/qt5/*.la files programmatically by tucking a space
> > before the hash character brings linking with Qt5 assisted (encumbered?) by
> > libtool back to life.
> > 
> > --Vadim
> > 
> 
> This patch to the qtbase port should fix the problem at source (I'll leave
> it building and test later). However it will also require REVISION bumps
> on all ports including .la files produced by this.
> 
> Index: Makefile
> ===
> RCS file: /cvs/ports/x11/qt5/qtbase/Makefile,v
> retrieving revision 1.29
> diff -u -p -w -u -r1.29 Makefile
> --- Makefile  20 May 2019 22:15:29 -  1.29
> +++ Makefile  20 Jun 2019 15:43:00 -
> @@ -15,13 +15,13 @@ PKGNAME-global =  qt5-global-${VERSION}
>  PKGNAME-psql =   qt5-postgresql-${VERSION}
>  PKGNAME-sqlite2 =qt5-sqlite2-${VERSION}
>  PKGNAME-tds =qt5-tds-${VERSION}
> +
>  REVISION-global =   0
> +REVISION-main =  5
>  REVISION-mysql = 0
>  REVISION-psql =  0
>  REVISION-sqlite2 =   0
>  REVISION-tds =   0
> -
> -REVISION-main =  4
>  
>  PKG_ARCH-global =*
>  PKG_ARCH-examples =  *
> Index: patches/patch-qmake_generators_unix_unixmake2_cpp
> ===
> RCS file: 
> /cvs/ports/x11/qt5/qtbase/patches/patch-qmake_generators_unix_unixmake2_cpp,v
> retrieving revision 1.3
> diff -u -p -w -u -r1.3 patch-qmake_generators_unix_unixmake2_cpp
> --- patches/patch-qmake_generators_unix_unixmake2_cpp 5 Jul 2018 09:49:13 
> -   1.3
> +++ patches/patch-qmake_generators_unix_unixmake2_cpp 20 Jun 2019 15:43:00 
> -
> @@ -136,13 +136,14 @@ Index: qmake/generators/unix/unixmake2.c
>   } else if (!project->isEmpty("QMAKE_AIX_SHLIB")) {
>   
> project->values("TARGET_").append(project->first("QMAKE_PREFIX_STATICLIB") + 
> project->first("TARGET")
>   + "." + project->first("QMAKE_EXTENSION_STATICLIB"));
> -@@ -1465,18 +1498,32 @@ UnixMakefileGenerator::writeLibtoolFile()
> +@@ -1465,18 +1498,33 @@ UnixMakefileGenerator::writeLibtoolFile()
> << QT_VERSION_STR << ")";
>   t << "\n";
>   
>  +if (!project->isEmpty("QMAKE_OPENBSD_SHLIB"))
>  +  t << "LIB" << fileVar("QMAKE_ORIG_TARGET") << "_VERSION="
> -+<< project->first("VER_MAJ") << "." << project->first("VER_MIN");
> ++<< project->first("VER_MAJ") << "." << project->first("VER_MIN")
> ++<< "\n";

This's what Qt 5.13 doas. They use "<< endl;" instead of "<< "\n";", I
would like to prefer that. std::endl calls std::flush which synchronizes
with the underlying storage device.

RS

>  +
>   t << "# The name that we can dlopen(3).\n"
>  -  << "dlname='" << fileVar(project->isActiveConfig("plugin") ? "TARGET" 
> : "TARGET_x")
> 



Re: witness report: vmmaplk, inode

2018-06-12 Thread Rafael Sadowski
On Wed Jun 13, 2018 at 07:47:42AM +1200, richard.n.proc...@gmail.com wrote:
> Hi, 
> 
> I found this witness log on my computestick but not here.
> 
> I was doing little at the time besides using emacs and some vanilla 
> chrome and possibly firefox. Hope it's of use.
> 
> cheers, 
> Richard. 
> 
> OpenBSD 6.3-current (GENERIC.MP) #10: Mon Jun 11 14:02:36 NZST 2018
> procter@dill.internal:/usr/src/sys/arch/amd64/compile/GENERIC.MP
> 
> (CVS checkout on this date, clean but for a pf patch. NZST is 12 
> hours ahead of UTC.) 
> 
> lock order reversal:
>  1st 0xff0009fe22f8 vmmaplk (>lock) @ 
>   /usr/src/sys/uvm/uvm_map.c:4433
>  2nd 0xff00691ec0a0 inode (>i_lock) @ 
>   /usr/src/sys/ufs/ufs/ufs_vnops.c:1555
> lock order ">i_lock"(rrwlock) -> ">lock"(rwlock) first seen at:
> #0  witness_checkorder+0x4b4
> #1  _rw_enter_read+0x49
> #2  uvmfault_lookup+0x8d
> #3  uvm_fault+0x72
> #4  trap+0x516
> #5  recall_trap+0x8
> #6  copyout+0x48
> #7  ffs_read+0x1f0
> #8  VOP_READ+0x49
> #9  vn_read+0xca
> #10 dofilereadv+0x21c
> #11 sys_read+0x82
> #12 syscall+0x32a
> #13 Xsyscall_untramp+0xc0
> lock order ">lock"(rwlock) -> ">i_lock"(rrwlock) first seen at:
> #0  witness_checkorder+0x4b4
> #1  _rw_enter+0x68
> #2  _rrw_enter+0x3e
> #3  VOP_LOCK+0x3d
> #4  vn_lock+0x34
> #5  uvn_io+0x1b8
> #6  uvm_pager_put+0x109
> #7  uvn_flush+0x424
> #8  uvm_map_clean+0x3e7
> #9  syscall+0x32a
> #10 Xsyscall_untramp+0xc0
> 
> 

Same here.

OpenBSD 6.3-current (GENERIC.MP) #92: Sun Jun 10 09:11:20 MDT 2018
dera...@amd64.openbsd.org:/usr/src/sys/arch/amd64/compile/GENERIC.MP

lock order reversal:
 1st 0xff03ab07b188 vmmaplk (>lock) @ /usr/src/sys/uvm/uvm_map.c:4433
 2nd 0xff044fe231a8 inode (>i_lock) @ 
/usr/src/sys/ufs/ufs/ufs_vnops.c:1555
lock order ">i_lock"(rrwlock) -> ">lock"(rwlock) first seen at:
#0  witness_checkorder+0x4b4
#1  _rw_enter_read+0x49
#2  uvmfault_lookup+0x8d
#3  uvm_fault+0x72
#4  trap+0x516
#5  recall_trap+0x8
#6  copyout+0x48
#7  ffs_read+0x1f0
#8  VOP_READ+0x49
#9  vn_read+0xca
#10 dofilereadv+0x21c
#11 sys_read+0x82
#12 syscall+0x32a
#13 Xsyscall_untramp+0xc0
lock order ">lock"(rwlock) -> ">i_lock"(rrwlock) first seen at:
#0  witness_checkorder+0x4b4
#1  _rw_enter+0x68
#2  _rrw_enter+0x3e
#3  VOP_LOCK+0x3d
#4  vn_lock+0x34
#5  uvn_io+0x1b8
#6  uvm_pager_put+0x109
#7  uvn_flush+0x424
#8  uvm_map_clean+0x3e7
#9  syscall+0x32a
#10 Xsyscall_untramp+0xc0




Wrong character in hackathons.html

2016-10-31 Thread Rafael Sadowski
Hi tech@,

see diff.

Kind regrads,

Rafael

Index: hackathons.html
===
RCS file: /cvs/www/hackathons.html,v
retrieving revision 1.104
diff -u -p -u -p -r1.104 hackathons.html
--- hackathons.html 31 Oct 2016 04:20:42 -  1.104
+++ hackathons.html 31 Oct 2016 22:26:23 -
@@ -1,4 +1,4 @@
-vhttp://www.w3.org/TR/html4/loose.dtd;>
 
 



posix_spawn(3)

2012-03-08 Thread Rafael Sadowski
Hello tech@

my last 2 hours I worked on octopress[1]. After fighting with ruby (I'm
NOT a fan) and build a port for devel/ruby-posix-spawn (depend by
octopress) I was surprised, I could not find posix_spawn(3)[2].

ed schouten e...@freebsd.org, hacked posix_spawn(3) and posix_spawnp(3)
for FreeBSD. It is already ported to NetBSD.

Long description, sort question: Is a patch welcome?

best regards

Rafael Sadowski


[1]: http://octopress.org
[2]: 
http://www.freebsd.org/cgi/man.cgi?query=posix_spawnpsektion=3apropos=0manpath=FreeBSD+9.0-RELEASE



Re: posix_spawn(3)

2012-03-08 Thread Rafael Sadowski
Hello Frank, hello tech@,

nice one, thanks! This diff works well with -current. My
ruby-posix-spawn build and works with posix_spawn(3) and
posix_spawnp(3). Currently I play with octopress and all looks great.
-- It was my first aim ;)

I hope any developer could check and commit it. Test with
ruby-posix-spawn, OK!

Best regards

Rafael Sadowski

On Thu Mar 08, 2012 at 01:24:00PM -0800, Frank Denis wrote:
 See http://download.pureftpd.org/misc/OpenBSD/patches/posix_spawn.diff
 
 -Frank.
 
 On Mar 8, 2012, at 1:08 PM, Rafael Sadowski raf...@sizeofvoid.org wrote:
 
  Hello tech@
  
  my last 2 hours I worked on octopress[1]. After fighting with ruby (I'm
  NOT a fan) and build a port for devel/ruby-posix-spawn (depend by
  octopress) I was surprised, I could not find posix_spawn(3)[2].
  
  ed schouten e...@freebsd.org, hacked posix_spawn(3) and posix_spawnp(3)
  for FreeBSD. It is already ported to NetBSD.
  
  Long description, sort question: Is a patch welcome?
  
  best regards
  
 Rafael Sadowski
  
  
  [1]: http://octopress.org
  [2]: 
  http://www.freebsd.org/cgi/man.cgi?query=posix_spawnpsektion=3apropos=0manpath=FreeBSD+9.0-RELEASE



delete at_* prototypes in ifconfig

2011-09-19 Thread Rafael Sadowski
Hello,

any comment? ;-)

best regards 

Rafael Sadowski


cvs server: Diffing ifconfig
Index: ifconfig/ifconfig.c
===
RCS file: /cvs/src/sbin/ifconfig/ifconfig.c,v
retrieving revision 1.249
diff -u -r1.249 ifconfig.c
--- ifconfig/ifconfig.c 21 Aug 2011 06:28:31 -  1.249
+++ ifconfig/ifconfig.c 19 Sep 2011 18:16:05 -
@@ -526,8 +526,6 @@
 void   in6_getaddr(const char *, int);
 void   in6_getprefix(const char *, int);
 #endif /* INET6 */
-voidat_status(int);
-voidat_getaddr(const char *, int);
 void   ieee80211_status(void);
 void   ieee80211_listchans(void);
 void   ieee80211_listnodes(void);



Re: issues with yacc/lex(er) from OpenBSD across my rules/grammer

2011-06-07 Thread Rafael Sadowski
On Wed Jun 01, 2011 at 11:03:46AM +0200, Otto Moerbeek wrote:
 On Wed, Jun 01, 2011 at 10:54:05AM +0200, Rafael Sadowski wrote:
 
  Hello @tech,
  
  I hope anybody can help my with my yacc rules/grammer. I can't find bugs
  in my grammer. I think the problem is in the lexer but I have no idea,
  how debug it. GDB tells me: No Source Available for yyparse (). Any
  advice, how debug it? This is my first experience with YACC! 
  
  Maybe any yacc/lex hacker has a minute to look over my parse.y. I am
  grateful for any advice. My parse.y based on ospfd and relayd.
 
 Run yacc with -t and set yydebug = 1 in your code. That will reveal
 the tokens yacc sees and what it does with them. 
 
   -Otto
 

Thanks Otto, this helped me a lot. Now, I'm one step big forward. 

I found one (In my opinion) strangeness in my grammeri/rule. It is
important to declare the TOKEN in dependence to other TOKEN?

It will not work with following rule, if I change WIRELESSNAME to
NETMASK it works file. I don't know why, what is the different between
WIRELESSNAME and NETMASK?


wirelessoptsl   : WIRELESSNAME STRING '{' {
 }
 | PRIORITY NUMBER optnl {
 }
 '}'
;


### my tokes:

%token NETWORK  ETHERNETNAME WIRELESSNAME 
%token BSSID CHANNEL DHCP DOMAINNAME DOMAINNAMESERVERS ERROR
%token INCLUDE INET INTERFACE YES
%token LLADDR MINSIGNAL NETMASK NWID NO PRIORITY RUNDOWN RUNUP 
%token UPDATEINTERVAL WEP WEPKEY 
%token WPA WPAAKMS WPACIPHERS WPAGROUPCIPHER WPAKEY
%token  v.string  STRING
%token  v.number  NUMBER
%type   v.string  string

### my keywords:

static const struct keywords keywords[] = {
{ bssid,  BSSID },
{ channel,CHANNEL },
{ dhcp,   DHCP },
{ domain-name,DOMAINNAME },
{ domain-name-servers,DOMAINNAMESERVERS },
{ error,  ERROR },
{ ethernet,   ETHERNETNAME },
{ include,INCLUDE },
{ inet,   INET },
{ interface,  INTERFACE },
{ yes,YES },
{ lladdr, LLADDR },
{ minsignal,  MINSIGNAL },
{ netmask,NETMASK },
{ network,NETWORK },
{ nwid,   NWID },
{ no, NO },
{ priority,   PRIORITY },
{ run-down,   RUNDOWN },
{ run-up, RUNUP },
{ update_interval,UPDATEINTERVAL },
{ wireless,   WIRELESSNAME },
{ wep,WEP},
{ wepkey, WEPKEY},
{ wpa,WPA},
{ wpaakms,WPAAKMS },
{ wpaciphers, WPACIPHERS },
{ wpagroupcipher, WPAGROUPCIPHER },
{ wpakey, WPAKEY }
};
const struct keywords   *p;

### my config file (crashed with wireless, works with netmask):

network local { 
ethernet home {
priority 23
}
ethernet work {
priority 23
}
wireless park {
priority 23
}
}

-- 
http://www.sizeofvoid.org - raf...@sizeofvoid.org
XMPP: z...@jabber.ccc.de
Key fingerprint: BDDD 91E9 28CB 3A52 3E99  61B0 C359 2691 BAC6 A3B1



Re: issues with yacc/lex(er) from OpenBSD across my rules/grammer

2011-06-07 Thread Rafael Sadowski
On Tue Jun 07, 2011 at 12:22:11PM +0200, Alexander Schrijver wrote:
 Your keywords aren't sorted.
 
shot me, you're damn right ;) Thanks Alexander

-- 
http://www.sizeofvoid.org - raf...@sizeofvoid.org
XMPP: z...@jabber.ccc.de
Key fingerprint: BDDD 91E9 28CB 3A52 3E99  61B0 C359 2691 BAC6 A3B1



issues with yacc/lex(er) from OpenBSD across my rules/grammer

2011-06-01 Thread Rafael Sadowski
Hello @tech,

I hope anybody can help my with my yacc rules/grammer. I can't find bugs
in my grammer. I think the problem is in the lexer but I have no idea,
how debug it. GDB tells me: No Source Available for yyparse (). Any
advice, how debug it? This is my first experience with YACC! 

Maybe any yacc/lex hacker has a minute to look over my parse.y. I am
grateful for any advice. My parse.y based on ospfd and relayd.


My parse.y should parse stuff like this:

network private {
ethernet local-fake-lladdr {
interface em0
priority 2
dhcp yes
# more options
}

ethernet local {
interface em1
priority 1
# more options
}

wireless openhome {
interface iwn0
priority 3

nwid WLAN NAME
bssid 00:21:6a:5f:11:92
chan 6
wpa {
wpakey=
wpagroupcipher=
wpaciphers=
wpaakms=
}
}
}
network private {
#... more ethernet and wireless stuff
}


But it crashed at my first ethernet area. network private { works,
but that is unfortunately all.

## parse.y

/*
 * Copyright (c) 2011 Rafael Sadowski raf...@sizeofvoid.org
 * Copyright (c) 2010 Reyk Floeter r...@vantronix.net
 * Copyright (c) 2004, 2005 Hans-Joerg Hoexer hshoe...@openbsd.org
 * Copyright (c) 2002, 2003, 2004 Henning Brauer henn...@openbsd.org
 * Copyright (c) 2001 Markus Friedl.  All rights reserved.
 * Copyright (c) 2001 Daniel Hartmeier.  All rights reserved.
 * Copyright (c) 2001 Theo de Raadt.  All rights reserved.
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED AS IS AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

%{
#include sys/types.h
#include sys/socket.h
#include sys/stat.h
#include sys/queue.h

#include ctype.h
#include unistd.h
#include err.h
#include errno.h
#include stdio.h
#include string.h

#include ifconfigd.h

TAILQ_HEAD(files, file)  files = TAILQ_HEAD_INITIALIZER(files);
static struct file {
TAILQ_ENTRY(file)entry;
FILE*stream;
char*name;
int  lineno;
int  errors;
} *file;
struct file *pushfile(const char *, int);
int  popfile(void);
int  check_file_secrecy(int, const char *);
int  yyparse(void);
int  yylex(void);
int  yyerror(const char *, ...);
int  yywarn(const char *, ...);
int  kw_cmp(const void *, const void *);
int  lookup(char *);
int  lgetc(int);
int  lungetc(int);
int  findeol(void);

TAILQ_HEAD(symhead, sym) symhead = TAILQ_HEAD_INITIALIZER(symhead);
struct sym {
TAILQ_ENTRY(sym) entry;
int  used;
int  persist;
char*nam;
char*val;
};
int  symset(const char *, const char *, int);
char*symget(const char *);


static struct ifconfigd_conf*conf;
static int   errors = 0;

typedef struct {
union {
int64_t  number;
char*string;
} v;
int lineno;
} YYSTYPE;
%}

/*
 * BEGIN yacc Deklarationen
 */
%token BSSID CHANNEL DHCP DOMAINNAME DOMAINNAMESERVERS ETHERNET ERROR
%token INCLUDE INET INTERFACE YES
%token LLADDR MINSIGNAL NETMASK NETWORK NWID NO  PRIORITY RUNDOWN RUNUP
%token UPDATEINTERVAL WEP WEPKEY WIRELESS
%token WPA WPAAKMS WPACIPHERS WPAGROUPCIPHER WPAKEY

%token  v.string  STRING
%token  v.number  NUMBER
%type   v.string  string
%type   v.interface   interface
%type   v.number  yesno

/*
 * BEGIN yacc rules/grammer
 */
%%
grammar : /* empty */
| grammar include '\n'
| grammar '\n'
| grammar global '\n'
| grammar varset '\n'
| grammar network '\n'
| grammar error '\n'{ file-errors++; }
;

optnl   : '\n' optnl

Re: Network Interface Daemon and ifconfig header file

2011-05-24 Thread Rafael Sadowski
On Wed May 04, 2011 at 08:09:44PM -0400, Arnaud Bergeron wrote:
 2011/5/4 Rafael Sadowski raf...@sizeofvoid.org:
  Hello @tech and all honorable OpenBSD Developer,
 
  first of all, I happy about any help or helpful advice!
 
  Based on Edd Barrett (edd@) idea[1] to develop a Network Interface
  Daemon for OpenBSD, I'm currently hack on it.
 
  My first really huge problem is similar to Edd thoughts:
 
  I guess this would mean moving all of the functions apart from main()
  from ifconfig.c into another file (complete with header), so that we can
  call them from the new ifconfigd? I'm no expert
 
  My first initial solution was similar. I created ifconfig.h. This diff
  is just for example. It works fine with ifconfig but how can I use it
  from another directory like src/usr.sbin/ifconfigd.
 
  My first try with modify[2] PATH and -L and -I CFLAGS doesn't work. It
  break with suff like this (I understand the error but I not know any
  solution):
 
 
  cc B  -o ifconfigd parse.o log.o control.o ifconfigd.o ifconfigde.o
 ifconfig.o bioctl.o pbkdf2.o -levent -lutil
  ifconfig.o(.text+0x2220): In function `usage':
  : multiple definition of `usage'[1;3B
  ifconfigd.o(.text+0x400): first defined here
  /usr/bin/ld: Warning: size of symbol `usage' changed from 38 in ifconfigd.o
 to 35 in ifconfig.o
 
 This
 
  ifconfig.o(.text+0xa440): In function `main':
  : multiple definition of `main'
  ifconfigd.o(.text+0x430): first defined here
  /usr/bin/ld: Warning: size of symbol `main' changed from 883 in ifconfigd.o
 to 1790 in ifconfig.o
 
 and this tells me you just copied all the function declarations in a
 header and tried to compile ifconfig.c in your program.  This will
 obviously not work since ifconfig.c defines a main() function (in
 addition to a usage()) and you want to use your own.
 
 You have to make a separate file in the ifconfig directory that holds
 the main() and usage() functions (or a separate file for all the other
 functions as edd suggests) and includes the ifconfig.h header and
 change the accompanying build instructions.
 

separate header file with all the other functions works fine with
ifconfig and ifconfigd.

Index: ifconfig/ifconfig.c
===
RCS file: /cvs/src/sbin/ifconfig/ifconfig.c,v
retrieving revision 1.246
diff -u -r1.246 ifconfig.c
--- ifconfig/ifconfig.c 23 Mar 2011 18:36:41 -  1.246
+++ ifconfig/ifconfig.c 2 May 2011 15:19:09 -
@@ -105,6 +105,7 @@
 #include ifaddrs.h
 
 #include brconfig.h
+#include ifconfig.h
 #include pbkdf2.h
 
 struct ifreq   ifr, ridreq;
@@ -137,126 +138,6 @@
 intshownet80211chans;
 intshownet80211nodes;
 
-void   notealias(const char *, int);
-void   setifaddr(const char *, int);
-void   setifrtlabel(const char *, int);
-void   setiflladdr(const char *, int);
-void   setifdstaddr(const char *, int);
-void   setifflags(const char *, int);
-void   setifxflags(const char *, int);
-void   setifbroadaddr(const char *, int);
-void   setifmtu(const char *, int);
-void   setifnwid(const char *, int);
-void   setifbssid(const char *, int);
-void   setifnwkey(const char *, int);
-void   setifwpa(const char *, int);
-void   setifwpaprotos(const char *, int);
-void   setifwpaakms(const char *, int);
-void   setifwpaciphers(const char *, int);
-void   setifwpagroupcipher(const char *, int);
-void   setifwpakey(const char *, int);
-void   setifchan(const char *, int);
-void   setifscan(const char *, int);
-void   setiftxpower(const char *, int);
-void   setifnwflag(const char *, int);
-void   unsetifnwflag(const char *, int);
-void   setifnetmask(const char *, int);
-void   setifprefixlen(const char *, int);
-void   setatrange(const char *, int);
-void   setatphase(const char *, int);
-void   settunnel(const char *, const char *);
-void   deletetunnel(const char *, int);
-void   settunnelinst(const char *, int);
-#ifdef INET6
-void   setia6flags(const char *, int);
-void   setia6pltime(const char *, int);
-void   setia6vltime(const char *, int);
-void   setia6lifetime(const char *, const char *);
-void   setia6eui64(const char *, int);
-void   setkeepalive(const char *, const char *);
-void   unsetkeepalive(const char *, int);
-#endif /* INET6 */
-void   checkatrange(struct sockaddr_at *);
-void   setmedia(const char *, int);
-void   setmediaopt(const char *, int);
-void   setmediamode(const char *, int);
-void   clone_create(const char *, int);
-void   clone_destroy(const char *, int);
-void   unsetmediaopt(const char *, int);
-void   setmediainst(const char *, int);
-void   settimeslot(const char *, int);
-void   timeslot_status(void);
-void   setmpelabel(const char *, int);
-void   setvlantag(const char *, int);
-void   setvlanprio(const char *, int);
-void   setvlandev(const char *, int);
-void   unsetvlandev(const char *, int);
-void   mpe_status(void);
-void   vlan_status(void);
-void   setinstance(const char *, int);
-intmain(int, char *[]);
-intprefix(void *val

Network Interface Daemon and ifconfig header file

2011-05-04 Thread Rafael Sadowski
(int);
-void   in6_getaddr(const char *, int);
-void   in6_getprefix(const char *, int);
-#endif /* INET6 */
-voidat_status(int);
-voidat_getaddr(const char *, int);
-void   ieee80211_status(void);
-void   ieee80211_listchans(void);
-void   ieee80211_listnodes(void);
-void   ieee80211_printnode(struct ieee80211_nodereq *);
-
-/* Known address families */
-const struct afswtch {
-   char *af_name;
-   short af_af;
-   void (*af_status)(int);
-   void (*af_getaddr)(const char *, int);
-   void (*af_getprefix)(const char *, int);
-   u_long af_difaddr;
-   u_long af_aifaddr;
-   caddr_t af_ridreq;
-   caddr_t af_addreq;
-} afs[] = {
-#define C(x) ((caddr_t) x)
-   { inet, AF_INET, in_status, in_getaddr, in_getprefix,
-   SIOCDIFADDR, SIOCAIFADDR, C(ridreq), C(in_addreq) },
-#ifdef INET6
-   { inet6, AF_INET6, in6_status, in6_getaddr, in6_getprefix,
-   SIOCDIFADDR_IN6, SIOCAIFADDR_IN6, C(in6_ridreq), C(in6_addreq) },
-#endif /* INET6 */
-#ifndef SMALL
-   { atalk, AF_APPLETALK, at_status, at_getaddr, NULL,
-   SIOCDIFADDR, SIOCAIFADDR, C(addreq), C(addreq) },
-#endif
-   { 0,0,  0,  0 }
-};

-const struct afswtch *afp; /*the address family being set or asked about*/

 int ifaliases = 0;
 int aflag = 0;
Index: ifconfig/ifconfig.h
===
RCS file: ifconfig/ifconfig.h
diff -N ifconfig/ifconfig.h
--- /dev/null   1 Jan 1970 00:00:00 -
+++ ifconfig/ifconfig.h 4 May 2011 09:03:50 -
@@ -0,0 +1,529 @@
+/*
+ * Copyright (c) 2011 Rafael Sadowski raf...@sizeofvoid.org
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED AS IS AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
+ * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+#ifndef _IFCONFIG_H_
+#define _IFCONFIG_H_
+
+#include sys/param.h
+#include sys/socket.h
+#include sys/ioctl.h
+
+#include net/if.h
+#include net/if_dl.h
+#include net/if_media.h
+#include net/if_types.h
+#include netinet/in.h
+#include netinet/in_var.h
+#include netinet6/nd6.h
+#include arpa/inet.h
+#include netinet/ip_ipsp.h
+#include netinet/if_ether.h
+#include net/if_enc.h
+#include net80211/ieee80211.h
+#include net80211/ieee80211_ioctl.h
+#include net/pfvar.h
+#include net/if_pfsync.h
+#include net/if_pflow.h
+#include net/if_pppoe.h
+#include net/if_trunk.h
+#include net/if_sppp.h
+#include net/ppp_defs.h
+
+#include netatalk/at.h
+
+#include netinet/ip_carp.h
+
+#include netdb.h
+
+#include net/if_vlan_var.h
+
+#include netmpls/mpls.h
+
+#include ctype.h
+#include err.h
+#include errno.h
+#include stdio.h
+#include stdlib.h
+#include string.h
+#include unistd.h
+#include ifaddrs.h
+
+#include brconfig.h
+
+/*
+#include sys/param.h
+#include sys/socket.h
+#include sys/ioctl.h
+
+#include netinet6/in6_var.h
+#include net80211/ieee80211.h
+#include net80211/ieee80211_ioctl.h
+
+#include net/if_sppp.h
+
+#include netatalk/at.h
+#include net/if_media.h
+
+#include brconfig.h
+#include pbkdf2.h
+*/
+struct ifreq   ifr, ridreq;
+struct in_aliasreq in_addreq;
+#ifdef INET6
+struct in6_ifreq   ifr6;
+struct in6_ifreq   in6_ridreq;
+struct in6_aliasreqin6_addreq;
+#endif /* INET6 */
+struct sockaddr_in netmask;
+
+#ifndef SMALL
+struct ifaliasreq  addreq;
+struct  netrange   at_nr;  /* AppleTalk net range */
+#endif /* SMALL */
+
+void   notealias(const char *, int);
+void   setifaddr(const char *, int);
+void   setifrtlabel(const char *, int);
+void   setiflladdr(const char *, int);
+void   setifdstaddr(const char *, int);
+void   setifflags(const char *, int);
+void   setifxflags(const char *, int);
+void   setifbroadaddr(const char *, int);
+void   setifmtu(const char *, int);
+void   setifnwid(const char *, int);
+void   setifbssid(const char *, int);
+void   setifnwkey(const char *, int);
+void   setifwpa(const char *, int);
+void   setifwpaprotos(const char *, int);
+void   setifwpaakms(const char *, int);
+void   setifwpaciphers(const char *, int);
+void   setifwpagroupcipher(const char *, int);
+void   setifwpakey(const char *, int);
+void   setifchan(const char *, int);
+void   setifscan(const char *, int);
+void   setiftxpower(const char *, int);
+void   setifnwflag(const char *, int);
+void   unsetifnwflag(const char *, int);
+void   setifnetmask(const char *, int);
+void   setifprefixlen(const