summaryrefslogtreecommitdiffstats
path: root/serial.c
diff options
context:
space:
mode:
authorNiklas Söderlund <niso@kth.se>2012-07-30 19:42:33 +0000
committerStefan Tauner <stefan.tauner@alumni.tuwien.ac.at>2012-07-30 19:42:33 +0000
commit2a95e8713b941f58a7f5ff94aee38edae70af15d (patch)
treef97dccd7ef57d80a4fbee2c5d23a67869c298cb0 /serial.c
parent00ec027368e5ef46d9dec430124357915dc8b903 (diff)
downloadast2050-flashrom-2a95e8713b941f58a7f5ff94aee38edae70af15d.zip
ast2050-flashrom-2a95e8713b941f58a7f5ff94aee38edae70af15d.tar.gz
Remove more exit calls
This patch removes the remaining exit calls from - sp_openserport - sp_opensocket - sp_docommand - internal_init Almost all of this was done by Niklas. Corresponding to flashrom svn r1557. Signed-off-by: Niklas Söderlund <niso@kth.se> Signed-off-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at> Acked-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at>
Diffstat (limited to 'serial.c')
-rw-r--r--serial.c29
1 files changed, 18 insertions, 11 deletions
diff --git a/serial.c b/serial.c
index 0a56568..7443a3c 100644
--- a/serial.c
+++ b/serial.c
@@ -113,8 +113,10 @@ fdtype sp_openserport(char *dev, unsigned int baud)
(tolower((unsigned char)dev[1]) == 'o') &&
(tolower((unsigned char)dev[2]) == 'm')) {
dev2 = malloc(strlen(dev) + 5);
- if (!dev2)
- sp_die("Error: Out of memory");
+ if (!dev2) {
+ msg_perr("Error: Out of memory: %s\n", strerror(errno));
+ return -1;
+ }
strcpy(dev2, "\\\\.\\");
strcpy(dev2 + 4, dev);
}
@@ -123,11 +125,13 @@ fdtype sp_openserport(char *dev, unsigned int baud)
if (dev2 != dev)
free(dev2);
if (fd == INVALID_HANDLE_VALUE) {
- sp_die("Error: cannot open serial port");
+ msg_perr("Error: cannot open serial port: %s\n", strerror(errno));
+ return -1;
}
DCB dcb;
if (!GetCommState(fd, &dcb)) {
- sp_die("Error: Could not fetch serial port configuration");
+ msg_perr("Error: Could not fetch serial port configuration: %s\n", strerror(errno));
+ return -1;
}
switch (baud) {
case 9600: dcb.BaudRate = CBR_9600; break;
@@ -135,29 +139,32 @@ fdtype sp_openserport(char *dev, unsigned int baud)
case 38400: dcb.BaudRate = CBR_38400; break;
case 57600: dcb.BaudRate = CBR_57600; break;
case 115200: dcb.BaudRate = CBR_115200; break;
- default: sp_die("Error: Could not set baud rate");
+ default: msg_perr("Error: Could not set baud rate: %s\n", strerror(errno));
+ return -1;
}
dcb.ByteSize = 8;
dcb.Parity = NOPARITY;
dcb.StopBits = ONESTOPBIT;
if (!SetCommState(fd, &dcb)) {
- sp_die("Error: Could not change serial port configuration");
+ msg_perr("Error: Could not change serial port configuration: %s\n", strerror(errno));
+ return -1;
}
return fd;
#else
struct termios options;
int fd, i;
fd = open(dev, O_RDWR | O_NOCTTY | O_NDELAY);
- if (fd < 0)
- sp_die("Error: cannot open serial port");
+ if (fd < 0) {
+ msg_perr("Error: cannot open serial port: %s\n", strerror(errno));
+ return -1;
+ }
fcntl(fd, F_SETFL, 0);
tcgetattr(fd, &options);
for (i = 0;; i++) {
if (sp_baudtable[i].baud == 0) {
close(fd);
- msg_perr("Error: cannot configure for baudrate %d\n",
- baud);
- exit(1);
+ msg_perr("Error: cannot configure for baudrate %d\n", baud);
+ return -1;
}
if (sp_baudtable[i].baud == baud) {
cfsetispeed(&options, sp_baudtable[i].flag);
OpenPOWER on IntegriCloud