🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.sun
Article #6967

u_cwd structure on Suns doesn't come out now?

#6967
From: Brendan Kehoe
Date: Fri, 15 Mar 1991 22:44
92 lines
3145 bytes
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@cs.widener.edu
  Widener University in Chester, PA                A Bloody Sun-Dec War Zone
Technical Details
Message-ID: <1908@brchh104.bnr.ca>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!cunews!bnrgate!brtph3!brchh104!brchs1!bnr.ca!rice.edu!sun-spots-request

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!cunews!bnrgate!brtph3!brchh104!brchs1!bnr.ca!rice.edu!sun-spots-request
From: brendan@cs.widener.edu (Brendan Kehoe)
Newsgroups: comp.sys.sun
Subject: u_cwd structure on Suns doesn't come out now?
Keywords: SunOS
Message-ID: <1908@brchh104.bnr.ca>
Date: 15 Mar 91 22:44:00 GMT
Sender: news@brchh104.bnr.ca
Organization: Sun-Spots
Lines: 92
Approved: Sun-Spots@rice.edu
X-Original-Date: Wed, 27 Feb 91 00:30:02 GMT
X-Sun-Spots-Digest: Volume 10, Issue 54, message 4
X-Note: Submissions: sun-spots@rice.edu, Admin: sun-spots-request@rice.edu