summaryrefslogtreecommitdiff
path: root/src/udev/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/udev/util.c')
-rw-r--r--src/udev/util.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/udev/util.c b/src/udev/util.c
index 6d826b6f5e..d8c5bb2e1e 100644
--- a/src/udev/util.c
+++ b/src/udev/util.c
@@ -4296,6 +4296,46 @@ bool dirent_is_file_with_suffix(const struct dirent *de, const char *suffix) {
return endswith(de->d_name, suffix);
}
+int execute_command(const char *command, char *const argv[])
+{
+
+ pid_t pid;
+ int status;
+
+ if ((status = access(command, X_OK)) != 0)
+ return status;
+
+ if ((pid = fork()) < 0) {
+ log_error("Failed to fork: %m");
+ return pid;
+ }
+
+ if (pid == 0) {
+
+ execv(command, argv);
+
+ log_error("Failed to execute %s: %m", command);
+ _exit(EXIT_FAILURE);
+ }
+ else while (1)
+ {
+ siginfo_t si;
+
+ int r = waitid(P_PID, pid, &si, WEXITED);
+
+ if (!is_clean_exit(si.si_code, si.si_status, NULL)) {
+ if (si.si_code == CLD_EXITED)
+ log_error("%s exited with exit status %i.", command, si.si_status);
+ else
+ log_error("%s terminated by signal %s.", command, signal_to_string(si.si_status));
+ } else
+ log_debug("%s exited successfully.", command);
+
+ return si.si_status;
+
+ }
+}
+
void execute_directory(const char *directory, DIR *d, char *argv[]) {
DIR *_d = NULL;
struct dirent *de;