Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 17 Mar 2004 21:36:39 +0300
From:      Roman Bogorodskiy <bogorodskiy@inbox.ru>
To:        "Jacques A. Vidrine" <nectar@FreeBSD.org>, Toni Andjelkovic <toni@soth.at>, Artis Caune <ac-lists@latnet.lv>, freebsd-hackers@freebsd.org
Subject:   Re: kernel modules programming: struct proc question
Message-ID:  <20040317183639.GA635@lame.novel.ru>
In-Reply-To: <20040317175340.GA88110@madman.celabo.org>
References:  <20040316163956.GD638@lame.novel.ru> <20040316181307.GA6576@tv.soth.at> <20040317142451.GC2506@lame.novel.ru> <opr40hacqdcpfy5d@mail.latnet.lv> <20040317154530.GD6576@tv.soth.at> <20040317175340.GA88110@madman.celabo.org>

next in thread | previous in thread | raw e-mail | index | archive | help

[-- Attachment #1 --]
 Jacques wrote:

> That's only correct for machines with 32-bit ints.  In any case, POSIX
> only specifies that pid_t is a signed integer type... it could be any
> size supported by the implementation.  For portability, you probably
> want to cast to the `biggest' type and use the appropriate printf
> specifier, e.g.
> 
>    printf("%ld", (long)pid_t);
> or
>    printf("%jd", (intmax_t)pid_t); // C99


I've tried all of this ways, and I still have a wrong pid displayed...
I have no idea what I'm doing wrong. 

Here is the full code:

module.c

>---cut 8<---

#include <sys/types.h>
#include <sys/param.h>
#include <sys/proc.h>
#include <sys/module.h>
#include <sys/sysent.h>
#include <sys/types.h>
#include <sys/kernel.h>
#include <sys/systm.h>
#include <sys/sysproto.h>
#include <sys/syscall.h>
#include <sys/ucred.h>

static int new_open(struct proc *p, register struct open_args *);

static int offset = NO_SYSCALL;

static int 
new_open(struct proc *p, register struct open_args *uap)
{
	char name[NAME_MAX];
	size_t size;
	pid_t pid;

	pid = p->p_pid;

	if((const void*)copyinstr(uap->path, name, NAME_MAX, &size) == (const void*)EFAULT)
		return(EFAULT);

	
	if (name[0] == '/' && name[1] == 't' && name[2] == 'm' && name[3] == 'p' && name[4] == '/') {
		printf("open(2): %s pid: %jd\n", name, (intmax_t)pid);//, (char *)&p->p_comm);
	}
	
	return (open(p, uap));
}

#define AS(name) (sizeof(struct name) / sizeof(register_t))

static struct sysent new_open_sysent = {
	        AS(open_args),
	        (sy_call_t *)new_open
};


static int
load (struct module *module, int cmd, void *arg)
{
        int error = 0;

        switch (cmd) {
	        case MOD_LOAD :
			printf("syscall loaded\n");
			sysent[SYS_open] = new_open_sysent;
			break;
		case MOD_UNLOAD :
		        printf ("syscall unloaded\n");
			sysent[SYS_open].sy_call = (sy_call_t *)open;
		        break;
		default :
		        error = EINVAL;
		        break;
	
	}
	
	return error;
}

SYSCALL_MODULE(syscall, &offset, &new_open_sysent, load, NULL);

>---cut 8<---

Makefile:

>---cut 8<---

KMOD=   tmp_watch
SRCS=   module.c

.include <bsd.kmod.mk>

>---cut 8<---

And uname -rm
5.2.1-RELEASE i386


-Roman Bogorodskiy


[-- Attachment #2 --]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (FreeBSD)

iQEVAwUBQFiatypMDQ8aPhy0AQLkpwf9G272V4noHblJYtx6hoAPy9LXJ6xsJA6N
64exV7+bQrIyq4KV/spy0BoIftnPebH2r8f3V/h7aUKxzafL6z+vPK77x0N4Hbz/
BoOXv89y1bXD8LW05DMOpYrZ6eYoXi7gNKv2SMYC4vyKpF+Om+Et4AFCvAmt+xtA
bsLKAe63Mq7uZzBzE4SXQyGJOwEz3weAKk1+sxXFF5lIbynDw8GqMYKkbPEgHoeM
JBM+0WKOH9CRRoIIdx0GLOdPCIVHJiTEOEfR8u/vGmLh4mvqnEKmzEQPRce6CoQd
nZUGjhik3Iqw/eY639+EodZWSzPIMiOor1WGjAGjuZK9jr4sQxyDYA==
=dbue
-----END PGP SIGNATURE-----

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040317183639.GA635>