Skip to content

Commit

Permalink
Merge branch 'magao-x:dev' into upstream_sync
Browse files Browse the repository at this point in the history
  • Loading branch information
stefi07 authored Mar 12, 2024
2 parents 17b3389 + 19e13d4 commit fb86f74
Show file tree
Hide file tree
Showing 202 changed files with 12,114 additions and 5,684 deletions.
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@ apps/bmcCtrl/bmcCtrl
#c
apps/cacaoInterface/cacaoInterface
apps/cameraSim/cameraSim
apps/closedLoopIndi/closedLoopIndi

#d
apps/dmMode/dmMode
apps/dmModulator/dmModulator
apps/dmSpeckle/
apps/dmPokeCenter/dmPokeCenter
apps/dmSpeckle/dmSpeckle

#f
apps/filterWheelCtrl/filterWheelCtrl
Expand Down Expand Up @@ -119,6 +121,7 @@ apps/siglentSDG/siglentSDG
apps/siglentSDG/tests/siglentSDG_test
apps/smc100ccCtrl/smc100ccCtrl
apps/sshDigger/sshDigger
apps/stateRuleEngine/stateRuleEngine
apps/streamCircBuff/streamCircBuff
apps/streamWriter/streamWriter

Expand Down Expand Up @@ -190,3 +193,7 @@ vm/calib/
vm/config/
vm/
*.swp

