[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[SCM] libgnokii and core programs branch, master, updated. rel_0_6_29-33
From: |
Pawel Kot |
Subject: |
[SCM] libgnokii and core programs branch, master, updated. rel_0_6_29-337-g4d38aee |
Date: |
Sat, 24 Dec 2011 13:53:41 +0000 |
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "libgnokii and core programs".
The branch, master has been updated
via 4d38aee466e61305538c25bb505c5de4e5369832 (commit)
from 9e5af7fa0566ac8b66db8caed89995699340c7a3 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://git.savannah.gnu.org/cgit/gnokii.git/commit/?id=4d38aee466e61305538c25bb505c5de4e5369832
commit 4d38aee466e61305538c25bb505c5de4e5369832
Author: Pawel Kot <address@hidden>
Date: Sat Dec 24 00:52:59 2011 +0100
Make device_script() generic for all connection types.
Currently device_script() was executed only for unixserial and tcp device
drivers. This change makes it generic -- for all connection types. It
moves also the execution after the full open procedure is executed. So far
in unixserial some additional device settings were executed afterwards.
diff --git a/ChangeLog b/ChangeLog
index b7f3b1a..104c995 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,9 @@
driver (PaweÅ Kot)
o add optional authentication during the initialization phase
(PaweÅ Kot)
+ o move device_script() to generic device; it will cause ability
+ to execute connect_script and disconnect_script with all
+ connection types (PaweÅ Kot)
* at driver updates
o in the default case autodetect if PDU SMS starts with SMSC
(Daniele Forsi)
diff --git a/common/device.c b/common/device.c
index 0b0d29e..64d3fdd 100644
--- a/common/device.c
+++ b/common/device.c
@@ -8,7 +8,7 @@
Copyright (C) 1999-2000 Hugh Blemings & Pavel Janík ml.
Copyright (C) 2001 Chris Kemp
- Copyrught (C) 2001-2004 Pawel Kot
+ Copyrught (C) 2001-2011 Pawel Kot
Copyright (C) 2002-2003 BORBELY Zoltan
Copyright (C) 2002 Pavel Machek, Marcin Wiacek
@@ -27,11 +27,65 @@
#include "devices/dku2libusb.h"
#include "devices/socketphonet.h"
+#include <errno.h>
+
GNOKII_API int device_getfd(struct gn_statemachine *state)
{
return state->device.fd;
}
+/* Script handling: */
+static void device_script_cfgfunc(const char *section, const char *key, const
char *value)
+{
+ setenv(key, value, 1); /* errors ignored */
+}
+
+int device_script(int fd, const char *section, struct gn_statemachine *state)
+{
+ pid_t pid;
+ const char *scriptname;
+ int status;
+
+ if (!strcmp(section, "connect_script"))
+ scriptname = state->config.connect_script;
+ else
+ scriptname = state->config.disconnect_script;
+ if (scriptname[0] == '\0')
+ return 0;
+
+ errno = 0;
+ switch ((pid = fork())) {
+ case -1:
+ fprintf(stderr, _("device_script(\"%s\"): fork() failure:
%s!\n"), scriptname, strerror(errno));
+ return -1;
+
+ case 0: /* child */
+ cfg_foreach(section, device_script_cfgfunc);
+ errno = 0;
+ if (dup2(fd, 0) != 0 || dup2(fd, 1) != 1 || close(fd)) {
+ fprintf(stderr, _("device_script(\"%s\"): file
descriptor preparation failure: %s\n"), scriptname, strerror(errno));
+ _exit(-1);
+ }
+ /* FIXME: close all open descriptors - how to track them?
+ */
+ execl("/bin/sh", "sh", "-c", scriptname, NULL);
+ fprintf(stderr, _("device_script(\"%s\"): script execution
failure: %s\n"), scriptname, strerror(errno));
+ _exit(-1);
+ /* NOTREACHED */
+
+ default:
+ if (pid == waitpid(pid, &status, 0 /* options */) &&
WIFEXITED(status) && !WEXITSTATUS(status))
+ return 0;
+ fprintf(stderr, _("device_script(\"%s\"): child script
execution failure: %s, exit code=%d\n"), scriptname,
+ (WIFEXITED(status) ? _("normal exit") : _("abnormal
exit")),
+ (WIFEXITED(status) ? WEXITSTATUS(status) : -1));
+ errno = EIO;
+ return -1;
+
+ }
+ /* NOTREACHED */
+}
+
int device_open(const char *file, int with_odd_parity, int with_async,
int with_hw_handshake, gn_connection_type device_type,
struct gn_statemachine *state)
@@ -39,7 +93,7 @@ int device_open(const char *file, int with_odd_parity, int
with_async,
state->device.type = device_type;
state->device.device_instance = NULL;
- dprintf("Serial device: opening device %s\n", (device_type ==
GN_CT_DKU2LIBUSB) ? "USB" : file);
+ dprintf("device: opening device %s\n", (device_type ==
GN_CT_DKU2LIBUSB) ? "USB" : file);
switch (state->device.type) {
case GN_CT_DKU2:
@@ -69,12 +123,27 @@ int device_open(const char *file, int with_odd_parity, int
with_async,
state->device.fd = -1;
break;
}
+ /*
+ * handle config file connect_script:
+ */
+ if (device_script(state->device.fd, "connect_script", state) == -1) {
+ dprintf("gnokii open device: connect_script\n");
+ device_close(state);
+ return 0;
+ }
+
return (state->device.fd >= 0);
}
void device_close(struct gn_statemachine *state)
{
- dprintf("Serial device: closing device\n");
+ dprintf("device: closing device\n");
+
+ /*
+ * handle config file disconnect_script:
+ */
+ if (device_script(state->device.fd, "disconnect_script", state) == -1)
+ dprintf("gnokii device close: disconnect_script\n");
switch (state->device.type) {
case GN_CT_DKU2:
@@ -119,7 +188,7 @@ void device_setdtrrts(int dtr, int rts, struct
gn_statemachine *state)
case GN_CT_DKU2:
case GN_CT_Serial:
case GN_CT_Infrared:
- dprintf("Serial device: setting RTS to %s and DTR to %s\n", rts
? "high" : "low", dtr ? "high" : "low");
+ dprintf("device: setting RTS to %s and DTR to %s\n", rts ?
"high" : "low", dtr ? "high" : "low");
serial_setdtrrts(state->device.fd, dtr, rts, state);
break;
case GN_CT_Irda:
@@ -139,11 +208,11 @@ void device_changespeed(int speed, struct gn_statemachine
*state)
case GN_CT_DKU2:
case GN_CT_Serial:
case GN_CT_Infrared:
- dprintf("Serial device: setting speed to %d\n", speed);
+ dprintf("device: setting speed to %d\n", speed);
serial_changespeed(state->device.fd, speed, state);
break;
case GN_CT_Tekram:
- dprintf("Serial device: setting speed to %d\n", speed);
+ dprintf("device: setting speed to %d\n", speed);
tekram_changespeed(state->device.fd, speed, state);
break;
case GN_CT_Irda:
diff --git a/common/devices/tcp.c b/common/devices/tcp.c
index 362d6bf..565c51a 100644
--- a/common/devices/tcp.c
+++ b/common/devices/tcp.c
@@ -15,7 +15,6 @@
#include "config.h"
#include "misc.h"
#include "devices/tcp.h"
-#include "devices/serial.h"
#ifndef WIN32
@@ -145,11 +144,6 @@ fail_close:
int tcp_close(int fd, struct gn_statemachine *state)
{
- /* handle config file disconnect_script:
- */
- if (device_script(fd, "disconnect_script", state) == -1)
- fprintf(stderr, _("Gnokii tcp_close: disconnect_script\n"));
-
return close(fd);
}
@@ -168,17 +162,8 @@ int tcp_opendevice(const char *file, int with_async,
struct gn_statemachine *sta
if (fd < 0)
return fd;
- /* handle config file connect_script:
- */
- if (device_script(fd, "connect_script", state) == -1) {
- fprintf(stderr, _("Gnokii tcp_opendevice: connect_script\n"));
- tcp_close(fd, state);
- return -1;
- }
-
- /* Allow process/thread to receive SIGIO */
-
#if !(__unices__)
+ /* Allow process/thread to receive SIGIO */
retcode = fcntl(fd, F_SETOWN, getpid());
if (retcode == -1) {
perror(_("Gnokii tcp_opendevice: fcntl(F_SETOWN)"));
diff --git a/common/devices/unixserial.c b/common/devices/unixserial.c
index b9584f8..e4eefc4 100644
--- a/common/devices/unixserial.c
+++ b/common/devices/unixserial.c
@@ -9,7 +9,7 @@
Copyright (C) 1999-2000 Hugh Blemings & Pavel Janik ml.
Copyright (C) 2001 Chris Kemp, Manfred Jonsson, Jank Kratochvil
Copyright (C) 2002 Ladis Michl, Pavel Machek
- Copyright (C) 2001-2004 Pawel Kot
+ Copyright (C) 2001-2011 Pawel Kot
Copyright (C) 2002-2004 BORBELY Zoltan
*/
@@ -76,63 +76,8 @@ static int cfsetspeed(struct termios *t, int speed)
/* Structure to backup the setting of the terminal. */
struct termios serial_termios;
-/* Script handling: */
-static void device_script_cfgfunc(const char *section, const char *key, const
char *value)
-{
- setenv(key, value, 1); /* errors ignored */
-}
-
-int device_script(int fd, const char *section, struct gn_statemachine *state)
-{
- pid_t pid;
- const char *scriptname;
- int status;
-
- if (!strcmp(section, "connect_script"))
- scriptname = state->config.connect_script;
- else
- scriptname = state->config.disconnect_script;
- if (scriptname[0] == '\0')
- return 0;
-
- errno = 0;
- switch ((pid = fork())) {
- case -1:
- fprintf(stderr, _("device_script(\"%s\"): fork() failure:
%s!\n"), scriptname, strerror(errno));
- return -1;
-
- case 0: /* child */
- cfg_foreach(section, device_script_cfgfunc);
- errno = 0;
- if (dup2(fd, 0) != 0 || dup2(fd, 1) != 1 || close(fd)) {
- fprintf(stderr, _("device_script(\"%s\"): file
descriptor preparation failure: %s\n"), scriptname, strerror(errno));
- _exit(-1);
- }
- /* FIXME: close all open descriptors - how to track them?
- */
- execl("/bin/sh", "sh", "-c", scriptname, NULL);
- fprintf(stderr, _("device_script(\"%s\"): script execution
failure: %s\n"), scriptname, strerror(errno));
- _exit(-1);
- /* NOTREACHED */
-
- default:
- if (pid == waitpid(pid, &status, 0 /* options */) &&
WIFEXITED(status) && !WEXITSTATUS(status))
- return 0;
- fprintf(stderr, _("device_script(\"%s\"): child script
execution failure: %s, exit code=%d\n"), scriptname,
- (WIFEXITED(status) ? _("normal exit") : _("abnormal
exit")),
- (WIFEXITED(status) ? WEXITSTATUS(status) : -1));
- errno = EIO;
- return -1;
-
- }
- /* NOTREACHED */
-}
-
-
-int serial_close(int fd, struct gn_statemachine *state);
-
-
-/* Open the serial port and store the settings.
+/*
+ * Open the serial port and store the settings.
* Returns a file descriptor on success, or -1 if an error occurred.
*/
int serial_open(const char *file, int oflag)
@@ -157,16 +102,12 @@ int serial_open(const char *file, int oflag)
return fd;
}
-/* Close the serial port and restore old settings.
+/*
+ * Close the serial port and restore old settings.
* Returns zero on success, -1 if an error occurred or fd was invalid.
*/
int serial_close(int fd, struct gn_statemachine *state)
{
- /* handle config file disconnect_script:
- */
- if (device_script(fd, "disconnect_script", state) == -1)
- dprintf("Gnokii serial_close: disconnect_script\n");
-
if (fd >= 0) {
serial_termios.c_cflag |= HUPCL; /* production == 1 */
tcsetattr(fd, TCSANOW, &serial_termios);
@@ -176,7 +117,8 @@ int serial_close(int fd, struct gn_statemachine *state)
return -1;
}
-/* Open a device with standard options.
+/*
+ * Open a device with standard options.
* Use value (-1) for "with_hw_handshake" if its specification is required
from the user.
*/
int serial_opendevice(const char *file, int with_odd_parity,
@@ -189,7 +131,8 @@ int serial_opendevice(const char *file, int with_odd_parity,
/* Open device */
- /* O_NONBLOCK MUST be used here as the CLOCAL may be currently off
+ /*
+ * O_NONBLOCK MUST be used here as the CLOCAL may be currently off
* and if DCD is down the "open" syscall would be stuck waiting for DCD.
*/
fd = serial_open(file, O_RDWR | O_NOCTTY | O_NONBLOCK);
@@ -235,28 +178,8 @@ int serial_opendevice(const char *file, int
with_odd_parity,
if (serial_changespeed(fd, state->config.serial_baudrate, state) !=
GN_ERR_NONE)
serial_changespeed(fd, 19200 /* default value */, state);
- /* We need to turn off O_NONBLOCK now (we have CLOCAL set so it is
safe).
- * When we run some device script it really doesn't expect NONBLOCK!
- */
-
- retcode = fcntl(fd, F_SETFL, 0);
- if (retcode == -1) {
- perror("Gnokii serial_opendevice: fcntl(F_SETFL)");
- serial_close(fd, state);
- return -1;
- }
-
- /* handle config file connect_script:
- */
- if (device_script(fd, "connect_script", state) == -1) {
- dprintf("Gnokii serial_opendevice: connect_script\n");
- serial_close(fd, state);
- return -1;
- }
-
- /* Allow process/thread to receive SIGIO */
-
#if !(__unices__)
+ /* Allow process/thread to receive SIGIO */
retcode = fcntl(fd, F_SETOWN, getpid());
if (retcode == -1) {
perror("Gnokii serial_opendevice: fcntl(F_SETOWN)");
@@ -267,7 +190,8 @@ int serial_opendevice(const char *file, int with_odd_parity,
/* Make filedescriptor asynchronous. */
if (with_async) {
- /* We need to supply FNONBLOCK (or O_NONBLOCK) again as it
would get reset
+ /*
+ * We need to supply FNONBLOCK (or O_NONBLOCK) again as it
would get reset
* by F_SETFL as a side-effect!
*/
#ifdef FNONBLOCK
@@ -336,7 +260,8 @@ static int serial_wselect(int fd, struct timeval *timeout,
struct gn_statemachin
}
-/* Change the speed of the serial device.
+/*
+ * Change the speed of the serial device.
* RETURNS: Success
*/
gn_error serial_changespeed(int fd, int speed, struct gn_statemachine *state)
diff --git a/include/devices/serial.h b/include/devices/serial.h
index 532b683..cb56a82 100644
--- a/include/devices/serial.h
+++ b/include/devices/serial.h
@@ -33,6 +33,4 @@ int serial_select(int fd, struct timeval *timeout, struct
gn_statemachine *state
gn_error serial_nreceived(int fd, int *n, struct gn_statemachine *state);
gn_error serial_flush(int fd, struct gn_statemachine *state);
-extern int device_script(int fd, const char *section, struct gn_statemachine
*state);
-
#endif /* __devices_serial_h */
-----------------------------------------------------------------------
Summary of changes:
ChangeLog | 3 +
common/device.c | 81 +++++++++++++++++++++++++++++++---
common/devices/tcp.c | 17 +-------
common/devices/unixserial.c | 103 ++++++-------------------------------------
include/devices/serial.h | 2 -
5 files changed, 93 insertions(+), 113 deletions(-)
hooks/post-receive
--
libgnokii and core programs
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [SCM] libgnokii and core programs branch, master, updated. rel_0_6_29-337-g4d38aee,
Pawel Kot <=