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

--8t9RHnE3ZwKMSgU+
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

 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.
>=20
>    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.=20

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 =3D NO_SYSCALL;

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

	pid =3D p->p_pid;

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

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

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

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


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

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

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

>---cut 8<---

Makefile:

>---cut 8<---

KMOD=3D   tmp_watch
SRCS=3D   module.c

=2Einclude <bsd.kmod.mk>

>---cut 8<---

And uname -rm
5.2.1-RELEASE i386


-Roman Bogorodskiy


--8t9RHnE3ZwKMSgU+
Content-Type: application/pgp-signature
Content-Disposition: inline

-----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-----

--8t9RHnE3ZwKMSgU+--



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