Skip to content

Commit

Permalink
Include panic logs for vfs in diagnose
Browse files Browse the repository at this point in the history
  • Loading branch information
jeschu1 committed Aug 2, 2019
1 parent 34ed486 commit 54209de
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 2 deletions.
2 changes: 2 additions & 0 deletions GVFS/GVFS.Common/GVFSPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ public static void Register(GVFSPlatform platform)

public abstract void ConfigureVisualStudio(string gitBinPath, ITracer tracer);

public abstract bool TryCopyPanicLogs(string copyToDir, out string error);

public abstract bool TryGetGVFSHooksVersion(out string hooksVersion, out string error);
public abstract bool TryInstallGitCommandHooks(GVFSContext context, string executingDirectory, string hookName, string commandHookPath, out string errorMessage);

Expand Down
32 changes: 32 additions & 0 deletions GVFS/GVFS.Platform.Mac/MacPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ namespace GVFS.Platform.Mac
public partial class MacPlatform : POSIXPlatform
{
private const string UpgradeProtectedDataDirectory = "/usr/local/vfsforgit_upgrader";
private const string DiagnosticReportsDirectory = "/Library/Logs/DiagnosticReports";
private const string PanicFileExtention = "*panic";

public MacPlatform() : base(
underConstruction: new UnderConstructionFlags(
Expand Down Expand Up @@ -141,6 +143,36 @@ public override void IsServiceInstalledAndRunning(string name, out bool installe
running = installed && gvfsService.IsRunning;
}

public override bool TryCopyPanicLogs(string copyToDir, out string error)
{
error = null;
try
{
if (!Directory.Exists(DiagnosticReportsDirectory))
{
return true;
}

string copyToPanicDir = Path.Combine(copyToDir, ProjFSKext.DriverLogDirectory, "panic_logs");
Directory.CreateDirectory(copyToPanicDir);

foreach (string filePath in Directory.GetFiles(DiagnosticReportsDirectory, PanicFileExtention))
{
if (File.ReadAllText(filePath).Contains(ProjFSKext.DriverName))
{
File.Copy(filePath, Path.Combine(copyToPanicDir, Path.GetFileName(filePath)));
}
}

return true;
}
catch (Exception ex)
{
error = $"{nameof(this.TryCopyPanicLogs)}: Failed to copy panic logs: {ex.ToString()}";
return false;
}
}

public class MacPlatformConstants : POSIXPlatformConstants
{
public override string InstallerExtension
Expand Down
6 changes: 4 additions & 2 deletions GVFS/GVFS.Platform.Mac/ProjFSKext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ namespace GVFS.Platform.Mac
{
public class ProjFSKext : IKernelDriver
{
private const string DriverName = "org.vfsforgit.PrjFSKext";
public const string DriverName = "org.vfsforgit.PrjFSKext";
public const string DriverLogDirectory = "PrjFSKext";

private const int LoadKext_ExitCode_Success = 0;

// This exit code was found in the following article
Expand All @@ -24,7 +26,7 @@ public string LogsFolderPath
{
get
{
return Path.Combine(System.IO.Path.GetTempPath(), "PrjFSKext");
return Path.Combine(System.IO.Path.GetTempPath(), DriverLogDirectory);
}
}

Expand Down
6 changes: 6 additions & 0 deletions GVFS/GVFS.Platform.POSIX/POSIXPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,12 @@ public override bool TryKillProcessTree(int processId, out int exitCode, out str
return result.ExitCode == 0;
}

public override bool TryCopyPanicLogs(string copyToDir, out string error)
{
error = null;
return true;
}

[DllImport("libc", EntryPoint = "getuid", SetLastError = true)]
private static extern uint Getuid();

Expand Down
6 changes: 6 additions & 0 deletions GVFS/GVFS.Platform.Windows/WindowsPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,12 @@ public override bool TryKillProcessTree(int processId, out int exitCode, out str
return result.ExitCode == 0;
}

public override bool TryCopyPanicLogs(string copyToDir, out string error)
{
error = null;
return true;
}

private static object GetValueFromRegistry(RegistryHive registryHive, string key, string valueName, RegistryView view)
{
RegistryKey localKey = RegistryKey.OpenBaseKey(registryHive, view);
Expand Down
6 changes: 6 additions & 0 deletions GVFS/GVFS.UnitTests/Mock/Common/MockPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,12 @@ public override bool TryKillProcessTree(int processId, out int exitCode, out str
return true;
}

public override bool TryCopyPanicLogs(string copyToDir, out string error)
{
error = null;
return true;
}

public class MockPlatformConstants : GVFSPlatformConstants
{
public override string ExecutableExtension
Expand Down
6 changes: 6 additions & 0 deletions GVFS/GVFS/CommandLine/DiagnoseVerb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ protected override void Execute(GVFSEnlistment enlistment)
this.CopyFile(GVFSPlatform.Instance.GetDataRootForGVFS(), archiveFolderPath, LocalGVFSConfig.FileName);
}
// kernel panics
if (!GVFSPlatform.Instance.TryCopyPanicLogs(archiveFolderPath, out string errorMessage))
{
this.WriteMessage(errorMessage);
}
return true;
},
"Copying logs");
Expand Down

0 comments on commit 54209de

Please sign in to comment.