int shell_exec(const ss_ &command, const ExecOptions &opts) { log_d(MODULE, "shell_exec(\"%s\")", cs(command)); int f = fork(); if(f == 0){ execl("/bin/sh", "sh", "-c", command.c_str(), (const char*)nullptr); } int exit_status; while(wait(&exit_status) > 0); return exit_status; }
void add(const ss_ &path, std::function<void(const ss_ &path)> cb) { for(auto &pair : m_watch){ sp_<WatchThing> &watch = pair.second; if(watch->path == path){ log_d(MODULE, "Adding callback to path \"%s\" (inotify fd=%i)", cs(path), pair.first); watch->cbs.push_back(cb); return; } } int r = inotify_add_watch(m_fd, path.c_str(), IN_CLOSE_WRITE | IN_MOVED_TO | IN_CREATE | IN_MOVED_FROM | IN_DELETE | IN_MODIFY | IN_ATTRIB); if(r == -1){ throw Exception(ss_()+"inotify_add_watch() failed: "+ strerror(errno)+" (path="+path+")"); } log_d(MODULE, "Watching path \"%s\" (inotify fd=%i)", cs(path), m_fd); m_watch[r] = sp_<WatchThing>(new WatchThing(path, {cb})); }
static void arduino_serial_write(const ss_ &data) { arduino_serial_write(data.c_str(), data.size()); }