28 #include <sys/inotify.h>
31 #include "secure_wrapper.h"
53 # define ALIGNAS(TYPE) __attribute__ ((aligned(__alignof__(TYPE))))
55 # define ALIGNAS(TYPE)
58 static volatile int interrupted = 0;
93 const char* command_to_run,
94 const char* command_args,
95 const char *
const *
const patterns,
96 const size_t pattern_count)
101 const char * errmsg =
"unknown error";
103 notifyfd = inotify_init();
106 errmsg =
"inotify_init";
109 watchfd = inotify_add_watch(notifyfd, directory, IN_CREATE);
112 errmsg =
"inotify_add_watch";
117 char buffer[
sizeof(
struct inotify_event) + NAME_MAX + 1] ALIGNAS(struct inotify_event) = {0};
118 const struct inotify_event * event_ptr;
120 ssize_t count = read(notifyfd, buffer, (
sizeof(buffer) - 1));
128 event_ptr = (
const struct inotify_event *) buffer;
129 assert(event_ptr->wd == watchfd);
130 assert(event_ptr->mask & IN_CREATE);
134 for (i = 0; i < pattern_count; ++i)
136 switch (fnmatch(patterns[i], event_ptr->name, FNM_PATHNAME))
140 if (printf(
"%s\n", event_ptr->name) < 0)
148 if(strncmp(command_to_run,
"NULL",4) == 0){
149 printf(
"Flag file is created. Exiting from wait \n");
152 printf(
"Calling the binary %s\n",command_to_run);
154 v_secure_system(
"sh -c '%s %s'",command_to_run,command_args);
158 if(command_to_run == NULL || command_args == NULL)
164 if (
sizeof(command) <= (strlen(command_to_run)+strlen(command_args)+strlen(
"ssh -c ' '")))
166 errmsg =
"command buffer overflow";
169 sprintf(command,
"sh -c '%s %s'",command_to_run,command_args);
173 printf(
"The script /lib/rdk/uploadDumps.sh execution completed..!");
188 int status = close(watchfd);
192 errmsg =
"close(watchfd)";
198 int status = close(notifyfd);
202 errmsg =
"close(notifyfd)";
225 main(
const int argc,
const char *
const *
const argv)
229 fprintf(stderr,
"usage: %s DIRECTORY COMMAND_TO_RUN COMMAND_ARGS PATTERN...\n", argv[0]);
235 sigemptyset(&sa.sa_mask);
237 sigaction(SIGINT, &sa, NULL);