Lines Matching refs:pss
28 static const char id[] = "\n@(#)$Id: pss library (AT&T Research) 2011-05-09 $\0\n";
30 static const char lib[] = "std:pss";
37 * open a pss stream
43 register Pss_t* pss;
48 if (!(vm = vmopen(Vmdcheap, Vmbest, 0)) || !(pss = vmnewof(vm, 0, Pss_t, 1, 0)))
50 pss->id = lib;
51 pss->disc = disc;
52 pss->vm = vm;
53 pss->ttybynamedisc.key = offsetof(Tty_t, name);
54 pss->ttybynamedisc.size = 0;
55 pss->ttybynamedisc.link = offsetof(Tty_t, byname);
56 pss->ttybydevdisc.key = offsetof(Tty_t, dev);
57 pss->ttybydevdisc.size = sizeof(Pss_dev_t);
58 pss->ttybydevdisc.link = offsetof(Tty_t, bydev);
59 if (!(pss->ttybyname = dtnew(pss->vm, &pss->ttybynamedisc, Dtset)) ||
60 !(pss->ttybydev = dtnew(pss->vm, &pss->ttybydevdisc, Dtset)))
62 pss->meth = (_pss_ps && ((disc->flags & PSS_PS) || getenv("_PSS_ps"))) ? _pss_ps : _pss_method;
63 while (pss->meth->initf && (*pss->meth->initf)(pss) <= 0)
64 if (pss->meth == _pss_ps || !(pss->meth = _pss_ps))
69 return pss;
79 * close a pss stream
83 pssclose(Pss_t* pss)
87 if (!pss || !pss->vm)
89 r = (pss->meth->donef && (*pss->meth->donef)(pss) <= 0) ? -1 : 0;
90 if ((pss->disc->flags & PSS_VERBOSE) && pss->disc->errorf)
91 (*pss->disc->errorf)(pss, pss->disc, 1, "%s: method done", pss->meth->name);
92 vmclose(pss->vm);
97 * return the pss entry for pid
102 pssread(register Pss_t* pss, Pss_id_t pid)
104 register unsigned long fields = pss->meth->fields;
105 register unsigned long flags = pss->disc->flags;
114 if ((*pss->meth->readf)(pss, pid) <= 0)
116 if (!pss->ent && !(pss->ent = vmnewof(pss->vm, 0, Pssent_t, 1, 0)))
118 if (pss->disc->errorf)
119 (*pss->disc->errorf)(pss, pss->disc, ERROR_SYSTEM|2, "out of space");
122 pe = pss->ent;
123 if ((i = (*pss->meth->partf)(pss, pe)) < 0)
128 pe->pid = pss->pid;
132 pe->pss = PSS_EXPLICIT;
134 pe->pss = PSS_MATCHED;
139 if ((flags & PSS_TTY) && pe->tty != TTYMAP(pss, pss->disc->tty))
141 if ((flags & PSS_UID) && pe->uid != pss->disc->uid)
169 pe->pss = PSS_MATCHED;
171 if (mp = pss->disc->match)
191 if (pss->meth->ttymapf)
193 dp->data = TTYMAP(pss, dp->data);
199 if (pss->disc->errorf)
200 (*pss->disc->errorf)(pss, pss->disc, 2, "%08lx selection not implemented", mp->field);
209 pe->pss = PSS_MATCHED;
216 pe->pss = 0;
222 if (pss->meth->fullf && (*pss->meth->fullf)(pss, pe) <= 0)
238 psssave(register Pss_t* pss, register Pssent_t* pe)
240 register unsigned long fields = pss->disc->fields & pss->meth->fields;
243 pe->args = vmstrdup(pss->vm, pe->args);
245 pe->command = vmstrdup(pss->vm, pe->command);
247 pe->sched = vmstrdup(pss->vm, pe->sched);
249 pe->ttyname = vmstrdup(pss->vm, pe->ttyname);
250 pss->ent = 0;
259 pssttyadd(register Pss_t* pss, const char* name, Pss_dev_t dev)
263 if (!dtmatch(pss->ttybyname, name))
265 if (!(tty = vmnewof(pss->vm, 0, Tty_t, 1, strlen(name))))
267 if (pss->disc->errorf)
268 (*pss->disc->errorf)(pss, pss->disc, ERROR_SYSTEM|2, "out of space");
273 dtinsert(pss->ttybyname, tty);
274 if (!dtmatch(pss->ttybydev, &dev))
275 dtinsert(pss->ttybydev, tty);
285 ttyscan(register Pss_t* pss)
295 pss->ttyscan = 1;
299 if (pss->disc->errorf)
300 (*pss->disc->errorf)(pss, pss->disc, ERROR_SYSTEM|2, "%s: cannot read", path);
333 if (pssttyadd(pss, name, st.st_rdev))
354 pssttydev(register Pss_t* pss, const char* name)
363 if (pss->meth->ttydevf)
364 return (*pss->meth->ttydevf)(pss, s);
365 if (tty = (Tty_t*)dtmatch(pss->ttybyname, s))
369 sfsprintf(pss->buf, sizeof(pss->buf), "/dev/%s", name);
370 s = (const char*)pss->buf;
373 sfsprintf(pss->buf, sizeof(pss->buf), "/dev/tty%s", name);
376 if (pss->disc->errorf)
377 (*pss->disc->errorf)(pss, pss->disc, ERROR_SYSTEM|2, "%s: unknown tty", name);
381 pssttyadd(pss, name, st.st_rdev);
390 pssttyname(register Pss_t* pss, Pssent_t* pe)
396 if (pss->meth->ttynamef && (s = (*pss->meth->ttynamef)(pss, pe)))
403 if (tty = (Tty_t*)dtmatch(pss->ttybydev, &dev))
405 if (!pss->ttyscan)
406 ttyscan(pss);
407 if (tty = (Tty_t*)dtmatch(pss->ttybydev, &dev))
409 sfsprintf(pss->buf, sizeof(pss->buf), "%03d,%03d", major(dev), minor(dev));
410 return pss->buf;