Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sched_setaffinity() and sched_getaffinity() implicitly declared #404

Closed
giampaolo opened this issue May 23, 2014 · 7 comments
Closed

sched_setaffinity() and sched_getaffinity() implicitly declared #404

giampaolo opened this issue May 23, 2014 · 7 comments

Comments

@giampaolo
Copy link
Owner

From [email protected] on June 29, 2013 09:13:32

sched.h of glibc declares sched_setaffinity() and sched_getaffinity() when 
_GNU_SOURCE is defined. See `man sched_setaffinity`.

When _GNU_SOURCE is not defined anywhere, then compilation might fail:

psutil/_psutil_linux.c: In function ‘get_process_cpu_affinity’:
psutil/_psutil_linux.c:182:5: error: implicit declaration of function 
‘sched_getaffinity’ [-Werror=implicit-function-declaration]
     if (sched_getaffinity(pid, len, (cpu_set_t *)&mask) < 0) {
     ^
psutil/_psutil_linux.c: In function ‘set_process_cpu_affinity’:
psutil/_psutil_linux.c:202:5: error: implicit declaration of function 
‘sched_setaffinity’ [-Werror=implicit-function-declaration]
     if (sched_setaffinity(pid, len, (cpu_set_t *)&mask)) {
     ^

Fix:

--- psutil/_psutil_linux.c
+++ psutil/_psutil_linux.c
@@ -11,6 +11,7 @@
 #include <stdlib.h>
 #include <mntent.h>
 #include <utmp.h>
+#define _GNU_SOURCE
 #include <sched.h>
 #include <sys/syscall.h>
 #include <sys/sysinfo.h>

Original issue: http://code.google.com/p/psutil/issues/detail?id=404

@giampaolo
Copy link
Owner Author

From [email protected] on June 30, 2013 00:40:28

Python.h indirectly includes features.h, which has _FEATURES_H check against 
multiple inclusion, so _GNU_SOURCE needs to be defined earlier.

Updated patch:
--- psutil/_psutil_linux.c
+++ psutil/_psutil_linux.c
@@ -6,6 +6,7 @@
  * Linux-specific functions.
  */

+#define _GNU_SOURCE
 #include <Python.h>
 #include <errno.h>
 #include <stdlib.h>

@giampaolo
Copy link
Owner Author

From g.rodola on July 04, 2013 07:05:39

Fixed in revision b304cfaf3b7c . Thanks for the patch.

Status: FixedInHG
Labels: OpSys-Linux Milestone-1.0.0

@giampaolo
Copy link
Owner Author

From [email protected] on July 04, 2013 07:39:26

First patch was not working. Please move '#define _GNU_SOURCE' before inclusion 
of Python.h.

@giampaolo
Copy link
Owner Author

From g.rodola on July 06, 2013 06:02:29

whops! right.
done, thanks.

@giampaolo
Copy link
Owner Author

From g.rodola on July 11, 2013 01:54:35

Status: Fixed

@giampaolo
Copy link
Owner Author

From g.rodola on August 28, 2013 09:24:42

I'm reopening this as right now we're getting a compiler warning because of 
this change:

/usr/include/python2.7/pyconfig.h:1139:0: warning: "_GNU_SOURCE" redefined 
[enabled by default]

Since I couldn't and still cannot reproduce the original issue, before I commit 
can you please tell me if the following patch breaks anything?


diff --git a/psutil/_psutil_linux.c b/psutil/_psutil_linux.c
--- a/psutil/_psutil_linux.c
+++ b/psutil/_psutil_linux.c
@@ -6,22 +6,26 @@
  * Linux-specific functions.
  */

-#define _GNU_SOURCE
 #include <Python.h>
 #include <errno.h>
 #include <stdlib.h>
 #include <mntent.h>
 #include <utmp.h>
-#include <sched.h>
 #include <sys/syscall.h>
 #include <sys/sysinfo.h>
 #include <sys/time.h>
 #include <sys/resource.h>
 #include <linux/unistd.h>

+// "man sched_setaffinity" dictates to include _GNU_SOURCE but this may
+// be already defined elsewhere
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+#include <sched.h>
+
 #include "_psutil_linux.h"

-
 #define HAS_IOPRIO defined(__NR_ioprio_get) && defined(__NR_ioprio_set)

 #if HAS_IOPRIO

Status: ReOpened

@giampaolo
Copy link
Owner Author

From g.rodola on December 02, 2013 11:40:06

Closing this out again as I believe the warning is gone now.

Status: Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant