From: David Marchand <david.marchand@6wind.com>
To: qemu-devel@nongnu.org
Cc: kvm@vger.kernel.org, stefanha@gmail.com,
claudio.fontana@huawei.com, armbru@redhat.com,
arei.gonglei@huawei.com, pbonzini@redhat.com,
jani.kokkonen@huawei.com, cam@cs.ualberta.ca
Subject: [Qemu-devel] [PATCH v4 05/14] contrib/ivshmem-*: switch to QEMU headers
Date: Tue, 2 Sep 2014 17:25:23 +0200 [thread overview]
Message-ID: <1409671532-12706-6-git-send-email-david.marchand@6wind.com> (raw)
In-Reply-To: <1409671532-12706-1-git-send-email-david.marchand@6wind.com>
Reuse parsers from QEMU, C99 boolean.
Signed-off-by: David Marchand <david.marchand@6wind.com>
---
contrib/ivshmem-client/ivshmem-client.c | 12 +----
contrib/ivshmem-client/ivshmem-client.h | 4 +-
contrib/ivshmem-client/main.c | 12 +----
contrib/ivshmem-server/ivshmem-server.c | 14 +-----
contrib/ivshmem-server/ivshmem-server.h | 4 +-
contrib/ivshmem-server/main.c | 73 +++++--------------------------
6 files changed, 20 insertions(+), 99 deletions(-)
diff --git a/contrib/ivshmem-client/ivshmem-client.c b/contrib/ivshmem-client/ivshmem-client.c
index ce3a5d2..2ba40a7 100644
--- a/contrib/ivshmem-client/ivshmem-client.c
+++ b/contrib/ivshmem-client/ivshmem-client.c
@@ -6,19 +6,11 @@
* top-level directory.
*/
-#include <stdio.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
-#include <unistd.h>
-#include <inttypes.h>
-
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
+#include "qemu-common.h"
#include "qemu/queue.h"
#include "ivshmem-client.h"
@@ -149,7 +141,7 @@ handle_server_msg(IvshmemClient *client)
int
ivshmem_client_init(IvshmemClient *client, const char *unix_sock_path,
ivshmem_client_notif_cb_t notif_cb, void *notif_arg,
- int verbose)
+ bool verbose)
{
unsigned i;
diff --git a/contrib/ivshmem-client/ivshmem-client.h b/contrib/ivshmem-client/ivshmem-client.h
index e3b284d..45f2b64 100644
--- a/contrib/ivshmem-client/ivshmem-client.h
+++ b/contrib/ivshmem-client/ivshmem-client.h
@@ -78,7 +78,7 @@ struct IvshmemClient {
ivshmem_client_notif_cb_t notif_cb; /**< notification callback */
void *notif_arg; /**< notification argument */
- int verbose; /**< true to enable debug */
+ bool verbose; /**< true to enable debug */
};
/**
@@ -101,7 +101,7 @@ struct IvshmemClient {
*/
int ivshmem_client_init(IvshmemClient *client, const char *unix_sock_path,
ivshmem_client_notif_cb_t notif_cb, void *notif_arg,
- int verbose);
+ bool verbose);
/**
* Connect to the server
diff --git a/contrib/ivshmem-client/main.c b/contrib/ivshmem-client/main.c
index 778d0f2..f8a7b66 100644
--- a/contrib/ivshmem-client/main.c
+++ b/contrib/ivshmem-client/main.c
@@ -6,15 +6,7 @@
* top-level directory.
*/
-#include <stdio.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
-#include <unistd.h>
-#include <inttypes.h>
-#include <getopt.h>
+#include "qemu-common.h"
#include "ivshmem-client.h"
@@ -22,7 +14,7 @@
#define DEFAULT_UNIX_SOCK_PATH "/tmp/ivshmem_socket"
typedef struct IvshmemClientArgs {
- int verbose;
+ bool verbose;
char *unix_sock_path;
} IvshmemClientArgs;
diff --git a/contrib/ivshmem-server/ivshmem-server.c b/contrib/ivshmem-server/ivshmem-server.c
index e58864d..0afa6e8 100644
--- a/contrib/ivshmem-server/ivshmem-server.c
+++ b/contrib/ivshmem-server/ivshmem-server.c
@@ -6,23 +6,13 @@
* top-level directory.
*/
-#include <stdio.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
-#include <unistd.h>
-#include <inttypes.h>
-#include <fcntl.h>
-
#include <sys/mman.h>
-#include <sys/stat.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/eventfd.h>
+#include "qemu-common.h"
#include "qemu/queue.h"
#include "ivshmem-server.h"
@@ -246,7 +236,7 @@ ivshmem_ftruncate(int fd, unsigned shmsize)
int
ivshmem_server_init(IvshmemServer *server, const char *unix_sock_path,
const char *shm_path, size_t shm_size, unsigned n_vectors,
- int verbose)
+ bool verbose)
{
memset(server, 0, sizeof(*server));
diff --git a/contrib/ivshmem-server/ivshmem-server.h b/contrib/ivshmem-server/ivshmem-server.h
index acd17a8..5ccc7af 100644
--- a/contrib/ivshmem-server/ivshmem-server.h
+++ b/contrib/ivshmem-server/ivshmem-server.h
@@ -69,7 +69,7 @@ typedef struct IvshmemServer {
int shm_fd; /**< shm file descriptor */
unsigned n_vectors; /**< number of vectors */
long cur_id; /**< id to be given to next client */
- int verbose; /**< true in verbose mode */
+ bool verbose; /**< true in verbose mode */
IvshmemServerPeerList peer_list; /**< list of peers */
} IvshmemServer;
@@ -97,7 +97,7 @@ typedef struct IvshmemServer {
int
ivshmem_server_init(IvshmemServer *server, const char *unix_sock_path,
const char *shm_path, size_t shm_size, unsigned n_vectors,
- int verbose);
+ bool verbose);
/**
* Open the shm, then create and bind to the unix socket
diff --git a/contrib/ivshmem-server/main.c b/contrib/ivshmem-server/main.c
index a4504c3..f00e6f9 100644
--- a/contrib/ivshmem-server/main.c
+++ b/contrib/ivshmem-server/main.c
@@ -6,17 +6,7 @@
* top-level directory.
*/
-#include <stdio.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
-#include <unistd.h>
-#include <inttypes.h>
-#include <sys/types.h>
-#include <limits.h>
-#include <getopt.h>
+#include "qemu-common.h"
#include "ivshmem-server.h"
@@ -30,8 +20,8 @@
/* arguments given by the user */
typedef struct IvshmemServerArgs {
- int verbose;
- int foreground;
+ bool verbose;
+ bool foreground;
char *pid_file;
char *unix_socket_path;
char *shm_path;
@@ -67,59 +57,13 @@ usage(const char *name, int code)
exit(code);
}
-/* parse the size of shm */
-static int
-parse_size(const char *val_str, size_t *val)
-{
- char *endptr;
- unsigned long long tmp;
-
- errno = 0;
- tmp = strtoull(val_str, &endptr, 0);
- if ((errno == ERANGE && tmp == ULLONG_MAX) || (errno != 0 && tmp == 0)) {
- return -1;
- }
- if (endptr == val_str) {
- return -1;
- }
- if (endptr[0] == 'K' && endptr[1] == '\0') {
- tmp *= 1024;
- } else if (endptr[0] == 'M' && endptr[1] == '\0') {
- tmp *= 1024 * 1024;
- } else if (endptr[0] == 'G' && endptr[1] == '\0') {
- tmp *= 1024 * 1024 * 1024;
- } else if (endptr[0] != '\0') {
- return -1;
- }
-
- *val = tmp;
- return 0;
-}
-
-/* parse an unsigned int */
-static int
-parse_uint(const char *val_str, unsigned *val)
-{
- char *endptr;
- unsigned long tmp;
-
- errno = 0;
- tmp = strtoul(val_str, &endptr, 0);
- if ((errno == ERANGE && tmp == ULONG_MAX) || (errno != 0 && tmp == 0)) {
- return -1;
- }
- if (endptr == val_str || endptr[0] != '\0') {
- return -1;
- }
- *val = tmp;
- return 0;
-}
-
/* parse the program arguments, exit on error */
static void
parse_args(IvshmemServerArgs *args, int argc, char *argv[])
{
char c;
+ unsigned long long v;
+ Error *errp;
while ((c = getopt(argc, argv,
"h" /* help */
@@ -158,17 +102,20 @@ parse_args(IvshmemServerArgs *args, int argc, char *argv[])
break;
case 'l': /* shm_size */
- if (parse_size(optarg, &args->shm_size) < 0) {
+ parse_option_size("shm_size", optarg, &args->shm_size, &errp);
+ if (errp) {
+ error_free(errp);
fprintf(stderr, "cannot parse shm size\n");
usage(argv[0], 1);
}
break;
case 'n': /* n_vectors */
- if (parse_uint(optarg, &args->n_vectors) < 0) {
+ if (parse_uint_full(optarg, &v, 0) < 0) {
fprintf(stderr, "cannot parse n_vectors\n");
usage(argv[0], 1);
}
+ args->n_vectors = v;
break;
default:
--
1.7.10.4
next prev parent reply other threads:[~2014-09-02 15:26 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-02 15:25 [Qemu-devel] [PATCH v4 00/14] ivshmem: update documentation, add client/server tools David Marchand
2014-09-02 15:25 ` [Qemu-devel] [PATCH v4 01/14] contrib: add ivshmem client and server David Marchand
2014-09-02 20:20 ` Eric Blake
2014-09-02 15:25 ` [Qemu-devel] [PATCH v4 02/14] docs: update ivshmem device spec David Marchand
2014-09-02 20:24 ` Eric Blake
2014-09-02 15:25 ` [Qemu-devel] [PATCH v4 03/14] contrib/ivshmem-*: comply with QEMU coding style David Marchand
2014-09-02 15:25 ` [Qemu-devel] [PATCH v4 04/14] contrib/ivshmem-*: reuse qemu/queue.h David Marchand
2014-09-02 15:25 ` David Marchand [this message]
2014-09-02 20:28 ` [Qemu-devel] [PATCH v4 05/14] contrib/ivshmem-*: switch to QEMU headers Eric Blake
2014-09-02 15:25 ` [Qemu-devel] [PATCH v4 06/14] contrib/ivshmem-server: set client sockets as non blocking David Marchand
2014-09-02 15:25 ` [Qemu-devel] [PATCH v4 07/14] contrib/ivshmem-*: add missing const and static attrs David Marchand
2014-09-02 15:25 ` [Qemu-devel] [PATCH v4 08/14] contrib/ivshmem-*: plug client and server in QEMU top Makefile David Marchand
2014-09-02 15:25 ` [Qemu-devel] [PATCH v4 09/14] contrib/ivshmem-*: switch to g_malloc0/g_free David Marchand
2014-09-02 15:25 ` [Qemu-devel] [PATCH v4 10/14] contrib/ivshmem-server: fix mem leak on error David Marchand
2014-09-02 15:25 ` [Qemu-devel] [PATCH v4 11/14] contrib/ivshmem-*: rework error handling David Marchand
2014-09-02 15:25 ` [Qemu-devel] [PATCH v4 12/14] contrib/ivshmem-*: various fixes David Marchand
2014-09-02 15:25 ` [Qemu-devel] [PATCH v4 13/14] contrib/ivshmem-server: align server default parameter values David Marchand
2014-09-02 15:25 ` [Qemu-devel] [PATCH v4 14/14] ivshmem: add check on protocol version in QEMU David Marchand
2014-09-02 20:31 ` [Qemu-devel] [PATCH v4 00/14] ivshmem: update documentation, add client/server tools Eric Blake
2014-09-03 13:01 ` David Marchand
2014-09-03 14:47 ` Eric Blake
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=1409671532-12706-6-git-send-email-david.marchand@6wind.com \
--to=david.marchand@6wind.com \
--cc=arei.gonglei@huawei.com \
--cc=armbru@redhat.com \
--cc=cam@cs.ualberta.ca \
--cc=claudio.fontana@huawei.com \
--cc=jani.kokkonen@huawei.com \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).