ISC Unix 2.2 nlist Help/Where's adb?
Conor P. Cahill
cpcahil at virtech.uucp
Thu Sep 20 20:29:27 AEST 1990
In article <49 at sgtech.UUCP> adnan at sgtech.uucp (Adnan Yaqub) writes:
>I am trying to write a program which reads values from /dev/kmem. The
>program works great except when I try to lseek to the value returned
This should work without any problems. I have attached a sample program
that can be used to modify a kernel value. (I use this to change the
NFS variable nobody to 0 so that root users on other systems in our
network get root privileges on thier NFS mounted file systems)
>On a related topic, what happened to adb? It didn't seem to come with
>ISC Unix 2.2.
adb has been gone from AT&T unix since SVR2 although some vendors still
supply it (they do the porting/maintenance themselves). sdb is the
supported debugger (and 2.2 comes with codewatch, although I don't know
how well that works since I haven't tried it).
X#include <sys/types.h>
X#include <nlist.h>
X#include <fcntl.h>
X#include <stdio.h>
X
Xmain(argc,argv)
X int argc;
X char * argv[];
X{
X int err;
X char * kernelfile = "/dev/kmem";
X int kfd;
X struct nlist nl;
X int oflags;
X long oldvalue;
X int setval;
X char * unixfileptr = "/unix";
X long value;
X
X if( (argc != 2) && (argc != 3) )
X {
X fprintf(stderr,"Usage: %s symbol [value]\n",argv[0]);
X exit(10);
X }
X
X nl.n_name = argv[1];
X if( argc == 3 )
X {
X value = atoi(argv[2]);
X setval = 1;
X oflags = O_RDWR;
X }
X else
X {
X setval = 0;
X oflags = O_RDONLY;
X }
X
X err = nlist(unixfileptr,&nl);
X
X if( (err == -1) || (nl.n_value == 0) )
X {
X fprintf(stderr,"Unable to find symbol '%s' in '%s'\n",
X nl.n_name, unixfileptr);
X exit(10);
X }
X
X if( (kfd=open(kernelfile,oflags)) == -1)
X {
X fprintf(stderr,"Unable to open '%s'\n", kernelfile);
X exit(40);
X }
X
X if( lseek(kfd,nl.n_value,0) != nl.n_value)
X {
X fprintf(stderr,"Unable to seek to %s's location\n",nl.n_name);
X exit(50);
X }
X
X if( read(kfd,(char *) &oldvalue,sizeof(long)) != sizeof(long))
X {
X fprintf(stderr,"Unable to read %s's data\n",nl.n_name);
X exit(60);
X }
X
X if( ! setval )
X {
X fprintf(stdout,"value of %s is %ld\n", nl.n_name, oldvalue);
X exit(0);
X }
X
X /*
X * Now go change the value to be what we want it to be...
X */
X
X if( lseek(kfd,nl.n_value,0) != nl.n_value)
X {
X fprintf(stderr,"Unable to seek to %s's location\n",nl.n_name);
X exit(70);
X }
X
X if( write(kfd,(char *) &value,sizeof(long)) != sizeof(long))
X {
X fprintf(stderr,"Unable to change %s's data\n",nl.n_name);
X exit(80);
X }
X
X fprintf(stdout,"Value of %s changed from %ld to %ld\n",
X nl.n_name, oldvalue, value);
X exit(0);
X}
--
Conor P. Cahill (703)430-9247 Virtual Technologies, Inc.,
uunet!virtech!cpcahil 46030 Manekin Plaza, Suite 160
Sterling, VA 22170
More information about the Comp.unix.sysv386
mailing list