This source file includes following definitions.
- pmix_compress_base_tar_create
- pmix_compress_base_tar_extract
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 #include "pmix_config.h"
17
18 #include <string.h>
19 #include <sys/wait.h>
20 #if HAVE_SYS_TYPES_H
21 #include <sys/types.h>
22 #endif
23 #if HAVE_UNISTD_H
24 #include <unistd.h>
25 #endif
26 #ifdef HAVE_FCNTL_H
27 #include <fcntl.h>
28 #endif
29 #ifdef HAVE_SYS_STAT_H
30 #include <sys/stat.h>
31 #endif
32
33 #include "pmix_common.h"
34 #include "src/mca/mca.h"
35 #include "src/mca/base/base.h"
36 #include "src/util/os_dirpath.h"
37 #include "src/util/output.h"
38 #include "src/util/argv.h"
39 #include "src/util/printf.h"
40
41 #include "src/mca/pcompress/pcompress.h"
42 #include "src/mca/pcompress/base/base.h"
43
44
45
46
47
48
49
50
51
52 int pmix_compress_base_tar_create(char ** target)
53 {
54 int exit_status = PMIX_SUCCESS;
55 char *tar_target = NULL;
56 char **argv = NULL;
57 pid_t child_pid = 0;
58 int status = 0;
59
60 pmix_asprintf(&tar_target, "%s.tar", *target);
61
62 child_pid = fork();
63 if( 0 == child_pid ) {
64 char *cmd;
65 pmix_asprintf(&cmd, "tar -cf %s %s", tar_target, *target);
66
67 argv = pmix_argv_split(cmd, ' ');
68 status = execvp(argv[0], argv);
69
70 pmix_output(0, "compress:base: Tar:: Failed to exec child [%s] status = %d\n", cmd, status);
71 exit(PMIX_ERROR);
72 }
73 else if(0 < child_pid) {
74 waitpid(child_pid, &status, 0);
75
76 if( !WIFEXITED(status) ) {
77 exit_status = PMIX_ERROR;
78 goto cleanup;
79 }
80
81 free(*target);
82 *target = strdup(tar_target);
83 }
84 else {
85 exit_status = PMIX_ERROR;
86 goto cleanup;
87 }
88
89 cleanup:
90 if( NULL != tar_target ) {
91 free(tar_target);
92 }
93
94 return exit_status;
95 }
96
97 int pmix_compress_base_tar_extract(char ** target)
98 {
99 int exit_status = PMIX_SUCCESS;
100 char **argv = NULL;
101 pid_t child_pid = 0;
102 int status = 0;
103
104 child_pid = fork();
105 if( 0 == child_pid ) {
106 char *cmd;
107 pmix_asprintf(&cmd, "tar -xf %s", *target);
108
109 argv = pmix_argv_split(cmd, ' ');
110 status = execvp(argv[0], argv);
111
112 pmix_output(0, "compress:base: Tar:: Failed to exec child [%s] status = %d\n", cmd, status);
113 exit(PMIX_ERROR);
114 }
115 else if(0 < child_pid) {
116 waitpid(child_pid, &status, 0);
117
118 if( !WIFEXITED(status) ) {
119 exit_status = PMIX_ERROR;
120 goto cleanup;
121 }
122
123
124 (*target)[strlen(*target)-4] = '\0';
125 }
126 else {
127 exit_status = PMIX_ERROR;
128 goto cleanup;
129 }
130
131 cleanup:
132
133 return exit_status;
134 }
135
136
137
138