static void tune_in(void) { int selfd; //logmsg("[%s: tune_in(...)] *** ENTER ***", __FILE__); init_signals(); //logmsg("[%s: tune_in(...)] Signals initialized", __FILE__); //lock_ourselves(); init_regexps(); //logmsg("[%s: tune_in(...)] Regexps initialized", __FILE__); // BEGIN HERE if (fifo_exists(ZTEBLADEFM_PIPE_CMD)) { int rv = mkfifo(ZTEBLADEFM_PIPE_CMD, 0666); if (rv < 0) { // handle condition here.. panic("[%s:tune_in(...) @ %d] - Could not mkfifo %s.", __FILE__, __LINE__, ZTEBLADEFM_PIPE_CMD); } } if (fifo_exists(ZTEBLADEFM_PIPE_STATUS)) { int rv = mkfifo(ZTEBLADEFM_PIPE_STATUS, 0666); if (rv < 0) { // handle condition here.. panic("[%s:tune_in(...) @ %d] - Could not mkfifo %s.", __FILE__, __LINE__, ZTEBLADEFM_PIPE_STATUS); } } #if __t0mm13b_defiant__ int rv = mkfifo(ZTEBLADEFM_PIPE_CMD, 0666); if (rv < 0) { // handle condition here.. panic("[%s:tune_in(...) @ %d] - Could not mkfifo %s.", __FILE__, __LINE__, ZTEBLADEFM_PIPE_CMD); } rv = mkfifo(ZTEBLADEFM_PIPE_STATUS, 0666); if (rv < 0) { // handle condition here.. panic("[%s:tune_in(...) @ %d] - Could not mkfifo %s.", __FILE__, __LINE__, ZTEBLADEFM_PIPE_STATUS); } #else g_rdfmdev = open(FM_DEV, O_RDONLY); #endif // init_open_statuspipe(); init_open_commandpipe(); // logic routine from here ... http://stackoverflow.com/questions/1735781/non-blocking-pipe-using-popen while (g_keepRunning) { selfd = select(FD_SETSIZE, &g_fdset_r, (fd_set*)0, (fd_set*)0,NULL); if (selfd < 0) panic("Could not select..."); if (selfd > 0) { check_select(); } } if (g_fprdcmdpipe != NULL) fclose(g_fprdcmdpipe); if (g_fpwrstatpipe != NULL) fclose(g_fpwrstatpipe); #ifdef __t0mm13b_defiant__ ; #else close(g_rdfmdev); #endif cleanup_regexps(); // END HERE }
int fifo_has_reader(const char *path, int prepare) { int fd; /* ** Check that fifo exists and is a fifo. ** If not, there can be no reader process. */ switch (fifo_exists(path, prepare)) { case 0: return 0; case -1: return -1; } /* ** Open the fifo for non-blocking write. ** If there is no reader process, open() ** will fail with errno == ENXIO. */ if ((fd = open(path, O_WRONLY | O_NONBLOCK)) == -1) return (errno == ENXIO) ? 0 : -1; if (close(fd) == -1) return -1; return 1; }
/* Opens a file descriptor whcich could be a FIFO or just a file. On error returns -1*/ int fd_open (int type, void * data, int perms) { int fd = 0; if(type == _FD_FIFO) { int key = fifo_exists(data); if(key) { return fd_find(type, key); } FIFO_allocator_size++; if(FIFO_allocator_size == FIFO_allocator_end - FIFO_allocator - 1) { return -1; } fd = FIFO_allocator_index++; if(FIFO_allocator_index == FIFO_allocator_end - 1) { FIFO_allocator_index = FIFO_allocator; } } else if(type == _FD_FILE) { fd_allocator_size++; if(fd_allocator_size == fd_allocator_end - fd_allocator - 1) { return -1; } fd = fd_allocator_index++; if(fd_allocator_index == fd_allocator_end - 1) { fd_allocator_index = fd_allocator; } } else { return -1; } return fd_open_with_index(fd, type, data, perms); }
/* * This function basically sets up the .port (for wireshark use) */ void infoInit(char *rpath, char *rname) { int fd, status; sprintf(iconf.path, "%s/%s.%s", rpath, rname, "info"); iconf.updateinterval = 10; // set default update time to 10 sec if (fifo_exists(iconf.path, 1)) { verbose(2, "[infoInit]:: WARNING! existing FIFO %s removed .. creating a new one ", iconf.path); remove(iconf.path); if (iconf.threadid != 0) pthread_cancel(iconf.id); } if ((fd = fifo_open(iconf.path, S_IRUSR | S_IWUSR | S_IWGRP | S_IWOTH, 1, &(iconf.id))) == -1) { error("[infoInit]:: unable to create socket .. %s", iconf.path); return; } iconf.qtargets = list_create(NULL); status = pthread_create(&(iconf.threadid), NULL, (void *)infoHandler, (void *)NULL); if (status != 0) error("Unable to create the info handler thread... "); return; }