mirror of
https://github.com/eddyem/boltwood.git
synced 2026-03-22 09:41:10 +03:00
fix bug in socket.c
This commit is contained in:
@@ -24,7 +24,6 @@
|
||||
#define __CMDLNOPTS_H__
|
||||
|
||||
#include "parseargs.h"
|
||||
#include "term.h"
|
||||
|
||||
/*
|
||||
* here are some typedef's for global data
|
||||
|
||||
@@ -32,13 +32,12 @@
|
||||
|
||||
#include "usefull_macros.h"
|
||||
#include "imfunctions.h"
|
||||
#include "term.h"
|
||||
#include "socket.h"
|
||||
|
||||
/**
|
||||
* All image-storing functions modify ctime of saved files to be the time of
|
||||
* exposition start!
|
||||
*/
|
||||
*
|
||||
void modifytimestamp(char *filename, time_t tv_sec){
|
||||
if(!filename) return;
|
||||
struct timespec times[2];
|
||||
@@ -46,7 +45,7 @@ void modifytimestamp(char *filename, time_t tv_sec){
|
||||
times[0].tv_nsec = UTIME_OMIT;
|
||||
times[1].tv_sec = tv_sec; // change mtime
|
||||
if(utimensat(AT_FDCWD, filename, times, 0)) WARN(_("Can't change timestamp for %s"), filename);
|
||||
}
|
||||
}*/
|
||||
|
||||
/**
|
||||
* Test if `name` is a fits file with 2D image
|
||||
@@ -133,15 +132,22 @@ static void gotodir(char *relpath){ // create directory structure
|
||||
* @return 1 if it's dark
|
||||
*/
|
||||
int fits_is_dark(char *name){
|
||||
int ret = 0;
|
||||
mmapbuf *buf = My_mmap(name);
|
||||
if(!buf) return 0;
|
||||
char *key = memmem(buf->data, buf->len, "IMAGETYP", 8);
|
||||
if(!key) return 0;
|
||||
if(buf->len - (key - buf->data) < 30) return 0;
|
||||
if(!key) goto light;
|
||||
if(buf->len - (key - buf->data) < 30) goto light;
|
||||
key += 9;
|
||||
char *dark = memmem(key, 20, "'dark", 5);
|
||||
if(dark) return 1;
|
||||
return 0;
|
||||
if(dark){
|
||||
DBG("DARK!");
|
||||
ret = 1;
|
||||
}
|
||||
light:
|
||||
My_munmap(buf);
|
||||
DBG("LIGHT");
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define TRYFITS(f, ...) \
|
||||
@@ -244,7 +250,7 @@ ret:
|
||||
status = 0;
|
||||
if(ofptr){
|
||||
fits_close_file(ofptr, &status);
|
||||
modifytimestamp(newname, (time_t)modtm);
|
||||
//modifytimestamp(newname, (time_t)modtm);
|
||||
}
|
||||
// as cfitsio removes old file instead of trunkate it, we need to refresh inotify every time!
|
||||
if(chdir(oldwd)){ // return back to BD root directory
|
||||
|
||||
@@ -251,13 +251,11 @@ static void client_(char *FITSpath, int infd, int sock){
|
||||
DBG("changed?");
|
||||
if(fds.revents & POLLIN){
|
||||
ssize_t len = read(infd, &buf, sizeof(buf));
|
||||
if (len == -1 && errno != EAGAIN) {
|
||||
if (len == -1 && errno != EAGAIN){
|
||||
ERR("read");
|
||||
return;
|
||||
}else{
|
||||
DBG("file changed");
|
||||
usleep(100000); // wait a little for file changes
|
||||
fds.fd = watch_fits(FITSpath);
|
||||
if(dtime() - lastTstorage > minstoragetime){
|
||||
DBG("lastT: %.2g, now: %.2g", lastTstorage, dtime());
|
||||
lastTstorage = dtime();
|
||||
@@ -265,6 +263,7 @@ static void client_(char *FITSpath, int infd, int sock){
|
||||
}else if(fits_is_dark(FITSpath)) // save darks nevertheless time
|
||||
store_fits(FITSpath, last_good_msrment);
|
||||
}
|
||||
fds.fd = watch_fits(FITSpath);
|
||||
}
|
||||
}
|
||||
if(!waittoread(sock)) continue;
|
||||
@@ -285,7 +284,7 @@ static void client_(char *FITSpath, int infd, int sock){
|
||||
}
|
||||
rlc(offset);
|
||||
recvBuff[offset] = 0;
|
||||
DBG("read %zd bytes", offset);
|
||||
//DBG("read %zd bytes", offset);
|
||||
parse_data(recvBuff, &last_good_msrment);
|
||||
}
|
||||
}
|
||||
@@ -305,7 +304,7 @@ void daemonize(glob_pars *G){
|
||||
// run fork before socket opening to prevent daemon's death if there's no network
|
||||
#ifndef EBUG
|
||||
green("Daemonize\n");
|
||||
if(daemon(1, 0)){
|
||||
if(daemon(1, 0))
|
||||
ERR("daemon()");
|
||||
while(1){ // guard for dead processes
|
||||
pid_t childpid = fork();
|
||||
@@ -318,7 +317,7 @@ void daemonize(glob_pars *G){
|
||||
prctl(PR_SET_PDEATHSIG, SIGTERM); // send SIGTERM to child when parent dies
|
||||
break; // go out to normal functional
|
||||
}
|
||||
}}
|
||||
}
|
||||
#endif
|
||||
int sock = -1;
|
||||
struct addrinfo hints, *res, *p;
|
||||
|
||||
Reference in New Issue
Block a user