36 |
#include "strbuf.h" |
#include "strbuf.h" |
37 |
#include "xargs.h" |
#include "xargs.h" |
38 |
|
|
39 |
|
static int exec_line_limit(int); |
40 |
static char *repeat_find_read(void); |
static char *repeat_find_read(void); |
41 |
static void repeat_find_next(void); |
static void repeat_find_next(void); |
42 |
static FILE *execute_command(XARGS *); |
static FILE *execute_command(XARGS *); |
56 |
* xargs_close(xp); |
* xargs_close(xp); |
57 |
*/ |
*/ |
58 |
/* |
/* |
59 |
|
* exec_line_limit: upper limit of bytes of exec line. |
60 |
|
* |
61 |
|
* i) length command line length |
62 |
|
* r) 0: unknown or cannot afford long line. |
63 |
|
* > 0: upper limit of exec line |
64 |
|
*/ |
65 |
|
static int |
66 |
|
exec_line_limit(int length) |
67 |
|
{ |
68 |
|
int limit = 0; |
69 |
|
|
70 |
|
#ifdef ARG_MAX |
71 |
|
/* |
72 |
|
* POSIX.2 limits the exec(2) line length to ARG_MAX - 2048. |
73 |
|
*/ |
74 |
|
limit = ARG_MAX - 2048; |
75 |
|
/* |
76 |
|
* The reason is unknown but the xargs(1) in GNU findutils |
77 |
|
* use this limit. |
78 |
|
*/ |
79 |
|
if (limit > 20 * 1024) |
80 |
|
limit = 20 * 1024; |
81 |
|
/* |
82 |
|
* Add the command line length. |
83 |
|
* We estimates additional 80 bytes for popen(3) and space for |
84 |
|
* the additional sort command. |
85 |
|
* |
86 |
|
* for "/bin/sh -c " 11bytes |
87 |
|
* for " | gnusort -k 1,1 -k 3,3 -k 2,2n" 32bytes |
88 |
|
* reserve 37bytes |
89 |
|
* ---------------------------------------------------- |
90 |
|
* Total 80 bytes |
91 |
|
*/ |
92 |
|
limit -= length + 80; |
93 |
|
|
94 |
|
limit -= env_size(); |
95 |
|
if (limit < 0) |
96 |
|
limit = 0; |
97 |
|
#endif |
98 |
|
return limit; |
99 |
|
} |
100 |
|
/* |
101 |
* repeatable find_read |
* repeatable find_read |
102 |
*/ |
*/ |
103 |
static char *repeat_lastpath; |
static char *repeat_lastpath; |