]> www.infradead.org Git - users/hch/nvmetcli.git/commitdiff
nvmetcli: print a useful warning when not called as root user
authorChristoph Hellwig <hch@lst.de>
Wed, 23 Mar 2016 19:21:07 +0000 (20:21 +0100)
committerChristoph Hellwig <hch@lst.de>
Wed, 23 Mar 2016 19:32:10 +0000 (20:32 +0100)
Signed-off-by: Christoph Hellwig <hch@lst.de>
nvmetcli

index 0650cab9ec60a0a4229e656d5ce64036feb13992..f8ef5c6cdb5d565fc405bcdb60637ac8c12ddfcb 100755 (executable)
--- a/nvmetcli
+++ b/nvmetcli
@@ -18,6 +18,9 @@ License for the specific language governing permissions and limitations
 under the License.
 '''
 
+from __future__ import print_function
+
+import os
 import sys
 import configshell_fb as configshell
 import nvmet.nvme as nvme
@@ -215,6 +218,10 @@ funcs = dict(save=save, restore=restore, clear=clear)
 
 
 def main():
+    if os.geteuid() != 0:
+        print("%s: must run as root." % sys.argv[0], file=sys.stderr)
+        sys.exit(-1)
+
     if len(sys.argv) > 3:
         usage()