Created attachment 149422 [details] svn diff Based on Porter's handbook, the usage of /proc is not suggested. In the patch set, implement pgrep-like code and using sysctl to get proc information.
Created attachment 149423 [details] portlint -AC output
this probably is freebsd-specific -- e.g. breaks dragonfly and the other BSDs (only dragonfly is important in ports though)
Created attachment 149519 [details] port test log
Created attachment 149736 [details] svn diff
Created attachment 149737 [details] port test log
(In reply to Jingfeng Yan from comment #5) > Created attachment 149737 [details] > port test log /proc is optional, and not required.
A commit references this bug: Author: marino Date: Fri Nov 28 08:00:24 UTC 2014 New revision: 373533 URL: https://svnweb.freebsd.org/changeset/ports/373533 Log: net-mgmt/ccnet: rework to avoid use of /proc PR: 195023 Submitted by: maintainer Changes: head/net-mgmt/ccnet/Makefile head/net-mgmt/ccnet/files/patch-lib_Makefile.am head/net-mgmt/ccnet/files/patch-lib_utils.c
Thanks!
as a follow up, DragonFly is now broken, as expected: utils.c: In function 'count_running_process_kvm': utils.c:1635:13: error: 'P_KTHREADP' undeclared (first use in this function) utils.c:1635:13: note: each undeclared identifier is reported only once for each function it appears in *** [utils.lo] Error code 1
(In reply to John Marino from comment #9) > as a follow up, DragonFly is now broken, as expected: > > utils.c: In function 'count_running_process_kvm': > utils.c:1635:13: error: 'P_KTHREADP' undeclared (first use in this function) > utils.c:1635:13: note: each undeclared identifier is reported only once for > each function it appears in > *** [utils.lo] Error code 1 It could be some header file issue. I will update this soon. Based on v3.8.2 DF, P_KTHREADP should be defined.
(In reply to Jingfeng Yan from comment #10) > (In reply to John Marino from comment #9) > > as a follow up, DragonFly is now broken, as expected: > > > > utils.c: In function 'count_running_process_kvm': > > utils.c:1635:13: error: 'P_KTHREADP' undeclared (first use in this function) > > utils.c:1635:13: note: each undeclared identifier is reported only once for > > each function it appears in > > *** [utils.lo] Error code 1 > > It could be some header file issue. I will update this soon. Based on > v3.8.2 DF, P_KTHREADP should be defined. This seems odd. The P_KTHREADP is defined under sys/proc.h, which is included in sys/user.h. It means, if _SYS_PROC_H_ is not defined, sys/user.h will include sys/proc.h, which has the definition. DF code: 45 #if !defined(_KERNEL) && !defined(_KERNEL_STRUCTURES) 46 47 #error "Userland must include sys/user.h instead of sys/proc.h" 48 49 #else ......
This may also be a new issue because I've seen another port with the exact same error message that was building fine before. This is on DragonFly 4.1. Sometimes a program has to define _KERNEL_STRUCTURES and then undefine it when it's not needed. However, it sounds like DF headers may have changed between 4.0 and 4.1.
or conversely, for dragonfly, include sys/user.h instead of sys/proc.h" with a macro
(In reply to John Marino from comment #13) > or conversely, for dragonfly, include sys/user.h instead of sys/proc.h" with > a macro code draft: +#elif defined(__DragonFly__) +#if __DragonFly_version < 400000 +#define PSKIP(kp) ((kp)->kp_pid == mypid || \ + (!kthreads && ((kp)->kp_flags & P_KTHREADP) != 0)) +#else +#define PSKIP(kp) ((kp)->kp_pid == mypid || \ + (!kthreads && (kp)->kp_pid <= 0)) +#endif ...
apparently K_THREADP never worked: http://gitweb.dragonflybsd.org/dragonfly.git/commit/4f7720f07b34275a5b653c79996db831244ca40d So you don't need to check for versions (I would have checked for definition of K_THREADP instead anyway) According to commit message, we need to be using "P_SYSTEM" flag somehow.
(In reply to Jingfeng Yan from comment #14) > (In reply to John Marino from comment #13) > > or conversely, for dragonfly, include sys/user.h instead of sys/proc.h" with > > a macro > > code draft: > > +#elif defined(__DragonFly__) > +#if __DragonFly_version < 400000 > +#define PSKIP(kp) ((kp)->kp_pid == mypid || \ > + (!kthreads && ((kp)->kp_flags & P_KTHREADP) != 0)) > +#else > +#define PSKIP(kp) ((kp)->kp_pid == mypid || \ > + (!kthreads && (kp)->kp_pid <= 0)) > +#endif > ... maybe something like: #elif defined(__DragonFly__) #define PSKIP(kp) ((kp)->kp_pid == mypid || \ (!kthreads && ((kp)->kp_flags & P_SYSTEM) != 0)) (untested)
(In reply to John Marino from comment #16) > (In reply to Jingfeng Yan from comment #14) > > (In reply to John Marino from comment #13) > > > or conversely, for dragonfly, include sys/user.h instead of sys/proc.h" with > > > a macro > > > > code draft: > > > > +#elif defined(__DragonFly__) > > +#if __DragonFly_version < 400000 > > +#define PSKIP(kp) ((kp)->kp_pid == mypid || \ > > + (!kthreads && ((kp)->kp_flags & P_KTHREADP) != 0)) > > +#else > > +#define PSKIP(kp) ((kp)->kp_pid == mypid || \ > > + (!kthreads && (kp)->kp_pid <= 0)) > > +#endif > > ... > > maybe something like: > #elif defined(__DragonFly__) > #define PSKIP(kp) ((kp)->kp_pid == mypid || \ > (!kthreads && ((kp)->kp_flags & P_SYSTEM) != 0)) > > > (untested) Thank you for your reply. The PSKIP() marco is from DragonflyBSD "usr.bin/pkill/pkill.c". In kernel 3.8 around, it means to skip itself, and anything marked as Kernel thread. In Kernel 4.0 around, it does not say anything about kernel thread, but use kp_pid <= 0. I have no idea what kp_pid <= 0 means. (It seems that I just get lazy work done. :)) Problem one: There is no more concept of kernel thread. What is kp_pid <= 0 mean? this kind of pid should mean something. Problem two: Yes, we want to skip to check all non-userland processes/ threads. So, for kernel thread, is it also kernel process? For example, in 3.8, when P_KTHREADP is set, P_SYSTEM is also set. Even if this is not kernel thread, this is system process, we also have P_SYSTEM. Anyway, I have standalone program to play with this. Will let you know. Best, Jingfeng
> maybe something like: > #elif defined(__DragonFly__) > #define PSKIP(kp) ((kp)->kp_pid == mypid || \ > (!kthreads && ((kp)->kp_flags & P_SYSTEM) != 0)) > > > (untested) I will adopt this. I don't find anywhere else than pkill.c uses P_KTHREADP in 3.8. :) In the 4.0 pkill.c, kp_pid <= 0 will cover all the (xxx) process, which pid is -1, and 0 (swapper). But, it does not include something like /sbin/init, but it is marked as P_SYSTEM.