Skip to content

Commit

Permalink
Define unshare() macro to avoid dependence on __GNU_SOURCE
Browse files Browse the repository at this point in the history
unshare() is a linux syscall that we need. Unfortunately, access to it
depends on __GNU_SOURCE, which we would like to avoid. As such, we
define a macro to invoke it by its syscall code. This is necessary to
avoid the following warning from Clang:

implicit declaration of function 'unshare' is invalid in C99
[-Wimplicit-function-declaration]

Signed-off-by: Richard Yao <ryao@gentoo.org>
  • Loading branch information
ryao committed Nov 18, 2012
1 parent 2182f78 commit 189d09a
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/test/test-udev.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@

#include "udev.h"

#ifndef SYS_unshare
#error "libc fails to set SYS_unshare: please file a bug report with eudev"
#endif

#ifndef unshare
#define unshare(__X) syscall(SYS_unshare, __X)
#endif

void udev_main_log(struct udev *udev, int priority,
const char *file, int line, const char *fn,
const char *format, va_list args) {}
Expand Down

7 comments on commit 189d09a

@nwmcsween
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nak this is ugly, utilize __GNU_SOURCE for things that are __GNU_SOURCE in this case it's needed

@nwmcsween
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also doing this allows me to send random crap to the syscall instead of an int

@ryao
Copy link
Contributor Author

@ryao ryao commented on 189d09a Nov 18, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__GNU_SOURCE is a glibcism. Using it would cause problems for issue #9, which requests that we remove glibcisms.

@nwmcsween
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What? glibcisms are global (not feature macored) functions that don't follow / are not in POSIX standards or are just plain broken. Do not make a syscall macro, that is ugly as sin.

@ryao
Copy link
Contributor Author

@ryao ryao commented on 189d09a Nov 18, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue is that the glibc authors decided to declare that a Linux kernel feature to be a GNU extension. If a feature test macro existed that did not require enabling GNU extensions, we could use that.

@nwmcsween
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As it should be it's an non-standard function the feature macro could be called anything that doesn't matter.

@ryao
Copy link
Contributor Author

@ryao ryao commented on 189d09a Nov 18, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The distinction is that __GNU_SOURCE should apply to extensions specific to the GNU operating system whose userland is often used with Linux. Since unshare() is a Linux syscall, it should not depend on __GNU_SOURCE. Setting it would enable things that we do not want.

Please sign in to comment.