| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
#ifdef HAVE_CONFIG_H |
|---|
| 20 |
# include <config.h> |
|---|
| 21 |
#endif |
|---|
| 22 |
#include "util.h" |
|---|
| 23 |
|
|---|
| 24 |
#include <errno.h> |
|---|
| 25 |
#include <string.h> |
|---|
| 26 |
#include <fcntl.h> |
|---|
| 27 |
#include <unistd.h> |
|---|
| 28 |
|
|---|
| 29 |
#define ENSC_WRAPPERS_PREFIX "chain-echo: " |
|---|
| 30 |
#define ENSC_WRAPPERS_FCNTL 1 |
|---|
| 31 |
#define ENSC_WRAPPERS_UNISTD 1 |
|---|
| 32 |
#define ENSC_WRAPPERS_IO 1 |
|---|
| 33 |
#include <wrappers.h> |
|---|
| 34 |
|
|---|
| 35 |
int wrapper_exit_code = 255; |
|---|
| 36 |
|
|---|
| 37 |
static void |
|---|
| 38 |
showHelp(char const *cmd) |
|---|
| 39 |
{ |
|---|
| 40 |
WRITE_MSG(1, "Usage: "); |
|---|
| 41 |
WRITE_STR(1, cmd); |
|---|
| 42 |
WRITE_MSG(1, |
|---|
| 43 |
" [--] <file> <data> <command> <args>*\n\n" |
|---|
| 44 |
"Please report bugs to " PACKAGE_BUGREPORT "\n"); |
|---|
| 45 |
exit(0); |
|---|
| 46 |
} |
|---|
| 47 |
|
|---|
| 48 |
static void |
|---|
| 49 |
showVersion() |
|---|
| 50 |
{ |
|---|
| 51 |
WRITE_MSG(1, |
|---|
| 52 |
"chain-echo " VERSION " -- puts data into a file within a command-chain\n" |
|---|
| 53 |
"This program is part of " PACKAGE_STRING "\n\n" |
|---|
| 54 |
"Copyright (C) 2004 Enrico Scholz\n" |
|---|
| 55 |
VERSION_COPYRIGHT_DISCLAIMER); |
|---|
| 56 |
exit(0); |
|---|
| 57 |
} |
|---|
| 58 |
|
|---|
| 59 |
int main(int argc, char *argv[]) |
|---|
| 60 |
{ |
|---|
| 61 |
int idx = 1; |
|---|
| 62 |
int fd; |
|---|
| 63 |
|
|---|
| 64 |
if (argc>=2) { |
|---|
| 65 |
if (strcmp(argv[1], "--help") ==0) showHelp(argv[0]); |
|---|
| 66 |
if (strcmp(argv[1], "--version")==0) showVersion(); |
|---|
| 67 |
if (strcmp(argv[1], "--") ==0) ++idx; |
|---|
| 68 |
} |
|---|
| 69 |
|
|---|
| 70 |
if (argc<idx+3) { |
|---|
| 71 |
WRITE_MSG(2, "Not enough parameters; use '--help' for more information\n"); |
|---|
| 72 |
return wrapper_exit_code; |
|---|
| 73 |
} |
|---|
| 74 |
|
|---|
| 75 |
if (argv[idx][0]=='\0') |
|---|
| 76 |
fd = 1; |
|---|
| 77 |
else { |
|---|
| 78 |
fd = Eopen(argv[idx], O_WRONLY|O_NOFOLLOW, 0600); |
|---|
| 79 |
Efcntl(fd, F_SETFD, FD_CLOEXEC); |
|---|
| 80 |
} |
|---|
| 81 |
|
|---|
| 82 |
if (argv[idx+1][0]!='\0') |
|---|
| 83 |
EwriteAll(fd, argv[idx+1], strlen(argv[idx+1])); |
|---|
| 84 |
|
|---|
| 85 |
Eexecv(argv[idx+2], argv+idx+2); |
|---|
| 86 |
} |
|---|