[89463] trunk/base/src/pextlib1.0/system.c
jmr at macports.org
jmr at macports.org
Mon Jan 30 07:37:12 PST 2012
Revision: 89463
http://trac.macports.org/changeset/89463
Author: jmr at macports.org
Date: 2012-01-30 07:37:10 -0800 (Mon, 30 Jan 2012)
Log Message:
-----------
better error handling in SystemCmd
Modified Paths:
--------------
trunk/base/src/pextlib1.0/system.c
Modified: trunk/base/src/pextlib1.0/system.c
===================================================================
--- trunk/base/src/pextlib1.0/system.c 2012-01-30 15:11:29 UTC (rev 89462)
+++ trunk/base/src/pextlib1.0/system.c 2012-01-30 15:37:10 UTC (rev 89463)
@@ -132,12 +132,14 @@
* popen() itself is not used because stderr is also desired.
*/
if (pipe(fdset) != 0) {
+ Tcl_SetResult(interp, strerror(errno), TCL_STATIC);
return TCL_ERROR;
}
pid = fork();
switch (pid) {
case -1: /* error */
+ Tcl_SetResult(interp, strerror(errno), TCL_STATIC);
return TCL_ERROR;
break;
case 0: /* child */
@@ -193,47 +195,52 @@
pos = 0;
memset(circbuf, 0, sizeof(circbuf));
pdes = fdopen(fdset[0], "r");
- while ((buf = fgetln(pdes, &linelen)) != NULL) {
- char *sbuf;
- int slen;
-
- /*
- * Allocate enough space to insert a terminating
- * '\0' if the line is not terminated with a '\n'
- */
- if (buf[linelen - 1] == '\n')
- slen = linelen;
- else
- slen = linelen + 1;
-
- if (circbuf[pos].len == 0)
- sbuf = malloc(slen);
- else {
- sbuf = realloc(circbuf[pos].line, slen);
+ if (pdes) {
+ while ((buf = fgetln(pdes, &linelen)) != NULL) {
+ char *sbuf;
+ int slen;
+
+ /*
+ * Allocate enough space to insert a terminating
+ * '\0' if the line is not terminated with a '\n'
+ */
+ if (buf[linelen - 1] == '\n')
+ slen = linelen;
+ else
+ slen = linelen + 1;
+
+ if (circbuf[pos].len == 0)
+ sbuf = malloc(slen);
+ else {
+ sbuf = realloc(circbuf[pos].line, slen);
+ }
+
+ if (sbuf == NULL) {
+ read_failed = 1;
+ break;
+ }
+
+ memcpy(sbuf, buf, linelen);
+ /* terminate line with '\0',replacing '\n' if it exists */
+ sbuf[slen - 1] = '\0';
+
+ circbuf[pos].line = sbuf;
+ circbuf[pos].len = slen;
+
+ if (pos++ == CBUFSIZ - 1) {
+ pos = 0;
+ }
+
+ if (ui_info(interp, sbuf) != TCL_OK) {
+ read_failed = 1;
+ break;
+ }
}
-
- if (sbuf == NULL) {
- read_failed = 1;
- break;
- }
-
- memcpy(sbuf, buf, linelen);
- /* terminate line with '\0',replacing '\n' if it exists */
- sbuf[slen - 1] = '\0';
-
- circbuf[pos].line = sbuf;
- circbuf[pos].len = slen;
-
- if (pos++ == CBUFSIZ - 1) {
- pos = 0;
- }
-
- if (ui_info(interp, sbuf) != TCL_OK) {
- read_failed = 1;
- break;
- }
+ fclose(pdes);
+ } else {
+ read_failed = 1;
+ Tcl_SetResult(interp, strerror(errno), TCL_STATIC);
}
- fclose(pdes);
status = TCL_ERROR;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macports-changes/attachments/20120130/8c03cf3a/attachment.html>
More information about the macports-changes
mailing list