![busybox ash shellを使用して、変更されたargv[0]を持つプログラムを実行するにはどうすればよいですか?](https://rvso.com/image/110476/busybox%20ash%20shell%E3%82%92%E4%BD%BF%E7%94%A8%E3%81%97%E3%81%A6%E3%80%81%E5%A4%89%E6%9B%B4%E3%81%95%E3%82%8C%E3%81%9Fargv%5B0%5D%E3%82%92%E6%8C%81%E3%81%A4%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%A0%E3%82%92%E5%AE%9F%E8%A1%8C%E3%81%99%E3%82%8B%E3%81%AB%E3%81%AF%E3%81%A9%E3%81%86%E3%81%99%E3%82%8C%E3%81%B0%E3%82%88%E3%81%84%E3%81%A7%E3%81%99%E3%81%8B%3F.png)
では、bash
単に を使用しますexec -a
。busybox でこれを行うにはどうすればよいですか? これは可能ですか、それとも直接呼び出すために独自の C プログラムを作成する必要がありますかexec(3)
?
答え1
ビジーボックスのどのバージョンをお持ちですか?https://git.busybox.net/busybox/tree/shell/ash.cexec
9352行目あたりに次のようなコードが見つかるかもしれない。exec [-a customname] ...
execcmd(int argc UNUSED_PARAM, char **argv)
{
optionarg = NULL;
while (nextopt("a:") != '\0')
/* nextopt() sets optionarg to "-a ARGV0" */;
argv = argptr;
if (argv[0]) {
char *prog;
iflag = 0; /* exit on error */
mflag = 0;
optschanged();
/* We should set up signals for "exec CMD"
* the same way as for "CMD" without "exec".
* But optschanged->setinteractive->setsignal
* still thought we are a root shell. Therefore, for example,
* SIGQUIT is still set to IGN. Fix it:
*/
shlvl++;
setsignal(SIGQUIT);
/*setsignal(SIGTERM); - unnecessary because of iflag=0 */
/*setsignal(SIGTSTP); - unnecessary because of mflag=0 */
/*setsignal(SIGTTOU); - unnecessary because of mflag=0 */
prog = argv[0];
if (optionarg)
argv[0] = optionarg;
shellexec(prog, argv, pathval(), 0);
答え2
exec -a
Busybox 1.27以降でサポートされていますの回答もご覧くださいターゲット アプリケーションの 0 番目の引数を設定する POSIX の方法はありますか?別の方法でそれを達成する方法について。