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