[PATCH v3 3/4] staging: usbip: properly handle -l / --log option

2013-08-22 Thread Anthony Foiani
This option is in the long options list, and it's handled in the
option processing loop, but the optstring didn't include it.

Signed-off-by: Anthony Foiani anthony.foi...@gmail.com
---
 drivers/staging/usbip/userspace/src/usbip.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/usbip/userspace/src/usbip.c 
b/drivers/staging/usbip/userspace/src/usbip.c
index 69ac4b5..b4f299e 100644
--- a/drivers/staging/usbip/userspace/src/usbip.c
+++ b/drivers/staging/usbip/userspace/src/usbip.c
@@ -152,7 +152,7 @@ int main(int argc, char *argv[])
usbip_use_stderr = 1;
opterr = 0;
for (;;) {
-   opt = getopt_long(argc, argv, +dt:, opts, NULL);
+   opt = getopt_long(argc, argv, +dlt:, opts, NULL);
 
if (opt == -1)
break;
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe linux-usb in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 4/4] staging: usbip: fix up alignment in long options list

2013-08-22 Thread Anthony Foiani
Re-align the option lists.

Signed-off-by: Anthony Foiani anthony.foi...@gmail.com
---
 drivers/staging/usbip/userspace/src/usbip.c  |  8 
 drivers/staging/usbip/userspace/src/usbipd.c | 12 ++--
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/staging/usbip/userspace/src/usbip.c 
b/drivers/staging/usbip/userspace/src/usbip.c
index b4f299e..04a5f20 100644
--- a/drivers/staging/usbip/userspace/src/usbip.c
+++ b/drivers/staging/usbip/userspace/src/usbip.c
@@ -139,10 +139,10 @@ static int run_command(const struct command *cmd, int 
argc, char *argv[])
 int main(int argc, char *argv[])
 {
static const struct option opts[] = {
-   { debug, no_argument, NULL, 'd' },
-   { log,   no_argument, NULL, 'l' },
-   { tcp-port,  required_argument, NULL, 't' },
-   { NULL,0,   NULL,  0  }
+   { debug,no_argument,   NULL, 'd' },
+   { log,  no_argument,   NULL, 'l' },
+   { tcp-port, required_argument, NULL, 't' },
+   { NULL,   0, NULL,  0  }
};
 
char *cmd;
diff --git a/drivers/staging/usbip/userspace/src/usbipd.c 
b/drivers/staging/usbip/userspace/src/usbipd.c
index f41ba5b..1c76cfd 100644
--- a/drivers/staging/usbip/userspace/src/usbipd.c
+++ b/drivers/staging/usbip/userspace/src/usbipd.c
@@ -560,13 +560,13 @@ static int do_standalone_mode(int daemonize)
 int main(int argc, char *argv[])
 {
static const struct option longopts[] = {
-   { daemon,  no_argument, NULL, 'D' },
-   { debug,   no_argument, NULL, 'd' },
-   { pid, optional_argument, NULL, 'P' },
+   { daemon,   no_argument,   NULL, 'D' },
+   { debug,no_argument,   NULL, 'd' },
+   { pid,  optional_argument, NULL, 'P' },
{ tcp-port, required_argument, NULL, 't' },
-   { help,no_argument, NULL, 'h' },
-   { version, no_argument, NULL, 'v' },
-   { NULL,  0,   NULL,  0  }
+   { help, no_argument,   NULL, 'h' },
+   { version,  no_argument,   NULL, 'v' },
+   { NULL,   0, NULL,  0  }
};
 
enum {
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe linux-usb in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 2/4] staging: usbip: set usbipd server port via -t / --tcp-port option.

2013-08-19 Thread Anthony Foiani
Greg KH g...@kroah.com writes:

 On Sat, Aug 17, 2013 at 03:34:32PM -0600, Anthony Foiani wrote:
  +int USBIP_PORT = 3240;
  +char *USBIP_PORT_STRING = 3240;

 Variables shouldn't be ALL_CAPS, those are what #defines are for.
 Yes, I know you moved from a define to a variable,

Right, I was trying to minimize churn.  Guess I should have followed
with another patch to convert to sane usage.

 but please make it obvious and change the name as well, otherwise
 stuff like:

 +USBIP_PORT = port;
 +USBIP_PORT_STRING = arg;

 Just makes my head hurt.

Ok.  Will try to respin in the next few days.

Thanks!

Tony
--
To unsubscribe from this list: send the line unsubscribe linux-usb in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 1/4] staging: usbip: add -P / --pid option to save usbipd process id

2013-08-19 Thread Anthony Foiani
Greg KH gre...@linuxfoundation.org writes:

 On Sat, Aug 17, 2013 at 03:34:31PM -0600, Anthony Foiani wrote:
  Introduce option -P / --pid to request that usbipd save its
  PID to a file while running.

 Shouldn't this be the requirement of the tool that starts it up
 (i.e.  systemd or sysvinit)?  Putting stuff like /var/run into the
 daemon seems like a bad idea.

By that logic, we should remove the daemonize code entirely, since one
can't otherwise get the PID post-daemonize.

(I'll admit that I'm using it in a project that has no init scripts,
so I'd carry this change regardless.)

Finally, the /var/run/usbipd.pid is just a default; the user is
welcome to specify whatever path their distribution or layout
requires.  (Assuming I coded the getopt bits correctly!)

As always, feel free to drop.  I just wanted to follow up on my
previous patches with a more final version, in case anyone else needs
or wants these features.

Thanks,
Tony
--
To unsubscribe from this list: send the line unsubscribe linux-usb in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 3/4] staging: usbip: properly handle -l / --log option

2013-08-17 Thread Anthony Foiani
This option is in the long options list, and it's handled in the
option processing loop, but the optstring didn't include it.

Signed-off-by: Anthony Foiani anthony.foi...@gmail.com
---
 drivers/staging/usbip/userspace/src/usbip.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/usbip/userspace/src/usbip.c 
b/drivers/staging/usbip/userspace/src/usbip.c
index 69ac4b5..b4f299e 100644
--- a/drivers/staging/usbip/userspace/src/usbip.c
+++ b/drivers/staging/usbip/userspace/src/usbip.c
@@ -152,7 +152,7 @@ int main(int argc, char *argv[])
usbip_use_stderr = 1;
opterr = 0;
for (;;) {
-   opt = getopt_long(argc, argv, +dt:, opts, NULL);
+   opt = getopt_long(argc, argv, +dlt:, opts, NULL);
 
if (opt == -1)
break;
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe linux-usb in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 4/4] staging: usbip: fix up alignment in long options list

2013-08-17 Thread Anthony Foiani
Re-align the option lists.

Signed-off-by: Anthony Foiani anthony.foi...@gmail.com
---
 drivers/staging/usbip/userspace/src/usbip.c  |  8 
 drivers/staging/usbip/userspace/src/usbipd.c | 12 ++--
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/staging/usbip/userspace/src/usbip.c 
b/drivers/staging/usbip/userspace/src/usbip.c
index b4f299e..04a5f20 100644
--- a/drivers/staging/usbip/userspace/src/usbip.c
+++ b/drivers/staging/usbip/userspace/src/usbip.c
@@ -139,10 +139,10 @@ static int run_command(const struct command *cmd, int 
argc, char *argv[])
 int main(int argc, char *argv[])
 {
static const struct option opts[] = {
-   { debug, no_argument, NULL, 'd' },
-   { log,   no_argument, NULL, 'l' },
-   { tcp-port,  required_argument, NULL, 't' },
-   { NULL,0,   NULL,  0  }
+   { debug,no_argument,   NULL, 'd' },
+   { log,  no_argument,   NULL, 'l' },
+   { tcp-port, required_argument, NULL, 't' },
+   { NULL,   0, NULL,  0  }
};
 
char *cmd;
diff --git a/drivers/staging/usbip/userspace/src/usbipd.c 
b/drivers/staging/usbip/userspace/src/usbipd.c
index c0bb689..1659683 100644
--- a/drivers/staging/usbip/userspace/src/usbipd.c
+++ b/drivers/staging/usbip/userspace/src/usbipd.c
@@ -560,13 +560,13 @@ static int do_standalone_mode(int daemonize)
 int main(int argc, char *argv[])
 {
static const struct option longopts[] = {
-   { daemon,  no_argument, NULL, 'D' },
-   { debug,   no_argument, NULL, 'd' },
-   { pid, optional_argument, NULL, 'P' },
+   { daemon,   no_argument,   NULL, 'D' },
+   { debug,no_argument,   NULL, 'd' },
+   { pid,  optional_argument, NULL, 'P' },
{ tcp-port, required_argument, NULL, 't' },
-   { help,no_argument, NULL, 'h' },
-   { version, no_argument, NULL, 'v' },
-   { NULL,  0,   NULL,  0  }
+   { help, no_argument,   NULL, 'h' },
+   { version,  no_argument,   NULL, 'v' },
+   { NULL,   0, NULL,  0  }
};
 
enum {
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe linux-usb in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 1/4] staging: usbip: add -P / --pid option to save usbipd process id

2013-08-17 Thread Anthony Foiani
Introduce option -P / --pid to request that usbipd save its PID to
a file while running.

Signed-off-by: Anthony Foiani anthony.foi...@gmail.com
---
 drivers/staging/usbip/userspace/src/usbipd.c | 40 +++-
 1 file changed, 39 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/usbip/userspace/src/usbipd.c 
b/drivers/staging/usbip/userspace/src/usbipd.c
index 1ecca9d..f31b8b4 100644
--- a/drivers/staging/usbip/userspace/src/usbipd.c
+++ b/drivers/staging/usbip/userspace/src/usbipd.c
@@ -50,6 +50,8 @@
 
 #define MAIN_LOOP_TIMEOUT 10
 
+#define DEFAULT_PID_FILE /var/run/ PROGNAME .pid
+
 static const char usbip_version_string[] = PACKAGE_STRING;
 
 static const char usbipd_help_string[] =
@@ -60,6 +62,10 @@ static const char usbipd_help_string[] =
   -d, --debug\n
   Print debugging information.\n
\n
+  -PFILE, --pid FILE\n
+  Write process id to FILE.\n
+  If no FILE specified, use  DEFAULT_PID_FILE \n
+   \n
   -h, --help\n
   Print this help.\n
\n
@@ -439,6 +445,31 @@ static void set_signal(void)
sigaction(SIGCLD, act, NULL);
 }
 
+static const char *pid_file;
+
+static void write_pid_file()
+{
+   if (pid_file) {
+   dbg(creating pid file %s, pid_file);
+   FILE *fp = fopen(pid_file, w);
+   if (!fp) {
+   err(pid_file: %s: %d (%s),
+   pid_file, errno, strerror(errno));
+   return;
+   }
+   fprintf(fp, %d\n, getpid());
+   fclose(fp);
+   }
+}
+
+static void remove_pid_file()
+{
+   if (pid_file) {
+   dbg(removing pid file %s, pid_file);
+   unlink(pid_file);
+   }
+}
+
 static int do_standalone_mode(int daemonize)
 {
struct addrinfo *ai_head;
@@ -465,6 +496,7 @@ static int do_standalone_mode(int daemonize)
usbip_use_syslog = 1;
}
set_signal();
+   write_pid_file();
 
ai_head = do_getaddrinfo(NULL, PF_UNSPEC);
if (!ai_head) {
@@ -527,6 +559,7 @@ int main(int argc, char *argv[])
static const struct option longopts[] = {
{ daemon,  no_argument, NULL, 'D' },
{ debug,   no_argument, NULL, 'd' },
+   { pid, optional_argument, NULL, 'P' },
{ help,no_argument, NULL, 'h' },
{ version, no_argument, NULL, 'v' },
{ NULL,  0,   NULL,  0  }
@@ -540,6 +573,7 @@ int main(int argc, char *argv[])
 
int daemonize = 0;
int opt, rc = -1;
+   pid_file = NULL;
 
usbip_use_stderr = 1;
usbip_use_syslog = 0;
@@ -549,7 +583,7 @@ int main(int argc, char *argv[])
 
cmd = cmd_standalone_mode;
for (;;) {
-   opt = getopt_long(argc, argv, Ddhv, longopts, NULL);
+   opt = getopt_long(argc, argv, DdP::hv, longopts, NULL);
 
if (opt == -1)
break;
@@ -564,6 +598,9 @@ int main(int argc, char *argv[])
case 'h':
cmd = cmd_help;
break;
+   case 'P':
+   pid_file = optarg ? optarg : DEFAULT_PID_FILE;
+   break;
case 'v':
cmd = cmd_version;
break;
@@ -577,6 +614,7 @@ int main(int argc, char *argv[])
switch (cmd) {
case cmd_standalone_mode:
rc = do_standalone_mode(daemonize);
+   remove_pid_file();
break;
case cmd_version:
printf(PROGNAME  (%s)\n, usbip_version_string);
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe linux-usb in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 0/4] staging: usbip: minor features and bug fix

2013-08-17 Thread Anthony Foiani
In the course of adapting the USBIP tools to our project, I added a
few features:

 * Specify USBIP TCP/IP port number for 'usbip' and 'usbipd'
 * Request that 'usbipd' write its process id to a file

I did some minor cleaning along the way: some checkpatch, later to
repair alignments broken while adding new options.

Finally, the log option was not properly accepted by 'usbip'.

This is based off linux-next commit 1e712b0818569846d6b926ecb6bf32b3dea73609
(which is tag next-20130816)

Original thread at these urls:
  http://markmail.org/thread/6re24e7r443kn2nj
  http://www.mail-archive.com/linux-usb@vger.kernel.org/msg23959.html

Changes from v1 - v2:
 * Use -t / --tcp-port instead of -p / --port; the 'usbip'
   command already has a -p option for the usbip port in use.
 * Make sure that 'usbipd' records its PID *after* daemonizing.
 * Drop first three patches from v1 (they're already accepted).

Anthony Foiani (4):
  staging: usbip: add -P / --pid option to save usbipd process id
  staging: usbip: set usbipd server port via -t / --tcp-port option.
  staging: usbip: properly handle -l / --log option
  staging: usbip: fix up alignment in long options list

 drivers/staging/usbip/userspace/src/usbip.c| 15 --
 .../staging/usbip/userspace/src/usbip_network.c| 30 
 .../staging/usbip/userspace/src/usbip_network.h|  5 +-
 drivers/staging/usbip/userspace/src/usbipd.c   | 57 +++---
 4 files changed, 94 insertions(+), 13 deletions(-)

-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe linux-usb in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 4/7] staging: usbip: add option for usbipd to save its process id.

2013-07-08 Thread Anthony Foiani
Introduce option -P / --pid to request that usbipd save its PID to
a file while running.

Signed-Off-By: Anthony Foiani anthony.foi...@gmail.com
---
 drivers/staging/usbip/userspace/src/usbipd.c | 38 +++-
 1 file changed, 37 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/usbip/userspace/src/usbipd.c 
b/drivers/staging/usbip/userspace/src/usbipd.c
index 1ecca9d..9c83148 100644
--- a/drivers/staging/usbip/userspace/src/usbipd.c
+++ b/drivers/staging/usbip/userspace/src/usbipd.c
@@ -50,6 +50,8 @@
 
 #define MAIN_LOOP_TIMEOUT 10
 
+#define DEFAULT_PID_FILE /var/run/ PROGNAME .pid
+
 static const char usbip_version_string[] = PACKAGE_STRING;
 
 static const char usbipd_help_string[] =
@@ -60,6 +62,10 @@ static const char usbipd_help_string[] =
   -d, --debug\n
   Print debugging information.\n
\n
+  -PFILE, --pid FILE\n
+  Write process id to FILE.\n
+  If no FILE specified, use  DEFAULT_PID_FILE \n
+   \n
   -h, --help\n
   Print this help.\n
\n
@@ -522,11 +528,35 @@ static int do_standalone_mode(int daemonize)
return 0;
 }
 
+static void write_pid_file(const char *pid_file)
+{
+   if (pid_file) {
+   dbg(creating pid file %s, pid_file);
+   FILE *fp = fopen(pid_file, w);
+   if (!fp) {
+   err(pid_file: %s: %d (%s),
+   pid_file, errno, strerror(errno));
+   return;
+   }
+   fprintf(fp, %d\n, getpid());
+   fclose(fp);
+   }
+}
+
+static void remove_pid_file(const char *pid_file)
+{
+   if (pid_file) {
+   dbg(removing pid file %s, pid_file);
+   unlink(pid_file);
+   }
+}
+
 int main(int argc, char *argv[])
 {
static const struct option longopts[] = {
{ daemon,  no_argument, NULL, 'D' },
{ debug,   no_argument, NULL, 'd' },
+   { pid, optional_argument, NULL, 'P' },
{ help,no_argument, NULL, 'h' },
{ version, no_argument, NULL, 'v' },
{ NULL,  0,   NULL,  0  }
@@ -540,6 +570,7 @@ int main(int argc, char *argv[])
 
int daemonize = 0;
int opt, rc = -1;
+   const char *pid_file = NULL;
 
usbip_use_stderr = 1;
usbip_use_syslog = 0;
@@ -549,7 +580,7 @@ int main(int argc, char *argv[])
 
cmd = cmd_standalone_mode;
for (;;) {
-   opt = getopt_long(argc, argv, Ddhv, longopts, NULL);
+   opt = getopt_long(argc, argv, DdP::hv, longopts, NULL);
 
if (opt == -1)
break;
@@ -564,6 +595,9 @@ int main(int argc, char *argv[])
case 'h':
cmd = cmd_help;
break;
+   case 'P':
+   pid_file = optarg ? optarg : DEFAULT_PID_FILE;
+   break;
case 'v':
cmd = cmd_version;
break;
@@ -576,7 +610,9 @@ int main(int argc, char *argv[])
 
switch (cmd) {
case cmd_standalone_mode:
+   write_pid_file(pid_file);
rc = do_standalone_mode(daemonize);
+   remove_pid_file(pid_file);
break;
case cmd_version:
printf(PROGNAME  (%s)\n, usbip_version_string);
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe linux-usb in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/7] staging: usbip: clean up checkpatch warnings in usbipd.c

2013-07-08 Thread Anthony Foiani
A few whitespace changes allows the file to pass checkpatch --strict
(other than ignoring the CamelCase derived from the USB standard.)

Signed-Off-By: Anthony Foiani anthony.foi...@gmail.com
---
 drivers/staging/usbip/userspace/src/usbipd.c | 31 ++--
 1 file changed, 16 insertions(+), 15 deletions(-)

diff --git a/drivers/staging/usbip/userspace/src/usbipd.c 
b/drivers/staging/usbip/userspace/src/usbipd.c
index 3e913b8..9d38241 100644
--- a/drivers/staging/usbip/userspace/src/usbipd.c
+++ b/drivers/staging/usbip/userspace/src/usbipd.c
@@ -53,18 +53,18 @@
 static const char usbip_version_string[] = PACKAGE_STRING;
 
 static const char usbipd_help_string[] =
-   usage: usbipd [options]\n
-  -D, --daemon\n
-  Run as a daemon process.\n
-  \n
-  -d, --debug \n
-  Print debugging information.\n
-  \n
-  -h, --help  \n
-  Print this help.\n
-  \n
-  -v, --version   \n
-  Show version.   \n;
+   usage: usbipd [options]\n
+  -D, --daemon\n
+  Run as a daemon process.\n
+   \n
+  -d, --debug\n
+  Print debugging information.\n
+   \n
+  -h, --help\n
+  Print this help.\n
+   \n
+  -v, --version\n
+  Show version.\n;
 
 static void usbipd_help(void)
 {
@@ -286,13 +286,13 @@ static int do_accept(int listenfd)
 
memset(ss, 0, sizeof(ss));
 
-   connfd = accept(listenfd, (struct sockaddr *) ss, len);
+   connfd = accept(listenfd, (struct sockaddr *)ss, len);
if (connfd  0) {
err(failed to accept connection);
return -1;
}
 
-   rc = getnameinfo((struct sockaddr *) ss, len, host, sizeof(host),
+   rc = getnameinfo((struct sockaddr *)ss, len, host, sizeof(host),
 port, sizeof(port), NI_NUMERICHOST | NI_NUMERICSERV);
if (rc)
err(getnameinfo: %s, gai_strerror(rc));
@@ -496,8 +496,9 @@ static int do_standalone_mode(int daemonize)
process_request(sockfdlist[i]);
}
}
-   } else
+   } else {
dbg(heartbeat timeout on ppoll());
+   }
}
 
info(shutting down  PROGNAME);
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe linux-usb in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 0/7] staging: usbip: features and a tiny fix

2013-07-08 Thread Anthony Foiani
In the course of adapting the USBIP tools to our project, I added a
few features:

 * Configure TCP/IP port number
 * Save process id of 'usbipd'

I did some minor cleaning along the way: some checkpatch, later to
repair alignments broken while adding new options.

Finally, the log option was not properly accepted by 'usbip'.

This is based off linux-next commit 985b84a0d18aaad943103c75f82accc94f475a15

Thanks,
Tony

Anthony Foiani (7):
  staging: usbip: clean up checkpatch warnings in usbipd.c
  staging: usbip: use local variable while setting up socket
  staging: usbip: improve error reporting
  staging: usbip: add option for usbipd to save its process id.
  staging: usbip: set server port via option.
  staging: usbip: properly handle -l / --log option
  staging: usbip: fix up alignment in long options list

 drivers/staging/usbip/userspace/src/usbip.c|  15 ++-
 .../staging/usbip/userspace/src/usbip_network.c|  30 +
 .../staging/usbip/userspace/src/usbip_network.h|   5 +-
 drivers/staging/usbip/userspace/src/usbipd.c   | 135 +++--
 4 files changed, 139 insertions(+), 46 deletions(-)

-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe linux-usb in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 3/7] staging: usbip: improve error reporting

2013-07-08 Thread Anthony Foiani
Give useful error messages when we can't create server sockets.

Signed-Off-By: Anthony Foiani anthony.foi...@gmail.com
---
 drivers/staging/usbip/userspace/src/usbipd.c | 28 ++--
 1 file changed, 22 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/usbip/userspace/src/usbipd.c 
b/drivers/staging/usbip/userspace/src/usbipd.c
index d833e7b..1ecca9d 100644
--- a/drivers/staging/usbip/userspace/src/usbipd.c
+++ b/drivers/staging/usbip/userspace/src/usbipd.c
@@ -328,52 +328,68 @@ int process_request(int listenfd)
return 0;
 }
 
-static void log_addrinfo(struct addrinfo *ai)
+static void addrinfo_to_text(struct addrinfo *ai, char buf[],
+const size_t buf_size)
 {
char hbuf[NI_MAXHOST];
char sbuf[NI_MAXSERV];
int rc;
 
+   buf[0] = '\0';
+
rc = getnameinfo(ai-ai_addr, ai-ai_addrlen, hbuf, sizeof(hbuf),
 sbuf, sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV);
if (rc)
err(getnameinfo: %s, gai_strerror(rc));
 
-   info(listening on %s:%s, hbuf, sbuf);
+   snprintf(buf, buf_size, %s:%s, hbuf, sbuf);
 }
 
 static int listen_all_addrinfo(struct addrinfo *ai_head, int sockfdlist[])
 {
struct addrinfo *ai;
int ret, nsockfd = 0;
+   const size_t ai_buf_size = NI_MAXHOST + NI_MAXSERV + 2;
+   char ai_buf[ai_buf_size];
 
for (ai = ai_head; ai  nsockfd  MAXSOCKFD; ai = ai-ai_next) {
-   int sock = socket(ai-ai_family, ai-ai_socktype,
- ai-ai_protocol);
-   if (sock  0)
+   int sock;
+   addrinfo_to_text(ai, ai_buf, ai_buf_size);
+   dbg(opening %s, ai_buf);
+   sock = socket(ai-ai_family, ai-ai_socktype, ai-ai_protocol);
+   if (sock  0) {
+   err(socket: %s: %d (%s),
+   ai_buf, errno, strerror(errno));
continue;
+   }
 
usbip_net_set_reuseaddr(sock);
usbip_net_set_nodelay(sock);
 
if (sock = FD_SETSIZE) {
+   err(FD_SETSIZE: %s: sock=%d, max=%d,
+   ai_buf, sock, FD_SETSIZE);
close(sock);
continue;
}
 
ret = bind(sock, ai-ai_addr, ai-ai_addrlen);
if (ret  0) {
+   err(bind: %s: %d (%s),
+   ai_buf, errno, strerror(errno));
close(sock);
continue;
}
 
ret = listen(sock, SOMAXCONN);
if (ret  0) {
+   err(listen: %s: %d (%s),
+   ai_buf, errno, strerror(errno));
close(sock);
continue;
}
 
-   log_addrinfo(ai);
+   info(listening on %s, ai_buf);
sockfdlist[nsockfd++] = sock;
}
 
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe linux-usb in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 5/7] staging: usbip: set server port via option.

2013-07-08 Thread Anthony Foiani
Add an option -p / --port to specify the TCP port to listen on.

Signed-Off-By: Anthony Foiani anthony.foi...@gmail.com
---
 drivers/staging/usbip/userspace/src/usbip.c|  9 +--
 .../staging/usbip/userspace/src/usbip_network.c| 30 ++
 .../staging/usbip/userspace/src/usbip_network.h|  5 ++--
 drivers/staging/usbip/userspace/src/usbipd.c   |  9 ++-
 4 files changed, 48 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/usbip/userspace/src/usbip.c 
b/drivers/staging/usbip/userspace/src/usbip.c
index fff4b76..e71256a 100644
--- a/drivers/staging/usbip/userspace/src/usbip.c
+++ b/drivers/staging/usbip/userspace/src/usbip.c
@@ -26,6 +26,7 @@
 #include syslog.h
 
 #include usbip_common.h
+#include usbip_network.h
 #include usbip.h
 
 static int usbip_help(int argc, char *argv[]);
@@ -34,7 +35,7 @@ static int usbip_version(int argc, char *argv[]);
 static const char usbip_version_string[] = PACKAGE_STRING;
 
 static const char usbip_usage_string[] =
-   usbip [--debug] [--log] [version]\n
+   usbip [--debug] [--log] [--port PORT] [version]\n
 [help] command args\n;
 
 static void usbip_usage(void)
@@ -140,6 +141,7 @@ int main(int argc, char *argv[])
static const struct option opts[] = {
{ debug, no_argument, NULL, 'd' },
{ log,   no_argument, NULL, 'l' },
+   { port,  required_argument, NULL, 'p' },
{ NULL,0,   NULL,  0  }
};
 
@@ -150,7 +152,7 @@ int main(int argc, char *argv[])
usbip_use_stderr = 1;
opterr = 0;
for (;;) {
-   opt = getopt_long(argc, argv, +d, opts, NULL);
+   opt = getopt_long(argc, argv, +dp:, opts, NULL);
 
if (opt == -1)
break;
@@ -163,6 +165,9 @@ int main(int argc, char *argv[])
usbip_use_syslog = 1;
openlog(, LOG_PID, LOG_USER);
break;
+   case 'p':
+   usbip_setup_port_number(optarg);
+   break;
case '?':
printf(usbip: invalid option\n);
default:
diff --git a/drivers/staging/usbip/userspace/src/usbip_network.c 
b/drivers/staging/usbip/userspace/src/usbip_network.c
index b12448e..3e8eed4 100644
--- a/drivers/staging/usbip/userspace/src/usbip_network.c
+++ b/drivers/staging/usbip/userspace/src/usbip_network.c
@@ -28,6 +28,36 @@
 #include usbip_common.h
 #include usbip_network.h
 
+int USBIP_PORT = 3240;
+char *USBIP_PORT_STRING = 3240;
+
+void usbip_setup_port_number(char *arg)
+{
+   dbg(parsing port arg '%s', arg);
+   char *end;
+   unsigned long int port = strtoul(arg, end, 10);
+
+   if (end == arg) {
+   err(port: could not parse '%s' as a decimal integer, arg);
+   return;
+   }
+
+   if (*end != '\0') {
+   err(port: garbage at end of '%s', arg);
+   return;
+   }
+
+   if (port  UINT16_MAX) {
+   err(port: %s too high (max=%d),
+   arg, UINT16_MAX);
+   return;
+   }
+
+   USBIP_PORT = port;
+   USBIP_PORT_STRING = arg;
+   info(using port %d (\%s\), USBIP_PORT, USBIP_PORT_STRING);
+}
+
 void usbip_net_pack_uint32_t(int pack, uint32_t *num)
 {
uint32_t i;
diff --git a/drivers/staging/usbip/userspace/src/usbip_network.h 
b/drivers/staging/usbip/userspace/src/usbip_network.h
index 1bbefc9..203858c 100644
--- a/drivers/staging/usbip/userspace/src/usbip_network.h
+++ b/drivers/staging/usbip/userspace/src/usbip_network.h
@@ -14,8 +14,9 @@
 
 #include stdint.h
 
-#define USBIP_PORT 3240
-#define USBIP_PORT_STRING 3240
+extern int USBIP_PORT;
+extern char *USBIP_PORT_STRING;
+void usbip_setup_port_number(char *arg);
 
 /* -- */
 /* Common header for all the kinds of PDUs. */
diff --git a/drivers/staging/usbip/userspace/src/usbipd.c 
b/drivers/staging/usbip/userspace/src/usbipd.c
index 9c83148..5224cc8 100644
--- a/drivers/staging/usbip/userspace/src/usbipd.c
+++ b/drivers/staging/usbip/userspace/src/usbipd.c
@@ -66,6 +66,9 @@ static const char usbipd_help_string[] =
   Write process id to FILE.\n
   If no FILE specified, use  DEFAULT_PID_FILE \n
\n
+  -pPORT, --port PORT\n
+  Listen on TCP/IP port PORT.\n
+   \n
   -h, --help\n
   Print this help.\n
\n
@@ -557,6 +560,7 @@ int main(int argc, char *argv[])
{ daemon,  no_argument, NULL, 'D' },
{ debug,   no_argument, NULL, 'd' },
{ pid, optional_argument, NULL, 'P' },
+   { port,required_argument, NULL, 'p' },
{ help,no_argument, NULL, 'h' },
{ version, no_argument, NULL, 'v

[PATCH 6/7] staging: usbip: properly handle -l / --log option

2013-07-08 Thread Anthony Foiani
This option is checked for, and is in the long options list, but the
optstring didn't include it.

Signed-Off-By: Anthony Foiani anthony.foi...@gmail.com
---
 drivers/staging/usbip/userspace/src/usbip.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/usbip/userspace/src/usbip.c 
b/drivers/staging/usbip/userspace/src/usbip.c
index e71256a..728748b 100644
--- a/drivers/staging/usbip/userspace/src/usbip.c
+++ b/drivers/staging/usbip/userspace/src/usbip.c
@@ -152,7 +152,7 @@ int main(int argc, char *argv[])
usbip_use_stderr = 1;
opterr = 0;
for (;;) {
-   opt = getopt_long(argc, argv, +dp:, opts, NULL);
+   opt = getopt_long(argc, argv, +dlp:, opts, NULL);
 
if (opt == -1)
break;
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe linux-usb in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 7/7] staging: usbip: fix up alignment in long options list

2013-07-08 Thread Anthony Foiani
Re-align the option lists.

Signed-Off-By: Anthony Foiani anthony.foi...@gmail.com
---
 drivers/staging/usbip/userspace/src/usbip.c  |  6 +++---
 drivers/staging/usbip/userspace/src/usbipd.c | 10 +-
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/usbip/userspace/src/usbip.c 
b/drivers/staging/usbip/userspace/src/usbip.c
index 728748b..7c351bc 100644
--- a/drivers/staging/usbip/userspace/src/usbip.c
+++ b/drivers/staging/usbip/userspace/src/usbip.c
@@ -139,10 +139,10 @@ static int run_command(const struct command *cmd, int 
argc, char *argv[])
 int main(int argc, char *argv[])
 {
static const struct option opts[] = {
-   { debug, no_argument, NULL, 'd' },
-   { log,   no_argument, NULL, 'l' },
+   { debug, no_argument,   NULL, 'd' },
+   { log,   no_argument,   NULL, 'l' },
{ port,  required_argument, NULL, 'p' },
-   { NULL,0,   NULL,  0  }
+   { NULL,0, NULL,  0  }
};
 
char *cmd;
diff --git a/drivers/staging/usbip/userspace/src/usbipd.c 
b/drivers/staging/usbip/userspace/src/usbipd.c
index 5224cc8..cf93b46 100644
--- a/drivers/staging/usbip/userspace/src/usbipd.c
+++ b/drivers/staging/usbip/userspace/src/usbipd.c
@@ -557,13 +557,13 @@ static void remove_pid_file(const char *pid_file)
 int main(int argc, char *argv[])
 {
static const struct option longopts[] = {
-   { daemon,  no_argument, NULL, 'D' },
-   { debug,   no_argument, NULL, 'd' },
+   { daemon,  no_argument,   NULL, 'D' },
+   { debug,   no_argument,   NULL, 'd' },
{ pid, optional_argument, NULL, 'P' },
{ port,required_argument, NULL, 'p' },
-   { help,no_argument, NULL, 'h' },
-   { version, no_argument, NULL, 'v' },
-   { NULL,  0,   NULL,  0  }
+   { help,no_argument,   NULL, 'h' },
+   { version, no_argument,   NULL, 'v' },
+   { NULL,  0, NULL,  0  }
};
 
enum {
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe linux-usb in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/7] staging: usbip: use local variable while setting up socket

2013-07-08 Thread Anthony Foiani
Using a simple integer makes the code easier to read and removes the
need to blank out array elements in case of errors.

Signed-Off-By: Anthony Foiani anthony.foi...@gmail.com
---
 drivers/staging/usbip/userspace/src/usbipd.c | 27 ---
 1 file changed, 12 insertions(+), 15 deletions(-)

diff --git a/drivers/staging/usbip/userspace/src/usbipd.c 
b/drivers/staging/usbip/userspace/src/usbipd.c
index 9d38241..d833e7b 100644
--- a/drivers/staging/usbip/userspace/src/usbipd.c
+++ b/drivers/staging/usbip/userspace/src/usbipd.c
@@ -348,36 +348,33 @@ static int listen_all_addrinfo(struct addrinfo *ai_head, 
int sockfdlist[])
int ret, nsockfd = 0;
 
for (ai = ai_head; ai  nsockfd  MAXSOCKFD; ai = ai-ai_next) {
-   sockfdlist[nsockfd] = socket(ai-ai_family, ai-ai_socktype,
-ai-ai_protocol);
-   if (sockfdlist[nsockfd]  0)
+   int sock = socket(ai-ai_family, ai-ai_socktype,
+ ai-ai_protocol);
+   if (sock  0)
continue;
 
-   usbip_net_set_reuseaddr(sockfdlist[nsockfd]);
-   usbip_net_set_nodelay(sockfdlist[nsockfd]);
+   usbip_net_set_reuseaddr(sock);
+   usbip_net_set_nodelay(sock);
 
-   if (sockfdlist[nsockfd] = FD_SETSIZE) {
-   close(sockfdlist[nsockfd]);
-   sockfdlist[nsockfd] = -1;
+   if (sock = FD_SETSIZE) {
+   close(sock);
continue;
}
 
-   ret = bind(sockfdlist[nsockfd], ai-ai_addr, ai-ai_addrlen);
+   ret = bind(sock, ai-ai_addr, ai-ai_addrlen);
if (ret  0) {
-   close(sockfdlist[nsockfd]);
-   sockfdlist[nsockfd] = -1;
+   close(sock);
continue;
}
 
-   ret = listen(sockfdlist[nsockfd], SOMAXCONN);
+   ret = listen(sock, SOMAXCONN);
if (ret  0) {
-   close(sockfdlist[nsockfd]);
-   sockfdlist[nsockfd] = -1;
+   close(sock);
continue;
}
 
log_addrinfo(ai);
-   nsockfd++;
+   sockfdlist[nsockfd++] = sock;
}
 
if (nsockfd == 0)
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe linux-usb in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 4/7] staging: usbip: add option for usbipd to save its process id.

2013-07-08 Thread Anthony Foiani
Anthony Foiani anthony.foi...@gmail.com writes:

 Introduce option -P / --pid to request that usbipd save its PID to
 a file while running.

I've already spotted one problem with this patch:

 + write_pid_file(pid_file);
   rc = do_standalone_mode(daemonize);
 + remove_pid_file(pid_file);

I need to write the PID *after* the daemon(3) call.  (I suspect I did
all my testing in foreground mode, so didn't notice this until I
actually tried to use it on my project...)

So there will be a v2, but I'll probably wait for more feedback before
doing an official respin.

Thanks,
Tony
--
To unsubscribe from this list: send the line unsubscribe linux-usb in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 5/7] staging: usbip: set server port via option.

2013-07-08 Thread Anthony Foiani
Anthony Foiani anthony.foi...@gmail.com writes:

 Add an option -p / --port to specify the TCP port to listen on.

This is unfortunate, as port is also used to indicate which usbip
port is in use by a particular connection.

So I might change this to -t / --tcp-port in v2.

It's not a fatal flaw, since this option is interpreted by the main
usbip driver, and not by the subcommand (which is where the port
sub-option is interpreted for detach).

Input welcome.

(Speaking of which, what ever happened to the usbip port subcommand?
Is that info now in sysfs somewhere?  In my application, there's
always at most 1 port in use, so I can always disconnect usbip port 0
-- but that's not very helpful if the situation ever gets more
complicated than that...)

(For that matter, input telling me to either: (1) bag it entirely; or
(2) you're basing it off the wrong tree, idiot; ... would not exactly
be *welcome*, but it'd probably be healthy.)

Thanks,
Tony
--
To unsubscribe from this list: send the line unsubscribe linux-usb in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html