Bug 195023 - [maintainer-update] net-mgmt/ccnet: remove requirements of /proc
Summary: [maintainer-update] net-mgmt/ccnet: remove requirements of /proc
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: John Marino
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-11-15 01:50 UTC by Jingfeng Yan
Modified: 2014-12-14 03:14 UTC (History)
2 users (show)

See Also:


Attachments
svn diff (4.94 KB, patch)
2014-11-15 01:50 UTC, Jingfeng Yan
no flags Details | Diff
portlint -AC output (230 bytes, text/plain)
2014-11-15 01:53 UTC, Jingfeng Yan
no flags Details
port test log (185.54 KB, text/plain)
2014-11-17 15:54 UTC, Jingfeng Yan
no flags Details
svn diff (7.63 KB, patch)
2014-11-23 02:31 UTC, Jingfeng Yan
no flags Details | Diff
port test log (185.54 KB, text/plain)
2014-11-23 02:32 UTC, Jingfeng Yan
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jingfeng Yan 2014-11-15 01:50:35 UTC
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.
Comment 1 Jingfeng Yan 2014-11-15 01:53:43 UTC
Created attachment 149423 [details]
portlint -AC output
Comment 2 John Marino freebsd_committer freebsd_triage 2014-11-15 11:14:55 UTC
this probably is freebsd-specific -- e.g. breaks dragonfly and the other BSDs (only dragonfly is important in ports though)
Comment 3 Jingfeng Yan 2014-11-17 15:54:34 UTC
Created attachment 149519 [details]
port test log
Comment 4 Jingfeng Yan 2014-11-23 02:31:55 UTC
Created attachment 149736 [details]
svn diff
Comment 5 Jingfeng Yan 2014-11-23 02:32:25 UTC
Created attachment 149737 [details]
port test log
Comment 6 Jingfeng Yan 2014-11-23 02:33:21 UTC
(In reply to Jingfeng Yan from comment #5)
> Created attachment 149737 [details]
> port test log

/proc is optional, and not required.
Comment 7 commit-hook freebsd_committer freebsd_triage 2014-11-28 08:01:08 UTC
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
Comment 8 John Marino freebsd_committer freebsd_triage 2014-11-28 08:02:11 UTC
Thanks!
Comment 9 John Marino freebsd_committer freebsd_triage 2014-12-11 07:50:11 UTC
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
Comment 10 Jingfeng Yan 2014-12-12 05:54:36 UTC
(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.
Comment 11 Jingfeng Yan 2014-12-12 06:53:19 UTC
(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
......
Comment 12 John Marino freebsd_committer freebsd_triage 2014-12-12 11:48:41 UTC
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.
Comment 13 John Marino freebsd_committer freebsd_triage 2014-12-12 11:56:09 UTC
or conversely, for dragonfly, include sys/user.h instead of sys/proc.h" with a macro
Comment 14 Jingfeng Yan 2014-12-13 05:18:45 UTC
(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
...
Comment 15 John Marino freebsd_committer freebsd_triage 2014-12-13 07:08:35 UTC
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.
Comment 16 John Marino freebsd_committer freebsd_triage 2014-12-13 07:13:19 UTC
(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)
Comment 17 Jingfeng Yan 2014-12-13 15:36:09 UTC
(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
Comment 18 Jingfeng Yan 2014-12-14 03:14:01 UTC
> 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.