Handle failed system calls

Introduce a separate TU for utility functions util.c. Add a function
exec_cmd to simplify execution of system commands with error handling.

While at it, suppress a warning about unused result when executing a
shell command. As we only display the command's output we do not care
about the exit code.

This fixes Debian bug #398989[0]

[0]: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=398989
This commit is contained in:
Rene Kita
2022-12-25 15:11:44 +01:00
parent 7c7af9e70c
commit 4e23ee03ca
5 changed files with 44 additions and 16 deletions

26
util.c Normal file
View File

@@ -0,0 +1,26 @@
#include "util.h"
#include "display.h"
#include "terms.h"
#include <stdio.h>
#include <stdlib.h>
int
exec_cmd(char *cmd)
{
int rv;
fmTerm();
if ((rv = system(cmd))) {
printf("\n[Hit any key]");
fflush(stdout);
fmInit();
getch();
return rv;
}
fmInit();
return 0;
}