inline int system_cmd(const Argv& argv) { int ret = -1; if (argv.size()) ret = system_cmd(argv[0], argv); return ret; }
~tmp_dir() { if(!name.empty()) { std::string cmd = "rm -rf " + name; system_cmd(cmd); } }
virtual void execute() { if (!argv.empty()) { OPENVPN_LOG(to_string()); system_cmd(argv[0], argv); } else OPENVPN_LOG("WARNING: Command::execute called with empty argv"); }
static void exec_command(char *cmd) { #if SFX_LEVEL>=ARJSFXV char *cur_dir; #else char cur_dir[FILENAME_MAX]; #endif if(target_dir[0]=='\0') system_cmd(cmd); else { #if SFX_LEVEL>=ARJSFXV cur_dir=(char *)malloc_msg(FILENAME_MAX); #endif file_getcwd(cur_dir, FILENAME_MAX); file_chdir(target_dir); system_cmd(cmd); file_chdir(cur_dir); #if SFX_LEVEL>=ARJSFXV free(cur_dir); #endif } }
static void configure_hostname() { debug("configure_hostname"); char hostname[128] = "\0"; if (options.hostname_pattern) { // Set the hostname based on a pattern char unique_id[64] = "xxxxxxxx"; if (options.uniqueid_exec) system_cmd(options.uniqueid_exec, unique_id, sizeof(unique_id)); sprintf(hostname, options.hostname_pattern, unique_id); } else { // Set the hostname from /etc/hostname FILE *fp = fopen("/etc/hostname", "r"); if (!fp) { warn("/etc/hostname not found"); return; } // The hostname should be the first line of the file if (fgets(hostname, sizeof(hostname), fp)) trim_whitespace(hostname); fclose(fp); } if (*hostname == '\0') { warn("Not setting empty hostname"); return; } debug("Hostname: %s", hostname); #ifndef UNITTEST OK_OR_WARN(sethostname(hostname, strlen(hostname)), "Error setting hostname: %s", strerror(errno)); #endif }
void execute(std::string exe, std::string args) { std::string cd = "cd " + this->name + "; "; std::string cmd = cd + exe + " " + args; // + " > /dev/null"; system_cmd(cmd); }
static void read_sql_lines(void) { char *cp; char *firstword; char firstword_separator; char *line = NULL; char foobuf[40]; bool in_comment = false; reset_ibuf(); while (1) { if (no_prompt) { foobuf[0] = '\0'; } else { sprintf(foobuf, "%d>> ", ibuflines + 1); } free(line); line = readline(foobuf); if (line == NULL) { reset_term(); dbexit(); exit(default_exit); } for (cp = line; *cp && isspace((unsigned char) *cp); cp++) continue; if (*cp) { add_history(line); } if (in_comment) { goto append_line; } if (!(strncasecmp(line, "!!", 2))) { system_cmd(line + 2); continue; } /* XXX: isql off-by-one line count error for :r not duplicated */ if (!(strncasecmp(line, ":r", 2))) { readfile_cmd(line); continue; } firstword = line; firstword_separator = '\0'; for (cp = firstword; *cp; cp++) { if (isspace((unsigned char) *cp)) { firstword_separator = *cp; *cp = '\0'; break; } } if ((!(strcasecmp(firstword, "exit"))) || (!(strcasecmp(firstword, "quit")))) { reset_term(); dbexit(); exit(default_exit); } if (!(strcasecmp(firstword, "reset"))) { reset_ibuf(); continue; } if (!(strcasecmp(firstword, cmdend))) { if (ibuflines == 0) { continue; } break; } if ((!(strcasecmp(firstword, "vi"))) || (!(strcasecmp(firstword, editor)))) { vi_cmd(firstword); continue; } firstword[strlen(firstword)] = firstword_separator; append_line: in_comment = update_comment(in_comment, line); append_line(line); line = NULL; } }