aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukas Berk2012-10-09 10:32:23 (EDT)
committerSami Wagiaalla2012-10-10 13:14:52 (EDT)
commit43a682f1eeb64214fcd785b71493bb0367ccad44 (patch)
treee5bff7a85c039c91d10cfc13540207967010cbba
parente4cece71641311ed94bbaa496f9aa558744f27c4 (diff)
downloadorg.eclipse.linuxtools-43a682f1eeb64214fcd785b71493bb0367ccad44.zip
org.eclipse.linuxtools-43a682f1eeb64214fcd785b71493bb0367ccad44.tar.gz
org.eclipse.linuxtools-43a682f1eeb64214fcd785b71493bb0367ccad44.tar.bz2
Check that user belongs to stapdev for callgraph views
Callgraph would throw NPE's if the user wasn't properly assigned to the stapdev group. Now we properly check that the user belongs to the stapdev group, and if not, avoid running the views causing the NPE, instead throwing an error message informing the user, and providing the command to properly add the user to the correct group ($usermod -aG stapdev user). Strings have been properly externalized. Change-Id: I36448b14207a157e69b85a866f9f613ad55fc8e2 Reviewed-on: https://git.eclipse.org/r/8100 Tested-by: Hudson CI Reviewed-by: Sami Wagiaalla <swagiaal@redhat.com> IP-Clean: Sami Wagiaalla <swagiaal@redhat.com> Tested-by: Sami Wagiaalla <swagiaal@redhat.com>
-rw-r--r--systemtap/org.eclipse.linuxtools.callgraph/src/org/eclipse/linuxtools/internal/callgraph/CallgraphView.java177
-rw-r--r--systemtap/org.eclipse.linuxtools.callgraph/src/org/eclipse/linuxtools/internal/callgraph/messages.properties2
2 files changed, 119 insertions, 60 deletions
diff --git a/systemtap/org.eclipse.linuxtools.callgraph/src/org/eclipse/linuxtools/internal/callgraph/CallgraphView.java b/systemtap/org.eclipse.linuxtools.callgraph/src/org/eclipse/linuxtools/internal/callgraph/CallgraphView.java
index ba93447..794cdbf 100644
--- a/systemtap/org.eclipse.linuxtools.callgraph/src/org/eclipse/linuxtools/internal/callgraph/CallgraphView.java
+++ b/systemtap/org.eclipse.linuxtools.callgraph/src/org/eclipse/linuxtools/internal/callgraph/CallgraphView.java
@@ -11,11 +11,13 @@
package org.eclipse.linuxtools.internal.callgraph;
+import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
+import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;
@@ -37,6 +39,7 @@ import org.eclipse.linuxtools.internal.callgraph.core.SystemTapParser;
import org.eclipse.linuxtools.internal.callgraph.core.SystemTapUIErrorMessages;
import org.eclipse.linuxtools.internal.callgraph.core.SystemTapView;
import org.eclipse.linuxtools.internal.callgraph.graphlisteners.AutoScrollSelectionListener;
+import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
@@ -587,76 +590,130 @@ public class CallgraphView extends SystemTapView {
public void createViewActions() {
//Set drawmode to tree view
- view_treeview = new Action(Messages.getString("CallgraphView.TreeView")){ //$NON-NLS-1$
- @Override
- public void run() {
- g.draw(StapGraph.CONSTANT_DRAWMODE_TREE, g.getAnimationMode(),
- g.getRootVisibleNodeNumber());
- g.scrollTo(g.getNode(g.getRootVisibleNodeNumber()).getLocation().x
- - g.getBounds().width / 2, g.getNode(
- g.getRootVisibleNodeNumber()).getLocation().y);
- if (play != null)
- play.setEnabled(true);
- }
- };
- ImageDescriptor treeImage = CallgraphPlugin.getImageDescriptor("icons/tree_view.gif"); //$NON-NLS-1$
- view_treeview.setImageDescriptor(treeImage);
-
-
- //Set drawmode to radial view
- view_radialview = new Action(Messages.getString("CallgraphView.RadialView")){ //$NON-NLS-1$
- @Override
- public void run(){
- g.draw(StapGraph.CONSTANT_DRAWMODE_RADIAL, g.getAnimationMode(),
- g.getRootVisibleNodeNumber());
- if (play != null)
- play.setEnabled(true);
- }
- };
- ImageDescriptor d = CallgraphPlugin.getImageDescriptor("/icons/radial_view.gif"); //$NON-NLS-1$
- view_radialview.setImageDescriptor(d);
+ try {
+ final Process p = new ProcessBuilder("/usr/bin/bash", "-c", "id | grep stapdev").start();
+ p.waitFor();
+ view_treeview = new Action(Messages.getString("CallgraphView.TreeView")){ //$NON-NLS-1$
+ @Override
+ public void run() {
+ if(p != null && p.exitValue() == 0) {
+ g.draw(StapGraph.CONSTANT_DRAWMODE_TREE, g.getAnimationMode(),
+ g.getRootVisibleNodeNumber());
+ g.scrollTo(g.getNode(g.getRootVisibleNodeNumber()).getLocation().x
+ - g.getBounds().width / 2, g.getNode(
+ g.getRootVisibleNodeNumber()).getLocation().y);
+ if (play != null)
+ play.setEnabled(true);
+ } else {
+ stapPermissionError();
+ }
+ }
+ };
+ ImageDescriptor treeImage = CallgraphPlugin.getImageDescriptor("icons/tree_view.gif"); //$NON-NLS-1$
+ view_treeview.setImageDescriptor(treeImage);
- //Set drawmode to aggregate view
- view_aggregateview = new Action(Messages.getString("CallgraphView.AggregateView")){ //$NON-NLS-1$
- @Override
- public void run(){
- g.draw(StapGraph.CONSTANT_DRAWMODE_AGGREGATE, g.getAnimationMode(),
- g.getRootVisibleNodeNumber());
- if (play != null)
- play.setEnabled(false);
- }
- };
- ImageDescriptor aggregateImage = CallgraphPlugin.getImageDescriptor("/icons/view_aggregateview.gif"); //$NON-NLS-1$
- view_aggregateview.setImageDescriptor(aggregateImage);
+ //Set drawmode to radial view
+ view_radialview = new Action(Messages.getString("CallgraphView.RadialView")){ //$NON-NLS-1$
+ @Override
+ public void run(){
+ if(p != null && p.exitValue() == 0) {
+ g.draw(StapGraph.CONSTANT_DRAWMODE_RADIAL, g.getAnimationMode(),
+ g.getRootVisibleNodeNumber());
+ if (play != null)
+ play.setEnabled(true);
+ } else {
+ stapPermissionError();
+ }
+ }
+ };
+ ImageDescriptor d = CallgraphPlugin.getImageDescriptor("/icons/radial_view.gif"); //$NON-NLS-1$
+ view_radialview.setImageDescriptor(d);
- //Set drawmode to level view
- view_levelview = new Action(Messages.getString("CallgraphView.LevelView")){ //$NON-NLS-1$
- @Override
- public void run(){
- g.draw(StapGraph.CONSTANT_DRAWMODE_LEVEL, g.getAnimationMode(),
- g.getRootVisibleNodeNumber());
- if (play != null)
- play.setEnabled(true);
- }
- };
- ImageDescriptor levelImage = CallgraphPlugin.getImageDescriptor("/icons/showchild_mode.gif"); //$NON-NLS-1$
- view_levelview.setImageDescriptor(levelImage);
+ //Set drawmode to aggregate view
+ view_aggregateview = new Action(Messages.getString("CallgraphView.AggregateView")){ //$NON-NLS-1$
+ @Override
+ public void run(){
+ if(p != null && p.exitValue() == 0) {
+ g.draw(StapGraph.CONSTANT_DRAWMODE_AGGREGATE, g.getAnimationMode(),
+ g.getRootVisibleNodeNumber());
+ if (play != null)
+ play.setEnabled(false);
+ } else {
+ stapPermissionError();
+ }
+ }
+ };
+ ImageDescriptor aggregateImage = CallgraphPlugin.getImageDescriptor("/icons/view_aggregateview.gif"); //$NON-NLS-1$
+ view_aggregateview.setImageDescriptor(aggregateImage);
- setView_refresh(new Action(Messages.getString("CallgraphView.Reset")){ //$NON-NLS-1$
- @Override
- public void run(){
- g.reset();
- }
- });
- ImageDescriptor refreshImage = CallgraphPlugin.getImageDescriptor("/icons/nav_refresh.gif"); //$NON-NLS-1$
- getView_refresh().setImageDescriptor(refreshImage);
+ //Set drawmode to level view
+ view_levelview = new Action(Messages.getString("CallgraphView.LevelView")){ //$NON-NLS-1$
+ @Override
+ public void run(){
+ if(p != null && p.exitValue() == 0) {
+ g.draw(StapGraph.CONSTANT_DRAWMODE_LEVEL, g.getAnimationMode(),
+ g.getRootVisibleNodeNumber());
+ if (play != null)
+ play.setEnabled(true);
+ } else {
+ stapPermissionError();
+ }
+ }
+ };
+ ImageDescriptor levelImage = CallgraphPlugin.getImageDescriptor("/icons/showchild_mode.gif"); //$NON-NLS-1$
+ view_levelview.setImageDescriptor(levelImage);
+ setView_refresh(new Action(Messages.getString("CallgraphView.Reset")){ //$NON-NLS-1$
+ @Override
+ public void run(){
+ if(p != null && p.exitValue() == 0) {
+ g.reset();
+ } else {
+ stapPermissionError();
+ }
+ }
+ });
+ ImageDescriptor refreshImage = CallgraphPlugin.getImageDescriptor("/icons/nav_refresh.gif"); //$NON-NLS-1$
+ getView_refresh().setImageDescriptor(refreshImage);
+
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
}
+ public void stapPermissionError() {
+ Process p = null;
+ try {
+ p = new ProcessBuilder("/usr/bin/bash", "-c", "whoami").start();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ InputStreamReader isr = new InputStreamReader(p.getInputStream());
+ BufferedReader br = new BufferedReader(isr);
+ String user = null;
+ try {
+ user = br.readLine();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ SystemTapUIErrorMessages message = new SystemTapUIErrorMessages(
+ Messages.getString("CallgraphView.StapError1"),
+ Messages.getString("CallgraphView.StapError1"), NLS.bind(
+ Messages.getString("CallgraphView.StapError2"), user));
+ message.schedule();
+ }
/**
* Populates Animate menu.
*/
diff --git a/systemtap/org.eclipse.linuxtools.callgraph/src/org/eclipse/linuxtools/internal/callgraph/messages.properties b/systemtap/org.eclipse.linuxtools.callgraph/src/org/eclipse/linuxtools/internal/callgraph/messages.properties
index 9ce8804..29be9e6 100644
--- a/systemtap/org.eclipse.linuxtools.callgraph/src/org/eclipse/linuxtools/internal/callgraph/messages.properties
+++ b/systemtap/org.eclipse.linuxtools.callgraph/src/org/eclipse/linuxtools/internal/callgraph/messages.properties
@@ -44,6 +44,8 @@ CallgraphView.TreeView=Tree View
CallgraphView.RadialView=Radial View
CallgraphView.AggregateView=Aggregate View
CallgraphView.LevelView=Level View
+CallgraphView.StapError1=Stap permission error
+CallgraphView.StapError2=The user: {0} is not part of the stapdev group, you can correct this by running: $usermod -aG stapdev {0}
CallgraphView.AnimationMenu=Animation
CallgraphView.AnimationSlow=Slow
CallgraphView.AnimationFast=Fast