/* logwrapper.c - Record commands called out of $PATH to a log * * Copyright 2019 Rob Landley * * I made it up. Must be built standalone to work. (Is its own multiplexer.) USE_LOGWRAPPER(NEWTOY(logwrapper, 0, TOYFLAG_NOHELP|TOYFLAG_USR|TOYFLAG_BIN)) config LOGWRAPPER bool "logwrapper" default n help usage: logwrapper ... Append command line to $WRAPLOG, then call second instance of command in $PATH. */ #define FOR_logwrapper #include "toys.h" void logwrapper_main(void) { char *log = getenv("WRAPLOG"), *omnom = basename(*toys.argv), *s, *ss, *sss; struct string_list *list; int i, len; // Log the command line if (!log) error_exit("no $WRAPLOG"); len = strlen(omnom)+2; for (i = 0; istr, *toys.argv)) break; free(llist_pop(&list)); } } // Skip first instance and try to run next one, until out of instances. for (;;) { if (list) free(llist_pop(&list)); if (!list) error_exit("no %s after %s in $PATH=%s", omnom, **toys.argv == '/' ? *toys.argv : "logwrapper", getenv("PATH")); *toys.argv = list->str; execve(list->str, toys.argv, environ); } }