All of lore.kernel.org
 help / color / mirror / Atom feed
From: Philipp Hahn <hahn@univention.de>
To: Xen-devel@lists.xensource.com
Subject: [PATCH] no-fork option for tapdisk2 debugging
Date: Tue, 21 Jun 2011 15:29:34 +0200	[thread overview]
Message-ID: <201106211529.39113.hahn@univention.de> (raw)


[-- Attachment #1.1.1: Type: text/plain, Size: 661 bytes --]

Hello,

For debugging tapdisk2 it would be nice if forking into the background could 
be disabled by passing some command line argument. The attached patch adds 
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
-- 
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/

[-- Attachment #1.1.2: tapdisk2.diff --]
[-- Type: text/x-diff, Size: 1521 bytes --]

Add option to disable forking

To simplify running tapdisk2 from a debugger, add an opttion "-n" to disable foring into the background.

Signed-off-by: Philipp Hahn <hahn@univention.de>
--- xen-4.0.1.orig/tools/blktap2/drivers/tapdisk2.c	2010-08-25 12:22:07.000000000 +0200
+++ xen-4.0.1/tools/blktap2/drivers/tapdisk2.c	2011-06-17 17:37:35.000000000 +0200
@@ -402,7 +402,7 @@ tapdisk2_wait_for_device(void)
 static void
 usage(const char *app, int err)
 {
-	fprintf(stderr, "usage: %s <-n file>\n", app);
+	fprintf(stderr, "usage: %s [-f] -n driver:file\n", app);
 	exit(err);
 }
 
@@ -411,10 +411,11 @@ main(int argc, char *argv[])
 {
 	int c;
 	char *params;
+	int do_fork = 1;
 
 	params = NULL;
 
-	while ((c = getopt(argc, argv, "n:s:h")) != -1) {
+	while ((c = getopt(argc, argv, "n:s:fh")) != -1) {
 		switch (c) {
 		case 'n':
 			params = optarg;
@@ -430,6 +431,9 @@ main(int argc, char *argv[])
 			exit(EXIT_FAILURE);
 #endif
 			break;
+		case 'f':
+			do_fork = 0;
+			break;
 		default:
 			usage(argv[0], EINVAL);
 		}
@@ -438,12 +442,17 @@ main(int argc, char *argv[])
 	if (!params || optind != argc)
 		usage(argv[0], EINVAL);
 
+	if (do_fork) {
 	if (pipe(channel) == -1) {
 		printf("pipe failed: %d\n", errno);
 		return errno;
 	}
+	} else {
+		channel[0] = dup(STDIN_FILENO);
+		channel[1] = dup(STDERR_FILENO);
+	}
 
-	switch (fork()) {
+	switch (do_fork ? fork() : 0) {
 	case -1:
 		printf("fork failed: %d\n", errno);
 		return errno;

[-- Attachment #1.1.3: tapdisk2_indent.diff --]
[-- Type: text/x-diff, Size: 682 bytes --]

Re-indent lines.

Re-indent lines after applying patch to add no-fork option.

Signed-off-by: Philipp Hahn <hahn@univention.de>
--- xen-4.0.1.orig/tools/blktap2/drivers/tapdisk2.c	2010-08-25 12:22:07.000000000 +0200
+++ xen-4.0.1/tools/blktap2/drivers/tapdisk2.c	2011-06-17 17:37:35.000000000 +0200
@@ -443,10 +443,10 @@ main(int argc, char *argv[])
 		usage(argv[0], EINVAL);
 
 	if (do_fork) {
-	if (pipe(channel) == -1) {
-		printf("pipe failed: %d\n", errno);
-		return errno;
-	}
+		if (pipe(channel) == -1) {
+			printf("pipe failed: %d\n", errno);
+			return errno;
+		}
 	} else {
 		channel[0] = dup(STDIN_FILENO);
 		channel[1] = dup(STDERR_FILENO);

[-- Attachment #1.2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

[-- Attachment #2: Type: text/plain, Size: 138 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel

             reply	other threads:[~2011-06-21 13:29 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-21 13:29 Philipp Hahn [this message]
2011-06-21 14:29 ` [PATCH] no-fork option for tapdisk2 debugging Ian Jackson
2011-06-21 15:12   ` [PATCH v2] " Philipp Hahn
2011-06-21 15:14     ` Ian Jackson
2011-06-21 15:40       ` Philipp Hahn
2011-06-21 15:53         ` Ian Jackson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201106211529.39113.hahn@univention.de \
    --to=hahn@univention.de \
    --cc=Xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.