From patchwork Wed Aug 22 12:48:17 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Asias He X-Patchwork-Id: 1361151 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id F0D1D3FD40 for ; Wed, 22 Aug 2012 12:48:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932426Ab2HVMso (ORCPT ); Wed, 22 Aug 2012 08:48:44 -0400 Received: from mail-pz0-f46.google.com ([209.85.210.46]:48282 "EHLO mail-pz0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932165Ab2HVMsm (ORCPT ); Wed, 22 Aug 2012 08:48:42 -0400 Received: by dady13 with SMTP id y13so750890dad.19 for ; Wed, 22 Aug 2012 05:48:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=RApdf1GN+uujqreUB7fv/R9GqQKQr+1BUfsuZDh+YZg=; b=tc32BTU01pqHkiWQw7fjUKX9tndTuYxd89J0DOU8mgfb45QIOQylHqjk0z8/OQDIwq FEzqzsAI8OliuZ4HoKPf45m70JAkiKA6txNFe1jD2JbbrxXBMPb0eS0QEzwu9Yct33E9 nH1vwD5gj4vig3nq27WT8BTQUgpn48quvEZjYCyvxd6fFahjZptZse7/PpAQ6fC/F+MF DGPkt9hyFvAQqmqcS6ApZDNXnexeH0Is4DzT/eulsfugNkF3PmKZsLKmfa9Af06uyCs1 kg5wL3DyoP10weC2z7koVmj49v35fioqv9tmefF+SHzr7GwfkFqH6dborsWXSQI/iCA5 QyWw== Received: by 10.68.239.135 with SMTP id vs7mr34337515pbc.38.1345639721908; Wed, 22 Aug 2012 05:48:41 -0700 (PDT) Received: from hj.localdomain ([58.194.229.103]) by mx.google.com with ESMTPS id ou6sm3684076pbc.9.2012.08.22.05.48.39 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 22 Aug 2012 05:48:41 -0700 (PDT) From: Asias He To: Pekka Enberg Cc: Sasha Levin , Ingo Molnar , Cyrill Gorcunov , kvm@vger.kernel.org Subject: [PATCH 4/4] kvm tools: Make 'lkvm setup' work outside kernel/tools/kvm dir Date: Wed, 22 Aug 2012 20:48:17 +0800 Message-Id: <1345639697-22680-4-git-send-email-asias.hejun@gmail.com> X-Mailer: git-send-email 1.7.11.4 In-Reply-To: <1345639697-22680-1-git-send-email-asias.hejun@gmail.com> References: <1345639697-22680-1-git-send-email-asias.hejun@gmail.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Generate ~/.lkvm/$guest/virt/etc/passwd ~/.lkvm/$guest/virt/init on the fly. Signed-off-by: Asias He --- tools/kvm/builtin-setup.c | 33 +++++++++++++++++++++++++++++++-- tools/kvm/guest/passwd | 1 - 2 files changed, 31 insertions(+), 3 deletions(-) delete mode 100644 tools/kvm/guest/passwd diff --git a/tools/kvm/builtin-setup.c b/tools/kvm/builtin-setup.c index 232aa60..11aa676 100644 --- a/tools/kvm/builtin-setup.c +++ b/tools/kvm/builtin-setup.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -19,6 +20,9 @@ #include #include +extern char _binary_guest_init_start; +extern char _binary_guest_init_size; + static const char *instance_name; static const char * const setup_usage[] = { @@ -126,19 +130,44 @@ static const char *guestfs_symlinks[] = { static int copy_init(const char *guestfs_name) { char path[PATH_MAX]; + size_t size; + int fd, ret; + char *data; + size = (size_t)&_binary_guest_init_size; + data = (char *)&_binary_guest_init_start; snprintf(path, PATH_MAX, "%s%s/virt/init", kvm__get_dir(), guestfs_name); + remove(path); + fd = open(path, O_CREAT | O_WRONLY, 0755); + if (fd < 0) + die("Fail to setup %s", path); + ret = xwrite(fd, data, size); + if (ret < 0) + die("Fail to setup %s", path); + close(fd); - return copy_file("guest/init", path); + return 0; } static int copy_passwd(const char *guestfs_name) { char path[PATH_MAX]; + FILE *file; + int ret; snprintf(path, PATH_MAX, "%s%s/etc/passwd", kvm__get_dir(), guestfs_name); - return copy_file("guest/passwd", path); + file = fopen(path, "w"); + if (!file) + return -1; + + ret = fprintf(file, "root:x:0:0:root:/root:/bin/sh\n"); + if (ret < 0) + return ret; + + fclose(file); + + return 0; } static int make_guestfs_symlink(const char *guestfs_name, const char *path) diff --git a/tools/kvm/guest/passwd b/tools/kvm/guest/passwd deleted file mode 100644 index eb85a55..0000000 --- a/tools/kvm/guest/passwd +++ /dev/null @@ -1 +0,0 @@ -root:x:0:0:root:/root:/bin/sh