[Mono-devel-list] Re: problems with Syscall.syslog

Martin Honermeyer maze at strahlungsfrei.de
Fri Jun 24 01:25:34 EDT 2005


Hello Vorobiev,

Vorobiev Maksim wrote:

> Good day.
> 
> I've started using Syscall.syslog method and encounted several problems.
> It may be errors in mono, or I just missed some details. Please note,
> that I use Suse 9.2 linux distribute.
> 
> 1. In Syscall.cs enumeration SyslogFacility declared with members:
> 
> LOG_UUCP = 8 << 3,
> 
> LOG_CRON = 8 << 3
> 

Yes, it's a bug! Should be filed.

> 
> 2. There is no constant LOG_USRE in syslog.h under Suse, but it's
> LOG_USER. So, in support/map.c there is a bug (?) - no such definition
> found and error returned then code execution steps in this branch. The
> question is the same: is it mono problem, or Suse-platform specific
> header file?

This bug was fixed some days ago in SVN.
http://bugzilla.ximian.com/show_bug.cgi?id=75274

> 
> 3. It seems very strange that SyslogFacility enumeration declared with
> [Flag] attribute. Members of this enumeration are not "powers of 2", so
> their combination via OR-mask is something incorrect. And these
> constants should be used independantly, not in combination. Is it true
> or I missed something?

You are right. They are not to be used in combination. Quoting
http://blogs.msdn.com/kcwalina/archive/2004/05/18/134208.aspx):

"Do use the System.FlagsAttribute custom attribute for an enum only if a
bitwise OR operation is to be performed on the numeric values[1]." 

And, as an additional advice:

"Do use powers of two for the enum values so they can be easily combined."


It seems like this should be commented on by a real Mono dev..


> 4. In Mono_Posix_FromSyslogFacility in support/map.c constants from
> SyslogFacility interpreted as flags - they checked with OR-mask. It's
> incorrect as I understand, but more then it, there is such branch:
> 
> if ((x & Mono_Posix_SyslogFacility_LOG_USRE) ==
> Mono_Posix_SyslogFacility_LOG_USRE)
> 
> #ifdef LOG_USRE
> 
> *r |= LOG_USRE;
> 
> #else /* def LOG_USRE */
> 
> {errno = EINVAL; return -1;}
> 
> #endif /* ndef LOG_USRE */
> 
> This is combination of 2) and 3) issues. First of all, undefined macro
> LOG_USRE always runs to error return. The second one, that
> Mono_Posix_SyslogFacility_LOG_USRE declared as follows:
> 
> #define Mono_Posix_SyslogFacility_LOG_USRE 0x00000008
> 
> This means, that branch
> 
> if ((x & Mono_Posix_SyslogFacility_LOG_USRE) ==
> Mono_Posix_SyslogFacility_LOG_USRE)
> 
> will becomes true for all constants like #define
> Mono_Posix_SyslogFacility_LOG_DAEMON 0x00000018 #define
> Mono_Posix_SyslogFacility_LOG_SYSLOG 0x00000028 ...etc
> 
> And it always will generate error for Suse.

You are right. This is really wrong behaviour!

> 
> I'm ready to fix these issues and supply the patch. Is it OK to change
> SyslogFacility enumeration to simple enum, not flags? Is it OK to
> assume, that LOG_USRE is LOG_USER in real for all platforms?

As I said above, this has been fixed in Syscall.cs. map.c and map.h have yet
to be changed, though!

> 
> Is it good to change declaration of LOG_UUCP and LOG_CRON as LOG_UUCP =
> 8 << 3, LOG_CRON = 9 << 3 ?

I think so.


Greetz,
Martin





More information about the Mono-devel-list mailing list