本文整理汇总了C++中run_cmd函数的典型用法代码示例。如果您正苦于以下问题:C++ run_cmd函数的具体用法?C++ run_cmd怎么用?C++ run_cmd使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了run_cmd函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:ss-plus,项目名称:shadowsocksR-libev,代码行数:32,代码来源:acl.c
示例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();
}
开发者ID:aosm,项目名称:dovecot,代码行数:34,代码来源:test-dsync-proxy-server-cmd.c
示例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;
}
开发者ID:marcsances,项目名称:zesh,代码行数:57,代码来源:builtins.c
示例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;
}
开发者ID:cmccabe,项目名称:cmccabe-daemon-utils,代码行数:11,代码来源:run_cmd_unit.c
示例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();
}
开发者ID:aosm,项目名称:dovecot,代码行数:12,代码来源:test-dsync-proxy-server-cmd.c
示例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;
}
开发者ID:nanopack,项目名称:redd,代码行数:52,代码来源:vxlan.c
示例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);
}
开发者ID:coyizumi,项目名称:cs111,代码行数:52,代码来源:swapon.c
示例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;
}
开发者ID:cmccabe,项目名称:redfish,代码行数:13,代码来源:trivial_unit.c
示例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;
}
开发者ID:DSMan195276,项目名称:cmips,代码行数:27,代码来源:input.c
示例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);
}
开发者ID:simon-eh,项目名称:hw9,代码行数:35,代码来源:sehll.c
示例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;
}
开发者ID:RoyMenczer,项目名称:ibssa2,代码行数:30,代码来源:ssa_signal_handler.c
示例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;
}
开发者ID:DaveDaCoda,项目名称:multirom,代码行数:26,代码来源:adb.c
示例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();
}
开发者ID:aosm,项目名称:dovecot,代码行数:34,代码来源:test-dsync-proxy-server-cmd.c
示例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();
}
开发者ID:DSMan195276,项目名称:cmips,代码行数:26,代码来源:input.c
示例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;
}
开发者ID:blusjune,项目名称:.bd,代码行数:33,代码来源:wintrace_dump.c
示例16: run_script
int run_script(FILE *script)
{
int scripting = 1;
int size;
char **args, cmd[100];
while (scripting && !feof(script)) {
size = 0;
redirect_in = 0;
dup2(defin, STDIN_FILENO);
dup2(defout, STDOUT_FILENO);
/* get the input from user. */
fgets(cmd, 100, script);
args = parse_cmd(cmd, &size);
if (pipeFlag) {
scripting = run_pipe_cmd(size, args);
pipeFlag = 0;
} else {
scripting = run_cmd(size, args);
}
}
return cmd_exit_status;
}
开发者ID:luok,项目名称:XSSH,代码行数:27,代码来源:xssh.c
示例17: strlen
static char
*get_save_file_path(char *file_name)
{
char *save_file_name;
struct stat file_stat;
int len;
if (stat(server.save_path, &file_stat) != 0) {
char *cmd[] = {"mkdir", "-p", server.save_path, 0};
if (!run_cmd(cmd))
return NULL;
}
if (server.save_path == NULL) {
return NULL;
}
len = strlen(server.save_path);
if (len == 0) {
return NULL;
}
if (server.save_path[len - 1] == '/') {
save_file_name = (char *)malloc(len + strlen(file_name) + 1);
sprintf(save_file_name, "%s%s", server.save_path, file_name);
} else {
save_file_name = (char *)malloc(len + strlen(file_name) + 2);
sprintf(save_file_name, "%s/%s", server.save_path, file_name);
}
return save_file_name;
}
开发者ID:nanopack,项目名称:redd,代码行数:27,代码来源:helper.c
示例18: reset_firewall
static int
reset_firewall()
{
int ret = 0;
char cli[256];
if (getuid() != 0)
return -1;
if (mode == IPTABLES_MODE) {
sprintf(cli, ip6tables_remove_chain, chain_name, chain_name, chain_name);
ret |= system(cli);
sprintf(cli, iptables_remove_chain, chain_name, chain_name, chain_name);
ret |= system(cli);
} else if (mode == FIREWALLD_MODE) {
sprintf(cli, firewalld6_remove_chain, chain_name, chain_name, chain_name);
ret |= system(cli);
sprintf(cli, firewalld_remove_chain, chain_name, chain_name, chain_name);
ret |= system(cli);
}
if (shell_stdin != NULL) {
run_cmd("exit 0");
pclose(shell_stdin);
}
return ret;
}
开发者ID:ss-plus,项目名称:shadowsocksR-libev,代码行数:28,代码来源:acl.c
示例19: process_file
int process_file(char *batch_file)
{
FILE * batch_stream;
char *cmdLine;
READ_STATUS s;
batch_stream = fopen(batch_file, "r");
if (batch_stream == NULL) {
printError();
return 1;
}
for (s = readInput(batch_stream, &cmdLine);
(s != INPUT_READ_EOF) && (s != INPUT_READ_ERROR);
s = readInput(batch_stream, &cmdLine)) {
if (s == INPUT_READ_OVERFLOW) {
display_full_command(cmdLine);
free(cmdLine);
continue;
}
run_cmd(cmdLine, BATCH_MODE);
}
fclose(batch_stream);
return 0;
}
开发者ID:smihir,项目名称:homework,代码行数:27,代码来源:mysh.c
示例20: __wrap_main
int
__wrap_main(int argc, char **argv) // , char **envp
{
// NOTE: parse all ctrl args at beg (or end -- easy to discard)
while (argc > 1) {
if (!strcmp(argv[1], "-src-path")) {
printf("%s\n", src_path);
return 0;
} else if (!strcmp(argv[1], "-no-rebuild")) {
return __real_main(argc, argv);
} else
break;
--argc, argv[1] = argv[0], argv++;
}
char bin_path[PATH_MAX] = {0};
if (0 >= readlink("/proc/self/exe", bin_path, PATH_MAX)) {
error(2, errno, "readlink(\"%s\")", argv[0]);
}
// WARN: rebuild won't be triggered
// * changes saved directly during compilation
// ALT:(slow): -cmp-hash and func_ptr
// * updated static libs ALT:(slow): use make
if (0 < timestamp_cmp(src_path, bin_path)) {
if (0 != run_cmd(recompile_cmdv))
return 99;
execvp(bin_path, argv);
error(9, errno, "execvp");
}
return __real_main(argc, argv);
}
开发者ID:amerlyq,项目名称:airy,代码行数:32,代码来源:selfcompile.c
注:本文中的run_cmd函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论