johalun / sysctl-rs

A simplified Rust interface to the sysctl system call
MIT License
52 stars 23 forks source link

Thoughts on sysctls that take arguments? #51

Open inferiorhumanorgans opened 2 years ago

inferiorhumanorgans commented 2 years ago

e.g. from the sysctl manpage:

         int i, mib[4];
           size_t len;
           struct kinfo_proc kp;

           /* Fill out the first three components of the mib */
           len = 4;
           sysctlnametomib("kern.proc.pid", mib, &len);

           /* Fetch and print entries for pid's < 100 */
           for (i = 0; i < 100; i++) {
                   mib[3] = i;
                   len = sizeof(kp);
                   if (sysctl(mib, 4, &kp, &len, NULL, 0) == -1)
                           perror("sysctl");
                   else if (len > 0)
                           printkproc(&kp);
           }
orhun commented 2 years ago

Can you elaborate what you mean?

inferiorhumanorgans commented 2 years ago

Some sysctls like kern.proc.pid take an argument (mib[3]) and I was wondering if you had any thoughts/plans about implementing support for that.

johalun commented 2 years ago

No plans myself to implement that at this time. PRs are always welcome though :)