JBoss Native SVN: r1043 - trunk/sight/native/os/linux.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-09-25 01:55:25 -0400 (Tue, 25 Sep 2007)
New Revision: 1043
Modified:
trunk/sight/native/os/linux/scm.c
Log:
Cleanup resources on error
Modified: trunk/sight/native/os/linux/scm.c
===================================================================
--- trunk/sight/native/os/linux/scm.c 2007-09-24 07:39:31 UTC (rev 1042)
+++ trunk/sight/native/os/linux/scm.c 2007-09-25 05:55:25 UTC (rev 1043)
@@ -96,13 +96,23 @@
}
no->native = si;
while (scm_paths[i].flavor) {
+ char sname[PATH_MAX];
+ struct stat sb;
if ((sd = opendir(scm_paths[i].idpath))) {
+ sprintf(sname, scm_paths[i].rlpath, scm_paths[i].rlevel);
+ /* Check default run level path */
+ if (stat(sname, &sb) < 0) {
+ closedir(sd);
+ sd = NULL;
+ continue;
+ }
si->flavor = scm_paths[i].flavor;
si->idpath = scm_paths[i].idpath;
si->rlpath = scm_paths[i].rlpath;
si->what = scm_paths[i].rlevel;
if (!(si->services = sight_arr_new(16))) {
apr_status_t rv = apr_get_os_error();
+ closedir(sd);
scm_cleanup(0, no);
return rv;
}
17 years, 4 months
JBoss Native SVN: r1042 - trunk/sight/native/os/linux.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-09-24 03:39:31 -0400 (Mon, 24 Sep 2007)
New Revision: 1042
Modified:
trunk/sight/native/os/linux/scm.c
Log:
Fix Debian/Ubuntu paths
Modified: trunk/sight/native/os/linux/scm.c
===================================================================
--- trunk/sight/native/os/linux/scm.c 2007-09-24 06:25:50 UTC (rev 1041)
+++ trunk/sight/native/os/linux/scm.c 2007-09-24 07:39:31 UTC (rev 1042)
@@ -48,7 +48,7 @@
},
{ "debian",
"/etc/init.d/",
- "/etc/rc.d/rc%d.d/",
+ "/etc/rc%d.d/",
5
},
{ NULL,
17 years, 4 months
JBoss Native SVN: r1041 - in trunk/sight: java/org/jboss/sight and 1 other directory.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-09-24 02:25:50 -0400 (Mon, 24 Sep 2007)
New Revision: 1041
Added:
trunk/sight/java/org/jboss/sight/Signal.java
Modified:
trunk/sight/examples/org/jboss/sight/RunProcess.java
trunk/sight/java/org/jboss/sight/Process.java
Log:
Use Posix signal Enum instead directly using integer.
Modified: trunk/sight/examples/org/jboss/sight/RunProcess.java
===================================================================
--- trunk/sight/examples/org/jboss/sight/RunProcess.java 2007-09-24 05:50:42 UTC (rev 1040)
+++ trunk/sight/examples/org/jboss/sight/RunProcess.java 2007-09-24 06:25:50 UTC (rev 1041)
@@ -97,7 +97,7 @@
// Refresh the process
// This is noop for created processes
p.refresh();
- p.kill(-9);
+ p.kill(Signal.SIGKILL);
w = p.waitFor();
}
System.out.println();
Modified: trunk/sight/java/org/jboss/sight/Process.java
===================================================================
--- trunk/sight/java/org/jboss/sight/Process.java 2007-09-24 05:50:42 UTC (rev 1040)
+++ trunk/sight/java/org/jboss/sight/Process.java 2007-09-24 06:25:50 UTC (rev 1041)
@@ -263,13 +263,23 @@
/**
* Terminate a process.
* @param sig How to kill the process.
+ * @deprecated
*/
- public int kill(int sig)
+ @Deprecated public int kill(int sig)
{
return kill0(INSTANCE, sig);
}
/**
+ * Terminate a process.
+ * @param sig How to kill the process.
+ */
+ public int kill(Signal sig)
+ {
+ return kill0(INSTANCE, sig.valueOf());
+ }
+
+ /**
* Determine if any of stdin, stdout, or stderr should be linked to pipes
* when starting a child process. Valid values for each pipe are:
* <PRE>
Added: trunk/sight/java/org/jboss/sight/Signal.java
===================================================================
--- trunk/sight/java/org/jboss/sight/Signal.java (rev 0)
+++ trunk/sight/java/org/jboss/sight/Signal.java 2007-09-24 06:25:50 UTC (rev 1041)
@@ -0,0 +1,122 @@
+/*
+ * SIGHT - System information gathering hybrid tool
+ *
+ * Copyright(c) 2007 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ */
+
+package org.jboss.sight;
+
+/**
+ * Posix signals
+ */
+public enum Signal
+{
+
+ /** Unknown signal */
+ UNKNOWN( 0),
+ /** Hangup (POSIX). */
+ SIGHUP( 1),
+ /** Interrupt (ANSI). */
+ SIGINT( 2),
+ /** Quit (POSIX). */
+ SIGQUIT( 3),
+ /** Illegal instruction (ANSI). */
+ SIGILL( 4),
+ /** Trace trap (POSIX). */
+ SIGTRAP( 5),
+ /** Abort (ANSI). */
+ SIGABRT( 6),
+ /** IOT trap (4.2 BSD). */
+ SIGIOT( 6),
+ /** BUS error (4.2 BSD). */
+ SIGBUS( 7),
+ /** Floating-point exception (ANSI). */
+ SIGFPE( 8),
+ /** Kill, unblockable (POSIX). */
+ SIGKILL( 9),
+ /** User-defined signal 1 (POSIX). */
+ SIGUSR1( 10),
+ /** Segmentation violation (ANSI). */
+ SIGSEGV( 11),
+ /** User-defined signal 2 (POSIX). */
+ SIGUSR2( 12),
+ /** Broken pipe (POSIX). */
+ SIGPIPE( 13),
+ /** Alarm clock (POSIX). */
+ SIGALRM( 14),
+ /** Termination (ANSI). */
+ SIGTERM( 15),
+ /** Stack fault. */
+ SIGSTKFLT( 16),
+ /** Child status has changed (POSIX). */
+ SIGCHLD( 17),
+ /** Continue (POSIX). */
+ SIGCONT( 18),
+ /** Stop, unblockable (POSIX). */
+ SIGSTOP( 19),
+ /** Keyboard stop (POSIX). */
+ SIGTSTP( 20),
+ /** Background read from tty (POSIX). */
+ SIGTTIN( 21),
+ /** Background write to tty (POSIX). */
+ SIGTTOU( 22),
+ /** Urgent condition on socket (4.2 BSD). */
+ SIGURG( 23),
+ /** CPU limit exceeded (4.2 BSD). */
+ SIGXCPU( 24),
+ /** File size limit exceeded (4.2 BSD). */
+ SIGXFSZ( 25),
+ /** Virtual alarm clock (4.2 BSD). */
+ SIGVTALRM( 26),
+ /** Profiling alarm clock (4.2 BSD). */
+ SIGPROF( 27),
+ /** Window size change (4.3 BSD, Sun). */
+ SIGWINCH( 28),
+ /** I/O now possible (4.2 BSD). */
+ SIGIO( 29),
+ /** Power failure restart (System V). */
+ SIGPWR( 30),
+ /** Bad system call. */
+ SIGSYS( 31);
+
+
+ private int value;
+ private Signal(int v)
+ {
+ value = v;
+ }
+
+ public int valueOf()
+ {
+ return value;
+ }
+
+ public static Signal valueOf(int value)
+ {
+ for (Signal e : values()) {
+ if (e.value == value)
+ return e;
+ }
+ return UNKNOWN;
+ }
+
+}
Property changes on: trunk/sight/java/org/jboss/sight/Signal.java
___________________________________________________________________
Name: svn:eol-style
+ native
17 years, 4 months
JBoss Native SVN: r1040 - trunk/sight/native/share.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-09-24 01:50:42 -0400 (Mon, 24 Sep 2007)
New Revision: 1040
Modified:
trunk/sight/native/share/mutex.c
trunk/sight/native/share/shm.c
Log:
Destroy objects only on explicit destroy, not on pool callback
Modified: trunk/sight/native/share/mutex.c
===================================================================
--- trunk/sight/native/share/mutex.c 2007-09-21 11:48:13 UTC (rev 1039)
+++ trunk/sight/native/share/mutex.c 2007-09-24 05:50:42 UTC (rev 1040)
@@ -31,7 +31,7 @@
static void mutex_cleanup(int mode, sight_object_t *no)
{
- if (no && no->native) {
+ if (mode != POOL_CALLBACK && no && no->native) {
apr_proc_mutex_destroy((apr_proc_mutex_t *)no->native);
}
}
Modified: trunk/sight/native/share/shm.c
===================================================================
--- trunk/sight/native/share/shm.c 2007-09-21 11:48:13 UTC (rev 1039)
+++ trunk/sight/native/share/shm.c 2007-09-24 05:50:42 UTC (rev 1040)
@@ -31,7 +31,7 @@
static void shm_cleanup(int mode, sight_object_t *no)
{
- if (no && no->native) {
+ if (mode != POOL_CALLBACK && no && no->native) {
if (no->opaque)
apr_shm_detach((apr_shm_t *)no->native);
else
17 years, 4 months
JBoss Native SVN: r1039 - trunk/build/unix.
by jbossnative-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2007-09-21 07:48:13 -0400 (Fri, 21 Sep 2007)
New Revision: 1039
Modified:
trunk/build/unix/package.list
Log:
Use trunk for building (Otherwise it fails on ppc64 linux).
Modified: trunk/build/unix/package.list
===================================================================
--- trunk/build/unix/package.list 2007-09-20 15:19:15 UTC (rev 1038)
+++ trunk/build/unix/package.list 2007-09-21 11:48:13 UTC (rev 1039)
@@ -2,6 +2,7 @@
# add new versions of package after existing ones.
jboss-native|2.0.2|1.2.9|1.2.8|0.9.8e|TOMCAT_NATIVE_1_1_11
jboss-native|2.0.3|1.2.8|1.2.8|0.9.8e|TOMCAT_NATIVE_1_1_11
+jboss-native|2.0.3-dev|1.2.9|1.2.8|0.9.8e|trunk
# SIGHT
jboss-sight|1.0.0|1.2.9|1.2.8||trunk
jboss-sight|1.0.1|1.2.8|1.2.8||trunk
17 years, 4 months
JBoss Native SVN: r1038 - trunk/build/patch.
by jbossnative-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2007-09-20 11:19:15 -0400 (Thu, 20 Sep 2007)
New Revision: 1038
Modified:
trunk/build/patch/openssl-0.9.8e.patch
Log:
Arrange the linux-ppc64 entry.
Modified: trunk/build/patch/openssl-0.9.8e.patch
===================================================================
--- trunk/build/patch/openssl-0.9.8e.patch 2007-09-20 14:07:11 UTC (rev 1037)
+++ trunk/build/patch/openssl-0.9.8e.patch 2007-09-20 15:19:15 UTC (rev 1038)
@@ -91,3 +91,14 @@
}
return($ret);
}
+--- Configure 2007-09-20 11:02:30.000000000 -0400
++++ Configure 2007-09-20 11:03:32.000000000 -0400
+@@ -322,7 +322,7 @@
+ ####
+ "linux-generic64","gcc:-DTERMIO -O3 -Wall::-D_REENTRANT::-ldl:SIXTY_FOUR_BIT_LONG RC4_CHAR RC4_CHUNK DES_INT DES_UNROLL BF_PTR:${no_asm}:dlfcn:linux-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
+ # -bpowerpc64-linux is transient option, -m64 should be the one to use...
+-"linux-ppc64", "gcc:-bpowerpc64-linux -DB_ENDIAN -DTERMIO -O3 -Wall::-D_REENTRANT::-ldl:SIXTY_FOUR_BIT_LONG RC4_CHAR RC4_CHUNK DES_RISC1 DES_UNROLL::linux_ppc64.o::::::::::dlfcn:linux-shared:-fPIC:-bpowerpc64-linux:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
++"linux-ppc64", "gcc:-m64 -DB_ENDIAN -DTERMIO -O3 -Wall::-D_REENTRANT::-ldl:SIXTY_FOUR_BIT_LONG RC4_CHAR RC4_CHUNK DES_RISC1 DES_UNROLL::linux_ppc64.o::::::::::dlfcn:linux-shared:-fPIC:-m64:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
+ "linux-ia64", "gcc:-DL_ENDIAN -DTERMIO -O3 -Wall::-D_REENTRANT::-ldl:SIXTY_FOUR_BIT_LONG RC4_CHUNK:${ia64_asm}:dlfcn:linux-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
+ "linux-ia64-ecc","ecc:-DL_ENDIAN -DTERMIO -O2 -Wall -no_cpprt::-D_REENTRANT::-ldl:SIXTY_FOUR_BIT_LONG RC4_CHUNK:${ia64_asm}:dlfcn:linux-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
+ "linux-ia64-icc","icc:-DL_ENDIAN -DTERMIO -O2 -Wall -no_cpprt::-D_REENTRANT::-ldl:SIXTY_FOUR_BIT_LONG RC4_CHUNK:${ia64_asm}:dlfcn:linux-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)",
17 years, 4 months
JBoss Native SVN: r1037 - trunk/build/unix.
by jbossnative-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2007-09-20 10:07:11 -0400 (Thu, 20 Sep 2007)
New Revision: 1037
Modified:
trunk/build/unix/build.sh
trunk/build/unix/buildbin.jboss-sight.sh
Log:
Fix SIGHT build on linux ppc64.
Modified: trunk/build/unix/build.sh
===================================================================
--- trunk/build/unix/build.sh 2007-09-20 11:34:03 UTC (rev 1036)
+++ trunk/build/unix/build.sh 2007-09-20 14:07:11 UTC (rev 1037)
@@ -167,6 +167,9 @@
export JAVA_HOME
fi
;;
+ ppc64)
+ add_conf="${add_conf} CFLAGS=-m64"
+ ;;
esac
if [ "x" = "x$BUILD_SYS" ]; then
@@ -400,6 +403,9 @@
hpux-ia64)
./Configure ${ssl_target} ${ssl_common_flags} ${ssl_build_flags} hpux-ia64-cc
;;
+ linux2-ppc64)
+ ./Configure ${ssl_target} ${ssl_common_flags} ${ssl_build_flags} linux-ppc64
+ ;;
windows-i686)
./Configure ${ssl_target} VC-NT
ms/do_masm.bat
@@ -470,7 +476,7 @@
)
else
(cd ${apr_srcdir}
- ./configure --prefix=${apr_common_dir}
+ ./configure ${add_conf} --prefix=${apr_common_dir}
echo "Building APR ${apr_version} ..."
make
make install
@@ -513,7 +519,7 @@
)
else
(cd ${apu_srcdir}
- ./configure --with-apr=${apu_common_dir} --prefix=${apu_common_dir} --with-expat=builtin --with-dbm=sdbm
+ ./configure ${add_conf} --with-apr=${apu_common_dir} --prefix=${apu_common_dir} --with-expat=builtin --with-dbm=sdbm
echo "Building APR utilities ${apu_version} ..."
make
make install
Modified: trunk/build/unix/buildbin.jboss-sight.sh
===================================================================
--- trunk/build/unix/buildbin.jboss-sight.sh 2007-09-20 11:34:03 UTC (rev 1036)
+++ trunk/build/unix/buildbin.jboss-sight.sh 2007-09-20 14:07:11 UTC (rev 1037)
@@ -48,6 +48,11 @@
mkdir -p ${output_loc}/lib
mkdir -p ${output_loc}/doc/sight
+case ${BUILD_CPU} in
+ ppc64)
+ add_conf="${add_conf} CFLAGS=-m64 --with-java-home=/opt/jdk"
+esac
+
# Build native part.
(cd sight/native
./configure ${add_conf} --with-apr=${common_loc} --prefix=${prefix_loc} -enable-layout=generic
@@ -72,11 +77,14 @@
fi
# Build java part.
+if [ "x" != "x$JAVA_HOME" ]; then
+ jadd_conf="${jadd_conf} -Djava.home=$JAVA_HOME"
+fi
(cd sight
echo "Building Sight java"
- ant
- ant javadocs
- ant jar
+ ant ${jadd_conf}
+ ant ${jadd_conf} javadocs
+ ant ${jadd_conf} jar
)
current_loc=`pwd`
17 years, 4 months
JBoss Native SVN: r1036 - in trunk/sight: native/os/linux and 1 other directory.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-09-20 07:34:03 -0400 (Thu, 20 Sep 2007)
New Revision: 1036
Modified:
trunk/sight/examples/org/jboss/sight/ListServices.java
trunk/sight/native/os/linux/service.c
Log:
Figure out the ServiceState from pidfile
Modified: trunk/sight/examples/org/jboss/sight/ListServices.java
===================================================================
--- trunk/sight/examples/org/jboss/sight/ListServices.java 2007-09-20 11:18:58 UTC (rev 1035)
+++ trunk/sight/examples/org/jboss/sight/ListServices.java 2007-09-20 11:34:03 UTC (rev 1036)
@@ -44,7 +44,8 @@
scm.open(null, EnumSet.of(GenericAccessRights.READ));
for (Service s : scm.getServices()) {
- System.out.println("Service\t[" + s.Name + "] \t" +
+ System.out.println("Service " + s.State + "\t[" +
+ s.Name + "] \t" +
s.DisplayName + " \t" + s.Description);
}
System.out.println();
Modified: trunk/sight/native/os/linux/service.c
===================================================================
--- trunk/sight/native/os/linux/service.c 2007-09-20 11:18:58 UTC (rev 1035)
+++ trunk/sight/native/os/linux/service.c 2007-09-20 11:34:03 UTC (rev 1036)
@@ -224,6 +224,7 @@
if ((rd = opendir(rlpath))) {
struct dirent *sent, sbuf;
int found = 0;
+ int state = SIGHT_SS_UNKNOWN;
while (!readdir_r(rd, &sbuf, &sent)) {
char sname[PATH_MAX];
char smatch[PATH_MAX];
@@ -247,7 +248,18 @@
else
SET_IFIELD_S(0004, thiz, sent->d_name);
SET_IFIELD_S(0005, thiz, dn);
-
+
+ if (pf[0]) {
+ struct stat sb;
+ if (stat(pf, &sb) >= 0) {
+ /* If there is a pidfile the service
+ * is probably running
+ */
+ state = SIGHT_SS_RUNNING;
+ }
+ else
+ state = SIGHT_SS_STOPPED;
+ }
found = 1;
break;
}
@@ -255,7 +267,7 @@
closedir(rd);
if (found) {
/* Populate the fields */
- CALL_METHOD1(0000, thiz, SIGHT_SS_UNKNOWN);
+ CALL_METHOD1(0000, thiz, state);
}
else {
CALL_METHOD1(0000, thiz, SIGHT_SS_DISABLED);
17 years, 4 months
JBoss Native SVN: r1035 - in trunk/sight: native/os/linux and 1 other directory.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-09-20 07:18:58 -0400 (Thu, 20 Sep 2007)
New Revision: 1035
Modified:
trunk/sight/examples/org/jboss/sight/ListServices.java
trunk/sight/native/os/linux/service.c
Log:
Parse service descriptions from script files
Modified: trunk/sight/examples/org/jboss/sight/ListServices.java
===================================================================
--- trunk/sight/examples/org/jboss/sight/ListServices.java 2007-09-20 08:39:38 UTC (rev 1034)
+++ trunk/sight/examples/org/jboss/sight/ListServices.java 2007-09-20 11:18:58 UTC (rev 1035)
@@ -45,7 +45,7 @@
for (Service s : scm.getServices()) {
System.out.println("Service\t[" + s.Name + "] \t" +
- s.DisplayName );
+ s.DisplayName + " \t" + s.Description);
}
System.out.println();
for (Service s : scm.getDrivers()) {
Modified: trunk/sight/native/os/linux/service.c
===================================================================
--- trunk/sight/native/os/linux/service.c 2007-09-20 08:39:38 UTC (rev 1034)
+++ trunk/sight/native/os/linux/service.c 2007-09-20 11:18:58 UTC (rev 1035)
@@ -131,6 +131,67 @@
sight_unload_class(_E, &_clazzn);
}
+#define SCC_DESC "# description:"
+#define SCC_PNAM "# processname:"
+#define SCC_PIDF "# pidfile:"
+
+static void parse_service_script(const char *fname, char *description,
+ char *procname, char *pidfile)
+{
+ FILE *file;
+ char buf[8192];
+ int mdesc = 0;
+
+ if (!(file = fopen(fname, "r")))
+ return;
+ while (fgets(&buf[0], 8192, file)) {
+ char *pline = sight_trim(&buf[0]);
+ /* Skip empty lines */
+ if (pline) {
+ if (*pline != '#')
+ break;
+ if (mdesc) {
+ mdesc = 0;
+ if (buf[0] == '#' && buf[1] == ' ') {
+ pline = sight_trim(&buf[1]);
+ if (pline) {
+ if (strlen(description) + strlen(pline) < SIGHT_MBUFFER_LEN) {
+ strcat(description, pline);
+ if (description[strlen(description) - 1] == '\\') {
+ /* We have multi-line description */
+ description[strlen(description) - 1] = '\0';
+ mdesc = 1;
+ }
+ }
+ }
+ }
+ if (!mdesc)
+ continue;
+ }
+ if (!strncmp(pline, SCC_DESC, sizeof(SCC_DESC) - 1)) {
+ apr_cpystrn(description, pline + sizeof(SCC_DESC),
+ SIGHT_MBUFFER_SIZ);
+ if (description[strlen(description) - 1] == '\\') {
+ /* We have multi-line description */
+ description[strlen(description) - 1] = '\0';
+ mdesc = 1;
+ }
+ }
+ else if (!strncmp(pline, SCC_PNAM, sizeof(SCC_PNAM) - 1)) {
+ apr_cpystrn(procname, pline + sizeof(SCC_PNAM),
+ SIGHT_SBUFFER_SIZ);
+ }
+ else if (!strncmp(pline, SCC_PIDF, sizeof(SCC_PIDF) - 1)) {
+ apr_cpystrn(pidfile, pline + sizeof(SCC_PIDF),
+ SIGHT_SBUFFER_SIZ);
+ }
+ }
+ }
+
+ fclose(file);
+}
+
+
SIGHT_EXPORT_DECLARE(jint, Service, open0)(SIGHT_STDARGS,
jobject thiz,
jlong instance,
@@ -175,9 +236,18 @@
strcat(smatch, J2S(name));
/* Match the SnnName */
if (!sight_wmatch(sname, smatch)) {
+ char pn[SIGHT_SBUFFER_SIZ] = "";
+ char pf[SIGHT_SBUFFER_SIZ] = "";
+ char dn[SIGHT_MBUFFER_SIZ] = "";
+ parse_service_script(sname, dn, pn, pf);
SET_IFIELD_S(0001, thiz, sname);
SET_IFIELD_S(0003, thiz, sent->d_name);
- SET_IFIELD_S(0004, thiz, sent->d_name);
+ if (pn[0])
+ SET_IFIELD_S(0004, thiz, pn);
+ else
+ SET_IFIELD_S(0004, thiz, sent->d_name);
+ SET_IFIELD_S(0005, thiz, dn);
+
found = 1;
break;
}
17 years, 4 months
JBoss Native SVN: r1034 - in trunk/sight: native/include/arch/unix and 1 other directories.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-09-20 04:39:38 -0400 (Thu, 20 Sep 2007)
New Revision: 1034
Modified:
trunk/sight/java/org/jboss/sight/ServiceState.java
trunk/sight/native/include/arch/unix/sight_private.h
trunk/sight/native/os/linux/scm.c
trunk/sight/native/os/linux/service.c
Log:
Add Linux service implementation
Modified: trunk/sight/java/org/jboss/sight/ServiceState.java
===================================================================
--- trunk/sight/java/org/jboss/sight/ServiceState.java 2007-09-20 06:14:06 UTC (rev 1033)
+++ trunk/sight/java/org/jboss/sight/ServiceState.java 2007-09-20 08:39:38 UTC (rev 1034)
@@ -64,7 +64,11 @@
/**
* The service is paused.
*/
- PAUSED( 7);
+ PAUSED( 7),
+ /**
+ * The service is disabled.
+ */
+ DISABLED( 8);
private int value;
private ServiceState(int v)
Modified: trunk/sight/native/include/arch/unix/sight_private.h
===================================================================
--- trunk/sight/native/include/arch/unix/sight_private.h 2007-09-20 06:14:06 UTC (rev 1033)
+++ trunk/sight/native/include/arch/unix/sight_private.h 2007-09-20 08:39:38 UTC (rev 1034)
@@ -61,6 +61,21 @@
#define SIGHT_PLATFORM_DECLARE(RT, CL, FN) \
JNIEXPORT RT JNICALL Java_org_jboss_sight_platform_unix_##CL##_##FN
+typedef struct scm_instance_t {
+ sight_arr_t *services;
+ const char *flavor; /* Linux flavor */
+ const char *idpath; /* Path of the init.d scripts */
+ const char *rlpath; /* Path or the rc0.d ... rc6.d scripts */
+ int what;
+} scm_instance_t;
+
+/* ServiceState status */
+#define SIGHT_SS_UNKNOWN 0
+#define SIGHT_SS_STOPPED 1
+#define SIGHT_SS_RUNNING 4
+#define SIGHT_SS_PAUSED 7
+#define SIGHT_SS_DISABLED 8
+
/**
* IANA Network adapter types
*/
Modified: trunk/sight/native/os/linux/scm.c
===================================================================
--- trunk/sight/native/os/linux/scm.c 2007-09-20 06:14:06 UTC (rev 1033)
+++ trunk/sight/native/os/linux/scm.c 2007-09-20 08:39:38 UTC (rev 1034)
@@ -35,32 +35,167 @@
#include "sight_types.h"
#include "sight_private.h"
+static const struct {
+ const char *flavor; /* Linux flavor */
+ const char *idpath; /* Path of the init.d scripts */
+ const char *rlpath; /* Format or the rc0.d ... rc6.d scripts */
+ int rlevel; /* Default run level */
+} scm_paths[] = {
+ { "redhat",
+ "/etc/rc.d/init.d/",
+ "/etc/rc.d/rc%d.d/",
+ 5
+ },
+ { "debian",
+ "/etc/init.d/",
+ "/etc/rc.d/rc%d.d/",
+ 5
+ },
+ { NULL,
+ NULL,
+ NULL,
+ 0
+ }
+};
+
+static void scm_cleanup(int mode, sight_object_t *no)
+{
+ if (no && no->native) {
+ scm_instance_t *scm = (scm_instance_t *)no->native;
+ if (scm->services)
+ sight_arr_free(scm->services);
+ free(scm);
+ no->native = NULL;
+ }
+}
+
+
SIGHT_EXPORT_DECLARE(jint, ServiceControlManager, open0)(SIGHT_STDARGS,
jlong instance,
jstring database,
jint mode)
{
- UNREFERENCED_STDARGS;
- UNREFERENCED(instance);
+ int i = 0;
+ DIR *sd = NULL;
+ scm_instance_t *si;
+ sight_object_t *no = J2P(instance, sight_object_t *);
+
+ UNREFERENCED_O;
UNREFERENCED(database);
UNREFERENCED(mode);
- return APR_ENOTIMPL;
+
+ if (!no || !no->pool) {
+ return APR_EINVAL;
+ }
+ if (no->native)
+ scm_cleanup(0, no);
+ if (!(si = (scm_instance_t *)sight_calloc(_E,
+ sizeof(scm_instance_t),
+ THROW_FMARK))) {
+ return apr_get_os_error();
+ }
+ no->native = si;
+ while (scm_paths[i].flavor) {
+ if ((sd = opendir(scm_paths[i].idpath))) {
+ si->flavor = scm_paths[i].flavor;
+ si->idpath = scm_paths[i].idpath;
+ si->rlpath = scm_paths[i].rlpath;
+ si->what = scm_paths[i].rlevel;
+ if (!(si->services = sight_arr_new(16))) {
+ apr_status_t rv = apr_get_os_error();
+ scm_cleanup(0, no);
+ return rv;
+ }
+ break;
+ }
+ i++;
+ }
+ if (sd) {
+ struct dirent *sent, sbuf;
+ while (!readdir_r(sd, &sbuf, &sent)) {
+ char sname[PATH_MAX];
+ struct stat sb;
+ if (!sent)
+ break;
+ strcpy(sname, si->idpath);
+ strcat(sname, sent->d_name);
+ if (stat(sname, &sb) < 0)
+ continue;
+ if (!S_ISREG(sb.st_mode))
+ continue;
+ if (!(sb.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))
+ continue;
+ sight_arr_add(si->services, sent->d_name);
+ }
+ closedir(sd);
+ no->clean = scm_cleanup;
+ return APR_SUCCESS;
+ }
+ else {
+ apr_status_t rv = apr_get_os_error();
+ scm_cleanup(0, no);
+ return rv;
+ }
}
SIGHT_EXPORT_DECLARE(void, ServiceControlManager, close0)(SIGHT_STDARGS,
jlong instance)
{
+ sight_object_t *no = J2P(instance, sight_object_t *);
+
UNREFERENCED_STDARGS;
- UNREFERENCED(instance);
+
+ if (no) {
+ scm_cleanup(0, no);
+ no->clean = NULL;
+ }
}
SIGHT_EXPORT_DECLARE(jobjectArray, ServiceControlManager,
enum0)(SIGHT_STDARGS, jlong instance,
jint drivers, jint what)
{
- UNREFERENCED_STDARGS;
- UNREFERENCED(instance);
- UNREFERENCED(drivers);
- UNREFERENCED(what);
- return NULL;
+ sight_object_t *no = J2P(instance, sight_object_t *);
+ scm_instance_t *si;
+ jobjectArray ea = NULL;
+ jsize cnt = 0;
+ jint idx = 0;
+
+ UNREFERENCED_O;
+ if (!no || !no->pool || !no->native) {
+ return NULL;
+ }
+ if (drivers) {
+ /* There are no drivers on linux ?
+ * Perhaps we should have here the kernel modules
+ */
+ return NULL;
+ }
+ si = (scm_instance_t *)no->native;
+ if (what > 0)
+ si->what = what;
+ if (si->services && si->services->siz) {
+ jint i;
+ /* TODO: Calculate size according to the flags */
+ cnt = si->services->siz;
+ ea = sight_new_cc_array(_E, SIGHT_CC_STRING, cnt);
+ if (!ea || (*_E)->ExceptionCheck(_E)) {
+ ea = NULL;
+ goto cleanup;
+ }
+ for (i = 0; i < cnt; i++) {
+ jstring s = (*_E)->NewStringUTF(_E, si->services->arr[i]);
+ if (s)
+ (*_E)->SetObjectArrayElement(_E, ea, idx++, s);
+ else
+ break;
+ if ((*_E)->ExceptionCheck(_E)) {
+ ea = NULL;
+ break;
+ }
+ (*_E)->DeleteLocalRef(_E, s);
+ }
+ }
+cleanup:
+ return ea;
}
Modified: trunk/sight/native/os/linux/service.c
===================================================================
--- trunk/sight/native/os/linux/service.c 2007-09-20 06:14:06 UTC (rev 1033)
+++ trunk/sight/native/os/linux/service.c 2007-09-20 08:39:38 UTC (rev 1034)
@@ -138,13 +138,61 @@
jstring name,
jint access)
{
- UNREFERENCED_STDARGS;
- UNREFERENCED(thiz);
- UNREFERENCED(instance);
- UNREFERENCED(scm);
- UNREFERENCED(name);
+ sight_object_t *no = J2P(instance, sight_object_t *);
+ sight_object_t *ns = J2P(scm, sight_object_t *);
+ scm_instance_t *si;
+ SIGHT_ALLOC_CSTRING(name);
+ int rc = 0;
+ char rlpath[PATH_MAX];
+ DIR *rd = NULL;
+
+
+ UNREFERENCED_O;
UNREFERENCED(access);
- return APR_ENOTIMPL;
+
+ if (!no || !no->pool) {
+ SIGHT_FREE_CSTRING(name);
+ return APR_EINVAL;
+ }
+ if (!ns || !ns->native) {
+ SIGHT_FREE_CSTRING(name);
+ return APR_EINVAL;
+ }
+ si = (scm_instance_t *)ns->native;
+ sprintf(rlpath, si->rlpath, si->what);
+ if ((rd = opendir(rlpath))) {
+ struct dirent *sent, sbuf;
+ int found = 0;
+ while (!readdir_r(rd, &sbuf, &sent)) {
+ char sname[PATH_MAX];
+ char smatch[PATH_MAX];
+ struct stat sb;
+ if (!sent)
+ break;
+ strcpy(sname, rlpath);
+ strcat(sname, sent->d_name);
+ strcpy(smatch, "*/S??");
+ strcat(smatch, J2S(name));
+ /* Match the SnnName */
+ if (!sight_wmatch(sname, smatch)) {
+ SET_IFIELD_S(0001, thiz, sname);
+ SET_IFIELD_S(0003, thiz, sent->d_name);
+ SET_IFIELD_S(0004, thiz, sent->d_name);
+ found = 1;
+ break;
+ }
+ }
+ closedir(rd);
+ if (found) {
+ /* Populate the fields */
+ CALL_METHOD1(0000, thiz, SIGHT_SS_UNKNOWN);
+ }
+ else {
+ CALL_METHOD1(0000, thiz, SIGHT_SS_DISABLED);
+ }
+ }
+ SIGHT_FREE_CSTRING(name);
+ return APR_FROM_OS_ERROR(rc);
}
SIGHT_EXPORT_DECLARE(jint, Service, ctrl0)(SIGHT_STDARGS,
17 years, 4 months