linux同期ツール


linux同期ツール
プロジェクトソース
プロジェクト概要:linux環境でのサービス側とクライアントの同期ファイルの実現、ファイルの更新、ワンタッチ導入環境の実現
開発環境:linux,c++,vim,g++,gdb,make
主な技術:
1、正規表現:正規表現のメタ文字とc++で正規表現を使用することについて、まとめました:正規表現
2、デーモンプロセス:linuxの下で、man 7 daemonはデーモンプロセスの標準作成プロセスを得る.
 1. Close all open file descriptors except standard input, output, and error (i.e. the first three file descriptors 0, 1, 2). This ensures that no accidentally passed file descriptor stays around in the daemon process. On Linux, this is best implemented by iterating through /proc/self/fd, with a fallback of iterating from file descriptor 3 to the value returned by getrlimit() for RLIMIT_NOFILE.

2. Reset all signal handlers to their default. This is best done by iterating through the available signals up to the limit of _NSIG and resetting them to SIG_DFL.

3. Reset the signal mask using sigprocmask().

4. Sanitize the environment block, removing or resetting environment variables that might negatively impact daemon runtime.

5. Call fork(), to create a background process.

6. In the child, call setsid() to detach from any terminal and create an independent session.

7. In the child, call fork() again, to ensure that the daemon can never re-acquire a terminal again.

8. Call exit() in the first child, so that only the second child (the actual daemon process) stays around. This ensures that the daemon process is re-parented to init/PID 1, as all daemons should be.

9. In the daemon process, connect /dev/null to standard input, output, and error.

10. In the daemon process, reset the umask to 0, so that the file modes passed to open(), mkdir() and suchlike directly control the access mode of the created files and directories.

11. In the daemon process, change the current directory to the root directory (/), in order to avoid that the daemon involuntarily blocks mount points from being unmounted.

12. In the daemon process, write the daemon PID (as returned by getpid()) to a PID file, for example /run/foobar.pid (for a hypothetical daemon "foobar") to ensure that the daemon cannot be started more than once. This must be implemented in race-free fashion so that the PID file is only updated when it is verified at the same time that the PID previously stored in the PID file no longer exists or belongs to a foreign process.

13. In the daemon process, drop privileges, if possible and applicable.

14. From the daemon process, notify the original process started that initialization is complete. This can be implemented via an unnamed pipe or similar communication channel that is created before the first fork() and hence available in both the original and the daemon process.

15. Call exit() in the original process. The process that invoked the daemon must be able to rely on that this exit() happens after initialization is complete and all external communication channels are established and accessible.

3、構成ドキュメント:構成ドキュメントは主に正規表現で処理され、正規表現で取得するキーワードを抽出する.
4、生産消費者モデル:生産消費者モデル
5、設計モード:単例モード、単純工場モード、コマンドモード、仲介者モード
項目の特徴:
  • 文法規則に合致する前提の下で、c注釈とc++注釈の相互変換をサポートする.
  • ソフトウェアのインストールとアップグレード:複数のホストがaptまたはyumを介して指定したパッケージをインストールおよびアップグレードすることをトリガーできます.
  • スクリプト実行:クライアントがスクリプトファイルを実行することをリモートで制御し、ワンタッチ配置機能を達成することができます.
  • システム全体にログ機能がある