u_cwd structure on Suns doesn't come out now?
Brendan Kehoe
brendan at cs.widener.edu
Sat Mar 16 08:44:00 AEST 1991
When I upgraded to SunOS 4.1.1, I discovered something pretty odd. In the
user structure there's a member called u_cwd, a ucwd structure; it holds
the ascii representation of the directory the user's currently in.
Only in SunOS 4.1.1, you *CAN'T READ IT*. I've come at this one 10
different ways with the same results; the u_cwd->cw_dir pointer now points
to nothing. In 4.1 it pointed to the directory properly. Anyone have any
ideas?
Here's an example to show you:
-- cut --
#include <stdio.h>
#include <sys/types.h>
#include <kvm.h>
#include <fcntl.h>
#include <sys/user.h>
main()
{
struct user *u;
struct proc *p;
struct ucwd cwd;
int mypid;
kvm_t *kd;
char *dirp;
static char *root = "/", buf[100];
if ((kd = kvm_open ((char *)NULL, (char *)NULL, (char *)NULL, O_RDONLY,
*argv)) == NULL)
{
fprintf(stderr, "%s: couldn't open the kernel\n", *argv);
exit(1);
}
/*
* go through the kernel til we find the proc structure for this process
*/
mypid = getpid();
kvm_setproc(kd);
while ((p = kvm_nextproc(kd))->p_pid != mypid)
;
/*
* read in the u. structure
*/
if (!(u = kvm_getu(kd, p)))
{
fprintf(stderr, "%s: couldn't read the u-dot structure\n", *argv);
exit(1);
}
/*
* read in the u->u_cwd structure from the kernel
*/
if (kvm_read(kd, (unsigned long) u->u_cwd, (struct ucwd *) &cwd,
sizeof(struct ucwd)) < 0)
{
perror("kvm_read");
exit(1);
}
/*
* in the cwd structure, there are a few things, including cw_dir and
* cw_root .. cw_dir is the ascii version of the dir they're in, and
* cw_root is the process's vision of what the root directory is (per
* chroot() if any). Anyway, the pointers look like this now:
* cw_dir = 0xff001ffc cw_root = 0xff001ffd
* One away from each other! That's not right! They should be a few
* apart, since the string's longer than 1 char long, usually.
*/
/*
* if the cw_dir pointer was valid, dig again into the kernel to get
* the cw_dir string itself
*/
if (cwd.cw_dir)
if (kvm_read(kd, (unsigned long) cwd.cw_dir, buf, 100) < 0)
{
perror("kvm_read dir");
exit(1);
}
dirp = buf;
if (!*dirp)
dirp = root;
printf("Sitting in %s\n", (*dirp) ? dirp : root);
}
-- cut --
Brendan Kehoe - Widener Sun Network Manager - brendan at cs.widener.edu
Widener University in Chester, PA A Bloody Sun-Dec War Zone
More information about the Comp.sys.sun
mailing list