Pledge archivers/p7zip main executables

Index: CPP/7zip/UI/Console/Main.cpp
--- CPP/7zip/UI/Console/Main.cpp.orig
+++ CPP/7zip/UI/Console/Main.cpp
@@ -485,6 +485,20 @@ int Main2(
   #endif
 )
 {
+
+#ifndef EXTERNAL_CODECS
+
+#ifdef PLEDGE_DEBUG
+  printf("initial pledge: 7za 7zr\n");
+#endif
+
+  if (pledge("stdio rpath wpath cpath fattr tty ps", NULL) == -1) {
+    perror("pledge");
+    exit(2);
+  }
+
+#endif
+
   #if defined(_WIN32) && !defined(UNDER_CE)
   SetFileApisToOEM();
   #endif
@@ -581,6 +595,19 @@ int Main2(
   codecs->CaseSensitive = options.CaseSensitive;
   ThrowException_if_Error(codecs->Load());
 
+#ifdef EXTERNAL_CODECS
+
+#ifdef PLEDGE_DEBUG
+  printf("initial pledge: 7z\n");
+#endif
+
+  if (pledge("stdio rpath wpath cpath fattr tty ps", NULL) == -1) {
+    perror("pledge");
+    exit(2);
+  }
+
+#endif
+
   bool isExtractGroupCommand = options.Command.IsFromExtractGroup();
 
   if (codecs->Formats.Size() == 0 &&
@@ -637,6 +664,16 @@ int Main2(
 
   if (options.Command.CommandType == NCommandType::kInfo)
   {
+
+#ifdef PLEDGE_DEBUG
+  printf("reduced pledge: info\n");
+#endif
+
+  if (pledge("stdio", NULL) == -1) {
+    perror("pledge");
+    exit(2);
+  }
+
     CStdOutStream &so = (g_StdStream ? *g_StdStream : g_StdOut);
     unsigned i;
 
@@ -803,6 +840,16 @@ int Main2(
   }
   else if (options.Command.CommandType == NCommandType::kBenchmark)
   {
+
+#ifdef PLEDGE_DEBUG
+  printf("reduced pledge: benchmark\n");
+#endif
+
+  if (pledge("stdio ps", NULL) == -1) {
+    perror("pledge");
+    exit(2);
+  }
+
     CStdOutStream &so = (g_StdStream ? *g_StdStream : g_StdOut);
     hresultMain = BenchCon(EXTERNAL_CODECS_VARS_L
         options.Properties, options.NumIterations, (FILE *)so);
@@ -870,6 +917,17 @@ int Main2(
     if (hresultMain == S_OK)
     if (isExtractGroupCommand)
     {
+
+      if (options.Command.IsTestCommand() || options.StdOutMode) {
+#ifdef PLEDGE_DEBUG
+          printf("reduced pledge: test stdout\n");
+#endif
+          if (pledge("stdio rpath tty", NULL) == -1) {
+              perror("pledge");
+              exit(2);
+	  }
+      }
+
       CExtractCallbackConsole *ecs = new CExtractCallbackConsole;
       CMyComPtr<IFolderArchiveExtractCallback> extractCallback = ecs;
 
@@ -1030,6 +1088,16 @@ int Main2(
     }
     else
     {
+
+#ifdef PLEDGE_DEBUG
+  printf("reduced pledge: list\n");
+#endif
+
+  if (pledge("stdio rpath tty", NULL) == -1) {
+    perror("pledge");
+    exit(2);
+  }
+
       UInt64 numErrors = 0;
       UInt64 numWarnings = 0;
       
@@ -1140,6 +1208,16 @@ int Main2(
   }
   else if (options.Command.CommandType == NCommandType::kHash)
   {
+
+#ifdef PLEDGE_DEBUG
+  printf("reduced pledge: hash\n");
+#endif
+
+  if (pledge("stdio rpath", NULL) == -1) {
+    perror("pledge");
+    exit(2);
+  }
+
     const CHashOptions &uo = options.HashOptions;
 
     CHashCallbackConsole callback;
