From: Michal Privoznik
- virCommandPtr cmd = virCommandNew("/usr/bin/dnsmasq"); +virCommandPtr cmd = virCommandNew("/usr/bin/dnsmasq");
@@ -100,7 +100,7 @@
- virCommandAddArg(cmd, "-strict-order"); +virCommandAddArg(cmd, "-strict-order");
@@ -109,7 +109,7 @@
- virCommandAddArgPair(cmd, "--conf-file", "/etc/dnsmasq.conf"); +virCommandAddArgPair(cmd, "--conf-file", "/etc/dnsmasq.conf");
@@ -118,7 +118,7 @@
- virCommandAddArgFormat(cmd, "%d", count); +virCommandAddArgFormat(cmd, "%d", count);
@@ -127,11 +127,11 @@
- const char *const args[] = { - "--strict-order", "--except-interface", "lo", NULL - }; - virCommandAddArgSet(cmd, args); - virCommandAddArgList(cmd, "--domain", "localdomain", NULL); +const char *const args[] = { + "--strict-order", "--except-interface", "lo", NULL +}; +virCommandAddArgSet(cmd, args); +virCommandAddArgList(cmd, "--domain", "localdomain", NULL);
@@ -140,14 +140,14 @@
- const char *const args[] = { - "/usr/bin/dnsmasq", - "--strict-order", "--except-interface", - "lo", "--domain", "localdomain", NULL - }; - virCommandPtr cmd1 = virCommandNewArgs(cmd, args); - virCommandPtr cmd2 = virCommandNewArgList("/usr/bin/dnsmasq", - "--domain", "localdomain", NULL); +const char *const args[] = { + "/usr/bin/dnsmasq", + "--strict-order", "--except-interface", + "lo", "--domain", "localdomain", NULL +}; +virCommandPtr cmd1 = virCommandNewArgs(cmd, args); +virCommandPtr cmd2 = virCommandNewArgList("/usr/bin/dnsmasq", + "--domain", "localdomain", NULL);
- virCommandAddEnvPassCommon(cmd); +virCommandAddEnvPassCommon(cmd);
@@ -177,8 +177,8 @@
- virCommandAddEnvPass(cmd, "DISPLAY"); - virCommandAddEnvPass(cmd, "XAUTHORITY"); +virCommandAddEnvPass(cmd, "DISPLAY"); +virCommandAddEnvPass(cmd, "XAUTHORITY");
@@ -187,7 +187,7 @@
- virCommandAddEnvPair(cmd, "TERM", "xterm"); +virCommandAddEnvPair(cmd, "TERM", "xterm");
@@ -196,7 +196,7 @@
- virCommandAddEnvString(cmd, "TERM=xterm"); +virCommandAddEnvString(cmd, "TERM=xterm");
- virCommandDaemonize(cmd); +virCommandDaemonize(cmd);
@@ -221,7 +221,7 @@
- virCommandSetPidFile(cmd, "/var/run/dnsmasq.pid"); +virCommandSetPidFile(cmd, "/var/run/dnsmasq.pid");
@@ -240,7 +240,7 @@
- virCommandClearCaps(cmd); +virCommandClearCaps(cmd);
- int sharedfd = open("cmd.log", "w+"); - int childfd = open("conf.txt", "r"); - virCommandPassFD(cmd, sharedfd, 0); - virCommandPassFD(cmd, childfd, - VIR_COMMAND_PASS_FD_CLOSE_PARENT); - if (VIR_CLOSE(sharedfd) < 0) - goto cleanup; +int sharedfd = open("cmd.log", "w+"); +int childfd = open("conf.txt", "r"); +virCommandPassFD(cmd, sharedfd, 0); +virCommandPassFD(cmd, childfd, + VIR_COMMAND_PASS_FD_CLOSE_PARENT); +if (VIR_CLOSE(sharedfd) < 0) + goto cleanup;
@@ -282,7 +282,7 @@
- virCommandSetInputFD(cmd, 7); +virCommandSetInputFD(cmd, 7);
@@ -291,10 +291,10 @@
- int outfd = open("out.log", "w+"); - int errfd = open("err.log", "w+"); - virCommandSetOutputFD(cmd, &outfd); - virCommandSetErrorFD(cmd, &errfd); +int outfd = open("out.log", "w+"); +int errfd = open("err.log", "w+"); +virCommandSetOutputFD(cmd, &outfd); +virCommandSetErrorFD(cmd, &errfd);
@@ -304,10 +304,10 @@
- int outfd = -1; - int errfd = -1 - virCommandSetOutputFD(cmd, &outfd); - virCommandSetErrorFD(cmd, &errfd); +int outfd = -1; +int errfd = -1 +virCommandSetOutputFD(cmd, &outfd); +virCommandSetErrorFD(cmd, &errfd);
@@ -326,7 +326,7 @@
- virCommandNonblockingFDs(cmd); +virCommandNonblockingFDs(cmd);
- const char *input = "Hello World\n"; - virCommandSetInputBuffer(cmd, input); +const char *input = "Hello World\n"; +virCommandSetInputBuffer(cmd, input);
@@ -362,9 +362,9 @@
- char *output = NULL, *errors = NULL; - virCommandSetOutputBuffer(cmd, &output); - virCommandSetErrorBuffer(cmd, &errors); +char *output = NULL, *errors = NULL; +virCommandSetOutputBuffer(cmd, &output); +virCommandSetErrorBuffer(cmd, &errors);
@@ -392,7 +392,7 @@
- virCommandSetWorkingDirectory(cmd, LOCALSTATEDIR); +virCommandSetWorkingDirectory(cmd, LOCALSTATEDIR);
- virCommandSetPreExecHook(cmd, hook, opaque); +virCommandSetPreExecHook(cmd, hook, opaque);
- int logfd = ...; - char *timestamp = virTimestamp(); - char *string = NULL; - - dprintf(logfd, "%s: ", timestamp); - VIR_FREE(timestamp); - virCommandWriteArgLog(cmd, logfd); - - string = virCommandToString(cmd); - if (string) - VIR_DEBUG("about to run %s", string); - VIR_FREE(string); - if (virCommandRun(cmd, NULL) < 0) - return -1; +int logfd = ...; +char *timestamp = virTimestamp(); +char *string = NULL; + +dprintf(logfd, "%s: ", timestamp); +VIR_FREE(timestamp); +virCommandWriteArgLog(cmd, logfd); + +string = virCommandToString(cmd); +if (string) + VIR_DEBUG("about to run %s", string); +VIR_FREE(string); +if (virCommandRun(cmd, NULL) < 0) + return -1;
- if (virCommandRun(cmd, NULL) < 0) - return -1; +if (virCommandRun(cmd, NULL) < 0) + return -1;
@@ -465,19 +465,19 @@
- int status; - if (virCommandRun(cmd, &status) < 0) - return -1; - if (status == 1) { - ...do stuff... - } +int status; +if (virCommandRun(cmd, &status) < 0) + return -1; +if (status == 1) { + ...do stuff... +} - virCommandRawStatus(cmd2); - if (virCommandRun(cmd2, &status) < 0) - return -1; - if (WIFEXITED(status) && WEXITSTATUS(status) == 1) { - ...do stuff... - } +virCommandRawStatus(cmd2); +if (virCommandRun(cmd2, &status) < 0) + return -1; +if (WIFEXITED(status) && WEXITSTATUS(status) == 1) { + ...do stuff... +}
- pid_t pid; - if (virCommandRunAsync(cmd, &pid) < 0) - return -1; +pid_t pid; +if (virCommandRunAsync(cmd, &pid) < 0) + return -1; - ... do something while pid is running ... +... do something while pid is running ... - int status; - if (virCommandWait(cmd, &status) < 0) - return -1; +int status; +if (virCommandWait(cmd, &status) < 0) + return -1; - if (WEXITSTATUS(status)...) { - ..do stuff.. - } +if (WEXITSTATUS(status)...) { + ..do stuff.. +}
@@ -540,7 +540,7 @@
- virCommandFree(cmd); +virCommandFree(cmd);