1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

Added custom version of system(2) for better output handling

This commit is contained in:
Steffen Vogel 2014-12-05 12:40:33 +01:00
parent 4e911be070
commit 1f9d2880dc
2 changed files with 32 additions and 8 deletions

View file

@ -20,9 +20,8 @@ int tc_reset(struct interface *i)
snprintf(cmd, sizeof(cmd), "tc qdisc del dev %s root", i->name);
debug(6, "Reset traffic control for interface '%s'", i->name);
debug(8, "System: %s", cmd);
return system(cmd);
return system2(cmd);
}
int tc_prio(struct interface *i, tc_hdl_t handle, int bands)
@ -39,9 +38,8 @@ int tc_prio(struct interface *i, tc_hdl_t handle, int bands)
len += snprintf(cmd+len, sizeof(cmd)-len, " %u", priomap[i] + bands);
debug(6, "Replace master qdisc for interface '%s'", i->name);
debug(8, "System: %s", cmd);
return system(cmd);
return system2(cmd);
}
int tc_netem(struct interface *i, tc_hdl_t parent, struct netem *em)
@ -69,9 +67,8 @@ int tc_netem(struct interface *i, tc_hdl_t parent, struct netem *em)
len += snprintf(cmd+len, sizeof(cmd)-len, " corrupt %u", em->corrupt);
debug(6, "Setup netem qdisc for interface '%s'", i->name);
debug(8, "System: %s", cmd);
return system(cmd);
return system2(cmd);
}
int tc_mark(struct interface *i, tc_hdl_t flowid, int mark)
@ -83,8 +80,7 @@ int tc_mark(struct interface *i, tc_hdl_t flowid, int mark)
debug(7, "Add traffic filter to interface '%s': fwmark %u => flowid %u:%u",
i->name, mark, TC_HDL_MAJ(flowid), TC_HDL_MIN(flowid));
debug(8, "System: %s", cmd);
return system(cmd);
return system2(cmd);
}

View file

@ -4,6 +4,7 @@
* @copyright 2014, Institute for Automation of Complex Power Systems, EONERC
*/
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -144,3 +145,30 @@ void hist_dump(unsigned *hist, int length)
info("Matlab: hist = [ %s]", buf);
}
/** @todo: Proper way: create additional pipe for stderr in child process */
int system2(const char *cmd, ...)
{
char buf[1024];
va_list ap;
va_start(ap, cmd);
vsnprintf(buf, sizeof(buf), cmd, ap);
strncat(buf, " 2>&1", sizeof(buf));
va_end(ap);
debug(1, "System: %s", buf);
FILE *f = popen(buf, "r");
if (f == NULL)
perror("Failed to execute: '%s'", cmd);
while (!feof(f) && fgets(buf, sizeof(buf), f) != NULL) { INDENT
strtok(buf, "\n"); /* strip trailing newline */
info(buf);
}
return pclose(f);
}