//---------------------------------------------------------------------------- // wait until write fifo is empty, max time in msec static void wait_until_fifo_empty(struct pcandev *dev, u32 mTime) { u32 dwStart = get_mtime(); while (!atomic_read(&dev->DataSendReady) && ((get_mtime() - dwStart) < mTime)) schedule(); // force it atomic_set(&dev->DataSendReady, 1); }
int main (int argc, const char * argv[]) { print_cwd(); // prepare source dir content { mkdir_source(); chdir_source(); create_file("myfile"); create_symlink("myfile", "mylink"); system("/usr/bin/SetFile -P -m 11/11/2011 mylink"); system("/usr/bin/SetFile -m 01/01/2001 myfile"); chdir_parent(); } // copy content from source dir to target dir system("/bin/cp -Rp source target"); // verify target dir content { int ok = 1; { struct timespec t1 = get_mtime("source/myfile"); struct timespec t2 = get_mtime("target/myfile"); if((t1.tv_sec != t2.tv_sec) || (t1.tv_nsec != t2.tv_nsec)) { printf("TEST FAILED: timestamp on myfile differs\n"); ok = 0; } } { struct timespec t1 = get_mtime("source/mylink"); struct timespec t2 = get_mtime("target/mylink"); if((t1.tv_sec != t2.tv_sec) || (t1.tv_nsec != t2.tv_nsec)) { printf("TEST FAILED: timestamp on mylink differs\n"); ok = 0; } } if(ok) { printf("TEST SUCCESS: mtime is copied correct, mtime is the same"); } } return EXIT_SUCCESS; }
/* * wait until write fifo is empty, max time in msec */ static void wait_until_fifo_empty(struct pcandev *dev, u32 mTime) { u32 dwStart = get_mtime(); /* not need to wait for anything if device not plugged! */ if (!dev->ucPhysicallyInstalled) return; while (!atomic_read(&dev->DataSendReady) && ((get_mtime() - dwStart) < mTime)) schedule(); /* force it */ atomic_set(&dev->DataSendReady, 1); }
static void tags_cache_add (struct tags_cache *c, const char *file, DBT *key, struct file_tags *tags) { char *serialized_cache_rec; int serial_len; struct cache_record rec; DBT data; int ret; assert (tags != NULL); debug ("Adding/updating cache object"); rec.mod_time = get_mtime (file); rec.atime = time (NULL); rec.tags = tags; serialized_cache_rec = cache_record_serialize (&rec, &serial_len); if (!serialized_cache_rec) return; memset (&data, 0, sizeof(data)); data.data = serialized_cache_rec; data.size = serial_len; tags_cache_gc (c); ret = c->db->put (c->db, NULL, key, &data, 0); if (ret) error ("DB put error: %s", db_strerror (ret)); tags_cache_sync (c); free (serialized_cache_rec); }
/* Write out request file for given Reqserv. Return TRUE on success. If an I/O error occurs, it is logged, and FALSE is returned. */ static Bool writeRequestfile(Reqserv* rs) { Str filename; FILE* file; char** z; fileRequest(filename, rs->serv); Log_dbg("writing request file %s", filename); if (Log_check((file = fopen(filename, "w")) != 0, "could not open %s for writing: %s", filename, strerror(errno))) return FALSE; if (rs->reql) for (z = rs->reql; z < rs->reql+rs->reql_length; z++) if (*z) { if (Log_check( fputs(*z, file) != EOF && fputs("\n", file) != EOF, "write error: %s", strerror(errno))) return FALSE; } if (Log_check(fclose(file) != EOF, "could not close %s properly: %s\n", filename, strerror(errno))) return FALSE; rs->dirty = FALSE; rs->mtime = get_mtime(rs->serv); return TRUE; }
/* Delete Reqserv from cache, if not up-to-date */ static void cleanupReqserv( void ) { Reqserv *rs, *prev, *next; rs = reqserv; prev = NULL; while ( rs != NULL ) { ASSERT( ! rs->dirty ); next = rs->next; if ( get_mtime( rs->serv ) != rs->mtime ) { if ( prev != NULL ) prev->next = next; else reqserv = next; free( rs->serv ); rs->serv = NULL; free( rs->reql ); rs->reql = NULL; free( rs ); } prev = rs; rs = next; } }
/* Handle CMD_QUEUE_ADD, return 1 if ok or 0 on error. */ static int req_queue_add (const struct client *cli) { char *file; struct plist_item *item; file = get_str (cli->socket); if (!file) return 0; logit ("Adding '%s' to the queue", file); audio_queue_add (file); /* Wrap the filename in struct plist_item. * We don't need tags, because the player gets them * when playing the file. This may change if there is * support for viewing/reordering the queue and here * is the place to read the tags and fill them into * the item. */ item = plist_new_item (); item->file = xstrdup (file); item->type = file_type (file); item->mtime = get_mtime (file); add_event_all (EV_QUEUE_ADD, item); plist_free_item_fields (item); free (item); free (file); return 1; }
/* Add a file to the list. Return the index of the item. */ int plist_add (struct plist *plist, const char *file_name) { assert (plist != NULL); assert (plist->items != NULL); if (plist->allocated == plist->num) { plist->allocated *= 2; plist->items = (struct plist_item *)xrealloc (plist->items, sizeof(struct plist_item) * plist->allocated); } plist->items[plist->num].file = xstrdup (file_name); plist->items[plist->num].type = file_name ? file_type (file_name) : F_OTHER; plist->items[plist->num].deleted = 0; plist->items[plist->num].title_file = NULL; plist->items[plist->num].title_tags = NULL; plist->items[plist->num].tags = NULL; plist->items[plist->num].mtime = (file_name ? get_mtime(file_name) : (time_t)-1); plist->items[plist->num].queue_pos = 0; if (file_name) { rb_delete (plist->search_tree, file_name); rb_insert (plist->search_tree, (void *)(intptr_t)plist->num); } plist->num++; plist->not_deleted++; return plist->num - 1; }
FindData Archive::get_file_info(UInt32 index) { if (file_list.empty()) make_index(); FindData file_info; memzero(file_info); wcscpy(file_info.cFileName, file_list[index].name.c_str()); file_info.dwFileAttributes = get_attr(index); file_info.set_size(get_size(index)); file_info.ftCreationTime = get_ctime(index); file_info.ftLastWriteTime = get_mtime(index); file_info.ftLastAccessTime = get_atime(index); return file_info; }
int headers_to_stat(GList *headers, struct stat *stbuf) { GList *head = NULL, *next = NULL; head = g_list_first(headers); while(head != NULL) { next = head->next; HTTP_HEADER *header = head->data; // TODO: clean this up. if(strcmp(header->key, "x-amz-meta-uid") == 0) stbuf->st_uid = get_uid(header->value); else if(strcmp(header->key, "x-amz-meta-gid") == 0) stbuf->st_gid = get_gid(header->value); else if(strcmp(header->key, "x-amz-meta-ctime") == 0) stbuf->st_ctime = get_ctime(header->value); else if(strcmp(header->key, "x-amz-meta-mtime") == 0) stbuf->st_mtime = get_mtime(header->value); else if(strcmp(header->key, "x-amz-meta-rdev") == 0) stbuf->st_rdev = get_rdev(header->value); else if(strcmp(header->key, "Last-Modified") == 0 && stbuf->st_mtime == 0) stbuf->st_mtime = get_mtime(header->value); else if(strcmp(header->key, "x-amz-meta-mode") == 0) stbuf->st_mode = get_mode(header->value); else if(strcmp(header->key, "Content-Length") == 0) stbuf->st_size = get_size(header->value); else if(strcmp(header->key, "Content-Type") == 0) if(strstr(header->value, "x-directory")) stbuf->st_mode |= S_IFDIR; head = next; } return 0; }
/* Set file for an item. */ void plist_set_file (struct plist *plist, const int num, const char *file) { assert (LIMIT(num, plist->num)); assert (file != NULL); if (plist->items[num].file) { rb_delete (plist->search_tree, file); free (plist->items[num].file); } plist->items[num].file = xstrdup (file); plist->items[num].type = file_type (file); plist->items[num].mtime = get_mtime (file); rb_insert (plist->search_tree, (void *)(intptr_t)num); }
static void *locked_read_add (struct tags_cache *c, const char *file, const int tags_sel, const int client_id, DBT *key, DBT *serialized_cache_rec) { int ret; struct file_tags *tags = NULL; assert (c->db != NULL); ret = c->db->get (c->db, NULL, key, serialized_cache_rec, 0); if (ret && ret != DB_NOTFOUND) logit ("Cache DB get error: %s", db_strerror (ret)); /* If this entry is already present in the cache, we have 3 options: * we must read different tags (TAGS_*) or the tags are outdated * or this is an immediate tags read (client_id == -1) */ if (ret == 0) { struct cache_record rec; if (cache_record_deserialize (&rec, serialized_cache_rec->data, serialized_cache_rec->size, 0)) { time_t curr_mtime = get_mtime (file); if (rec.mod_time != curr_mtime) { debug ("Tags in the cache are outdated"); tags_free (rec.tags); /* remove them and reread tags */ } else if ((rec.tags->filled & tags_sel) == tags_sel && client_id == -1) { debug ("Tags are in the cache."); return rec.tags; } else { debug ("Tags in the cache are not what we want"); tags = rec.tags; /* read additional tags */ } } } tags = read_missing_tags (file, tags, tags_sel); tags_cache_add (c, file, key, tags); return tags; }
/* Add this tags object for the file to the cache. */ static void tags_cache_add (struct tags_cache *c, const char *file, struct file_tags *tags) { char *serialized_cache_rec; int serial_len; struct cache_record rec; DBT key; DBT data; int ret; assert (c != NULL); assert (tags != NULL); assert (file != NULL); rec.mod_time = get_mtime (file); rec.atime = time (NULL); rec.tags = tags; serialized_cache_rec = cache_record_serialize (&rec, &serial_len); if (!serialized_cache_rec) return; memset (&key, 0, sizeof(key)); memset (&data, 0, sizeof(data)); key.data = (void *)file; key.size = strlen(file); data.data = serialized_cache_rec; data.size = serial_len; tags_cache_gc (c); ret = c->db->put (c->db, NULL, &key, &data, 0); if (ret) { logit ("DB put error: %s", db_strerror(ret)); } free (serialized_cache_rec); }
/* Read request file into new, non-queued Reqserv. Save new Reqserv in "rsz" and return TRUE on success. Returns FALSE on failure, see errno. If the file doesn't exist, an empty Reqserv is returned. */ static Bool readRequestfile(const char* serv, Reqserv** rsz) { Str filename; Str line; FILE* file; Reqserv* rs; fileRequest(filename, serv); Log_dbg("reading request file %s", filename); file = fopen(filename, "r"); if (!file && (errno == ENOENT)) { *rsz = newReqserv(serv); (*rsz)->mtime = get_mtime(serv); return TRUE; } if (Log_check(file != 0, "could not open %s for reading: %s", filename, strerror(errno))) return FALSE; rs = *rsz = newReqserv(serv); while( readLn(line, file) == TRUE) { char* line1 = Utl_stripWhiteSpace(line); if (*line1) storeMsgId(rs, line1); } rs->dirty = FALSE; if (Log_check(fclose(file) != EOF, "could not close %s properly: %s\n", filename, strerror(errno))) return FALSE; return TRUE; }
int main(int argc, char *argv[]) { if(!glfwInit()) { std::cerr << "Failed to init GLFW" << std::endl; return 1; } atexit(glfwTerminate); glfwSetErrorCallback(error_callback); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); window = glfwCreateWindow(w, h, "Mandelbrot", NULL, NULL); if(!window) { std::cerr << "Failed to create window" << std::endl; return 1; } glfwSetKeyCallback(window, key_callback); glfwSetCursorPosCallback(window, cursor_callback); glfwSetMouseButtonCallback(window, mouse_button_callback); glfwSetScrollCallback(window, scroll_callback); glfwSetInputMode(window, GLFW_CURSOR_NORMAL, GLFW_STICKY_KEYS); glfwMakeContextCurrent(window); glewExperimental = GL_TRUE; glewInit(); std::cout << "Renderer: " << glGetString(GL_RENDERER) << std::endl; std::cout << "OpenGL Version: " << glGetString(GL_VERSION) << std::endl; GLuint prog; compile_shader(prog); last_mtime = get_mtime("shader.glsl"); float points[] = { -1.0f, 1.0f, 0.0f, -1.0f, -1.0f, 0.0f, 1.0f, -1.0f, 0.0f, -1.0f, 1.0f, 0.0f, 1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 0.0f, }; GLuint vbo = 0; glGenBuffers (1, &vbo); glBindBuffer (GL_ARRAY_BUFFER, vbo); glBufferData (GL_ARRAY_BUFFER, 2 * 9 * sizeof (float), points, GL_STATIC_DRAW); GLuint vao = 0; glGenVertexArrays (1, &vao); glBindVertexArray (vao); glEnableVertexAttribArray (0); glBindBuffer (GL_ARRAY_BUFFER, vbo); glVertexAttribPointer (0, 3, GL_FLOAT, GL_FALSE, 0, NULL); glUseProgram (prog); last_time = glfwGetTime(); glBindVertexArray (vao); while(!glfwWindowShouldClose(window)) { time_t new_time = get_mtime("shader.glsl"); if(new_time != last_mtime) { glDeleteProgram(prog); compile_shader(prog); glUseProgram(prog); last_mtime = new_time; std::cout << "Reloaded shader: " << last_mtime << std::endl; } glfwGetWindowSize(window, &w, &h); glUniform2d(glGetUniformLocation(prog, "screen_size"), (double)w, (double)h); glUniform1d(glGetUniformLocation(prog, "screen_ratio"), (double)w / (double)h); glUniform2d(glGetUniformLocation(prog, "center"), cx, cy); glUniform1d(glGetUniformLocation(prog, "zoom"), zoom); glUniform1i(glGetUniformLocation(prog, "itr"), itr); glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glDrawArrays (GL_TRIANGLES, 0, 6); glfwSwapBuffers(window); glfwPollEvents(); ticks++; current_time = glfwGetTime(); if(current_time - last_time > 1.0) { fps = ticks; update_window_title(); last_time = glfwGetTime(); ticks = 0; } } glfwDestroyWindow(window); }
void tags_cache_add_request (struct tags_cache *c, const char *file, const int tags_sel, const int client_id) { DBT serialized_cache_rec; DBT key; int db_ret; int got_lock; DB_LOCK lock; assert (c != NULL); assert (file != NULL); assert (client_id >= 0 && client_id < CLIENTS_MAX); debug ("Request for tags for %s from client %d", file, client_id); memset (&key, 0, sizeof(key)); key.data = (void *)file; key.size = strlen(file); memset (&serialized_cache_rec, 0, sizeof(serialized_cache_rec)); serialized_cache_rec.flags = DB_DBT_MALLOC; db_ret = c->db_env->lock_get (c->db_env, c->locker, 0, &key, DB_LOCK_WRITE, &lock); if (db_ret) { got_lock = 0; logit ("Can't get DB lock: %s", db_strerror(db_ret)); } else { got_lock = 1; } if (c->db) { db_ret = c->db->get(c->db, NULL, &key, &serialized_cache_rec, 0); if (db_ret && db_ret != DB_NOTFOUND) error ("Cache DB search error: %s", db_strerror(db_ret)); } else db_ret = DB_NOTFOUND; if (db_ret == 0) { struct cache_record rec; if (cache_record_deserialize(&rec, serialized_cache_rec.data, serialized_cache_rec.size, 0)) { if (rec.mod_time == get_mtime(file) && (rec.tags->filled & tags_sel) == tags_sel) { tags_response (client_id, file, rec.tags); tags_free (rec.tags); debug ("Tags are present in the cache"); goto end; } tags_free (rec.tags); debug ("Found outdated or incomplete tags in the cache"); } } LOCK (c->mutex); request_queue_add (&c->queues[client_id], file, tags_sel); pthread_cond_signal (&c->request_cond); UNLOCK (c->mutex); end: if (got_lock) { db_ret = c->db_env->lock_put (c->db_env, &lock); if (db_ret) logit ("Can't release DB lock: %s", db_strerror(db_ret)); } if (serialized_cache_rec.data) free (serialized_cache_rec.data); }
/* Read the selected tags for this file and add it to the cache. * If client_id != -1, the server is notified using tags_response(). * If client_id == -1, copy of file_tags is returned. */ static struct file_tags *tags_cache_read_add (struct tags_cache *c, const int client_id, const char *file, int tags_sel) { struct file_tags *tags = NULL; DBT key; DBT serialized_cache_rec; DB_LOCK lock; int got_lock = 0; int ret; assert (c != NULL); assert (c->db != NULL); assert (file != NULL); debug ("Getting tags for %s", file); memset (&key, 0, sizeof(key)); memset (&serialized_cache_rec, 0, sizeof(serialized_cache_rec)); key.data = (void *)file; key.size = strlen(file); serialized_cache_rec.flags = DB_DBT_MALLOC; ret = c->db_env->lock_get (c->db_env, c->locker, 0, &key, DB_LOCK_WRITE, &lock); if (ret) { logit ("Can't get DB lock: %s", db_strerror(ret)); } else { got_lock = 1; ret = c->db->get (c->db, NULL, &key, &serialized_cache_rec, 0); if (ret && ret != DB_NOTFOUND) logit ("Cache DB get error: %s", db_strerror(ret)); } /* If this entry is already present in the cache, we have 3 options: * we must read different tags (TAGS_*) or the tags are outdated * or this is an immediate tags read (client_id == -1) */ if (ret == 0) { struct cache_record rec; if (cache_record_deserialize (&rec, serialized_cache_rec.data, serialized_cache_rec.size, 0)) { time_t curr_mtime = get_mtime (file); if (rec.mod_time != curr_mtime) { /* outdated tags - remove them and reread */ tags_free (rec.tags); debug ("Tags in the cache are outdated"); } else if ((rec.tags->filled & tags_sel) == tags_sel && client_id == -1) { debug ("Tags are in the cache."); tags = rec.tags; goto end; } else { tags = rec.tags; /* read tags in addition to already present tags */ debug ("Tags in the cache are not what we want."); } } } if (tags == NULL) tags = tags_new (); if (tags_sel & TAGS_TIME) { int time; /* Try to get it from the server's playlist first. */ time = audio_get_ftime (file); if (time != -1) { tags->time = time; tags->filled |= TAGS_TIME; tags_sel &= ~TAGS_TIME; } } tags = read_file_tags (file, tags, tags_sel); debug ("Adding/updating cache object"); tags_cache_add (c, file, tags); if (client_id != -1) { tags_response (client_id, file, tags); tags_free (tags); tags = NULL; } /* TODO: Remove the oldest items from the cache if we exceeded the maximum * cache size */ end: if (got_lock) { ret = c->db_env->lock_put (c->db_env, &lock); if (ret) logit ("Can't release DB lock: %s", db_strerror(ret)); } if (serialized_cache_rec.data) free (serialized_cache_rec.data); return tags; }
int main(int argc,char *argv[]){ //get_mtime("/bassapp/bass2/panzw2/.profile"); time_print(get_mtime("c:\\boot.ini")); return 0; }
/** * Download a file. * * @param url URL. * @param cache_key Cache key. * * If the file is present in the cache, the cached version * will be retrieved. Otherwise, the file will be downloaded. * * If the file was not found on the server, or it was not found * the last time it was requested, an empty string will be * returned, and a zero-byte file will be stored in the cache. * * @return Absolute path to the cached file. */ string CacheManager::download( const string &url, const string &cache_key) { // Check the main cache key. string cache_filename = getCacheFilename(cache_key); if (cache_filename.empty()) { // Error obtaining the cache key filename. return string(); } // Lock the semaphore to make sure we don't // download too many files at once. SemaphoreLocker locker(m_dlsem); // Check if the file already exists. if (!access(cache_filename, R_OK)) { // File exists. // Is it larger than 0 bytes? int64_t sz = filesize(cache_filename); if (sz == 0) { // File is 0 bytes, which indicates it didn't exist // on the server. If the file is older than a week, // try to redownload it. // TODO: Configurable time. // TODO: How should we handle errors? time_t filetime; if (get_mtime(cache_filename, &filetime) != 0) return string(); struct timeval systime; if (gettimeofday(&systime, nullptr) != 0) return string(); if ((systime.tv_sec - filetime) < (86400*7)) { // Less than a week old. return string(); } // More than a week old. // Delete the cache file and redownload it. if (delete_file(cache_filename) != 0) return string(); } else if (sz > 0) { // File is larger than 0 bytes, which indicates // it was cached successfully. return cache_filename; } } // Check if the URL is blank. // This is allowed for some databases that are only available offline. if (url.empty()) { // Blank URL. Don't try to download anything. // Don't mark the file as unavailable by creating a // 0-byte dummy file, either. return string(); } // Make sure the subdirectories exist. // NOTE: The filename portion MUST be kept in cache_filename, // since the last component is ignored by rmkdir(). if (rmkdir(cache_filename) != 0) { // Error creating subdirectories. return string(); } // TODO: Keep-alive cURL connections (one per server)? m_downloader->setUrl(url); m_downloader->setProxyUrl(m_proxyUrl); int ret = m_downloader->download(); // Write the file to the cache. unique_ptr<IRpFile> file(new RpFile(cache_filename, RpFile::FM_CREATE_WRITE)); if (ret != 0 || !file || !file->isOpen()) { // Error downloading the file, or error opening // the file in the local cache. // TODO: Only keep a negative cache if it's a 404. // Keep the cached file as a 0-byte file to indicate // a "negative" hit, but return an empty filename. return string(); } // Write the file. file->write((void*)m_downloader->data(), m_downloader->dataSize()); file->close(); // Set the file's mtime if it was obtained by the downloader. // TODO: IRpFile::set_mtime()? time_t mtime = m_downloader->mtime(); if (mtime >= 0) { set_mtime(cache_filename, mtime); } // Return the cache filename. return cache_filename; }
int main (int argc, char* argv[]) { monitor(); int i, fd, length; int watchdog = 0, watchdog_errors = 0; int onesec_check = 0; time_t last_pv_time = 0, pv_time; char readbuf[MAX_COMMAND_LEN]; bcm_host_init(); // // read arguments // for(i=1; i<argc; i++) { if(strcmp(argv[i], "--version") == 0) { printf("RaspiMJPEG Version %s\n", VERSION); exit(0); } else if(strcmp(argv[i], "-md") == 0) { cfg_val[c_motion_detection] = 1; } } //default base media path asprintf(&cfg_stru[c_media_path], "%s", "/var/www/media"); // // read configs and init // read_config("/etc/raspimjpeg", 1); if (cfg_stru[c_user_config] != 0) read_config(cfg_stru[c_user_config], 0); createPath(cfg_stru[c_log_file], cfg_stru[c_base_path]); if (cfg_stru[c_boxing_path] != NULL) { char *bpath; asprintf(&bpath, "%s/temp", cfg_stru[c_boxing_path]); createPath(bpath, cfg_stru[c_base_path]); free(bpath); } printLog("RaspiMJPEG Version %s\n", VERSION); if(cfg_val[c_autostart]) start_all(0); // // run // if(cfg_val[c_autostart]) { if(cfg_stru[c_control_file] != 0){ printLog("MJPEG streaming, ready to receive commands\n"); //kick off motion detection at start if required. if(cfg_val[c_motion_detection] && cfg_val[c_motion_external]) { printLog("Autostart external motion kill any runnng motion\n"); if(system("killall motion") == -1) error("Could not stop external motion", 1); sleep(1); printLog("Autostart external motion start external motion\n"); if(system("motion") == -1) error("Could not start external motion", 1); } } else { printLog("MJPEG streaming\n"); } } else { if(cfg_stru[c_control_file] != 0) printLog("MJPEG idle, ready to receive commands\n"); else printLog("MJPEG idle\n"); } updateStatus(); struct sigaction action; memset(&action, 0, sizeof(struct sigaction)); action.sa_handler = term; sigaction(SIGTERM, &action, NULL); sigaction(SIGINT, &action, NULL); //Clear out anything in FIFO first do { fd = open(cfg_stru[c_control_file], O_RDONLY | O_NONBLOCK); if(fd < 0) error("Could not open PIPE", 1); fcntl(fd, F_SETFL, 0); length = read(fd, readbuf, 60); close(fd); } while (length != 0); //Send restart signal to scheduler send_schedulecmd("9"); // Main forever loop while(running) { if(cfg_stru[c_control_file] != 0) { fd = open(cfg_stru[c_control_file], O_RDONLY | O_NONBLOCK); if(fd < 0) error("Could not open PIPE", 1); fcntl(fd, F_SETFL, 0); length = read(fd, readbuf, MAX_COMMAND_LEN -2); close(fd); if(length) { process_cmd(readbuf, length); } } if(timelapse) { tl_cnt++; if(tl_cnt >= cfg_val[c_tl_interval]) { if(i_capturing == 0) { capt_img(); tl_cnt = 0; } } } // check to see if image preview changing if (!idle && cfg_val[c_watchdog_interval] > 0) { if(watchdog++ > cfg_val[c_watchdog_interval]) { watchdog = 0; pv_time = get_mtime(cfg_stru[c_preview_path]); if (pv_time == 0) { watchdog_errors++; } else { if (pv_time > last_pv_time) { watchdog_errors = 0; } else { watchdog_errors++; } last_pv_time = pv_time; } if (watchdog_errors >= cfg_val[c_watchdog_errors]) { printLog("Watchdog detected problem. Stopping"); running = 0; } } } else { watchdog_errors = 0; } if (++onesec_check >= 10) { //run check on background boxing every 10 ticks and check for video timer if capturing onesec_check = 0; check_box_files(); if (v_capturing && video_stoptime > 0) { if (time(NULL) >= video_stoptime) { printLog("Stopping video from timer\n"); stop_video(0); } } } usleep(100000); } if(system("killall motion") == -1) error("Could not stop external motion", 1); printLog("SIGINT/SIGTERM received, stopping\n"); // // tidy up // if(!idle) stop_all(); return 0; }