From mboxrd@z Thu Jan 1 00:00:00 1970 From: Philipp Hahn Subject: [PATCH] no-fork option for tapdisk2 debugging Date: Tue, 21 Jun 2011 15:29:34 +0200 Message-ID: <201106211529.39113.hahn@univention.de> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0749169566==" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org --===============0749169566== Content-Type: multipart/signed; boundary="nextPart34444537.uKkA6Si40n"; protocol="application/pgp-signature"; micalg=pgp-sha1 Content-Transfer-Encoding: 7bit --nextPart34444537.uKkA6Si40n Content-Type: multipart/mixed; boundary="Boundary-01=_/yJAO0dytgxJ7x6" Content-Transfer-Encoding: 7bit Content-Disposition: inline --Boundary-01=_/yJAO0dytgxJ7x6 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hello, =46or debugging tapdisk2 it would be nice if forking into the background co= uld=20 be disabled by passing some command line argument. The attached patch adds= =20 such an option (-n). The second patch re-indents four un-changed lines. It would be nice if this could be included into the source core repository. Sincerely Philipp Hahn =2D-=20 Philipp Hahn Open Source Software Engineer hahn@univention.de Univention GmbH Linux for Your Business fon: +49 421 22 232- 0 Mary-Somerville-Str.1 D-28359 Bremen fax: +49 421 22 232-99 http://www.univention.de/ --Boundary-01=_/yJAO0dytgxJ7x6 Content-Type: text/x-diff; charset="iso-8859-15"; name="tapdisk2.diff" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="tapdisk2.diff" Add option to disable forking To simplify running tapdisk2 from a debugger, add an opttion "-n" to disabl= e foring into the background. Signed-off-by: Philipp Hahn =2D-- xen-4.0.1.orig/tools/blktap2/drivers/tapdisk2.c 2010-08-25 12:22:07.0= 00000000 +0200 +++ xen-4.0.1/tools/blktap2/drivers/tapdisk2.c 2011-06-17 17:37:35.00000000= 0 +0200 @@ -402,7 +402,7 @@ tapdisk2_wait_for_device(void) static void usage(const char *app, int err) { =2D fprintf(stderr, "usage: %s <-n file>\n", app); + fprintf(stderr, "usage: %s [-f] -n driver:file\n", app); exit(err); } =20 @@ -411,10 +411,11 @@ main(int argc, char *argv[]) { int c; char *params; + int do_fork =3D 1; =20 params =3D NULL; =20 =2D while ((c =3D getopt(argc, argv, "n:s:h")) !=3D -1) { + while ((c =3D getopt(argc, argv, "n:s:fh")) !=3D -1) { switch (c) { case 'n': params =3D optarg; @@ -430,6 +431,9 @@ main(int argc, char *argv[]) exit(EXIT_FAILURE); #endif break; + case 'f': + do_fork =3D 0; + break; default: usage(argv[0], EINVAL); } @@ -438,12 +442,17 @@ main(int argc, char *argv[]) if (!params || optind !=3D argc) usage(argv[0], EINVAL); =20 + if (do_fork) { if (pipe(channel) =3D=3D -1) { printf("pipe failed: %d\n", errno); return errno; } + } else { + channel[0] =3D dup(STDIN_FILENO); + channel[1] =3D dup(STDERR_FILENO); + } =20 =2D switch (fork()) { + switch (do_fork ? fork() : 0) { case -1: printf("fork failed: %d\n", errno); return errno; --Boundary-01=_/yJAO0dytgxJ7x6 Content-Type: text/x-diff; charset="iso-8859-15"; name="tapdisk2_indent.diff" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="tapdisk2_indent.diff" Re-indent lines. Re-indent lines after applying patch to add no-fork option. Signed-off-by: Philipp Hahn =2D-- xen-4.0.1.orig/tools/blktap2/drivers/tapdisk2.c 2010-08-25 12:22:07.0= 00000000 +0200 +++ xen-4.0.1/tools/blktap2/drivers/tapdisk2.c 2011-06-17 17:37:35.00000000= 0 +0200 @@ -443,10 +443,10 @@ main(int argc, char *argv[]) usage(argv[0], EINVAL); =20 if (do_fork) { =2D if (pipe(channel) =3D=3D -1) { =2D printf("pipe failed: %d\n", errno); =2D return errno; =2D } + if (pipe(channel) =3D=3D -1) { + printf("pipe failed: %d\n", errno); + return errno; + } } else { channel[0] =3D dup(STDIN_FILENO); channel[1] =3D dup(STDERR_FILENO); --Boundary-01=_/yJAO0dytgxJ7x6-- --nextPart34444537.uKkA6Si40n Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEABECAAYFAk4AnL8ACgkQYPlgoZpUDjnPuQCgnqq7bMc2M/UUjtvmOBiG2tSi NuQAnRhrl0eoFHCQSJegQ6O8X+rXMLD8 =U95M -----END PGP SIGNATURE----- --nextPart34444537.uKkA6Si40n-- --===============0749169566== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --===============0749169566==--