|
|
@ -1,18 +1,19 @@ |
|
|
|
/* |
|
|
|
* --- T2-COPYRIGHT-NOTE-BEGIN --- |
|
|
|
* --- SDE-COPYRIGHT-NOTE-BEGIN --- |
|
|
|
* This copyright note is auto-generated by ./scripts/Create-CopyPatch. |
|
|
|
* |
|
|
|
* T2 SDE: misc/tools-source/cmd_wrapper.c |
|
|
|
* |
|
|
|
* Filename: src/tools-source/cmd_wrapper.c |
|
|
|
* Copyright (C) 2013 The OpenSDE Project |
|
|
|
* Copyright (C) 2004 - 2006 The T2 SDE Project |
|
|
|
* Copyright (C) 1998 - 2003 Clifford Wolf |
|
|
|
* |
|
|
|
* |
|
|
|
* More information can be found in the files COPYING and README. |
|
|
|
* |
|
|
|
* |
|
|
|
* This program is free software; you can redistribute it and/or modify |
|
|
|
* it under the terms of the GNU General Public License as published by |
|
|
|
* the Free Software Foundation; version 2 of the License. A copy of the |
|
|
|
* GNU General Public License can be found in the file COPYING. |
|
|
|
* --- T2-COPYRIGHT-NOTE-END --- |
|
|
|
* --- SDE-COPYRIGHT-NOTE-END --- |
|
|
|
* |
|
|
|
* Generic command wrapper. |
|
|
|
* |
|
|
@ -58,6 +59,38 @@ |
|
|
|
#define VERBOSE_DEBUG 1 |
|
|
|
int debug=1; |
|
|
|
|
|
|
|
static inline ssize_t write2(int fd, const char *buf, size_t count) |
|
|
|
{ |
|
|
|
int wc, wt = 0; |
|
|
|
while (count > 0) { |
|
|
|
wc = write(fd, buf, count); |
|
|
|
if (wc > 0) { |
|
|
|
wt += wc; |
|
|
|
count -= count; |
|
|
|
buf += wc; |
|
|
|
} else if (wc < 0 && errno != EINTR) { |
|
|
|
fprintf(stderr, "cmd_wrapper: write(%d): %s.\n", fd, strerror(errno)); |
|
|
|
return wc; |
|
|
|
} |
|
|
|
} |
|
|
|
return wt; |
|
|
|
} |
|
|
|
|
|
|
|
static inline ssize_t read2(int fd, char *buf, size_t count) |
|
|
|
{ |
|
|
|
ssize_t rc; |
|
|
|
|
|
|
|
read_retry: |
|
|
|
rc = read(fd, buf, count); |
|
|
|
if (rc < 0) { |
|
|
|
if (errno == EINTR) |
|
|
|
goto read_retry; |
|
|
|
else |
|
|
|
fprintf(stderr, "cmd_wrapper: read(%d): %s.\n", fd, strerror(errno)); |
|
|
|
} |
|
|
|
return rc; |
|
|
|
} |
|
|
|
|
|
|
|
/* |
|
|
|
* Clean config vars before using them |
|
|
|
*/ |
|
|
@ -373,8 +406,8 @@ int main(int argc, char ** argv) { |
|
|
|
|
|
|
|
/* Create content of input file */ |
|
|
|
for (c3=0; c3<c1; c3++) { |
|
|
|
write(infd, newargv[c3], strlen(newargv[c3])); |
|
|
|
write(infd, "\n", 1); |
|
|
|
write2(infd, newargv[c3], strlen(newargv[c3])); |
|
|
|
write2(infd, "\n", 1); |
|
|
|
} |
|
|
|
lseek(infd, 0, SEEK_SET); |
|
|
|
|
|
|
@ -397,7 +430,7 @@ int main(int argc, char ** argv) { |
|
|
|
size_t argvsize = lseek(outfd, 0, SEEK_END); |
|
|
|
char* argvmem = malloc (argvsize + 1); /* might not have trailing \n */ |
|
|
|
lseek(outfd, 0, SEEK_SET); |
|
|
|
read(outfd, argvmem, argvsize); |
|
|
|
read2(outfd, argvmem, argvsize); |
|
|
|
|
|
|
|
int newargc = 64; /* initial newargv size */ |
|
|
|
newargv = malloc( sizeof(char*) * newargc ); |
|
|
|