# Python caches, etc
*.egg-info
__pycache__
4 changes: 2 additions & 2 deletions INDI/INDI/compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ next_token ()
/* looks like a constant.
* leading +- already handled
*/
if (nconsts > MAX_OPX) {
if (nconsts >= MAX_OPX) {
(void) sprintf (err_msg, toomc, MAX_OPX);
return (ERR);
}
Expand All @@ -339,7 +339,7 @@ next_token ()
}
} else if (c == '"') {
/* a variable */
if (nvars > MAX_OPX) {
if (nvars >= MAX_OPX) {
(void) sprintf (err_msg, toomv, MAX_OPX);
return (ERR);
}
Expand Down
42 changes: 29 additions & 13 deletions INDI/INDI/indiserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
*
*/

#define _GNU_SOURCE

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
Expand Down Expand Up @@ -156,7 +158,7 @@ typedef struct {
int err; /* set on fatal error */
int rfd; /* driver's stdout read pipe fd if local, else socket */
int wfd; /* driver's stdin write pipe fd if local, else socket */
FILE *efp; /* driver's stderr read FILE pointer, iff local */
int efd; /* driver's stderr read pipe fd, if local */
pthread_t stderr_thr; /* stderr reader thread */
time_t start; /* time this driver was started */
int restarts; /* n times this process has been restarted */
Expand Down Expand Up @@ -503,7 +505,7 @@ startLocalDvr (DvrInfo *dp)
dp->pid = pid;
dp->rfd = rp[0];
dp->wfd = wp[1];
dp->efp = fdopen (ep[0], "r");
dp->efd = ep[0];
dp->err = 0;
dp->lp = newLilXML();
dp->mp = newMsg();
Expand Down Expand Up @@ -1142,17 +1144,23 @@ driverStderrReaderThread (void *vp)
/* log everthing until error */
while (1) {
/* read next whole line */
if (!fgets (buf, sizeof(buf), dp->efp)) {
if (feof (dp->efp))
logMessage ("from Driver %s: stderr EOF\n", dp->name);
if (ferror(dp->efp))
logMessage ("from Driver %s: stderr %s\n", dp->name, strerror(errno));
return (NULL); /* thread exit */
}
ssize_t rv = read(dp->efd, buf, sizeof(buf)-1);
if(rv == 0)
{
logMessage ("from Driver %s: stderr EOF\n", dp->name);
return NULL;
}
else if(rv < 0)
{
logMessage ("from Driver %s: stderr %s\n", dp->name, strerror(errno));
return NULL;
}
buf[rv] = '\0';

/* prefix each whole line to our stderr, save extra for next time */
logMessage ("Driver %s: %s", dp->name, buf); /* includes nl */
}


/* for lint */
return (NULL);
Expand Down Expand Up @@ -1236,10 +1244,13 @@ driverWriterThread (void *vp)
static void
onDriverError (DvrInfo *dp)
{
logMessage ("Driver %s: reader thread indicates it's time to restart\n", dp->name);
pthread_mutex_lock (&dp->q_lock);
logMessage ("Driver %s: locked mutex to set error condition\n", dp->name);
dp->err = 1;
pthread_cond_signal (&dp->go_cond);
pthread_mutex_unlock (&dp->q_lock);
logMessage ("Driver %s: reader thread signaled go_cond and unlocked q_lock\n", dp->name);
}

/* called by clientReaderThread to inform clientWriterThread it has
Expand Down Expand Up @@ -1340,16 +1351,21 @@ restartDvr (DvrInfo *dp)
else
logMessage ("Driver %s: Unknown exit condition\n", dp->name);
} else {
logMessage ("Driver %s: Killed: %d\n", dp->name,
logMessage ("Driver %s: Killed: %d\n", dp->name,
kill (dp->pid, SIGKILL));
(void) waitpid (dp->pid, &status, WNOHANG);
(void) waitpid (dp->pid, &status, WNOHANG);
}
//int thispid = (int)gettid();
logMessage ("Driver %s: closing dp->efd", dp->name);
close (dp->efd);
logMessage ("Driver %s: closing dp->wfd", dp->name);
close (dp->wfd);
logMessage ("Driver %s: closing dp->rfd", dp->name);
close (dp->rfd);
fclose (dp->efp);
}

/* free memory and locks */
logMessage ("Driver %s: freeing memory and locks\n", dp->name);
for (i = 0; i < dp->nsprops; i++)
free (dp->sprops[i]);
free (dp->sprops);
Expand All @@ -1358,7 +1374,7 @@ restartDvr (DvrInfo *dp)
pthread_mutex_destroy (&dp->q_lock);
pthread_cond_destroy (&dp->go_cond);
pthread_rwlock_destroy (&dp->sprops_rwlock);
if (verbose > 1)
// if (verbose > 1)
logMessage ("Driver %s: draining with %d on queue\n", dp->name, nFQ(dp->msgq));
drainMsgs (dp->msgq);
delFQ (dp->msgq);
Expand Down
27 changes: 20 additions & 7 deletions INDI/libcommon/IndiConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ IndiConnection::~IndiConnection()
//do nothing
}

if(m_fstreamOutput)
if(m_fstreamOutput && m_fstreamOutput != m_fstreamSTDOUT)
{
fclose(m_fstreamOutput);
}
Expand All @@ -118,6 +118,9 @@ void IndiConnection::construct( const string &szName,

// These are the two descriptors we will use to talk to the outside world.
m_fdInput = STDIN_FILENO;

//We start with STDOUT.
m_fstreamSTDOUT = fdopen(STDOUT_FILENO, "w+");
setOutputFd(STDOUT_FILENO);

// setup the signal handler.
Expand Down Expand Up @@ -424,12 +427,22 @@ void IndiConnection::setInputFd( const int &iFd )

void IndiConnection::setOutputFd( const int &iFd )
{
m_fdOutput = iFd;
if(m_fstreamOutput)
{
fclose(m_fstreamOutput);
}
m_fstreamOutput = fdopen(m_fdOutput, "w+");
m_fdOutput = iFd;

//Close if it's open as long as it isn't STDOUT
if(m_fstreamOutput && m_fstreamOutput != m_fstreamSTDOUT)
{
fclose(m_fstreamOutput);
}

if(iFd == STDOUT_FILENO)
{
m_fstreamOutput = m_fstreamSTDOUT;
}
else
{
m_fstreamOutput = fdopen(m_fdOutput, "w+");
}
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 2 additions & 0 deletions INDI/libcommon/IndiConnection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ class IndiConnection : public pcf::Thread
/// Stream for safer output
FILE * m_fstreamOutput {NULL};

FILE * m_fstreamSTDOUT {NULL};

/// If the processing of INDI messages is put in a separate thread,
/// this is the thread id of it.
pthread_t m_idProcessThread;
Expand Down
Loading

0 comments on commit fb86f74

Please sign in to comment.