tech-kern archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: Linux procfs
matthew green <mrg%eterna.com.au@localhost> wrote:
>Robert Swindells writes:
>>
>> Do we care about keeping all the Linux procfs code in
>> sys/miscfs/proc/procfs_linux.c ?
>>
>> Some Linux applications have started grovelling in /proc/self/status to
>> read various values.
>>
>> I have added some Linux emulation specific code to procfs_status.c but
>> can move it if people object.
>
>what are the extensions? maybe we want them for netbsd anyway?
It is mostly just changing the format of what is printed.
I haven't replicated everything that is in the procfs node under Linux,
just enough to get one application working (Xilinx Vivado). One of the
lines is used by the HTML browser in JavaFX though so it will probably
be needed elsewhere.
>can the code be structured such that most of it is in procfs_linux.c
>and called to from procfs_status.c?
I think it would be more a case of moving the whole contents of
procfs_status.c to procfs_linux.c
The diff is below.
Index: procfs_status.c
===================================================================
RCS file: /cvsroot/src/sys/miscfs/procfs/procfs_status.c,v
retrieving revision 1.37
diff -u -r1.37 procfs_status.c
--- procfs_status.c 14 Nov 2016 08:55:51 -0000 1.37
+++ procfs_status.c 26 Jun 2017 01:36:05 -0000
@@ -102,6 +102,7 @@
struct proc *p = l->l_proc;
char *ps;
const char *sep;
+ const char *emulname = curlwp->l_proc->p_emul->e_name;
int pid, ppid, pgid, sid;
u_int i;
char psbuf[256+MAXHOSTNAMELEN]; /* XXX - conservative */
@@ -119,65 +120,87 @@
sess = p->p_pgrp->pg_session;
sid = sess->s_sid;
-/* comm pid ppid pgid sid maj,min ctty,sldr start ut st wmsg uid gid groups ... */
-
ps = psbuf;
- memcpy(ps, p->p_comm, MAXCOMLEN);
- ps[MAXCOMLEN] = '\0';
- ps += strlen(ps);
- ps += snprintf(ps, sizeof(psbuf) - (ps - psbuf), " %d %d %d %d ",
- pid, ppid, pgid, sid);
-
- if ((p->p_lflag & PL_CONTROLT) && (tp = sess->s_ttyp))
- ps += snprintf(ps, sizeof(psbuf) - (ps - psbuf), "%llu,%llu ",
- (unsigned long long)major(tp->t_dev),
- (unsigned long long)minor(tp->t_dev));
- else
- ps += snprintf(ps, sizeof(psbuf) - (ps - psbuf), "%d,%d ",
- -1, -1);
-
- sep = "";
- if (sess->s_ttyvp) {
- ps += snprintf(ps, sizeof(psbuf) - (ps - psbuf), "%sctty", sep);
- sep = ",";
- }
- if (SESS_LEADER(p)) {
- ps += snprintf(ps, sizeof(psbuf) - (ps - psbuf), "%ssldr", sep);
- sep = ",";
- }
- if (*sep != ',')
- ps += snprintf(ps, sizeof(psbuf) - (ps - psbuf), "noflags");
-
- ps += snprintf(ps, sizeof(psbuf) - (ps - psbuf), " %lld,%ld",
- (long long)p->p_stats->p_start.tv_sec,
- (long)p->p_stats->p_start.tv_usec);
-
- {
- struct timeval ut, st;
+ if (strncmp(emulname, "linux", 5) == 0) {
+ ps += snprintf(ps, sizeof(psbuf), "Name:\t%s\n", p->p_comm);
+ ps += snprintf(ps, sizeof(psbuf) - (ps - psbuf), "Pid:\t%d\n", pid);
+ ps += snprintf(ps, sizeof(psbuf) - (ps - psbuf), "PPid:\t%d\n", ppid);
+ ps += snprintf(ps, sizeof(psbuf) - (ps - psbuf), "TracerPid:\t%d\n", 0);
+
+ cr = p->p_cred;
+ ngroups = kauth_cred_ngroups(cr);
+ ps += snprintf(ps, sizeof(psbuf) - (ps - psbuf), "Groups:\t");
+ for (i = 0; i < ngroups; i++)
+ ps += snprintf(ps, sizeof(psbuf) - (ps - psbuf), "%d ",
+ kauth_cred_group(cr, i));
+ ps += snprintf(ps, sizeof(psbuf) - (ps - psbuf), "\n");
- calcru(p, &ut, &st, (void *) 0, NULL);
ps += snprintf(ps, sizeof(psbuf) - (ps - psbuf),
- " %lld,%ld %lld,%ld", (long long)ut.tv_sec,
- (long)ut.tv_usec, (long long)st.tv_sec, (long)st.tv_usec);
- }
+ "VmPeak:\t%8lu kB\n", p->p_rlimit[RLIMIT_DATA].rlim_cur / 1024);
+ ps += snprintf(ps, sizeof(psbuf) - (ps - psbuf),
+ "VmSize:\t%8lu kB\n", p->p_rlimit[RLIMIT_DATA].rlim_cur / 1024);
+ ps += snprintf(ps, sizeof(psbuf) - (ps - psbuf),
+ "VmRSS:\t%8lu kB\n", p->p_rlimit[RLIMIT_RSS].rlim_cur / 1024);
- lwp_lock(l);
- ps += snprintf(ps, sizeof(psbuf) - (ps - psbuf), " %s",
- (l->l_wchan && l->l_wmesg) ? l->l_wmesg : "nochan");
- lwp_unlock(l);
-
- cr = p->p_cred;
-
- ps += snprintf(ps, sizeof(psbuf) - (ps - psbuf), " %d",
- kauth_cred_geteuid(cr));
- ps += snprintf(ps, sizeof(psbuf) - (ps - psbuf), " %d",
- kauth_cred_getegid(cr));
- ngroups = kauth_cred_ngroups(cr);
- for (i = 0; i < ngroups; i++)
- ps += snprintf(ps, sizeof(psbuf) - (ps - psbuf), ",%d",
- kauth_cred_group(cr, i));
- ps += snprintf(ps, sizeof(psbuf) - (ps - psbuf), "\n");
+ } else {
+/* comm pid ppid pgid sid maj,min ctty,sldr start ut st wmsg uid gid groups ... */
+ memcpy(ps, p->p_comm, MAXCOMLEN);
+ ps[MAXCOMLEN] = '\0';
+ ps += strlen(ps);
+ ps += snprintf(ps, sizeof(psbuf) - (ps - psbuf), " %d %d %d %d ",
+ pid, ppid, pgid, sid);
+
+ if ((p->p_lflag & PL_CONTROLT) && (tp = sess->s_ttyp))
+ ps += snprintf(ps, sizeof(psbuf) - (ps - psbuf), "%llu,%llu ",
+ (unsigned long long)major(tp->t_dev),
+ (unsigned long long)minor(tp->t_dev));
+ else
+ ps += snprintf(ps, sizeof(psbuf) - (ps - psbuf), "%d,%d ",
+ -1, -1);
+
+ sep = "";
+ if (sess->s_ttyvp) {
+ ps += snprintf(ps, sizeof(psbuf) - (ps - psbuf), "%sctty", sep);
+ sep = ",";
+ }
+ if (SESS_LEADER(p)) {
+ ps += snprintf(ps, sizeof(psbuf) - (ps - psbuf), "%ssldr", sep);
+ sep = ",";
+ }
+ if (*sep != ',')
+ ps += snprintf(ps, sizeof(psbuf) - (ps - psbuf), "noflags");
+
+ ps += snprintf(ps, sizeof(psbuf) - (ps - psbuf), " %lld,%ld",
+ (long long)p->p_stats->p_start.tv_sec,
+ (long)p->p_stats->p_start.tv_usec);
+
+ {
+ struct timeval ut, st;
+
+ calcru(p, &ut, &st, (void *) 0, NULL);
+ ps += snprintf(ps, sizeof(psbuf) - (ps - psbuf),
+ " %lld,%ld %lld,%ld", (long long)ut.tv_sec,
+ (long)ut.tv_usec, (long long)st.tv_sec, (long)st.tv_usec);
+ }
+
+ lwp_lock(l);
+ ps += snprintf(ps, sizeof(psbuf) - (ps - psbuf), " %s",
+ (l->l_wchan && l->l_wmesg) ? l->l_wmesg : "nochan");
+ lwp_unlock(l);
+
+ cr = p->p_cred;
+
+ ps += snprintf(ps, sizeof(psbuf) - (ps - psbuf), " %d",
+ kauth_cred_geteuid(cr));
+ ps += snprintf(ps, sizeof(psbuf) - (ps - psbuf), " %d",
+ kauth_cred_getegid(cr));
+ ngroups = kauth_cred_ngroups(cr);
+ for (i = 0; i < ngroups; i++)
+ ps += snprintf(ps, sizeof(psbuf) - (ps - psbuf), ",%d",
+ kauth_cred_group(cr, i));
+ ps += snprintf(ps, sizeof(psbuf) - (ps - psbuf), "\n");
+ }
mutex_exit(p->p_lock);
mutex_exit(proc_lock);
Home |
Main Index |
Thread Index |
Old Index