2
* Copyright (c) 2014 Jared González
4
* Permission is hereby granted, free of charge, to any
5
* person obtaining a copy of this software and associated
6
* documentation files (the "Software"), to deal in the
7
* Software without restriction, including without limitation
8
* the rights to use, copy, modify, merge, publish,
9
* distribute, sublicense, and/or sell copies of the
10
* Software, and to permit persons to whom the Software is
11
* furnished to do so, subject to the following conditions:
13
* The above copyright notice and this permission notice
14
* shall be included in all copies or substantial portions of
17
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
18
* KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
19
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
20
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
21
* OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
22
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
package com.jarego.jayatana;
28
import java.io.FileInputStream;
29
import java.lang.instrument.Instrumentation;
30
import java.util.logging.Level;
31
import java.util.logging.Logger;
34
* Este agente java permite evaluar si la arquitectura de las librerías nativas
35
* de integración son de la misma arquitectura de la máquina virtual. En caso
36
* de que conincidan inicia los procesos nativos de integración de lo contrario
39
* @author Jared González
43
* Evalua si la arquitectura de la librerías nativas de Jayatana coninciden con
44
* la arquitectura de la máquia virutal de Java.
46
* @param agentArgs argumentos de agente
47
* @param inst Control de la intrumentación de Java
49
public static void premain(String agentArgs, Instrumentation inst) {
51
// excluir versiones 1.5 y 1.4 pues no esta soportadas
52
if (System.getProperty("java.version").startsWith("1.5") ||
53
System.getProperty("java.version").startsWith("1.4"))
56
// obtienen el archivo de la librería nativa de integración
59
if ((libjayatanaag = System.getenv("JAYATANA_LIBAGPATH")) == null) {
60
libjayatanaag = "/usr/lib/jayatana/libjayatanaag.so";
62
System.err.println("JAYATANA_LIBAGPATH="+libjayatanaag);
64
} catch (Exception e) {
65
libjayatanaag = "/usr/lib/jayatana/libjayatanaag.so";
69
// obtener arquitectura de la librería
70
String libjayatanaagarch = "--";
71
FileInputStream fis = new FileInputStream(libjayatanaag);
76
libjayatanaagarch = "64";
78
libjayatanaagarch = "32";
83
// verificar si la arquitectura conicide con la máquina virtual
84
if (libjayatanaagarch.equals(System.getProperty("sun.arch.data.model")))
85
System.load(libjayatanaag);
86
} catch (Exception e) {}
87
} catch (Exception e) {
88
Logger.getLogger(Agent.class.getName())
89
.log(Level.WARNING, "can't load jayatana agent", e);