run_command.c 526 B

1234567891011121314151617181920212223242526272829
  1. /* See LICENSE file for copyright and license details. */
  2. #include <err.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include "../lib/util.h"
  6. void
  7. run_command(char *out,
  8. const char *cmd,
  9. uint32_t __unused _i,
  10. void __unused *_p)
  11. {
  12. char *p;
  13. FILE *fp;
  14. if (!(fp = popen(cmd, "re"))) {
  15. warn("popen(" QUOTED("%s") ", " QUOTED("re") ")", cmd);
  16. ERRRET(out);
  17. }
  18. p = fgets(out, BUFF_SZ - 1, fp);
  19. if (pclose(fp) == -1) ERRRET(out);
  20. if (!p) ERRRET(out);
  21. if (!!(p = strrchr(out, '\n'))) *p = '\0';
  22. }