在Minix中fork后执行mkdir后创建的奇怪目录(USER = root)

时间:2015-08-09 15:09:55

标签: c terminal minix

我正忙于在Minix 3.1上用C编写一个简单的终端。 Task.Delay(10000).ContinueWith( t => { }, _tokenSource.Token).Wait(); touch a.txt等简单命令运行正常。但是,当我创建一个名为date的目录时,它会创建一个名为mkdir test的目录,当我尝试创建另一个目录时,它会显示USER=root。我以root身份登录。我在C中使用execvp()来执行终端命令。

USER=root: already exists给了我这个:

ls

有谁知道这实际意味着什么以及如何解决这个问题。我已经尝试了我能在代码中想到的所有内容来尝试修复此问题,但没有任何效果。

感谢您提供任何帮助First part of my code

Second part of my code Last part of my code

我从另一个只返回状态的函数调用(null): HOME=/root: No such file or directory (null): PAGER=more: No such file or directory (null): LOGNAME=root: No such file or directory (null): TERM=minix: No such file or directory (null): PATH=/root/bin:/usr/local/bin:/vin:/usr/bin: No such file or directory (null): SHELL=/bin/sh: No such file or directory (null): TZ=GMT0: No such file or directory (null): EDITOR=vi: No such file or directory USER=root: 到loopShell

1 个答案:

答案 0 :(得分:2)

您正在为execvp错误地创建参数列表。您将返回在堆栈上分配的数组(具有自动存储持续时间的阵列)。一旦创建它的函数返回,数组就会被取消分配,并且指向它的指针不再有效。简单的快速修复就是使数组static在函数返回后保持分配状态。例如:

static char *tokens[SPLIT_SIZE];

您的计划中的另一个错误是尝试对未使用freemalloccalloc分配的对象使用realloc