本文整理汇总了C++中run_cmd函数的典型用法代码示例。如果您正苦于以下问题:C++ run_cmd函数的具体用法?C++ run_cmd怎么用?C++ run_cmd使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了run_cmd函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: set_firewall_rule
static int
set_firewall_rule(char *addr, int add)
{
char cli[256];
struct cork_ip ip;
if (getuid() != 0)
return -1;
if (cork_ip_init(&ip, addr))
return -1;
if (add) {
if (mode == IPTABLES_MODE)
sprintf(cli, ip.version == 4 ? iptables_add_rule : ip6tables_add_rule,
chain_name, addr);
else if (mode == FIREWALLD_MODE)
sprintf(cli, ip.version == 4 ? firewalld_add_rule : firewalld6_add_rule,
chain_name, addr);
return run_cmd(cli);
} else {
if (mode == IPTABLES_MODE)
sprintf(cli, ip.version == 4 ? iptables_remove_rule : ip6tables_remove_rule,
chain_name, addr);
else if (mode == FIREWALLD_MODE)
sprintf(cli, ip.version == 4 ? firewalld_remove_rule : firewalld6_remove_rule,
chain_name, addr);
return run_cmd(cli);
}
return 0;
}
示例2: test_dsync_proxy_box_create
static void test_dsync_proxy_box_create(void)
{
struct test_dsync_box_event event;
test_begin("proxy server box create");
test_assert(run_cmd("BOX-CREATE", "noselect", "/",
"553", "1", NULL) == 1);
test_assert(test_dsync_worker_next_box_event(test_worker, &event));
test_assert(event.type == LAST_BOX_TYPE_CREATE);
test_assert(strcmp(event.box.name, "noselect") == 0);
test_assert(event.box.name_sep == '/');
test_assert(event.box.last_change == 553);
test_assert(event.box.flags == DSYNC_MAILBOX_FLAG_NOSELECT);
test_assert(event.box.uid_validity == 0);
test_assert(run_cmd("BOX-CREATE", "selectable", "?",
"61", "2", TEST_MAILBOX_GUID2, "1234567890", "9876",
"4610", "28427847284728", "853", NULL) == 1);
test_assert(test_dsync_worker_next_box_event(test_worker, &event));
test_assert(event.type == LAST_BOX_TYPE_CREATE);
test_assert(strcmp(event.box.name, "selectable") == 0);
test_assert(event.box.name_sep == '?');
test_assert(memcmp(event.box.mailbox_guid.guid, test_mailbox_guid2, MAIL_GUID_128_SIZE) == 0);
test_assert(event.box.flags == 2);
test_assert(event.box.uid_validity == 1234567890);
test_assert(event.box.uid_next == 9876);
test_assert(event.box.message_count == 4610);
test_assert(event.box.highest_modseq == 28427847284728);
test_assert(event.box.first_recent_uid == 853);
test_assert(event.box.last_change == 61);
test_end();
}
示例3: _startpipe
int _startpipe(int* fd, int argc1, char **argv1, int argc2, char **argv2) {
int pid1 = fork();
int pid2;
_pid1=pid1;
_pid2=pid2;
int exitc1;
int exitc2;
signal(SIGDONE,sd_hd);
switch (pid1) {
case -1:
fprintf(stderr,"%s: fork: operation failed",shellname);
kill(pid2,SIGKILL);
return 1;
case 0:
// child process
close(0); // close stdin
dup(fd[0]); // connect stdin with pipe read end
close(fd[1]); // close write end of pipe
int c2 = run_cmd(argc2,argv2);
close(fd[0]); // close pipe read end
close(1); // close stdout
exit(c2); // terminate child
break;
default:
// parent process
pid2=fork();
switch (pid2) {
case -1:
fprintf(stderr,"%s: fork: operation failed",shellname);
kill(pid1,SIGKILL);
return 1;
case 0:
// child process
close(1); // close stdout
dup(fd[1]); // connect stdout with pipe write end
close(fd[0]); // close read end of pipe
int c = run_cmd(argc1,argv1);
close(fd[1]); // close pipe write end
close(0); // close stdin
kill(pid1,SIGTERM); // terminate child 1
kill(getppid(),SIGDONE);
exit(c); // terminate child
break;
}
}
pause();
fflush(stdout);
lastpid=pid2;
exitcode=exitc2;
pipeargc=0;
pipeargv=NULL;
return exitc2;
}
示例4: test_run_cmd
static int test_run_cmd(void)
{
int ret;
ret = run_cmd("/bin/ls", "/", (char*)NULL);
if (ret)
return ret;
ret = run_cmd("/bin/ls", (char*)NULL);
if (ret)
return ret;
return 0;
}
示例5: test_dsync_proxy_box_select
static void test_dsync_proxy_box_select(void)
{
test_begin("proxy server box select");
test_assert(run_cmd("BOX-SELECT", TEST_MAILBOX_GUID1, NULL) == 1);
test_assert(memcmp(test_worker->selected_mailbox.guid, test_mailbox_guid1, MAIL_GUID_128_SIZE) == 0);
test_assert(run_cmd("BOX-SELECT", TEST_MAILBOX_GUID2, NULL) == 1);
test_assert(memcmp(test_worker->selected_mailbox.guid, test_mailbox_guid2, MAIL_GUID_128_SIZE) == 0);
test_end();
}
示例6: init_vxlan
int
init_vxlan()
{
/*
* Run the following:
* ip link add vxlan0 type vxlan id 1 group 239.0.0.1 dev eth0
* ip link set vxlan0 up
*/
int retry;
int success = -1;
if (vxlan_exists() != 0) {
char *add_link_cmd[] = {"ip", "link", "add", server.vxlan_name, "type", "vxlan", "id", server.vxlan_vni, "dev", server.vxlan_interface, 0};
for (retry = 0; retry < server.vxlan_max_retries; retry++) {
if ((success = run_cmd(add_link_cmd)) == 0) {
break;
} else {
red_log(REDD_WARNING, "Failed to create link %s", server.vxlan_name);
sleep(1);
red_log(REDD_WARNING, "Retrying to create link %s", server.vxlan_name);
}
}
}
if (success == -1) return -1;
char *set_link_cmd[] = {"ip", "link", "set", server.vxlan_name, "up", 0};
for (retry = 0; retry < server.vxlan_max_retries; retry++) {
if ((success = run_cmd(set_link_cmd)) == 0) {
break;
} else {
red_log(REDD_WARNING, "Failed to set link %s up", server.vxlan_name);
sleep(1);
red_log(REDD_WARNING, "Retrying to set link %s up", server.vxlan_name);
}
}
if (success == -1) return -1;
char *set_route_cmd[] = {"bridge", "fdb", "add", "to", "00:00:00:00:00:00", "dst", server.vxlan_group, "via", server.tun_name, "dev", server.vxlan_name, 0};
for (retry = 0; retry < server.vxlan_max_retries; retry++) {
if ((success = run_cmd(set_route_cmd)) == 0) {
break;
} else {
red_log(REDD_WARNING, "Failed to set route %s", server.vxlan_name);
sleep(1);
red_log(REDD_WARNING, "Retrying to set route %s", server.vxlan_name);
}
}
return success;
}
示例7: swap_on_off_gbde
static const char *
swap_on_off_gbde(const char *name, int doingall)
{
const char *ret;
char pass[64 * 2 + 1];
unsigned char bpass[64];
char *dname;
int i, error;
dname = swap_basename(name);
if (dname == NULL)
return (NULL);
if (which_prog == SWAPON) {
arc4random_buf(bpass, sizeof(bpass));
for (i = 0; i < (int)sizeof(bpass); i++)
sprintf(&pass[2 * i], "%02x", bpass[i]);
pass[sizeof(pass) - 1] = '\0';
error = run_cmd(NULL, "%s init %s -P %s", _PATH_GBDE,
dname, pass);
if (error) {
/* bde device found. Ignore it. */
free(dname);
if (qflag == 0)
warnx("%s: Device already in use", name);
return (NULL);
}
error = run_cmd(NULL, "%s attach %s -p %s", _PATH_GBDE,
dname, pass);
free(dname);
if (error) {
warnx("gbde (attach) error: %s", name);
return (NULL);
}
}
ret = swap_on_off_sfile(name, doingall);
if (which_prog == SWAPOFF) {
error = run_cmd(NULL, "%s detach %s", _PATH_GBDE, dname);
free(dname);
if (error) {
/* bde device not found. Ignore it. */
if (qflag == 0)
warnx("%s: Device not found", name);
return (NULL);
}
}
return (ret);
}
示例8: main
int main(POSSIBLY_UNUSED(int argc), char **argv)
{
char st_trivial[PATH_MAX];
EXPECT_ZERO(get_colocated_path(argv[0], "st_trivial",
st_trivial, sizeof(st_trivial)));
EXPECT_ZERO(run_cmd(st_trivial, "-h", (char*)NULL));
EXPECT_ZERO(run_cmd(st_trivial, "-f", (char*)NULL));
snprintf(env_str, sizeof(env_str), "ST_ERROR=1");
putenv(env_str);
EXPECT_NONZERO(run_cmd(st_trivial, "-f", (char*)NULL));
return 0;
}
示例9: run_script
int run_script(const char *s_file)
{
char *line = NULL;
size_t len;
FILE *script;
script = fopen(s_file, "r");
if (!script) {
printf("Error opening script '%s'\n", s_file);
return -1;
}
while ((len = getline(&line, &len, script)) != -1 && !exit_inp_loop) {
if (line[len - 1] == '\n')
line[len - 1] = '\0';
if (len == 1)
continue ;
printf("%s%s\n", prompt, line);
run_cmd(line);
}
fclose(script);
free(line);
return 0;
}
示例10: main
int main() {
char *line = malloc(2*MAX_LINE_SIZE * sizeof(char) + 1);
char * const *args = malloc(MAX_ARGS*2 * sizeof(char*));
int *cmds = malloc(21 * sizeof(int));
int reached_eof = 0;
while(!reached_eof) {
if(signal(SIGINT, s_handler) == SIG_ERR) {
printf("Error catching interrupt signal.\n");
}
//if(signal(SIGCHLD, SIG_IGN) == SIG_ERR) {
// printf("Error catching child signal.\n");
//}
int status, pid;
while((pid=waitpid(-1, &status, WNOHANG)) > 0) {
printf("Child process %d exited.\n", pid);
}
background = 0;
printf("%s", PROMPT);
reached_eof = read_line(line, MAX_LINE_SIZE + 1);
if(*line == '\n') {
continue;
}
int num_cmds = parse(line, (char**)args, cmds);
if(num_cmds == 1) {
execute(*args, args);
}
else {
run_cmd(args, cmds, num_cmds);
}
}
free(line);
free((char**)args);
free(cmds);
}
示例11: main
int main (int argc, char **argv)
{
int rt, i, size = 0;
char *cmd;
char output[1024] = {};
if (argc == 1)
return 0;
for (i = 1; i < argc; ++i)
size += (strlen(argv[i]) + 1);
cmd = (char *) malloc(size + 1);
for (i = 1; i < argc; ++i) {
strcat(cmd, argv[i]);
strcat(cmd, " ");
}
printf("Command line : %s\n", cmd);
rt = run_cmd(cmd, output, 1024);
if (!rt)
fprintf(stderr, "Execution failed\n");
else
printf("%s\n", output);
free(cmd);
return 0;
}
示例12: adb_init_busybox
int adb_init_busybox(void)
{
mkdir("/mrom_bin", 0777);
copy_file(busybox_path, "/mrom_bin/busybox");
chmod("/mrom_bin/busybox", 0755);
static const char *install_cmd[] = {
"/mrom_bin/busybox", "--install", "/mrom_bin/", NULL
};
if(run_cmd((char**)install_cmd) != 0)
{
ERROR("adb: failed to --install busybox\n");
return -1;
}
mkdir("/dev/pts", 0666);
if(mount("devpts", "/dev/pts", "devpts", 0, NULL) < 0)
{
ERROR("Failed to mount devpts: %d (%s)\n", errno, strerror(errno));
return -1;
}
return 0;
}
示例13: test_dsync_proxy_msg_save
static void test_dsync_proxy_msg_save(void)
{
static const char *input = "..dotty\n..behavior\nfrom you\n.\nstop";
struct test_dsync_msg_event event;
const unsigned char *data;
size_t size;
test_begin("proxy server msg save");
server->input = i_stream_create_from_data(input, strlen(input));
test_assert(run_cmd("MSG-SAVE", "28492428", "pop3uidl",
"saveguid", "874", "33982482882924", "\\Flagged bar \\Answered",
"8294284", NULL) == 1);
test_assert(test_dsync_worker_next_msg_event(test_worker, &event));
test_assert(event.type == LAST_MSG_TYPE_SAVE);
test_assert(event.save_data.received_date == 28492428);
test_assert(strcmp(event.save_data.pop3_uidl, "pop3uidl") == 0);
test_assert(strcmp(event.save_body, ".dotty\n.behavior\nfrom you") == 0);
test_assert(strcmp(event.msg.guid, "saveguid") == 0);
test_assert(event.msg.uid == 874);
test_assert(event.msg.modseq == 33982482882924);
test_assert(event.msg.flags == (MAIL_FLAGGED | MAIL_ANSWERED));
test_assert(strcmp(event.msg.keywords[0], "bar") == 0);
test_assert(event.msg.keywords[1] == NULL);
test_assert(event.msg.save_date == 8294284);
data = i_stream_get_data(server->input, &size);
test_assert(size == 4 && memcmp(data, "stop", 4) == 0);
i_stream_destroy(&server->input);
test_end();
}
示例14: run_input_loop
void run_input_loop(void)
{
char *line = NULL;
if (cmips_arg_state.cmd_script) {
run_script(cmips_arg_state.cmd_script);
return ;
}
rl_attempted_completion_function = complete_line;
do {
line = readline(prompt);
if (line && *line)
add_history(line);
else
continue;
run_cmd(line);
if (line)
free(line);
} while (!exit_inp_loop);
clear_history();
}
示例15: WinMain
int WINAPI WinMain(HINSTANCE a1, HINSTANCE a2, LPSTR a3, int a4)
{
int answer = 0;
answer = MessageBox(0, "Click 'Yes' to dump iotrace to a file (iotrace.log)", THIS_PROG_NAME, MB_YESNO);
if (answer == IDYES)
{
#if 1
run_cmd(TRACE_CMD__DUMP);
/* seek and destroy the files called 'kernel.etl'
* on the first depth of directory of corresponding disk,
* for example, 'F:\kernel.etl' */
// run_cmd(TRACE_CMD__TRANSFORM);
#else
WinExec(TRACE_CMD__START, SW_HIDE);
Sleep(TRACE_TIME__IN_MILLI_SECOND);
WinExec(TRACE_CMD__DUMP, SW_HIDE);
WinExec(TRACE_CMD__TRANSFORM, SW_HIDE);
#endif
}
else /* answer == IDNO */
{
#if 1
MessageBox(0, "Nothing happened.\n\nMany Thanks,\nBrian", THIS_PROG_NAME, MB_OK);
#else
// run_cmd("\"c:\\windows\\system32\\calc.exe\"");
// WinExec("c:\\windows\\system32\\calc.exe", SW_HIDE);
WinExec("calc", SW_HIDE);
#endif
}
return 0;
}