git://git.jankratochvil.net
/
gnokii.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
VM_ThreadLoop select() silently restarted when EINTR
[gnokii.git]
/
common
/
data
/
virtmodem.c
diff --git
a/common/data/virtmodem.c
b/common/data/virtmodem.c
index
7c7f4e2
..
2ff532a
100644
(file)
--- a/
common/data/virtmodem.c
+++ b/
common/data/virtmodem.c
@@
-35,8
+35,10
@@
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
+#ifndef UCLINUX
#include <sys/poll.h>
#include <pthread.h>
#include <sys/poll.h>
#include <pthread.h>
+#endif /* UCLINUX */
#include <unistd.h>
#include "misc.h"
#include <unistd.h>
#include "misc.h"
@@
-50,30
+52,25
@@
/* Global variables */
//extern bool TerminateThread;
/* Global variables */
//extern bool TerminateThread;
-int ConnectCount;
/* Local variables */
int PtyRDFD; /* File descriptor for reading and writing to/from */
int PtyWRFD; /* pty interface - only different in debug mode. */
/* Local variables */
int PtyRDFD; /* File descriptor for reading and writing to/from */
int PtyWRFD; /* pty interface - only different in debug mode. */
-
bool
UseSTDIO; /* Use STDIO for debugging purposes instead of pty */
+
static bool
UseSTDIO; /* Use STDIO for debugging purposes instead of pty */
bool CommandMode;
bool CommandMode;
-
pthread_t Thread
;
-
bool RequestTerminate
;
-
+
static bool VM_ThreadLoop(void)
;
+
static GSM_Error VM_GSMInitialise(char *model, char *port, char *initlength, GSM_ConnectionType connection, char *synchronizetime)
;
+static int VM_PtySetup(char *bindir);
/* If initialised in debug mode, stdin/out is used instead
of ptys for interface. */
/* If initialised in debug mode, stdin/out is used instead
of ptys for interface. */
-bool
VM_Initialise(char *model,char *port, char *initlength, GSM_ConnectionType connection, char *bindir, bool debug_mode, bool GSMInit,char *synchronizetime)
+bool VM_Initialise(char *model,char *port, char *initlength, GSM_ConnectionType connection, char *bindir, bool debug_mode, bool GSMInit,char *synchronizetime)
{
{
- int rtn;
-
CommandMode = true;
CommandMode = true;
- RequestTerminate = false;
-
if (debug_mode == true) {
UseSTDIO = true;
}
if (debug_mode == true) {
UseSTDIO = true;
}
@@
-108,45
+105,47
@@
bool VM_Initialise(char *model,char *port, char *initlength, GSM_ConnectionType
return (false);
}
return (false);
}
- /* Create and start thread, */
- rtn = pthread_create(&Thread, NULL, (void *) VM_ThreadLoop, (void *)NULL);
-
- if (rtn == EAGAIN || rtn == EINVAL) {
- return (false);
- }
- return (true);
+ /* Create and start thread, */
+ return VM_ThreadLoop();
}
}
-void VM_ThreadLoop(void)
+static void VM_CharHandler(void);
+
+static bool VM_ThreadLoop(void)
{
int res;
{
int res;
- struct pollfd ufds;
+ fd_set readfds;
+ struct timeval timeout;
/* Note we can't use signals here as they are already used
in the FBUS code. This may warrant changing the FBUS
code around sometime to use select instead to free up
the SIGIO handler for mainline code. */
/* Note we can't use signals here as they are already used
in the FBUS code. This may warrant changing the FBUS
code around sometime to use select instead to free up
the SIGIO handler for mainline code. */
- ufds.fd=PtyRDFD;
- ufds.events=POLLIN;
-
- while (!RequestTerminate) {
+ for (;;) {
if (!CommandMode) {
sleep(1);
} else { /* If we are in data mode, leave it to datapump to get the data */
if (!CommandMode) {
sleep(1);
} else { /* If we are in data mode, leave it to datapump to get the data */
- res=poll(&ufds,1,500);
+ FD_ZERO(&readfds);
+ FD_SET(PtyRDFD,&readfds);
+ timeout.tv_sec=0;
+ timeout.tv_usec=500*1000;
+
+ res = select(PtyRDFD+1,&readfds,NULL/*writefds*/,NULL/*exceptfds*/,&timeout);
switch (res) {
case 0: /* Timeout */
break;
case -1:
switch (res) {
case 0: /* Timeout */
break;
case -1:
+ if (errno==EINTR)
+ continue;
perror("VM_ThreadLoop - select");
perror("VM_ThreadLoop - select");
-
exit (-1
);
+
return (false
);
default:
default:
- if (
ufds.revents==POLLIN
) {
+ if (
FD_ISSET(PtyRDFD,&readfds)
) {
VM_CharHandler();
} else usleep(500); /* Probably the file has been closed */
break;
VM_CharHandler();
} else usleep(500); /* Probably the file has been closed */
break;
@@
-160,34
+159,35
@@
void VM_ThreadLoop(void)
the virtual modem thread */
void VM_Terminate(void)
{
the virtual modem thread */
void VM_Terminate(void)
{
-
- /* Request termination of thread */
- RequestTerminate = true;
-
- /* Now wait for thread to terminate. */
- pthread_join(Thread, NULL);
-
if (!UseSTDIO) {
close (PtyRDFD);
close (PtyWRFD);
}
}
if (!UseSTDIO) {
close (PtyRDFD);
close (PtyWRFD);
}
}
+static int VM_GetMasterPty(char **name);
+
/* Open pseudo tty interface and (in due course create a symlink
to be /dev/gnokii etc. ) */
/* Open pseudo tty interface and (in due course create a symlink
to be /dev/gnokii etc. ) */
-
int
VM_PtySetup(char *bindir)
+
static int
VM_PtySetup(char *bindir)
{
int err;
{
int err;
+#ifndef UCLINUX
char mgnokiidev[200];
char mgnokiidev[200];
+#endif /* UCLINUX */
char *slave_name;
char *slave_name;
+#ifndef UCLINUX
char cmdline[200];
char cmdline[200];
+#endif /* UCLINUX */
+#ifndef UCLINUX
if (bindir) {
strncpy(mgnokiidev, bindir, 200);
strcat(mgnokiidev, "/");
}
strncat(mgnokiidev, "mgnokiidev", 200 - strlen(bindir));
if (bindir) {
strncpy(mgnokiidev, bindir, 200);
strcat(mgnokiidev, "/");
}
strncat(mgnokiidev, "mgnokiidev", 200 - strlen(bindir));
+#endif /* UCLINUX */
if (UseSTDIO) {
PtyRDFD = STDIN_FILENO;
if (UseSTDIO) {
PtyRDFD = STDIN_FILENO;
@@
-202,22
+202,40
@@
int VM_PtySetup(char *bindir)
}
PtyWRFD = PtyRDFD;
}
PtyWRFD = PtyRDFD;
+#ifndef UCLINUX
/* Check we haven't been installed setuid root for some reason
if so, don't create /dev/gnokii */
if (getuid() != geteuid()) {
fprintf(stderr, _("gnokiid should not be installed setuid root!\n"));
return (0);
}
/* Check we haven't been installed setuid root for some reason
if so, don't create /dev/gnokii */
if (getuid() != geteuid()) {
fprintf(stderr, _("gnokiid should not be installed setuid root!\n"));
return (0);
}
+#endif
#ifdef DEBUG
#ifdef DEBUG
- fprintf (stderr, _("Slave pty is %s, calling %s to create /dev/gnokii.\n"), slave_name, mgnokiidev);
+ fprintf (stderr, _("Slave pty is %s, calling %s to create /dev/gnokii.\n"), slave_name,
+#ifndef UCLINUX
+ mgnokiidev
+#else /* UCLINUX */
+ "<uClinux>"
+#endif /* UCLINUX */
+ );
#endif /* DEBUG */
#endif /* DEBUG */
+#ifndef UCLINUX
/* Create command line, something line ./mkgnokiidev ttyp0 */
sprintf(cmdline, "%s %s", mgnokiidev, slave_name);
/* And use system to call it. */
err = system (cmdline);
/* Create command line, something line ./mkgnokiidev ttyp0 */
sprintf(cmdline, "%s %s", mgnokiidev, slave_name);
/* And use system to call it. */
err = system (cmdline);
+#else /* UCLINUX */
+
+ /* Remove symlink in case it already exists. Don't care if it fails. */
+ unlink ("/dev/gnokii");
+
+ /* Create symlink */
+ err = symlink(slave_name, "/dev/gnokii");
+
+#endif /* UCLINUX */
return (err);
return (err);
@@
-225,7
+243,7
@@
int VM_PtySetup(char *bindir)
/* Handler called when characters received from serial port.
calls state machine code to process it. */
/* Handler called when characters received from serial port.
calls state machine code to process it. */
-void VM_CharHandler(void)
+
static
void VM_CharHandler(void)
{
unsigned char buffer[255];
int res;
{
unsigned char buffer[255];
int res;
@@
-250,7
+268,7
@@
void VM_CharHandler(void)
}
/* Initialise GSM interface, returning GSM_Error as appropriate */
}
/* Initialise GSM interface, returning GSM_Error as appropriate */
-
GSM_Error
VM_GSMInitialise(char *model, char *port, char *initlength, GSM_ConnectionType connection, char *synchronizetime)
+
static GSM_Error
VM_GSMInitialise(char *model, char *port, char *initlength, GSM_ConnectionType connection, char *synchronizetime)
{
int count=0;
GSM_Error error;
{
int count=0;
GSM_Error error;
@@
-289,7
+307,7
@@
GSM_Error VM_GSMInitialise(char *model, char *port, char *initlength, GSM_Conne
Applications by Troan and Johnson */
Applications by Troan and Johnson */
-
int
VM_GetMasterPty(char **name) {
+
static int
VM_GetMasterPty(char **name) {
#ifdef USE_UNIX98PTYS
int master, err;
#ifdef USE_UNIX98PTYS
int master, err;