]> git.proxmox.com Git - mirror_qemu.git/blobdiff - qemu-nbd.c
target-s390: Don't compile in virtio-pci
[mirror_qemu.git] / qemu-nbd.c
index 9101487128e204b7a872114b1aa8a937c278b291..a393583040a04ea9d03f18e3c84292157e47d8fc 100644 (file)
@@ -13,8 +13,7 @@
  *  GNU General Public License for more details.
  *
  *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA  02110-1301 USA
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
 #include <qemu-common.h>
@@ -31,6 +30,7 @@
 #include <netinet/tcp.h>
 #include <arpa/inet.h>
 #include <signal.h>
+#include <libgen.h>
 
 #define SOCKET_PATH    "/var/lock/qemu-nbd-%s"
 
@@ -192,28 +192,28 @@ int main(int argc, char **argv)
     char sockpath[128];
     const char *sopt = "hVb:o:p:rsnP:c:dvk:e:t";
     struct option lopt[] = {
-        { "help", 0, 0, 'h' },
-        { "version", 0, 0, 'V' },
-        { "bind", 1, 0, 'b' },
-        { "port", 1, 0, 'p' },
-        { "socket", 1, 0, 'k' },
-        { "offset", 1, 0, 'o' },
-        { "read-only", 0, 0, 'r' },
-        { "partition", 1, 0, 'P' },
-        { "connect", 1, 0, 'c' },
-        { "disconnect", 0, 0, 'd' },
-        { "snapshot", 0, 0, 's' },
-        { "nocache", 0, 0, 'n' },
-        { "shared", 1, 0, 'e' },
-        { "persistent", 0, 0, 't' },
-        { "verbose", 0, 0, 'v' },
-        { NULL, 0, 0, 0 }
+        { "help", 0, NULL, 'h' },
+        { "version", 0, NULL, 'V' },
+        { "bind", 1, NULL, 'b' },
+        { "port", 1, NULL, 'p' },
+        { "socket", 1, NULL, 'k' },
+        { "offset", 1, NULL, 'o' },
+        { "read-only", 0, NULL, 'r' },
+        { "partition", 1, NULL, 'P' },
+        { "connect", 1, NULL, 'c' },
+        { "disconnect", 0, NULL, 'd' },
+        { "snapshot", 0, NULL, 's' },
+        { "nocache", 0, NULL, 'n' },
+        { "shared", 1, NULL, 'e' },
+        { "persistent", 0, NULL, 't' },
+        { "verbose", 0, NULL, 'v' },
+        { NULL, 0, NULL, 0 }
     };
     int ch;
     int opt_ind = 0;
     int li;
     char *end;
-    int flags = 0;
+    int flags = BDRV_O_RDWR;
     int partition = -1;
     int ret;
     int shared = 1;
@@ -258,6 +258,7 @@ int main(int argc, char **argv)
             break;
         case 'r':
             readonly = true;
+            flags &= ~BDRV_O_RDWR;
             break;
         case 'P':
             partition = strtol(optarg, &end, 0);
@@ -353,7 +354,8 @@ int main(int argc, char **argv)
         }
 
         if (socket == NULL) {
-            sprintf(sockpath, SOCKET_PATH, basename(device));
+            snprintf(sockpath, sizeof(sockpath), SOCKET_PATH,
+                     basename(device));
             socket = sockpath;
         }
 
@@ -468,7 +470,7 @@ int main(int argc, char **argv)
             }
         }
     } while (persistent || nb_fds > 1);
-    qemu_free(data);
+    qemu_vfree(data);
 
     close(sharing_fds[0]);
     bdrv_close(bs);