2016-10-01 19:03
浏览 32

CLI还是程序的纯C / C ++库? [关闭]

Background / Context: I am developing a Linux NAS Server (Like FreeNAS or Rockstor) using Golang, the particular features will be a JSON-REST API so that you can interact with LVM2, shares, packages, etc.

Question: With respect to security, performance, and development time, what are the advantages / disadvantages / best practices of implmenting spawned processes or using a native library for certain features for a program?

Example: For my particular use case, the NAS management system will be using LVM2 to manage volumes. However you can use the CLI to manipulate volumes or you can attempt to use the LVM2 native C API and merge it with Golangs cgo package.

EDIT: Rephrased my question / information.

图片转代码服务由CSDN问答提供 功能建议

背景/上下文:我正在开发Linux NAS服务器(如FreeNAS或Rockstor) 使用Golang,特定功能将是JSON-REST API,以便您可以与LVM2,共享,程序包等进行交互。

问题: 安全性,性能和开发时间,实施衍生程序或使用本机库来实现程序某些功能的优点/缺点/最佳做法是什么?

示例:< / strong>对于我的特定用例,NAS管理系统将使用LVM2来管理卷。 但是,您可以使用CLI来操作卷,也可以尝试使用LVM2本机C API并将其与Golangs cgo 软件包合并。

EDIT :改写我的问题/信息。

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duanbichenhe1968 2016-10-01 19:26

    There are two things that may make using exec in the different variants a nogo: security and speed.

    • Security: If you shell out with system() or friends, you must be absolutely certain that you don't include any strings in the command that may do funny stuff with your command line. It's the same basic problem as SQL code injection, just at a much lower and even more disastrous layer (obligatory XKCD, just replace "'); DROP TABLE Students;--" with valid sh code along the lines of '"; echo "pwnd', well, you get the idea).

    • Speed: When you shell out to an existing program, you create a new process, and that may be the performance hit you cannot tolerate. It's perfectly ok if the task for which you shell out takes more than a few milliseconds (process creation is somewhere in the range of a millisecond on linux), but if you want more than a thousand calls per second, you definitely need to avoid this overhead.

    If these two points are taken care of or proven to be non-issues, then it's perfectly ok to shell out to other processes.

    打赏 评论

相关推荐 更多相似问题