-
Notifications
You must be signed in to change notification settings - Fork 0
/
exec.c
33 lines (26 loc) · 787 Bytes
/
exec.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/* exec.c - this file contains a wrapper for calling the
exec() syscall in order to replace the current
process */
#include "include/exec.h"
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
/* exec
Runs the program handed over with the string array.
The array handed over contains the commands with its arguments.
*/
void exec(char** command)
{
int execution_result = -1;
/* Run the entered command. */
execution_result = execvp(command[0], command);
/* Show error message if an error occured. */
if (execution_result == -1) {
fprintf(stderr, "Could not run %s: %s\n", command[0], strerror(errno));
}
/* Free allocated memory. */
free(command);
command = NULL;
}