From owner-freebsd-hackers@FreeBSD.ORG Wed Mar 17 10:37:06 2004 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id AD30F16A4CF; Wed, 17 Mar 2004 10:37:06 -0800 (PST) Received: from mx1.mail.ru (mx1.mail.ru [194.67.23.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id BE99E43D2D; Wed, 17 Mar 2004 10:37:05 -0800 (PST) (envelope-from bogorodskiy@inbox.ru) Received: from [194.186.150.37] (port=49178 helo=localhost) by mx1.mail.ru with esmtp id 1B3fuY-0001xt-00; Wed, 17 Mar 2004 21:37:03 +0300 Date: Wed, 17 Mar 2004 21:36:39 +0300 From: Roman Bogorodskiy To: "Jacques A. Vidrine" , Toni Andjelkovic , Artis Caune , freebsd-hackers@freebsd.org Message-ID: <20040317183639.GA635@lame.novel.ru> References: <20040316163956.GD638@lame.novel.ru> <20040316181307.GA6576@tv.soth.at> <20040317142451.GC2506@lame.novel.ru> <20040317154530.GD6576@tv.soth.at> <20040317175340.GA88110@madman.celabo.org> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="8t9RHnE3ZwKMSgU+" Content-Disposition: inline In-Reply-To: <20040317175340.GA88110@madman.celabo.org> "From: Roman Bogordskiy " User-Agent: Mutt/1.5.6i X-Spam: Not detected Subject: Re: kernel modules programming: struct proc question X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 17 Mar 2004 18:37:06 -0000 --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 #include #include #include #include #include #include #include #include #include #include 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 >---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+--