mirror of
https://github.com/freebsd/freebsd-src.git
synced 2024-11-27 09:12:44 +00:00
stdbuf: Code cleanup.
* Factor out path-setting code. * Normalize usage(). * Remove unnecessary switch case. Sponsored by: Klara, Inc. Reviewed by: kevans, imp Differential Revision: https://reviews.freebsd.org/D40799 (cherry picked from commit78baa63209
) libstdbuf: Add proper SEE ALSO section. Sponsored by: Klara, Inc. Reviewed by: bcr Differential Revision: https://reviews.freebsd.org/D40800 (cherry picked from commitc09909ed88
)
This commit is contained in:
parent
e441e0cf8e
commit
e4dee290ff
@ -22,7 +22,7 @@
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.Dd April 28, 2012
|
||||
.Dd June 29, 2023
|
||||
.Dt LIBSTDBUF 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
@ -80,9 +80,12 @@ output will not stall until the full buffer fills.
|
||||
STDBUF_1=L awk '$2 > 1 || $3 > 1' | cat -n
|
||||
.Ed
|
||||
.Pp
|
||||
See also the manpage of
|
||||
See
|
||||
.Xr stdbuf 1
|
||||
for a simpler way to do this.
|
||||
.Sh SEE ALSO
|
||||
.Xr rtld 1 ,
|
||||
.Xr stdbuf 1
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Nm
|
||||
|
@ -34,22 +34,38 @@
|
||||
#define LIBSTDBUF "/usr/lib/libstdbuf.so"
|
||||
#define LIBSTDBUF32 "/usr/lib32/libstdbuf.so"
|
||||
|
||||
extern char *__progname;
|
||||
static int
|
||||
appendenv(const char *key, const char *value)
|
||||
{
|
||||
char *curval, *newpair;
|
||||
int ret;
|
||||
|
||||
curval = getenv(key);
|
||||
if (curval == NULL)
|
||||
ret = asprintf(&newpair, "%s=%s", key, value);
|
||||
else
|
||||
ret = asprintf(&newpair, "%s=%s:%s", key, curval, value);
|
||||
if (ret > 0)
|
||||
ret = putenv(newpair);
|
||||
if (ret < 0)
|
||||
warn("Failed to set environment variable: %s", key);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
static void
|
||||
usage(int s)
|
||||
usage(void)
|
||||
{
|
||||
|
||||
fprintf(stderr, "Usage: %s [-e 0|L|B|<sz>] [-i 0|L|B|<sz>] [-o 0|L|B|<sz>] "
|
||||
"<cmd> [args ...]\n", __progname);
|
||||
exit(s);
|
||||
fprintf(stderr,
|
||||
"usage: stdbuf [-e 0|L|B|<sz>] [-i 0|L|B|<sz>] [-o 0|L|B|<sz>] "
|
||||
"<cmd> [args ...]\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
char *ibuf, *obuf, *ebuf;
|
||||
char *preload0, *preload1;
|
||||
int i;
|
||||
|
||||
ibuf = obuf = ebuf = NULL;
|
||||
@ -64,9 +80,8 @@ main(int argc, char *argv[])
|
||||
case 'o':
|
||||
obuf = optarg;
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
usage(1);
|
||||
usage();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -85,25 +100,8 @@ main(int argc, char *argv[])
|
||||
warn("Failed to set environment variable: %s=%s",
|
||||
"_STDBUF_E", ebuf);
|
||||
|
||||
preload0 = getenv("LD_PRELOAD");
|
||||
if (preload0 == NULL)
|
||||
i = asprintf(&preload1, "LD_PRELOAD=" LIBSTDBUF);
|
||||
else
|
||||
i = asprintf(&preload1, "LD_PRELOAD=%s:%s", preload0,
|
||||
LIBSTDBUF);
|
||||
|
||||
if (i < 0 || putenv(preload1) == -1)
|
||||
warn("Failed to set environment variable: LD_PRELOAD");
|
||||
|
||||
preload0 = getenv("LD_32_PRELOAD");
|
||||
if (preload0 == NULL)
|
||||
i = asprintf(&preload1, "LD_32_PRELOAD=" LIBSTDBUF32);
|
||||
else
|
||||
i = asprintf(&preload1, "LD_32_PRELOAD=%s:%s", preload0,
|
||||
LIBSTDBUF32);
|
||||
|
||||
if (i < 0 || putenv(preload1) == -1)
|
||||
warn("Failed to set environment variable: LD_32_PRELOAD");
|
||||
appendenv("LD_PRELOAD", LIBSTDBUF);
|
||||
appendenv("LD_32_PRELOAD", LIBSTDBUF32);
|
||||
|
||||
execvp(argv[0], argv);
|
||||
err(2, "%s", argv[0]);
|
||||
|
Loading…
Reference in New Issue
Block a user