Skip to content

Commit

Permalink
Merge pull request #1408: Include panic logs for vfs in diagnose
Browse files Browse the repository at this point in the history
Include panic logs for vfs in diagnose
  • Loading branch information
jeschu1 authored Aug 9, 2019
2 parents 1e9c5ec + 1313af0 commit 467fdc7
Show file tree
Hide file tree
Showing 7 changed files with 73 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
44 changes: 44 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 PanicFileNamePattern = "*panic";

public MacPlatform() : base(
underConstruction: new UnderConstructionFlags(
Expand Down Expand Up @@ -141,6 +143,48 @@ 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, PanicFileNamePattern))
{
try
{
// We only include panic logs caused by our kext
// Panics caused by our kext will be in the form DriverName(Version)
// We match the minimal requirement here
if (File.ReadAllText(filePath).Contains(ProjFSKext.DriverName + "("))
{
File.Copy(filePath, Path.Combine(copyToPanicDir, Path.GetFileName(filePath)));
}
}
catch (Exception ex)
{
error = error == null ? string.Empty : error + "\n";
error += $"{nameof(this.TryCopyPanicLogs)}: Failed to handle log {filePath}: {ex.ToString()}";
}
}
}
catch (Exception ex)
{
error = error == null ? string.Empty : error + "\n";
error += $"{nameof(this.TryCopyPanicLogs)}: Failed to copy panic logs: {ex.ToString()}";
return false;
}

return error == null;
}

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 @@ -10,7 +10,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
5 changes: 5 additions & 0 deletions GVFS/GVFS/CommandLine/DiagnoseVerb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ protected override void Execute(GVFSEnlistment enlistment)
this.CopyFile(GVFSPlatform.Instance.GetDataRootForGVFS(), archiveFolderPath, LocalGVFSConfig.FileName);
}
if (!GVFSPlatform.Instance.TryCopyPanicLogs(archiveFolderPath, out string errorMessage))
{
this.WriteMessage(errorMessage);
}
return true;
},
"Copying logs");
Expand Down

0 comments on commit 467fdc7

Please sign in to comment.