[PATCH] watchdog add settimeout ioctl

Tito farmatito at tiscali.it
Wed Aug 6 08:16:14 UTC 2008


On Wednesday 06 August 2008 09:16:58 you wrote:
> > Hi Darius,
> > 
> > Please remove the last argument as there is some preprocessor magic
> > in in libbb.h that will add it automagically depending on the setting
> > of f ENABLE_IOCTL_HEX2STR_ERROR
> 
> but it does not compile if ENABLE_IOCTL_HEX2STR_ERROR is set, because then bb_ioctl_or_warn() needs more arguments.
> if ENABLE_IOCTL_HEX2STR_ERROR is not set, ioctl name is replaced with hex number, what is not good readable.

Hi,
that is why you need to use ioctl_or_warn instead:
+       ioctl_or_warn(3, WDIOC_SETTIMEOUT,  &htimer_duration);
+       ioctl_or_warn(3, WDIOC_GETTIMEOUT,  &htimer_duration);

that way the preprocessor will transform it to:
1) if ENABLE_IOCTL_HEX2STR_ERROR is set:
                    bb_ioctl_or_warn(3, WDIOC_SETTIMEOUT,  &htimer_duration, "WDIOC_SETTIMEOUT");
                    bb_ioctl_or_warn(3, WDIOC_GETTIMEOUT,  &htimer_duration, "WDIOC_GETTIMEOUT");
2)if ENABLE_IOCTL_HEX2STR_ERROR is not set:
                    bb_ioctl_or_warn(3, WDIOC_SETTIMEOUT,  &htimer_duration);
                    bb_ioctl_or_warn(3, WDIOC_GETTIMEOUT,  &htimer_duration);
this is done to allow size reduction and is widely used in BB source code.
as you can see if you grep for ioctl_or_warn or xioctl.
If you want to use custom error messages use:

ioctl_or_perror(int fd, unsigned request, void *argp, const char *fmt,...)

Ciao,
Tito

> > 
> > #if ENABLE_IOCTL_HEX2STR_ERROR
> > int bb_ioctl_or_warn(int fd, unsigned request, void *argp, const char *ioctl_name) FAST_FUNC;
> > int bb_xioctl(int fd, unsigned request, void *argp, const char *ioctl_name) FAST_FUNC;
> > #define ioctl_or_warn(fd,request,argp) bb_ioctl_or_warn(fd,request,argp,#request)
> > #define xioctl(fd,request,argp)        bb_xioctl(fd,request,argp,#request)
> > #else
> > int bb_ioctl_or_warn(int fd, unsigned request, void *argp) FAST_FUNC;
> > int bb_xioctl(int fd, unsigned request, void *argp) FAST_FUNC;
> > #define ioctl_or_warn(fd,request,argp) bb_ioctl_or_warn(fd,request,argp)
> > #define xioctl(fd,request,argp)        bb_xioctl(fd,request,argp)
> > #endif
> > 
> > 
> > +       bb_ioctl_or_warn(3, WDIOC_SETTIMEOUT,  &htimer_duration, "error setting hardware timer");
> > +       bb_ioctl_or_warn(3, WDIOC_GETTIMEOUT,  &htimer_duration, "error getting timer value");
> > 
> > 
> > so you should change the calls to:
> > +       ioctl_or_warn(3, WDIOC_SETTIMEOUT,  &htimer_duration);
> > +       ioctl_or_warn(3, WDIOC_GETTIMEOUT,  &htimer_duration);
> > 
> > They will print the following error message depending on ENABLE_IOCTL_HEX2STR_ERROR:
> > 
> > ioctl WDIOC_SETTIMEOUT failed
> > 
> > or
> > 
> > ioctl 0x0000 failed
> > 
> > if you want to use your custom error messages you can use:
> > 
> > ioctl_or_perror(int fd, unsigned request, void *argp, const char *fmt,...)
> > 
> > but this will increase size.
> > 
> > Sorry for the inconvenience as i mislead a bit you with my first
> > mail but i forgot about this magic stuff.
> > 
> > Ciao,
> > Tito
> 
> 





More information about the busybox mailing list