GeneralSpacedbResult * cmd_spacedb (const char *dbname, T_CUBRID_MODE mode) { GeneralSpacedbResult *res = NULL; int minor_version, major_version; char out_file[PATH_MAX]; char cubrid_err_file[PATH_MAX]; char cmd_name[CUBRID_CMD_NAME_LEN]; char err_message[ERR_MSG_SIZE]; const char *argv[10]; int argc = 0; cubrid_err_file[0] = '\0'; find_and_parse_cub_admin_version (major_version, minor_version); if (major_version < 10 || (major_version == 10 && minor_version == 0)) { res = new SpaceDbResultOldFormat(); } else { res = new SpaceDbResultNewFormat(); } sprintf (out_file, "%s/DBMT_util_002.%d", sco.dbmt_tmp_dir, (int) getpid ()); cubrid_cmd_name (cmd_name); argv[argc++] = cmd_name; argv[argc++] = UTIL_OPTION_SPACEDB; argv[argc++] = get_cubrid_mode_opt (mode); argv[argc++] = "--" SPACE_SIZE_UNIT_L; argv[argc++] = "PAGE"; argv[argc++] = "--" SPACE_OUTPUT_FILE_L; argv[argc++] = out_file; argv[argc++] = dbname; argv[argc++] = "-p"; argv[argc++] = NULL; snprintf (cubrid_err_file, PATH_MAX, "%s/%s.%u.err.tmp", sco.dbmt_tmp_dir, "cmd_spacedb", getpid ()); run_child (argv, 1, NULL, NULL, cubrid_err_file, NULL); /* spacedb */ read_error_file (cubrid_err_file, err_message, ERR_MSG_SIZE); res->set_err_msg (err_message); read_spacedb_output (res, out_file); if (access (cubrid_err_file, F_OK) == 0) { unlink (cubrid_err_file); } unlink (out_file); return res; }
/* Takes optional arguments, consult optargs_bitmask. */ int do_tar_in (const char *dir, const char *compress) { const char *filter; int err, r; FILE *fp; CLEANUP_FREE char *cmd = NULL; char error_file[] = "/tmp/tarXXXXXX"; int fd, chown_supported; chown_supported = is_chown_supported (dir); if (chown_supported == -1) return -1; if ((optargs_bitmask & GUESTFS_TAR_IN_COMPRESS_BITMASK)) { if (STREQ (compress, "compress")) filter = " --compress"; else if (STREQ (compress, "gzip")) filter = " --gzip"; else if (STREQ (compress, "bzip2")) filter = " --bzip2"; else if (STREQ (compress, "xz")) filter = " --xz"; else if (STREQ (compress, "lzop")) filter = " --lzop"; else { reply_with_error ("unknown compression type: %s", compress); return -1; } } else filter = ""; fd = mkstemp (error_file); if (fd == -1) { reply_with_perror ("mkstemp"); return -1; } close (fd); /* "tar -C /sysroot%s -xf -" but we have to quote the dir. */ if (asprintf_nowarn (&cmd, "%s -C %R%s -xf - %s2> %s", str_tar, dir, filter, chown_supported ? "" : "--no-same-owner ", error_file) == -1) { err = errno; r = cancel_receive (); errno = err; reply_with_perror ("asprintf"); unlink (error_file); return -1; } if (verbose) fprintf (stderr, "%s\n", cmd); fp = popen (cmd, "w"); if (fp == NULL) { err = errno; r = cancel_receive (); errno = err; reply_with_perror ("%s", cmd); unlink (error_file); return -1; } /* The semantics of fwrite are too undefined, so write to the * file descriptor directly instead. */ fd = fileno (fp); r = receive_file (write_cb, &fd); if (r == -1) { /* write error */ cancel_receive (); CLEANUP_FREE char *errstr = read_error_file (error_file); reply_with_error ("write error on directory: %s: %s", dir, errstr); unlink (error_file); pclose (fp); return -1; } if (r == -2) { /* cancellation from library */ /* This error is ignored by the library since it initiated the * cancel. Nevertheless we must send an error reply here. */ reply_with_error ("file upload cancelled"); pclose (fp); unlink (error_file); return -1; } if (pclose (fp) != 0) { CLEANUP_FREE char *errstr = read_error_file (error_file); reply_with_error ("tar subcommand failed on directory: %s: %s", dir, errstr); unlink (error_file); return -1; } unlink (error_file); return 0; }
/* Has one FileIn parameter. */ int do_ntfsclone_in (const char *device) { int err, r; FILE *fp; char *cmd; char error_file[] = "/tmp/ntfscloneXXXXXX"; int fd; fd = mkstemp (error_file); if (fd == -1) { reply_with_perror ("mkstemp"); return -1; } close (fd); /* Construct the command. */ if (asprintf_nowarn (&cmd, "ntfsclone -O %s --restore-image - 2> %s", device, error_file) == -1) { err = errno; r = cancel_receive (); errno = err; reply_with_perror ("asprintf"); unlink (error_file); return -1; } if (verbose) fprintf (stderr, "%s\n", cmd); fp = popen (cmd, "w"); if (fp == NULL) { err = errno; r = cancel_receive (); errno = err; reply_with_perror ("%s", cmd); unlink (error_file); free (cmd); return -1; } free (cmd); /* The semantics of fwrite are too undefined, so write to the * file descriptor directly instead. */ fd = fileno (fp); r = receive_file (write_cb, &fd); if (r == -1) { /* write error */ cancel_receive (); char *errstr = read_error_file (error_file); reply_with_error ("write error on device: %s: %s", device, errstr); free (errstr); unlink (error_file); pclose (fp); return -1; } if (r == -2) { /* cancellation from library */ /* This error is ignored by the library since it initiated the * cancel. Nevertheless we must send an error reply here. */ reply_with_error ("ntfsclone cancelled"); pclose (fp); unlink (error_file); return -1; } if (pclose (fp) != 0) { char *errstr = read_error_file (error_file); reply_with_error ("ntfsclone subcommand failed on device: %s: %s", device, errstr); free (errstr); unlink (error_file); return -1; } unlink (error_file); return 0; }
T_CSQL_RESULT * cmd_csql (char *dbname, char *uid, char *passwd, T_CUBRID_MODE mode, char *infile, char *command, char *error_continue) { char cubrid_err_file[PATH_MAX]; char out_file[512]; T_CSQL_RESULT *res; char cmd_name[CUBRID_CMD_NAME_LEN]; const char *argv[15]; int argc = 0; cmd_name[0] = '\0'; cubrid_err_file[0] = '\0'; #if !defined (DO_NOT_USE_CUBRIDENV) sprintf (cmd_name, "%s/%s%s", sco.szCubrid, CUBRID_DIR_BIN, UTIL_CSQL_NAME); #else sprintf (cmd_name, "%s/%s", CUBRID_BINDIR, UTIL_CSQL_NAME); #endif argv[argc++] = cmd_name; argv[argc++] = get_cubrid_mode_opt (mode); if (uid) { argv[argc++] = "--" CSQL_USER_L; argv[argc++] = uid; if (passwd) { argv[argc++] = "--" CSQL_PASSWORD_L; argv[argc++] = passwd; } } if (infile) { argv[argc++] = "--" CSQL_INPUT_FILE_L; argv[argc++] = infile; } else if (command) { argv[argc++] = "--" CSQL_COMMAND_L; argv[argc++] = command; } else { return NULL; } if (uStringEqualIgnoreCase (error_continue, "y")) { argv[argc++] = "--" CSQL_ERROR_CONTINUE_L; } argv[argc++] = dbname; argv[argc++] = NULL; #if !defined (DO_NOT_USE_CUBRIDENV) sprintf (out_file, "%s/tmp/DBMT_util_003.%d", sco.szCubrid, (int) getpid ()); #else sprintf (out_file, "%s/DBMT_util_003.%d", CUBRID_TMPDIR, (int) getpid ()); #endif snprintf (cubrid_err_file, PATH_MAX, "%s/%s.%u.err.tmp", sco.dbmt_tmp_dir, "cmd_csql", getpid ()); SET_TRANSACTION_NO_WAIT_MODE_ENV (); run_child (argv, 1, NULL, NULL, out_file, NULL); /* csql */ res = new_csql_result (); if (res == NULL) { return NULL; } read_error_file (out_file, res->err_msg, ERR_MSG_SIZE); unlink (out_file); return res; }