]>
Commit | Line | Data |
---|---|---|
edce2aed LP |
1 | /*** |
2 | This file is part of systemd. | |
3 | ||
4 | Copyright 2015 Lennart Poettering | |
5 | ||
6 | systemd is free software; you can redistribute it and/or modify it | |
7 | under the terms of the GNU Lesser General Public License as published by | |
8 | the Free Software Foundation; either version 2.1 of the License, or | |
9 | (at your option) any later version. | |
10 | ||
11 | systemd is distributed in the hope that it will be useful, but | |
12 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | Lesser General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU Lesser General Public License | |
17 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
18 | ***/ | |
19 | ||
3ffd4af2 | 20 | #include "fd-util.h" |
edce2aed | 21 | #include "log.h" |
edce2aed | 22 | #include "qcow2-util.h" |
3ffd4af2 | 23 | #include "util.h" |
edce2aed LP |
24 | |
25 | int main(int argc, char *argv[]) { | |
26 | _cleanup_close_ int sfd = -1, dfd = -1; | |
27 | int r; | |
28 | ||
29 | if (argc != 3) { | |
30 | log_error("Needs two arguments."); | |
31 | return EXIT_FAILURE; | |
32 | } | |
33 | ||
34 | sfd = open(argv[1], O_RDONLY|O_CLOEXEC|O_NOCTTY); | |
35 | if (sfd < 0) { | |
36 | log_error_errno(errno, "Can't open source file: %m"); | |
37 | return EXIT_FAILURE; | |
38 | } | |
39 | ||
40 | dfd = open(argv[2], O_WRONLY|O_CREAT|O_CLOEXEC|O_NOCTTY, 0666); | |
41 | if (dfd < 0) { | |
42 | log_error_errno(errno, "Can't open destination file: %m"); | |
43 | return EXIT_FAILURE; | |
44 | } | |
45 | ||
46 | r = qcow2_convert(sfd, dfd); | |
47 | if (r < 0) { | |
48 | log_error_errno(r, "Failed to unpack: %m"); | |
49 | return EXIT_FAILURE; | |
50 | } | |
51 | ||
52 | return EXIT_SUCCESS; | |
53 | } |