GithubHelp home page GithubHelp logo

minishell's People

Contributors

armani843739 avatar sniper-fly avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

minishell's Issues

execveの仕様について

my_execveにおいて

	while (path_db_ptr[i])
	{
		command_path = get_command_path(cmd[0], path_db_ptr[i]);
		//2)prefixをつけてファイルが存在するか(openできるか)検索
		//3)ファイルが見つかったらprefixをつけてarguments二次元ポインタに格納する
		if (is_there_execute_file_at(command_path))
		{
			cmd[0] = command_path; // TODO:cmd[0]free必要?
			if (execve(command_path, cmd, envp) == ERROR)
				occur_an_error_at_execve();
		}
		free(command_path);
		++i;
	}

このループを回してコマンドを探して実行しています.
しかし,試しにcmd[0] = command_pathの行をコメントアウトして実行してみたところ特に問題なくコマンドが実行されました.
この行は消すべきでしょうか.

2段階目のパース

今までの設計ではうまくいかない例を発見してしまいました。

Image from Gyazo

環境変数だけコマンド実行前に展開すればいいやと思っていたんですが、
これは明らかに引数の数が変わってます。
echo $Aは {"echo", "a", "b"}
echo "$A" は{"echo", "a b"}で、引数の数が変わって解釈されているので、
最初のパースで引数の数を決定してしまうとこのケースに対応できません。

最初のパースでは;|の分割のみで、
次に実行しながら各プロセスのパースをする必要があります。

status

waitのstatusをstatic変数にする
exec_pipe関数の引数にstatusを渡す

2/9議事録

議題項目

・utilsに関数がたまり過ぎ
・グローバル変数の定義場所
・自動テスト
・1週間のスケジュール(完成予定日決め)

my_execveの作成

execve(char* arg1st, char** arg, char** envp)

my_execve(t_cmd_list *cmd)
このような形式の関数を作る。

中で環境変数リストを環境変数の文字列ポインタ配列に加工し、execveの第三引数に渡す。

execveは絶対パスで渡さないといけない。
PATHを:でsplitして、prefixとしてディレクトリを追加したときにファイルがOPENできるかどうかで判定する。
PATHは左から順に検査する。

ex)
cat -nを実行したい。
PATH=/bin:/usr/bin
/bin/cat openできない。
/usr/bin/cat openできた。
"/usr/bin/cat", "-n", NULL
を格納した二次元ポインタを作成し、execveに渡せば実行可能。

※PATHの検索対象のディレクトリの名前に:が含まれていたらどう動くのか??要検証

exitステータスの確認

exitステータスがおかしいケースがあったのでメモしておきます

minishell> ./minishell
minishell > exit 1
exit
minishell> echo $?
256

emptyファイルの作成

出力リダイレクトの数だけファイルを作成。実行部分に渡すのは最後のリダイレクトファイル名(と追記フラグ)のみ

リダイレクトのバグ

リダイレクトのテストで起こったバグを載せておきます
ただコマンド実行上のバグの可能性もあるので,あまり深く探しすぎなくても大丈夫です.

exit関数で複数引数を渡されたときの挙動が異なる

exit 1 1 1 1
のように渡されたとき、shell本体はexitしませんが、my_exitではexitされています。

また、普通にexitしたとき、コマンドラインには

exit

と表示されますが、これは標準出力ではなくエラー出力のようです。

並列パイプにしないと再現できない動作がある。

https://gist.github.com/sasakiyudai/f7cb5ccc5cd85ae7f23d37748bfb1cfa

下記のページは、上記syudaiさんの並列パイプからシステムコールのエラー処理を抜いたものです。

https://github.com/sniper-fly/minishell/blob/16ce8371ac8e7b4c20a132df35bbf639b0894334/study/rnakai/multi_pipe_with_same_parent.c

for(i = 0; i < cmd_len; i++)
wait(NULL);

ここのwaitが意味ないだろうと思っていたら意味がありありでした。

試しに、この2行を抜いてみるとcat | lsは一瞬で終了しますが、
2行を追加するとcat | lsはcatの終了をwaitするようになります。
waitは親プロセスから作成されたプロセスを、作成した数だけすべて待ってくれるようです。

ちなみに、親プロセスから孫プロセスをwaitすることはできないようです。
https://stackoverflow.com/questions/12822611/fork-and-wait-how-to-wait-for-all-grandchildren-to-finish
https://pubs.opengroup.org/onlinepubs/9699919799/functions/wait.html

A call to the wait() or waitpid() function only returns status on an immediate child process of the calling process; that is, a child that was produced by a single fork() call (perhaps followed by an exec or other function calls) from the parent. If a child produces grandchildren by further use of fork(), none of those grandchildren nor any of their descendants affect the behavior of a wait() from the original parent process. Nothing in this volume of POSIX.1-2017 prevents an implementation from providing extensions that permit a process to get status from a grandchild or any other process, but a process that does not use such extensions must be guaranteed to see status from only its direct children.

1/21木~1/27水の予定

1/21木~1/27水の予定

rnakai
複数プロセスでのシグナルの動作を調べる
文字列処理のフローチャート清書
ビルトインコマンドの例外的な動作を調べてまとめる
(echo hello | cd .. | echo world など)
できたら全体の処理の設計

yabumoto
入出力リダイレクトの実装

リダイレクトのみを入力したときにセグフォする

>hoge >fuga
など、これら単体で入力したときにセグフォします。

parseでこれらの文字列を一度空白文字に置き換えているため、procにはNULLのみが格納されるためNULLアクセスでセグフォになっているようです。

テスト自動化

minishellにコマンドライン引数をとるようにして、第一引数のコマンドを実行してくれる処理があるとシェルスクリプトで自動テストを書くことができるのでテストが楽になると思います。

ex)
./minishell 'echo "hello world" '

ただし必然的に空白を含む引数になるため、ダブルクォーテーションかシングルクォーテーションで囲む必要があり、", 'を含んだ例外的で複雑なコマンドを実行するときにめんどくさそうです。

環境変数

環境変数のグローバルのリスト作成
環境変数のリストから2次元ポインタに加工する関数

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.