├── src ├── media │ ├── logo.png │ ├── commons-logo-component.xcf │ └── commons-logo-component-100.xcf ├── site │ ├── resources │ │ ├── images │ │ │ └── logo.png │ │ ├── download_daemon.cgi │ │ ├── profile.jacoco │ │ └── profile.japicmp │ ├── xdoc │ │ ├── security.xml │ │ ├── binaries.xml │ │ └── faq.xml │ └── site.xml ├── native │ ├── windows │ │ ├── resources │ │ │ ├── commons.bmp │ │ │ ├── susers.bmp │ │ │ ├── procrunr.ico │ │ │ ├── procruns.ico │ │ │ └── procrunw.ico │ │ ├── include │ │ │ ├── console.h │ │ │ ├── security.h │ │ │ ├── rprocess.h │ │ │ ├── service.h │ │ │ ├── javajni.h │ │ │ ├── cmdline.h │ │ │ ├── registry.h │ │ │ └── log.h │ │ ├── apps │ │ │ ├── prunsrv │ │ │ │ ├── test │ │ │ │ │ └── scripts │ │ │ │ │ │ ├── stopservice.bat │ │ │ │ │ │ ├── deleteservice.bat │ │ │ │ │ │ ├── mybanner.bat │ │ │ │ │ │ ├── startservice.bat │ │ │ │ │ │ ├── testservice.bat │ │ │ │ │ │ ├── cleanstd.bat │ │ │ │ │ │ ├── waituntilstop.bat │ │ │ │ │ │ └── isemptystd.bat │ │ │ │ ├── prunsrv.h │ │ │ │ ├── prunsrv.manifest │ │ │ │ ├── prunsrv.rc │ │ │ │ └── Makefile │ │ │ └── prunmgr │ │ │ │ ├── prunmgr.manifest │ │ │ │ └── Makefile │ │ ├── src │ │ │ ├── mclib.h │ │ │ ├── security.c │ │ │ └── console.c │ │ ├── xdocs │ │ │ └── index.xml │ │ └── README.txt │ └── unix │ │ ├── man │ │ ├── README.txt │ │ └── fetch.sh │ │ ├── native │ │ ├── help.h │ │ ├── .indent.pro │ │ ├── location.h │ │ ├── dso.h │ │ ├── java.h │ │ ├── Makefile.in │ │ ├── signals.h │ │ ├── home.h │ │ ├── locks.h │ │ ├── locks.c │ │ ├── jsvc.h │ │ ├── replace.h │ │ ├── dso-dlfcn.c │ │ ├── debug.h │ │ ├── version.h │ │ ├── debug.c │ │ ├── arguments.h │ │ ├── signals.c │ │ ├── replace.c │ │ └── dso-dyld.c │ │ ├── Makedefs.in │ │ ├── support │ │ ├── buildconf.sh │ │ ├── apjava.m4 │ │ └── apfunctions.m4 │ │ ├── Makefile.in │ │ └── INSTALL.txt ├── main │ └── java │ │ └── org │ │ └── apache │ │ └── commons │ │ └── daemon │ │ ├── DaemonListener.java │ │ ├── DaemonUserSignal.java │ │ ├── DaemonContext.java │ │ ├── DaemonInitException.java │ │ ├── DaemonController.java │ │ └── Daemon.java ├── samples │ ├── Native.sh │ ├── Native.c │ ├── ServiceDaemon.sh │ ├── ProcrunServiceRemove.cmd │ ├── AloneDaemon.sh │ ├── ServiceDaemonReadThread.java │ ├── README.txt │ ├── SimpleApplication.sh │ ├── SimpleDaemon.sh │ ├── ProcrunServiceInstall.cmd │ ├── AloneService.java │ ├── build.xml │ └── ServiceDaemon.java ├── test │ └── java │ │ └── org │ │ └── apache │ │ └── commons │ │ └── daemon │ │ └── DaemonInitExceptionTest.java ├── assembly │ ├── win.xml │ ├── bin.xml │ ├── src.xml │ └── native-src.xml └── docs │ └── daemon.css ├── NOTICE.txt ├── .gitignore ├── .gitattributes ├── SECURITY.md ├── CODE_OF_CONDUCT.md ├── .github ├── GH-ROBOTS.txt ├── dependabot.yml ├── workflows │ ├── dependency-review.yml │ ├── maven.yml │ ├── scorecards-analysis.yml │ ├── codeql-analysis.yml │ └── windows.yml └── pull_request_template.md ├── .asf.yaml └── RELEASE-NOTES.txt /src/media/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/commons-daemon/HEAD/src/media/logo.png -------------------------------------------------------------------------------- /src/site/resources/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/commons-daemon/HEAD/src/site/resources/images/logo.png -------------------------------------------------------------------------------- /src/media/commons-logo-component.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/commons-daemon/HEAD/src/media/commons-logo-component.xcf -------------------------------------------------------------------------------- /src/media/commons-logo-component-100.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/commons-daemon/HEAD/src/media/commons-logo-component-100.xcf -------------------------------------------------------------------------------- /src/native/windows/resources/commons.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/commons-daemon/HEAD/src/native/windows/resources/commons.bmp -------------------------------------------------------------------------------- /src/native/windows/resources/susers.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/commons-daemon/HEAD/src/native/windows/resources/susers.bmp -------------------------------------------------------------------------------- /src/native/windows/resources/procrunr.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/commons-daemon/HEAD/src/native/windows/resources/procrunr.ico -------------------------------------------------------------------------------- /src/native/windows/resources/procruns.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/commons-daemon/HEAD/src/native/windows/resources/procruns.ico -------------------------------------------------------------------------------- /src/native/windows/resources/procrunw.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/commons-daemon/HEAD/src/native/windows/resources/procrunw.ico -------------------------------------------------------------------------------- /NOTICE.txt: -------------------------------------------------------------------------------- 1 | Apache Commons Daemon 2 | Copyright 1999-2025 The Apache Software Foundation 3 | 4 | This product includes software developed by 5 | The Apache Software Foundation (https://www.apache.org/). 6 | -------------------------------------------------------------------------------- /src/site/resources/download_daemon.cgi: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Just call the standard mirrors.cgi script. It will use download.html 3 | # as the input template. 4 | exec /www/www.apache.org/dyn/mirrors/mirrors.cgi $* -------------------------------------------------------------------------------- /src/native/unix/man/README.txt: -------------------------------------------------------------------------------- 1 | To build it use: 2 | docbook2man jsvc.1.xml 3 | 4 | If your docbook2man uses xalan and you are behind a firewall 5 | Modify jsvc.1.xml as below: 6 | +++ 7 | Index: jsvc.1.xml 8 | =================================================================== 9 | --- jsvc.1.xml (revision 170004) 10 | +++ jsvc.1.xml (working copy) 11 | @@ -1,6 +1,6 @@ 12 | 13 | 15 | + "docbookx.dtd"> 16 | 17 | 18 | JSVC 19 | +++ 20 | Use fetch.sh to get docbook files. 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /bin/ 2 | /.settings/ 3 | /.classpath 4 | /.project 5 | /src/native/unix/Makedefs 6 | /src/native/unix/Makefile 7 | /src/native/unix/autom4te.cache/ 8 | /src/native/unix/config.log 9 | /src/native/unix/config.nice 10 | /src/native/unix/config.status 11 | /src/native/unix/configure 12 | /src/native/unix/jsvc 13 | /src/native/unix/native/*.o 14 | /src/native/unix/native/Makefile 15 | /src/native/unix/native/libservice.a 16 | /src/native/unix/support/config.guess 17 | /src/native/unix/support/config.sub 18 | /src/native/windows/apps/prunmgr/*_GUI_RELEASE 19 | /src/native/windows/apps/prunsrv/*_RELEASE 20 | /target/ 21 | **/.vs/ 22 | /commons-daemon.iml 23 | **/.DS_Store 24 | 25 | # NetBeans files 26 | nb-configuration.xml 27 | nbactions.xml 28 | -------------------------------------------------------------------------------- /src/site/resources/profile.jacoco: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // https://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | -------------------------------------------------------------------------------- /src/site/resources/profile.japicmp: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // https://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | * text=auto 17 | *.cmd -text 18 | *.rtf -text 19 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | 17 | The Apache Commons security page is [https://commons.apache.org/security.html](https://commons.apache.org/security.html). 18 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | 17 | The Apache code of conduct page is [https://www.apache.org/foundation/policies/conduct.html](https://www.apache.org/foundation/policies/conduct.html). 18 | -------------------------------------------------------------------------------- /.github/GH-ROBOTS.txt: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | # Keeps on creating FUD PRs in test code 17 | # Does not follow Apache disclosure policies 18 | User-agent: JLLeitschuh/security-research 19 | Disallow: * 20 | -------------------------------------------------------------------------------- /src/native/unix/native/help.h: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __JSVC_HELP_H__ 18 | #define __JSVC_HELP_H__ 19 | 20 | void help(home_data *data); 21 | 22 | #endif /* __JSVC_HELP_H__ */ 23 | 24 | -------------------------------------------------------------------------------- /src/native/unix/native/.indent.pro: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | -i4 -npsl -di0 -br -nce -d0 -cli4 -npcs -nfc1 -nut -ncs -nbbo -l100 -c40 -il0 18 | -Tbool 19 | -Targ_data 20 | -Thome_data 21 | -Thome_jvm 22 | -Tdso_handle 23 | -Tcap_t 24 | -------------------------------------------------------------------------------- /src/native/windows/include/console.h: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _CONSOLE_H_INCLUDED_ 18 | #define _CONSOLE_H_INCLUDED_ 19 | 20 | __APXBEGIN_DECLS 21 | 22 | 23 | 24 | __APXEND_DECLS 25 | 26 | #endif /* _CONSOLE_H_INCLUDED_ */ 27 | -------------------------------------------------------------------------------- /src/native/windows/apps/prunsrv/test/scripts/stopservice.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | rem Licensed to the Apache Software Foundation (ASF) under one or more 3 | rem contributor license agreements. See the NOTICE file distributed with 4 | rem this work for additional information regarding copyright ownership. 5 | rem The ASF licenses this file to You under the Apache License, Version 2.0 6 | rem (the "License"); you may not use this file except in compliance with 7 | rem the License. You may obtain a copy of the License at 8 | rem 9 | rem https://www.apache.org/licenses/LICENSE-2.0 10 | rem 11 | rem Unless required by applicable law or agreed to in writing, software 12 | rem distributed under the License is distributed on an "AS IS" BASIS, 13 | rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | rem See the License for the specific language governing permissions and 15 | rem limitations under the License. 16 | 17 | call mybanner stopping 18 | %myserv% //SS//TestService 19 | if %errorlevel% neq 0 ( 20 | echo "stop failed" 21 | exit 1 22 | ) 23 | EXIT /B 0 24 | -------------------------------------------------------------------------------- /src/native/windows/apps/prunsrv/test/scripts/deleteservice.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | rem Licensed to the Apache Software Foundation (ASF) under one or more 3 | rem contributor license agreements. See the NOTICE file distributed with 4 | rem this work for additional information regarding copyright ownership. 5 | rem The ASF licenses this file to You under the Apache License, Version 2.0 6 | rem (the "License"); you may not use this file except in compliance with 7 | rem the License. You may obtain a copy of the License at 8 | rem 9 | rem https://www.apache.org/licenses/LICENSE-2.0 10 | rem 11 | rem Unless required by applicable law or agreed to in writing, software 12 | rem distributed under the License is distributed on an "AS IS" BASIS, 13 | rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | rem See the License for the specific language governing permissions and 15 | rem limitations under the License. 16 | 17 | call mybanner deleting 18 | %myserv% //DS//TestService 19 | if %errorlevel% neq 0 ( 20 | echo "delete failed" 21 | exit 1 22 | ) 23 | EXIT /B 0 24 | -------------------------------------------------------------------------------- /src/native/windows/apps/prunsrv/test/scripts/mybanner.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | rem Licensed to the Apache Software Foundation (ASF) under one or more 3 | rem contributor license agreements. See the NOTICE file distributed with 4 | rem this work for additional information regarding copyright ownership. 5 | rem The ASF licenses this file to You under the Apache License, Version 2.0 6 | rem (the "License"); you may not use this file except in compliance with 7 | rem the License. You may obtain a copy of the License at 8 | rem 9 | rem https://www.apache.org/licenses/LICENSE-2.0 10 | rem 11 | rem Unless required by applicable law or agreed to in writing, software 12 | rem distributed under the License is distributed on an "AS IS" BASIS, 13 | rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | rem See the License for the specific language governing permissions and 15 | rem limitations under the License. 16 | 17 | echo "*****************************************************" 18 | echo "%~1" 19 | echo "*****************************************************" 20 | EXIT /B 0 21 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | version: 2 17 | updates: 18 | - package-ecosystem: "maven" 19 | directory: "/" 20 | schedule: 21 | interval: "quarterly" 22 | - package-ecosystem: "github-actions" 23 | directory: "/" 24 | schedule: 25 | interval: "quarterly" 26 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/daemon/DaemonListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.daemon; 19 | 20 | import java.util.EventListener; 21 | 22 | /** 23 | * EvenListener type wrapper. 24 | */ 25 | public interface DaemonListener extends EventListener { 26 | // empty 27 | } 28 | -------------------------------------------------------------------------------- /src/native/windows/src/mclib.h: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _MCLIB_H_INCLUDED_ 18 | #define _MCLIB_H_INCLUDED_ 19 | 20 | #ifndef MIN 21 | #define MIN(a,b) (((a)<(b)) ? (a) : (b)) 22 | #endif 23 | #ifndef MAX 24 | #define MAX(a,b) (((a)>(b)) ? (a) : (b)) 25 | #endif 26 | 27 | #endif /* _MCLIB_H_INCLUDED_ */ 28 | -------------------------------------------------------------------------------- /src/native/windows/apps/prunsrv/test/scripts/startservice.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | rem Licensed to the Apache Software Foundation (ASF) under one or more 3 | rem contributor license agreements. See the NOTICE file distributed with 4 | rem this work for additional information regarding copyright ownership. 5 | rem The ASF licenses this file to You under the Apache License, Version 2.0 6 | rem (the "License"); you may not use this file except in compliance with 7 | rem the License. You may obtain a copy of the License at 8 | rem 9 | rem https://www.apache.org/licenses/LICENSE-2.0 10 | rem 11 | rem Unless required by applicable law or agreed to in writing, software 12 | rem distributed under the License is distributed on an "AS IS" BASIS, 13 | rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | rem See the License for the specific language governing permissions and 15 | rem limitations under the License. 16 | 17 | call mybanner starting 18 | %myserv% //ES//TestService 19 | if %errorlevel% neq 0 ( 20 | echo "start failed" 21 | %myserv% //PS//TestService 22 | dir %mypath% 23 | type %mypath%\*.log 24 | exit 1 25 | ) 26 | EXIT /B 0 27 | -------------------------------------------------------------------------------- /src/native/windows/apps/prunsrv/test/scripts/testservice.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | rem Licensed to the Apache Software Foundation (ASF) under one or more 3 | rem contributor license agreements. See the NOTICE file distributed with 4 | rem this work for additional information regarding copyright ownership. 5 | rem The ASF licenses this file to You under the Apache License, Version 2.0 6 | rem (the "License"); you may not use this file except in compliance with 7 | rem the License. You may obtain a copy of the License at 8 | rem 9 | rem https://www.apache.org/licenses/LICENSE-2.0 10 | rem 11 | rem Unless required by applicable law or agreed to in writing, software 12 | rem distributed under the License is distributed on an "AS IS" BASIS, 13 | rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | rem See the License for the specific language governing permissions and 15 | rem limitations under the License. 16 | 17 | call mybanner testing 18 | java -cp %myjar% org.apache.commons.daemon.ProcrunDaemon 0 19 | if %errorlevel% neq 0 ( 20 | echo "Java part of the service doesn't answer" 21 | exit 1 22 | ) 23 | echo "testing Done" 24 | EXIT /B 0 25 | -------------------------------------------------------------------------------- /src/native/unix/native/location.h: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __JSVC_LOCATION_H__ 18 | #define __JSVC_LOCATION_H__ 19 | 20 | #include "jsvc.h" 21 | 22 | extern char *location_home[]; 23 | extern char *location_jvm_cfg[]; 24 | extern char *location_jvm_default[]; 25 | extern char *location_jvm_configured[]; 26 | 27 | #endif /* __JSVC_LOCATION_H__ */ 28 | 29 | -------------------------------------------------------------------------------- /src/native/unix/Makedefs.in: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | # @author Pier Fumagalli 19 | 20 | CC = @CC@ 21 | CFLAGS = @CFLAGS@ 22 | CPPFLAGS = @CPPFLAGS@ 23 | INCLUDES = @INCLUDES@ 24 | LDFLAGS = @LDFLAGS@ 25 | LIBS = @LIBS@ 26 | RANLIB = @RANLIB@ 27 | LDCMD = @LDCMD@ 28 | STRIP = @STRIP@ 29 | 30 | .c.o: 31 | $(CC) $(CFLAGS) $(CPPFLAGS) $(EXTRA_CFLAGS) $(INCLUDES) -c $< -o $@ 32 | -------------------------------------------------------------------------------- /src/native/unix/support/buildconf.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Licensed to the Apache Software Foundation (ASF) under one or more 4 | # contributor license agreements. See the NOTICE file distributed with 5 | # this work for additional information regarding copyright ownership. 6 | # The ASF licenses this file to You under the Apache License, Version 2.0 7 | # (the "License"); you may not use this file except in compliance with 8 | # the License. You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | 18 | # The cache of automake always brings problems when changing *.m4 files. 19 | rm -rf autom4te.cache 20 | 21 | if test -f configure.ac ; then 22 | autoreconf -fi 23 | if test $? -ne 0 ; then 24 | echo "$0: cannot generate configure script" 25 | else 26 | echo "$0: configure script generated successfully" 27 | fi 28 | else 29 | echo "$0: cannot find source file configure.ac" 30 | fi 31 | -------------------------------------------------------------------------------- /src/native/windows/xdocs/index.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 20 | Daemon : Procrun 21 | Mladen Turk 22 | 23 | 24 | 25 |
26 |

27 | Procrun is a set of libraries and applications for making Java 28 | applications to run on WIN32 much easier. 29 |

30 |
31 | 32 | 33 |
34 | -------------------------------------------------------------------------------- /src/native/unix/Makefile.in: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | SUBDIRS = native 19 | 20 | all: native/all 21 | 22 | native/all: 23 | (cd native; $(MAKE) all) 24 | 25 | clean: 26 | (cd native; $(MAKE) clean) 27 | 28 | distclean: clean 29 | rm -f config.cache 30 | rm -f config.log 31 | rm -f config.status 32 | rm -f config.nice 33 | rm -f native/Makefile 34 | rm -f Makefile 35 | rm -f Makedefs 36 | rm -rf autom4te.cache 37 | 38 | realclean: distclean 39 | rm -f configure 40 | -------------------------------------------------------------------------------- /src/samples/Native.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Licensed to the Apache Software Foundation (ASF) under one or more 4 | # contributor license agreements. See the NOTICE file distributed with 5 | # this work for additional information regarding copyright ownership. 6 | # The ASF licenses this file to You under the Apache License, Version 2.0 7 | # (the "License"); you may not use this file except in compliance with 8 | # the License. You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | # for linux ;-) and Mac OS X 19 | case `uname -s` in 20 | Darwin) 21 | JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK 22 | INCLUDE=Headers 23 | OS= 24 | FLAGS=-dynamiclib 25 | ;; 26 | Linux) 27 | OS=linux 28 | INCLUDE=include 29 | FLAGS=-shared 30 | ;; 31 | esac 32 | 33 | gcc -c -I${JAVA_HOME}/${INCLUDE} -I${JAVA_HOME}/${INCLUDE}/${OS} Native.c 34 | gcc ${FLAGS} -o Native.so Native.o 35 | -------------------------------------------------------------------------------- /.github/workflows/dependency-review.yml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | name: 'Dependency Review' 19 | on: [pull_request] 20 | 21 | permissions: 22 | contents: read 23 | 24 | jobs: 25 | dependency-review: 26 | runs-on: ubuntu-latest 27 | steps: 28 | - name: 'Checkout Repository' 29 | uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 30 | - name: 'Dependency Review PR' 31 | uses: actions/dependency-review-action@3c4e3dcb1aa7874d2c16be7d79418e9b7efd6261 # v4.8.2 32 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/daemon/DaemonInitExceptionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.daemon; 19 | 20 | import static org.junit.jupiter.api.Assertions.assertEquals; 21 | 22 | import java.io.IOException; 23 | 24 | import org.junit.jupiter.api.Test; 25 | 26 | class DaemonInitExceptionTest { 27 | 28 | @Test 29 | void test() { 30 | final IOException e = new IOException(); 31 | assertEquals(e, new DaemonInitException("Test", e).getCause()); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/native/unix/native/dso.h: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __JSVC_DSO_H__ 18 | #define __JSVC_DSO_H__ 19 | 20 | #include "jsvc.h" 21 | 22 | /** 23 | * A library handle represents a unique pointer to its location in memory. 24 | */ 25 | #ifdef DSO_DYLD 26 | #include 27 | #endif 28 | typedef void *dso_handle; 29 | 30 | bool dso_init(void); 31 | dso_handle dso_link(const char *pth); 32 | bool dso_unlink(dso_handle lib); 33 | void *dso_symbol(dso_handle lib, const char *nam); 34 | char *dso_error(void); 35 | 36 | #endif /* __JSVC_DSO_H__ */ 37 | 38 | -------------------------------------------------------------------------------- /src/samples/Native.c: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /* 18 | * Native routine to core JVM 19 | */ 20 | #include 21 | 22 | #ifndef _Included_Native 23 | #define _Included_Native 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | /* 28 | * Class: Native 29 | * Method: toto 30 | * Signature: ()V 31 | */ 32 | JNIEXPORT void JNICALL Java_SimpleDaemon_toto 33 | (JNIEnv *env, jclass class) { 34 | int i; 35 | i = -1; 36 | memcpy(&i, &i, i); 37 | memset(&i, ' ', 1024); 38 | } 39 | 40 | #ifdef __cplusplus 41 | } 42 | #endif 43 | #endif 44 | -------------------------------------------------------------------------------- /src/native/windows/apps/prunsrv/prunsrv.h: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /* ==================================================================== 18 | * jar2exe -- convert .jar file to WIN32 executable. 19 | * Contributed by Mladen Turk 20 | * 05 Aug 2003 21 | * ==================================================================== 22 | */ 23 | 24 | #ifndef _PRUNSRV_H 25 | #define _PRUNSRV_H 26 | 27 | #undef PRG_VERSION 28 | #define PRG_VERSION "1.5.1.0" 29 | #define PRG_REGROOT L"Apache Software Foundation\\Procrun 2.0" 30 | 31 | #endif /* _PRUNSRV_H */ 32 | 33 | -------------------------------------------------------------------------------- /src/native/unix/native/java.h: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __JSVC_JAVA_H__ 18 | #define __JSVC_JAVA_H__ 19 | 20 | #define LOADER "org/apache/commons/daemon/support/DaemonLoader" 21 | 22 | char *java_library(arg_data *args, home_data *data); 23 | bool java_init(arg_data *args, home_data *data); 24 | bool java_destroy(void); 25 | bool java_load(arg_data *args); 26 | bool java_signal(void); 27 | bool java_start(void); 28 | bool java_stop(void); 29 | bool java_version(void); 30 | bool java_check(arg_data *args); 31 | bool JVM_destroy(int exit); 32 | 33 | #endif /* __JSVC_JAVA_H__ */ 34 | 35 | -------------------------------------------------------------------------------- /src/native/unix/native/Makefile.in: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | include ../Makedefs 18 | 19 | OBJS = arguments.o \ 20 | debug.o \ 21 | dso-dlfcn.o \ 22 | dso-dyld.o \ 23 | help.o \ 24 | home.o \ 25 | java.o \ 26 | location.o \ 27 | replace.o \ 28 | locks.o \ 29 | signals.o 30 | 31 | all: jsvc libservice.a 32 | 33 | libservice.a: $(OBJS) 34 | ar cr libservice.a $(OBJS) 35 | $(RANLIB) libservice.a 36 | 37 | jsvc: jsvc-unix.o libservice.a 38 | $(LDCMD) $(LDFLAGS) $(EXTRA_LDFLAGS) jsvc-unix.o libservice.a $(LIBS) -o ../jsvc 39 | $(STRIP) ../jsvc 40 | 41 | clean: 42 | rm -f $(OBJS) ../jsvc jsvc-unix.o libservice.a 43 | 44 | -------------------------------------------------------------------------------- /src/native/windows/apps/prunsrv/test/scripts/cleanstd.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | rem Licensed to the Apache Software Foundation (ASF) under one or more 3 | rem contributor license agreements. See the NOTICE file distributed with 4 | rem this work for additional information regarding copyright ownership. 5 | rem The ASF licenses this file to You under the Apache License, Version 2.0 6 | rem (the "License"); you may not use this file except in compliance with 7 | rem the License. You may obtain a copy of the License at 8 | rem 9 | rem https://www.apache.org/licenses/LICENSE-2.0 10 | rem 11 | rem Unless required by applicable law or agreed to in writing, software 12 | rem distributed under the License is distributed on an "AS IS" BASIS, 13 | rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | rem See the License for the specific language governing permissions and 15 | rem limitations under the License. 16 | 17 | rem the files: 18 | rem rw-r--r-- 1 Administrator None 0 Apr 28 00:55 testservice-stderr.2025-04-28.log 19 | rem rw-r--r-- 1 Administrator None 0 Apr 28 00:55 testservice-stdout.2025-04-28.log 20 | rem needs to be removed between tests. 21 | 22 | SET "full_date=%date:~4,10%" 23 | SET "month=%full_date:~0,2%" 24 | SET "day=%full_date:~3,2%" 25 | SET "year=%full_date:~6,4%" 26 | 27 | del "testservice-stdout.%year%-%month%-%day%.log" 2>nul 28 | 29 | del "testservice-stderr.%year%-%month%-%day%.log" 2>nul 30 | -------------------------------------------------------------------------------- /src/native/unix/native/signals.h: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __JSVC_SIGNALS_H__ 17 | #define __JSVC_SIGNALS_H__ 18 | 19 | /* 20 | * as Windows does not support signal, jsvc use event to emulate them. 21 | * The supported signal is SIGTERM. 22 | */ 23 | #ifdef OS_CYGWIN 24 | /* 25 | * set a routine handler for the signal 26 | * note that it cannot be used to change the signal handler 27 | * @param func The function to call on termination 28 | * @return Zero on success, a value less than 0 if an error was encountered 29 | */ 30 | int SetTerm(void (*func) (void)); 31 | 32 | #endif 33 | #endif /* ifndef __JSVC_SIGNALS_H__ */ 34 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/daemon/DaemonUserSignal.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.daemon; 19 | 20 | /** 21 | * Tags a Daemon as supporting some kind of 22 | * signaling method that allows the Java application to 23 | * perform a custom action. 24 | *

25 | * User must implement a signal method that will be called from 26 | * native upon receiving {@code SIGUSR2} signal from the operating system. 27 | *

28 | */ 29 | public interface DaemonUserSignal 30 | { 31 | 32 | /** 33 | * Performs a custom action on received user signal. 34 | */ 35 | void signal(); 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/native/unix/man/fetch.sh: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | mkdir -p ent 17 | rm -f JSVC.1 18 | while true 19 | do 20 | FILE=`docbook2man jsvc.1.xml 2>&1 | grep FileNotFoundException | awk -F FileNotFoundException: ' { print $2 } ' | awk ' { print $1 } '` 21 | if [ -f JSVC.1 ] 22 | then 23 | break 24 | fi 25 | echo "FILE: $FILE" 26 | file=`basename $FILE` 27 | dir=`dirname $FILE` 28 | man=`basename $dir` 29 | echo "file: $file dir: $dir man: $man" 30 | if [ "$man" = "ent" ] 31 | then 32 | (cd ent; wget http://www.oasis-open.org/docbook/xml/4.1.2/ent/$file) 33 | else 34 | wget http://www.oasis-open.org/docbook/xml/4.1.2/$file 35 | fi 36 | done 37 | -------------------------------------------------------------------------------- /src/native/windows/apps/prunsrv/test/scripts/waituntilstop.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | rem Licensed to the Apache Software Foundation (ASF) under one or more 3 | rem contributor license agreements. See the NOTICE file distributed with 4 | rem this work for additional information regarding copyright ownership. 5 | rem The ASF licenses this file to You under the Apache License, Version 2.0 6 | rem (the "License"); you may not use this file except in compliance with 7 | rem the License. You may obtain a copy of the License at 8 | rem 9 | rem https://www.apache.org/licenses/LICENSE-2.0 10 | rem 11 | rem Unless required by applicable law or agreed to in writing, software 12 | rem distributed under the License is distributed on an "AS IS" BASIS, 13 | rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | rem See the License for the specific language governing permissions and 15 | rem limitations under the License. 16 | 17 | SET result=0 18 | SETLOCAL ENABLEDELAYEDEXPANSION 19 | for /l %%x in (1, 1, 100) do ( 20 | echo "testing service %%x" 21 | java -cp %myjar% org.apache.commons.daemon.ProcrunDaemon 1 > nul 2>&1 22 | findstr Exception client.txt > nul 2>&1 23 | IF !ERRORLEVEL! EQU 0 ( 24 | echo "Found" 25 | SET result=1 26 | goto :EndLoop 27 | ) ELSE ( 28 | echo "NOT Found" 29 | ) 30 | timeout /t 10 > nul 31 | ) 32 | 33 | :EndLoop 34 | ENDLOCAL 35 | echo "Done result: %result%" 36 | IF %result% EQU 0 ( 37 | exit /b 0 38 | ) 39 | exit /b 1 40 | -------------------------------------------------------------------------------- /src/native/windows/include/security.h: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _SECURITY_H_INCLUDED_ 18 | #define _SECURITY_H_INCLUDED_ 19 | 20 | __APXBEGIN_DECLS 21 | 22 | #define DEFAULT_SERVICE_USER L"NT AUTHORITY\\LocalService" 23 | 24 | #define STAT_SERVICE L"NT AUTHORITY\\LocalService" 25 | #define STAT_NET_SERVICE L"NT AUTHORITY\\NetworkService" 26 | #define STAT_SYSTEM L"LocalSystem" 27 | 28 | #define STAT_SYSTEM_WITH_DOMAIN L"NT AUTHORITY\\System" 29 | 30 | DWORD 31 | apxSecurityGrantFileAccessToUser( 32 | LPCWSTR szPath, 33 | LPCWSTR szUser); 34 | 35 | __APXEND_DECLS 36 | 37 | #endif /* _SECURITY_H_INCLUDED_ */ 38 | -------------------------------------------------------------------------------- /.asf.yaml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | github: 17 | description: "Apache Commons Daemon" 18 | homepage: https://commons.apache.org/daemon/ 19 | 20 | notifications: 21 | commits: commits@commons.apache.org 22 | issues: issues@commons.apache.org 23 | pullrequests: issues@commons.apache.org 24 | jira_options: link label 25 | jobs: notifications@commons.apache.org 26 | # commits_bot_dependabot: dependabot@commons.apache.org 27 | issues_bot_dependabot: dependabot@commons.apache.org 28 | pullrequests_bot_dependabot: dependabot@commons.apache.org 29 | issues_bot_codecov-commenter: notifications@commons.apache.org 30 | pullrequests_bot_codecov-commenter: notifications@commons.apache.org 31 | -------------------------------------------------------------------------------- /src/native/windows/apps/prunsrv/prunsrv.manifest: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 20 | Apache Commons Daemon Service Runner 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /src/samples/ServiceDaemon.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Licensed to the Apache Software Foundation (ASF) under one or more 4 | # contributor license agreements. See the NOTICE file distributed with 5 | # this work for additional information regarding copyright ownership. 6 | # The ASF licenses this file to You under the Apache License, Version 2.0 7 | # (the "License"); you may not use this file except in compliance with 8 | # the License. You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | # Small shell script to show how to start the sample services. 19 | # 20 | # Adapt the following lines to your configuration 21 | JAVA_HOME=/cygdrive/c/jdk1.3.1_02 22 | HOME=c:\\cygwin\\home\\Standard 23 | DAEMON_HOME=$HOME\\jakarta-commons-sandbox\\daemon 24 | DAEMON_HOME_SH=/home/Standard/jakarta-commons-sandbox/daemon 25 | TOMCAT_USER=jakarta 26 | CLASSPATH=\ 27 | $DAEMON_HOME\\dist\\commons-daemon.jar\;\ 28 | $HOME\\commons-collections-1.0\\commons-collections.jar\;\ 29 | $DAEMON_HOME\\dist\\Service.jar 30 | 31 | $DAEMON_HOME_SH/dist/jsvc \ 32 | -home $JAVA_HOME \ 33 | -cp $CLASSPATH \ 34 | ServiceDaemon 35 | # 36 | # To get a verbose JVM 37 | #-verbose \ 38 | # To get a debug of jsvc. 39 | #-debug \ 40 | -------------------------------------------------------------------------------- /src/native/unix/native/home.h: -------------------------------------------------------------------------------- 1 | /* 2 | Licensed to the Apache Software Foundation (ASF) under one or more 3 | contributor license agreements. See the NOTICE file distributed with 4 | this work for additional information regarding copyright ownership. 5 | The ASF licenses this file to You under the Apache License, Version 2.0 6 | (the "License"); you may not use this file except in compliance with 7 | the License. You may obtain a copy of the License at 8 | 9 | https://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | */ 17 | #ifndef __JSVC_HOME_H__ 18 | #define __JSVC_HOME_H__ 19 | 20 | typedef struct home_jvm home_jvm; 21 | typedef struct home_data home_data; 22 | 23 | struct home_jvm 24 | { 25 | char *name; 26 | char *libr; 27 | }; 28 | 29 | struct home_data 30 | { 31 | char *path; 32 | char *cfgf; 33 | home_jvm **jvms; 34 | int jnum; 35 | }; 36 | 37 | /** 38 | * Attempt to locate a Java Home directory and build its structure. 39 | * 40 | * @param path The java home path specified on the command line. 41 | * @return A home_data structure containing all informations related to 42 | * the Java environment, or NULL if no home was found. 43 | */ 44 | home_data *home(char *path); 45 | 46 | #endif /* ifndef __JSVC_HOME_H__ */ 47 | -------------------------------------------------------------------------------- /src/native/unix/native/locks.h: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __JSVC_LOCKS_H__ 18 | #define __JSVC_LOCKS_H__ 19 | 20 | /* 21 | * as Cygwin does not support locks, jsvc use NT API to emulate them. 22 | */ 23 | #ifdef OS_CYGWIN 24 | 25 | #define F_ULOCK 0 /* Unlock a previously locked region */ 26 | #define F_LOCK 1 /* Lock a region for exclusive use */ 27 | 28 | /* 29 | * allow a file to be locked 30 | * @param fildes an open file descriptor 31 | * @param function a control value that specifies the action to be taken 32 | * @param size number of bytes to lock 33 | * @return Zero on success, a value less than 0 if an error was encountered 34 | */ 35 | int lockf(int fildes, int function, off_t size); 36 | 37 | #endif 38 | #endif /* __JSVC_LOCKS_H__ */ 39 | 40 | -------------------------------------------------------------------------------- /src/samples/ProcrunServiceRemove.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | rem 3 | rem Licensed to the Apache Software Foundation (ASF) under one or more 4 | rem contributor license agreements. See the NOTICE file distributed with 5 | rem this work for additional information regarding copyright ownership. 6 | rem The ASF licenses this file to You under the Apache License, Version 2.0 7 | rem (the "License"); you may not use this file except in compliance with 8 | rem the License. You may obtain a copy of the License at 9 | rem 10 | rem https://www.apache.org/licenses/LICENSE-2.0 11 | rem 12 | rem Unless required by applicable law or agreed to in writing, software 13 | rem distributed under the License is distributed on an "AS IS" BASIS, 14 | rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | rem See the License for the specific language governing permissions and 16 | rem limitations under the License. 17 | 18 | rem Batch script for removing the ProcrunService (JVM and Java versions) 19 | 20 | setlocal 21 | 22 | rem The service names (make sure they does not clash with an existing service) 23 | set SERVICE_JVM=ProcrunServiceJvm 24 | set SERVICE_JAVA=ProcrunServiceJava 25 | 26 | rem my location 27 | set MYPATH=%~dp0 28 | 29 | rem location of Prunsrv 30 | set PATH_PRUNSRV=%MYPATH% 31 | set PR_LOGPATH=%PATH_PRUNSRV% 32 | rem Allow prunsrv to be overridden 33 | if "%PRUNSRV%" == "" set PRUNSRV=%PATH_PRUNSRV%prunsrv 34 | 35 | echo Removing %SERVICE_JVM% 36 | %PRUNSRV% //DS//%SERVICE_JVM% 37 | 38 | echo Removing %SERVICE_JAVA% 39 | %PRUNSRV% //DS//%SERVICE_JAVA% 40 | %PRUNSRV% //IS//%SERVICE_JAVA% 41 | 42 | echo Finished 43 | -------------------------------------------------------------------------------- /src/native/unix/native/locks.c: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /* 18 | * as Cygwin does not support lockf, jsvc uses fcntl to emulate it. 19 | */ 20 | #ifdef OS_CYGWIN 21 | #include "jsvc.h" 22 | #include 23 | 24 | /* 25 | * File locking routine 26 | */ 27 | int lockf(int fildes, int function, off_t size) 28 | { 29 | struct flock buf; 30 | 31 | switch (function) { 32 | case F_LOCK: 33 | buf.l_type = F_WRLCK; 34 | break; 35 | case F_ULOCK: 36 | buf.l_type = F_UNLCK; 37 | break; 38 | default: 39 | return -1; 40 | } 41 | buf.l_whence = 0; 42 | buf.l_start = 0; 43 | buf.l_len = size; 44 | 45 | return fcntl(fildes, F_SETLK, &buf); 46 | } 47 | #else 48 | const char __unused_locks_c[] = __FILE__; 49 | #endif 50 | -------------------------------------------------------------------------------- /src/samples/AloneDaemon.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Licensed to the Apache Software Foundation (ASF) under one or more 4 | # contributor license agreements. See the NOTICE file distributed with 5 | # this work for additional information regarding copyright ownership. 6 | # The ASF licenses this file to You under the Apache License, Version 2.0 7 | # (the "License"); you may not use this file except in compliance with 8 | # the License. You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | # Small shell script to show how to start the sample services. 19 | # That is for Linux, if your are using cygwin look to ServiceDaemon.sh. 20 | # 21 | # Adapt the following lines to your configuration 22 | JAVA_HOME=`echo $JAVA_HOME` 23 | DAEMON_HOME=`(cd ../..; pwd)` 24 | USER_HOME=`(cd ../../../..; pwd)` 25 | TOMCAT_USER=`echo $USER` 26 | CLASSPATH=\ 27 | $DAEMON_HOME/dist/commons-daemon.jar:\ 28 | $USER_HOME/commons-collections-2.1/commons-collections.jar:\ 29 | $DAEMON_HOME/dist/aloneservice.jar 30 | 31 | $DAEMON_HOME/src/native/unix/jsvc \ 32 | -home $JAVA_HOME \ 33 | -cp $CLASSPATH \ 34 | -pidfile ./pidfile \ 35 | -debug \ 36 | AloneService 37 | # 38 | # To get a verbose JVM 39 | #-verbose \ 40 | # To get a debug of jsvc. 41 | #-debug \ 42 | # -user $TOMCAT_USER \ 43 | -------------------------------------------------------------------------------- /src/native/unix/native/jsvc.h: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __JSVC_H__ 18 | #define __JSVC_H__ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | /* Definitions for booleans */ 28 | #ifdef OS_DARWIN 29 | #include 30 | #else 31 | typedef enum { 32 | false, 33 | true 34 | } bool; 35 | #endif 36 | 37 | #include "version.h" 38 | #include "debug.h" 39 | #include "arguments.h" 40 | #include "home.h" 41 | #include "location.h" 42 | #include "replace.h" 43 | #include "dso.h" 44 | #include "java.h" 45 | #include "help.h" 46 | #include "signals.h" 47 | #include "locks.h" 48 | 49 | int main(int argc, char *argv[]); 50 | void main_reload(void); 51 | void main_shutdown(void); 52 | 53 | #endif /* ifndef __JSVC_H__ */ 54 | 55 | -------------------------------------------------------------------------------- /src/samples/ServiceDaemonReadThread.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | import java.io.InputStream; 19 | import java.io.IOException; 20 | import java.lang.Thread; 21 | import java.io.BufferedReader; 22 | import java.io.InputStreamReader; 23 | 24 | public class ServiceDaemonReadThread extends Thread { 25 | private BufferedReader in; 26 | ServiceDaemonReadThread(InputStream in) { 27 | this.in = new BufferedReader(new InputStreamReader(in)); 28 | } 29 | @Override 30 | public void run() { 31 | String buff; 32 | for (;;) { 33 | try { 34 | buff = in.readLine(); 35 | if (buff == null) break; 36 | System.err.print(in.readLine()); 37 | } catch (IOException ex) { 38 | break; // Exit thread. 39 | } 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/native/windows/apps/prunmgr/prunmgr.manifest: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 20 | Apache Procrun Service Manager 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /src/samples/README.txt: -------------------------------------------------------------------------------- 1 | The directory contains examples of Java daemons. 2 | The examples are compiled using Ant (just type ant). Each example creates a 3 | jar file in ../../dist 4 | 5 | SimpleDaemon 6 | ------------ 7 | 8 | SimpleDaemon demonstrates the feature of the daemon offered by 9 | Apache Commons Daemon. 10 | To run it, adapt the SimpleDaemon.sh file and connect to it using: 11 | telnet localhost 1200 12 | Additional information in ../native/unix/INSTALL.txt 13 | 14 | ServiceDaemon 15 | ------------- 16 | 17 | ServiceDaemon allows to start programs using the Commons Daemon. 18 | 19 | That could be useful when using Cygwin under Win9x because Cygwin only offers 20 | services support under Win NT/2000/XP. 21 | (See in ../native/nt/README how to install jsvc as a service in Win32). 22 | 23 | It uses Apache Commons Collections: 24 | https://commons.apache.org/collections/ 25 | To use it you need at least commons-collections-1.0 26 | Check in build.xml that the property commons-collections.jar correspond to the 27 | location of your commons-collections.jar file. 28 | 29 | You have to create a file named startfile that uses a property format: 30 | name = string to start the program 31 | 32 | For example: 33 | sshd=/usr/sbin/sshd -D 34 | router1=/home/Standard/router/router pop3 pop3.example.net 35 | router2=/home/Standard/router/smtp smtp.example.net 36 | socks5=/usr/local/bin/socks5 -f 37 | 38 | To run it, adapt the ServiceDaemon.sh file. 39 | 40 | AloneService 41 | ------------ 42 | 43 | AloneService is like ServiceDaemon except it does not use the Daemon interface. 44 | 45 | ProcrunService 46 | -------------- 47 | This is a simple Windows Service application. 48 | It can be run either in Jvm or Java modes. 49 | See ProcrunServiceInstall.cmd for a sample installation script. 50 | -------------------------------------------------------------------------------- /src/native/unix/native/replace.h: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __JSVC_REPLACE_H__ 18 | #define __JSVC_REPLACE_H__ 19 | 20 | /** 21 | * Replace all occurrences of mch in old with the new string rpl, and 22 | * stores the result in new, provided that its length (specified in len) 23 | * is enough. 24 | * 25 | * @param new The buffer where the result of the replace operation will be 26 | * stored into. 27 | * @param len The length of the previous buffer. 28 | * @param old The string where occurrences of mtch must be searched. 29 | * @param mch The characters to match in old (and to be replaced) 30 | * @param rpl The characters that will be replaced in place of mch. 31 | * @return Zero on success, a value less than 0 if an error was encountered 32 | * or a value greater than zero (indicating the required storage size 33 | * for new) if the buffer was too short to hold the new string. 34 | */ 35 | int replace(char *new, int len, char *old, char *mch, char *rpl); 36 | 37 | #endif /* ifndef __JSVC_REPLACE_H__ */ 38 | 39 | -------------------------------------------------------------------------------- /src/samples/SimpleApplication.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Licensed to the Apache Software Foundation (ASF) under one or more 4 | # contributor license agreements. See the NOTICE file distributed with 5 | # this work for additional information regarding copyright ownership. 6 | # The ASF licenses this file to You under the Apache License, Version 2.0 7 | # (the "License"); you may not use this file except in compliance with 8 | # the License. You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | # Small shell script to show how to start the sample services. 19 | # 20 | # Adapt the following lines to your configuration 21 | JAVA_HOME=/opt/java6 22 | PROGRAM=SimpleApplication 23 | CLASSPATH=`pwd`/$PROGRAM.jar:`pwd`/commons-daemon-1.5.1.jar 24 | 25 | case "$1" in 26 | start ) 27 | shift 28 | ./jsvc \ 29 | -home $JAVA_HOME \ 30 | -cp $CLASSPATH \ 31 | -nodetach \ 32 | -errfile "&2" \ 33 | -pidfile `pwd`/$PROGRAM.pid \ 34 | @$PROGRAM \ 35 | -start-method main \ 36 | $* 37 | exit $? 38 | ;; 39 | stop ) 40 | shift 41 | ./jsvc \ 42 | -home $JAVA_HOME \ 43 | -cp $CLASSPATH \ 44 | -stop \ 45 | -nodetach \ 46 | -errfile "&2" \ 47 | -pidfile `pwd`/$PROGRAM.pid \ 48 | @$PROGRAM \ 49 | -start-method main \ 50 | $* 51 | exit $? 52 | ;; 53 | * ) 54 | echo 'Usage SimpleApplication.sh start | stop' 55 | exit 1 56 | ;; 57 | esac 58 | -------------------------------------------------------------------------------- /src/assembly/win.xml: -------------------------------------------------------------------------------- 1 | 17 | 20 | bin-windows 21 | 22 | zip 23 | 24 | 25 | false 26 | 27 | 28 | 29 | LICENSE.txt 30 | NOTICE.txt 31 | RELEASE-NOTES.txt 32 | 33 | 34 | 35 | target 36 | 37 | 38 | *.exe 39 | amd64/*.exe 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /src/native/unix/native/dso-dlfcn.c: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jsvc.h" 18 | 19 | #ifdef DSO_DLFCN 20 | #include 21 | #ifdef OS_LINUX 22 | bool ld_library_path_set = false; 23 | #endif /* ifdef OS_LINUX */ 24 | 25 | /* Initialize all DSO stuff */ 26 | bool dso_init(void) 27 | { 28 | return true; 29 | } 30 | 31 | /* Attempt to link a library from a specified filename */ 32 | dso_handle dso_link(const char *path) 33 | { 34 | log_debug("Attemtping to load library %s", path); 35 | 36 | return ((void *)dlopen(path, RTLD_GLOBAL | RTLD_NOW)); 37 | } 38 | 39 | /* Attempt to unload a library */ 40 | bool dso_unlink(dso_handle libr) 41 | { 42 | if (dlclose(libr) == 0) 43 | return true; 44 | else 45 | return false; 46 | } 47 | 48 | /* Get the address for a specified symbol */ 49 | void *dso_symbol(dso_handle hdl, const char *nam) 50 | { 51 | return dlsym(hdl, nam); 52 | } 53 | 54 | /* Return the error message from dlopen */ 55 | char *dso_error(void) 56 | { 57 | return (dlerror()); 58 | } 59 | 60 | #endif /* ifdef DSO_DLFCN */ 61 | -------------------------------------------------------------------------------- /src/native/windows/apps/prunsrv/test/scripts/isemptystd.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | rem Licensed to the Apache Software Foundation (ASF) under one or more 3 | rem contributor license agreements. See the NOTICE file distributed with 4 | rem this work for additional information regarding copyright ownership. 5 | rem The ASF licenses this file to You under the Apache License, Version 2.0 6 | rem (the "License"); you may not use this file except in compliance with 7 | rem the License. You may obtain a copy of the License at 8 | rem 9 | rem https://www.apache.org/licenses/LICENSE-2.0 10 | rem 11 | rem Unless required by applicable law or agreed to in writing, software 12 | rem distributed under the License is distributed on an "AS IS" BASIS, 13 | rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | rem See the License for the specific language governing permissions and 15 | rem limitations under the License. 16 | 17 | rem the files: 18 | rem rw-r--r-- 1 Administrator None 0 Apr 28 00:55 testservice-stderr.2025-04-28.log 19 | rem rw-r--r-- 1 Administrator None 0 Apr 28 00:55 testservice-stdout.2025-04-28.log 20 | rem should NOT be empty 21 | 22 | SET "full_date=%date:~4,10%" 23 | SET "month=%full_date:~0,2%" 24 | SET "day=%full_date:~3,2%" 25 | SET "year=%full_date:~6,4%" 26 | CALL :TestFile "testservice-stdout.%year%-%month%-%day%.log" 27 | IF %ERRORLEVEL% EQU 1 ( 28 | echo "FAILED: stdout file empty or not existing" 29 | exit 1 30 | ) 31 | CALL :TestFile "testservice-stderr.%year%-%month%-%day%.log" 32 | IF %ERRORLEVEL% EQU 1 ( 33 | echo "FAILED stderr file empty or not existing" 34 | exit 1 35 | ) 36 | 37 | goto :eof 38 | 39 | :TestFile 40 | SET "filepath=%~1" 41 | IF NOT EXIST "%filepath%" ( 42 | echo "file %filepath% don't exist" 43 | exit /b 1 44 | ) 45 | echo %~z1 46 | If %~z1 EQU 0 ( 47 | echo "file %filepath% is empty" 48 | Exit /B 1 49 | ) 50 | echo "file %filepath% is NOT empty" 51 | Exit /B 0 52 | -------------------------------------------------------------------------------- /RELEASE-NOTES.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | Licensed to the Apache Software Foundation (ASF) under one or more 3 | contributor license agreements. See the NOTICE file distributed with 4 | this work for additional information regarding copyright ownership. 5 | The ASF licenses this file to You under the Apache License, Version 2.0 6 | (the "License"); you may not use this file except in compliance with 7 | the License. You may obtain a copy of the License at 8 | 9 | https://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | ================================================================================ 17 | 18 | Apache Commons Daemon 1.5.1 19 | Release Notes 20 | 21 | This document contains the release notes for this version of the 22 | Apache Commons Daemon package, and highlights new features in the 1.5 23 | releases compared to the 1.4 releases. 24 | 25 | 26 | New Features 27 | ------------ 28 | 29 | - Added support for --enable-native-access Java startup option in jsvc 30 | 31 | 32 | Bug Fixes 33 | --------- 34 | 35 | - Please see the change log 36 | https://commons.apache.org/proper/commons-daemon/changes-report.html 37 | 38 | 39 | Feedback 40 | -------- 41 | Open source works best when you give feedback: 42 | https://commons.apache.org/daemon/ 43 | 44 | Please direct all bug reports to JIRA 45 | https://issues.apache.org/jira/browse/DAEMON 46 | 47 | Or subscribe to the commons-user mailing list (prefix emails by [daemon]) 48 | https://commons.apache.org/mail-lists.html 49 | 50 | The Apache Commons Daemon Team 51 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/daemon/DaemonContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.daemon; 19 | 20 | /** 21 | * Defines a set of methods that a Daemon instance can use to 22 | * communicate with the Daemon container. 23 | */ 24 | public interface DaemonContext 25 | { 26 | 27 | /** 28 | * Gets a {@link DaemonController} object that can be used to control 29 | * the {@link Daemon} instance that this {@code DaemonContext} 30 | * is passed to. 31 | * 32 | * @return A {@link DaemonController} object that can be used to control 33 | * the {@link Daemon}. 34 | */ 35 | DaemonController getController(); 36 | 37 | /** 38 | * Gets an array of {@link String} arguments supplied by the environment 39 | * corresponding to the array of arguments given in the 40 | * {@code public static void main()} method used as an entry 41 | * point to most other Java programs. 42 | * 43 | * @return An array of {@link String} arguments supplied by the environment. 44 | */ 45 | String[] getArguments(); 46 | 47 | } 48 | 49 | -------------------------------------------------------------------------------- /src/assembly/bin.xml: -------------------------------------------------------------------------------- 1 | 17 | 20 | bin 21 | 22 | tar.gz 23 | zip 24 | 25 | false 26 | 27 | 28 | 29 | LICENSE.txt 30 | NOTICE.txt 31 | RELEASE-NOTES.txt 32 | 33 | 34 | 35 | target 36 | 37 | 38 | *.jar 39 | 40 | 41 | 42 | target/site/apidocs 43 | apidocs 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | 19 | 20 | Thanks for your contribution to [Apache Commons](https://commons.apache.org/)! Your help is appreciated! 21 | 22 | Before you push a pull request, review this list: 23 | 24 | - [ ] Read the [contribution guidelines](CONTRIBUTING.md) for this project. 25 | - [ ] Read the [ASF Generative Tooling Guidance](https://www.apache.org/legal/generative-tooling.html) if you use Artificial Intelligence (AI). 26 | - [ ] I used AI to create any part of, or all of, this pull request. Which AI tool was used to create this pull request, and to what extent did it contribute? 27 | - [ ] Run a successful build using the default [Maven](https://maven.apache.org/) goal with `mvn`; that's `mvn` on the command line by itself. 28 | - [ ] Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied. This may not always be possible, but it is a best practice. 29 | - [ ] Write a pull request description that is detailed enough to understand what the pull request does, how, and why. 30 | - [ ] Each commit in the pull request should have a meaningful subject line and body. Note that a maintainer may squash commits during the merge process. 31 | -------------------------------------------------------------------------------- /src/native/unix/native/debug.h: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __JSVC_DEBUG_H__ 18 | #define __JSVC_DEBUG_H__ 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | /** 24 | * Whether debugging is enabled or not. 25 | */ 26 | extern bool log_debug_flag; 27 | 28 | /* Whether SYSLOG logging (for stderr) is enable or not. */ 29 | extern bool log_stderr_syslog_flag; 30 | 31 | /* Whether SYSLOG logging (for stdout) is enable or not. */ 32 | extern bool log_stdout_syslog_flag; 33 | 34 | /** 35 | * The name of the jsvc binary. 36 | */ 37 | extern char *log_prog; 38 | 39 | /** 40 | * Helper macro to avoid NPEs in printf. 41 | */ 42 | #define PRINT_NULL(x) ((x) == NULL ? "null" : (x)) 43 | 44 | /** 45 | * Dump a debug message. 46 | * 47 | * @param fmt The printf style message format. 48 | * @param ... Any optional parameter for the message. 49 | */ 50 | void log_debug(const char *fmt, ...); 51 | 52 | /** 53 | * Dump an error message. 54 | * 55 | * @param fmt The printf style message format. 56 | * @param ... Any optional parameter for the message. 57 | */ 58 | void log_error(const char *fmt, ...); 59 | 60 | #ifdef __cplusplus 61 | } 62 | #endif 63 | #endif /* ifndef __JSVC_DEBUG_H__ */ 64 | 65 | -------------------------------------------------------------------------------- /src/native/windows/apps/prunsrv/prunsrv.rc: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "apxwin.h" 18 | #include "prunsrv.h" 19 | 20 | #define RSTR_PRUNSRV "Apache Commons Daemon Service Runner" 21 | 22 | IDI_MAINICON ICON "../../resources/procrunw.ico" 23 | CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "prunsrv.manifest" 24 | 25 | 1 VERSIONINFO 26 | FILEVERSION 1,5,1,0 27 | PRODUCTVERSION 1,5,1,0 28 | FILEFLAGSMASK 0x3fL 29 | #if defined(_DEBUG) 30 | FILEFLAGS 0x03L 31 | #else 32 | FILEFLAGS 0x02L 33 | #endif 34 | FILEOS 0x40004L 35 | FILETYPE 0x1L 36 | FILESUBTYPE 0x0L 37 | BEGIN 38 | BLOCK "StringFileInfo" 39 | BEGIN 40 | BLOCK "040904b0" 41 | BEGIN 42 | VALUE "Comments", "\0" 43 | VALUE "CompanyName", "Apache Software Foundation\0" 44 | VALUE "FileDescription", RSTR_PRUNSRV "\0" 45 | VALUE "FileVersion", PRG_VERSION 46 | VALUE "InternalName", RSTR_PRUNSRV "\0" 47 | VALUE "LegalCopyright", "Copyright (c) 2000-2025 The Apache Software Foundation.\0" 48 | VALUE "OriginalFilename", "prunsrv.exe\0" 49 | VALUE "ProductName", RSTR_PRUNSRV "\0" 50 | VALUE "ProductVersion", PRG_VERSION 51 | END 52 | END 53 | BLOCK "VarFileInfo" 54 | BEGIN 55 | VALUE "Translation", 0x409, 1200 56 | END 57 | END 58 | 59 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/daemon/DaemonInitException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Media Service Provider Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License./* 15 | */ 16 | package org.apache.commons.daemon; 17 | 18 | /** 19 | * Throw this during init if you can't initialize yourself for some expected reason. Using this exception will cause the 20 | * exception's message to come out on stdout, rather than a dirty great stack trace. 21 | */ 22 | public class DaemonInitException extends Exception { 23 | 24 | private static final long serialVersionUID = 5665891535067213551L; 25 | 26 | /** 27 | * Constructs a new exception with the given message. 28 | * 29 | * @param message the detail message accessible with {@link #getMessage()}. 30 | */ 31 | public DaemonInitException(final String message) { 32 | super(message); 33 | } 34 | 35 | /** 36 | * Constructs a new exception with the given detail and cause. 37 | * 38 | * @param message the detail message accessible with {@link #getMessage()}. 39 | * @param cause the cause accessible with {@link #getCause()}. 40 | */ 41 | public DaemonInitException(final String message, final Throwable cause) { 42 | super(message, cause); 43 | } 44 | 45 | /** 46 | * Gets the message with the cause as a postfix. 47 | * 48 | * @return the message with the cause as a postfix. 49 | */ 50 | public String getMessageWithCause() { 51 | final Throwable cause = getCause(); 52 | return getMessage() + (cause == null ? "" : ": " + cause.getMessage()); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/native/windows/README.txt: -------------------------------------------------------------------------------- 1 | Configuring and Building Apache Commons Daemon on Windows 2 | ========================================================= 3 | 4 | Using Visual Studio, you can build Apache Commons Daemon. 5 | The Makefile make file has a bunch of documentation about its 6 | options, but a trivial build is simply: 7 | 8 | All builds 9 | 10 | Set the JAVA_HOME environment variable to point to a Java 8 (or later) JDK. 11 | 12 | Windows X64 Build 13 | 14 | For MVS under "C:\Program Files (x86)": 15 | "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat" 16 | 17 | For MVS under "C:\Program Files": 18 | "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat" 19 | 20 | nmake CPU=X64 21 | 22 | Windows X86 Build 23 | 24 | For MVS under "C:\Program Files (x86)": 25 | "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars32.bat" 26 | 27 | For MVS under "C:\Program Files": 28 | "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars.bat" 29 | 30 | nmake CPU=X86 31 | 32 | 33 | Additional configuration 34 | ======================== 35 | 36 | Specifying the installation location (defaults to .\..\..\..\..\..\target which 37 | places the binary in the correct location for a release build): 38 | 39 | nmake CPU=X86 PREFIX=c:\desired\path\of\daemon install 40 | 41 | To disable the 'Static Hybrid CRT' build strategy and prevent the the resulting 42 | binaries from working on a clean Windows installation with no additional 43 | dependencies: 44 | 45 | nmake CPU=X86 NO_STATIC_CRT=true 46 | 47 | 48 | Release Builds 49 | ============== 50 | 51 | Release builds must not disable the static hybrid CRT build strategy. 52 | 53 | It is not necessary to build a 64-bit version of prunmgr since the 32-bit 54 | version works with both 32-bit and 64-bit services. 55 | 56 | 57 | Code signing 58 | ============ 59 | 60 | The Windows binaries are signed using the ASF's code signing service. For 61 | details of the service and instructions on how new release managers can request 62 | access to the service see: 63 | https://infra.apache.org/code-signing-access.html 64 | -------------------------------------------------------------------------------- /src/samples/SimpleDaemon.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Licensed to the Apache Software Foundation (ASF) under one or more 4 | # contributor license agreements. See the NOTICE file distributed with 5 | # this work for additional information regarding copyright ownership. 6 | # The ASF licenses this file to You under the Apache License, Version 2.0 7 | # (the "License"); you may not use this file except in compliance with 8 | # the License. You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | # Small shell script to show how to start the sample services. 19 | # 20 | # Adapt the following lines to your configuration 21 | JAVA_HOME=`echo $JAVA_HOME` 22 | #JAVA_HOME=/opt/java 23 | #JAVA_HOME=/opt/kaffe 24 | DAEMON_HOME=`(cd ../..; pwd)` 25 | TOMCAT_USER=`echo $USER` 26 | CLASSPATH=\ 27 | $DAEMON_HOME/dist/commons-daemon.jar:\ 28 | $DAEMON_HOME/dist/SimpleDaemon.jar 29 | 30 | PATH=$PATH:$DAEMON_HOME/src/native/unix 31 | export PATH 32 | 33 | # library could be used to test restart after a core. 34 | # -Dnative.library=${DAEMON_HOME}/src/samples/Native.so \ 35 | 36 | # options below are for kaffe. 37 | # -Xclasspath/a:$CLASSPATH \ 38 | # (to debug the class loader 39 | # -vmdebug VMCLASSLOADER \ 40 | 41 | # option below is for the sun JVM. 42 | # -cp $CLASSPATH \ 43 | 44 | if [ -f $JAVA_HOME/bin/kaffe ] 45 | then 46 | CLOPT="-Xclasspath/a:$CLASSPATH" 47 | else 48 | CLOPT="-cp $CLASSPATH" 49 | fi 50 | 51 | jsvc \ 52 | -user $TOMCAT_USER \ 53 | -home $JAVA_HOME \ 54 | $CLOPT \ 55 | -pidfile ./pidfile \ 56 | -wait 90 \ 57 | -debug \ 58 | -outfile toto.txt \ 59 | -errfile '&1' \ 60 | -Dnative.library=${DAEMON_HOME}/src/samples/Native.so \ 61 | SimpleDaemon \ 62 | # 63 | # To get a verbose JVM (sun JVM for example) 64 | #-verbose \ 65 | # To get a debug of jsvc. 66 | #-debug \ 67 | 68 | echo "result: $?" 69 | -------------------------------------------------------------------------------- /src/native/windows/include/rprocess.h: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _RPROCESS_H_INCLUDED_ 18 | #define _RPROCESS_H_INCLUDED_ 19 | 20 | __APXBEGIN_DECLS 21 | 22 | BOOL apxProcessExecute(APXHANDLE hProcess); 23 | 24 | APXHANDLE apxCreateProcessW(APXHANDLE hPool, DWORD dwOptions, 25 | LPAPXFNCALLBACK fnCallback, 26 | LPCWSTR szUsername, LPCWSTR szPassword, 27 | BOOL bLogonAsService); 28 | 29 | BOOL apxProcessSetExecutableW(APXHANDLE hProcess, LPCWSTR szName); 30 | 31 | BOOL apxProcessSetCommandLineW(APXHANDLE hProcess, LPCWSTR szCmdline); 32 | BOOL apxProcessSetCommandArgsW(APXHANDLE hProcess, LPCWSTR szTitle, 33 | DWORD dwArgc, LPCWSTR *lpArgs); 34 | 35 | BOOL apxProcessSetWorkingPathW(APXHANDLE hProcess, LPCWSTR szPath); 36 | 37 | DWORD apxProcessWrite(APXHANDLE hProcess, LPCVOID lpData, DWORD dwLen); 38 | 39 | VOID apxProcessCloseInputStream(APXHANDLE hProcess); 40 | BOOL apxProcessFlushStdin(APXHANDLE hProcess); 41 | 42 | DWORD apxProcessWait(APXHANDLE hProcess, DWORD dwMilliseconds, 43 | BOOL bKill); 44 | 45 | BOOL apxProcessRunning(APXHANDLE hProcess); 46 | DWORD apxProcessGetPid(APXHANDLE hProcess); 47 | 48 | BOOL apxProcessTerminateChild(DWORD dwProcessId, BOOL dryrun); 49 | 50 | 51 | __APXEND_DECLS 52 | 53 | #endif /* _RPROCESS_H_INCLUDED_ */ 54 | -------------------------------------------------------------------------------- /src/native/unix/native/version.h: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __VERSION_H__ 18 | #define __VERSION_H__ 19 | 20 | /** 21 | * Major API changes that could cause compatibility problems for older 22 | * programs such as structure size changes. No binary compatibility is 23 | * possible across a change in the major version. 24 | */ 25 | #define JSVC_MAJOR_VERSION 1 26 | 27 | /** 28 | * Minor API changes that do not cause binary compatibility problems. 29 | * Should be reset to 0 when upgrading JSVC_MAJOR_VERSION 30 | */ 31 | #define JSVC_MINOR_VERSION 5 32 | 33 | /** patch level */ 34 | #define JSVC_PATCH_VERSION 1 35 | 36 | /** 37 | * This symbol is defined for internal, "development" copies of JSVC. 38 | * This symbol will be #undef'd for releases. 39 | */ 40 | #define JSVC_IS_DEV_VERSION 1 41 | 42 | /** Properly quote a value as a string in the C preprocessor */ 43 | #define JSVC_STRINGIFY(n) JSVC_STRINGIFY_HELPER(n) 44 | /** Helper macro for JSVC_STRINGIFY */ 45 | #define JSVC_STRINGIFY_HELPER(n) #n 46 | 47 | 48 | /** The formatted string of APU's version */ 49 | #define JSVC_VERSION_STRING \ 50 | JSVC_STRINGIFY(JSVC_MAJOR_VERSION) "." \ 51 | JSVC_STRINGIFY(JSVC_MINOR_VERSION) "." \ 52 | JSVC_STRINGIFY(JSVC_PATCH_VERSION) \ 53 | JSVC_IS_DEV_STRING 54 | 55 | /** Internal: string form of the "is dev" flag */ 56 | #if JSVC_IS_DEV_VERSION 57 | #define JSVC_IS_DEV_STRING "-dev" 58 | #else 59 | #define JSVC_IS_DEV_STRING "" 60 | #endif 61 | 62 | #endif /* __VERSION_H__ */ 63 | 64 | -------------------------------------------------------------------------------- /.github/workflows/maven.yml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | name: Java CI 17 | 18 | on: [push, pull_request] 19 | 20 | permissions: 21 | contents: read 22 | 23 | jobs: 24 | build: 25 | 26 | runs-on: ${{ matrix.os }} 27 | continue-on-error: ${{ matrix.experimental }} 28 | strategy: 29 | matrix: 30 | os: [ubuntu-latest, windows-latest, macos-latest] 31 | java: [ 8, 11, 17 ] 32 | experimental: [false] 33 | # include: 34 | # - os: ubuntu-latest 35 | # java: 21 36 | # experimental: true 37 | # - os: ubuntu-latest 38 | # java: 23 39 | # experimental: true 40 | # - java: 24-ea 41 | # experimental: true 42 | 43 | steps: 44 | - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 45 | with: 46 | persist-credentials: false 47 | - uses: actions/cache@9255dc7a253b0ccc959486e2bca901246202afeb # v5.0.1 48 | with: 49 | path: ~/.m2/repository 50 | key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} 51 | restore-keys: | 52 | ${{ runner.os }}-maven- 53 | - name: Set up JDK ${{ matrix.java }} 54 | uses: actions/setup-java@f2beeb24e141e01a676f977032f5a29d81c9e27e # v5.1.0 55 | with: 56 | distribution: ${{ runner.os == 'macOS' && matrix.java == '8' && 'zulu' || 'temurin' }} 57 | java-version: ${{ matrix.java }} 58 | - name: Build with Maven 59 | run: mvn --errors --show-version --batch-mode --no-transfer-progress -Ddoclint=all 60 | -------------------------------------------------------------------------------- /src/site/xdoc/security.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 23 | 24 | Apache Commons Security Reports 25 | Apache Commons Team 26 | 27 | 28 |
29 |

30 | For information about reporting or asking questions about security, please see 31 | Apache Commons Security. 32 |

33 |

This page lists all security vulnerabilities fixed in released versions of this component. 34 |

35 |

Please note that binary patches are never provided. If you need to apply a source code patch, use the building instructions for the component version 36 | that you are using. 37 |

38 |

39 | If you need help on building this component or other help on following the instructions to mitigate the known vulnerabilities listed here, please send 40 | your questions to the public 41 | user mailing list. 42 |

43 |

If you have encountered an unlisted security vulnerability or other unexpected behavior that has security impact, or if the descriptions here are 44 | incomplete, please report them privately to the Apache Security Team. Thank you. 45 |

46 |
47 |
48 |

None.

49 |
50 | 51 |
-------------------------------------------------------------------------------- /src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /src/samples/ProcrunServiceInstall.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | rem 3 | rem Licensed to the Apache Software Foundation (ASF) under one or more 4 | rem contributor license agreements. See the NOTICE file distributed with 5 | rem this work for additional information regarding copyright ownership. 6 | rem The ASF licenses this file to You under the Apache License, Version 2.0 7 | rem (the "License"); you may not use this file except in compliance with 8 | rem the License. You may obtain a copy of the License at 9 | rem 10 | rem https://www.apache.org/licenses/LICENSE-2.0 11 | rem 12 | rem Unless required by applicable law or agreed to in writing, software 13 | rem distributed under the License is distributed on an "AS IS" BASIS, 14 | rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | rem See the License for the specific language governing permissions and 16 | rem limitations under the License. 17 | 18 | rem Batch script for defining the ProcrunService (JVM and Java versions) 19 | 20 | rem Copy this file and ProcrunService.jar into the same directory as prunsrv (or adjust the paths below) 21 | 22 | setlocal 23 | 24 | rem The service names (make sure they does not clash with an existing service) 25 | set SERVICE_JVM=ProcrunServiceJvm 26 | set SERVICE_JAVA=ProcrunServiceJava 27 | 28 | rem my location 29 | set MYPATH=%~dp0 30 | 31 | rem location of Prunsrv 32 | set PATH_PRUNSRV=%MYPATH% 33 | set PR_LOGPATH=%PATH_PRUNSRV% 34 | rem location of jarfile 35 | set PATH_JAR=%MYPATH% 36 | 37 | rem Allow prunsrv to be overridden 38 | if "%PRUNSRV%" == "" set PRUNSRV=%PATH_PRUNSRV%prunsrv 39 | 40 | rem Install the 2 services 41 | 42 | echo Installing %SERVICE_JVM% 43 | %PRUNSRV% //DS//%SERVICE_JVM% 44 | %PRUNSRV% //IS//%SERVICE_JVM% 45 | 46 | echo Setting the parameters for %SERVICE_JVM% 47 | %PRUNSRV% //US//%SERVICE_JVM% --Jvm=auto --StdOutput auto --StdError auto ^ 48 | --Classpath=%PATH_JAR%ProcrunService.jar ^ 49 | --StartMode=jvm --StartClass=ProcrunService --StartMethod=start ^ 50 | --StopMode=jvm --StopClass=ProcrunService --StopMethod=stop 51 | 52 | echo Installation of %SERVICE_JVM% is complete 53 | 54 | echo Installing %SERVICE_JAVA% 55 | %PRUNSRV% //DS//%SERVICE_JAVA% 56 | %PRUNSRV% //IS//%SERVICE_JAVA% 57 | 58 | echo Setting the parameters for %SERVICE_JAVA% 59 | %PRUNSRV% //US//%SERVICE_JAVA% --Jvm=auto --StdOutput auto --StdError auto ^ 60 | --Classpath=%PATH_JAR%ProcrunService.jar ^ 61 | --StartMode=java --StartClass=ProcrunService --StartParams=start ^ 62 | --StopMode=java --StopClass=ProcrunService --StopParams=stop 63 | 64 | echo Installation of %SERVICE_JAVA% is complete 65 | echo Finished 66 | -------------------------------------------------------------------------------- /src/native/unix/native/debug.c: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jsvc.h" 18 | #include 19 | #include 20 | #include 21 | 22 | /* Whether debug is enabled or not */ 23 | bool log_debug_flag = false; 24 | 25 | /* Whether SYSLOG logging (for stderr) is enable or not. */ 26 | bool log_stderr_syslog_flag = false; 27 | 28 | /* Whether SYSLOG logging (for stdout) is enable or not. */ 29 | bool log_stdout_syslog_flag = false; 30 | 31 | /* The name of the jsvc binary. */ 32 | char *log_prog = "jsvc"; 33 | 34 | /* Dump a debug trace message to stderr */ 35 | void log_debug(const char *fmt, ...) 36 | { 37 | va_list ap; 38 | time_t now; 39 | struct tm *nowtm; 40 | char buff[80]; 41 | 42 | if (log_debug_flag == false) 43 | return; 44 | if (fmt == NULL) 45 | return; 46 | 47 | now = time(NULL); 48 | nowtm = localtime(&now); 49 | strftime(buff, sizeof(buff), "%Y-%m-%d %T", nowtm); 50 | va_start(ap, fmt); 51 | if (log_stderr_syslog_flag) 52 | fprintf(stderr, "%s %d %s debug: ", buff, getpid(), log_prog); 53 | #if defined(DEBUG) || defined(_DEBUG) 54 | else 55 | fprintf(stderr, "[debug] %s %d ", buff, getpid()); 56 | #endif 57 | vfprintf(stderr, fmt, ap); 58 | fprintf(stderr, "\n"); 59 | fflush(stderr); 60 | va_end(ap); 61 | } 62 | 63 | /* Dump an error message to stderr */ 64 | void log_error(const char *fmt, ...) 65 | { 66 | va_list ap; 67 | time_t now; 68 | struct tm *nowtm; 69 | char buff[80]; 70 | 71 | if (fmt == NULL) 72 | return; 73 | 74 | va_start(ap, fmt); 75 | if (log_stderr_syslog_flag) { 76 | now = time(NULL); 77 | nowtm = localtime(&now); 78 | strftime(buff, sizeof(buff), "%Y-%m-%d %T", nowtm); 79 | fprintf(stderr, "%s %d %s error: ", buff, getpid(), log_prog); 80 | } 81 | vfprintf(stderr, fmt, ap); 82 | fprintf(stderr, "\n"); 83 | fflush(stderr); 84 | va_end(ap); 85 | } 86 | -------------------------------------------------------------------------------- /.github/workflows/scorecards-analysis.yml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache license, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the license for the specific language governing permissions and 14 | # limitations under the license. 15 | 16 | name: "Scorecards supply-chain security" 17 | 18 | on: 19 | branch_protection_rule: 20 | schedule: 21 | - cron: "30 1 * * 6" # Weekly on Saturdays 22 | push: 23 | branches: [ master ] 24 | 25 | permissions: read-all 26 | 27 | jobs: 28 | 29 | analysis: 30 | 31 | name: "Scorecards analysis" 32 | runs-on: ubuntu-latest 33 | permissions: 34 | # Needed to upload the results to the code-scanning dashboard. 35 | security-events: write 36 | actions: read 37 | id-token: write # This is required for requesting the JWT 38 | contents: read # This is required for actions/checkout 39 | 40 | steps: 41 | 42 | - name: "Checkout code" 43 | uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 44 | with: 45 | persist-credentials: false 46 | 47 | - name: "Run analysis" 48 | uses: ossf/scorecard-action@4eaacf0543bb3f2c246792bd56e8cdeffafb205a # 2.4.3 49 | with: 50 | results_file: results.sarif 51 | results_format: sarif 52 | # A read-only PAT token, which is sufficient for the action to function. 53 | # The relevant discussion: https://github.com/ossf/scorecard-action/issues/188 54 | repo_token: ${{ secrets.GITHUB_TOKEN }} 55 | # Publish the results for public repositories to enable scorecard badges. 56 | # For more details: https://github.com/ossf/scorecard-action#publishing-results 57 | publish_results: true 58 | 59 | - name: "Upload artifact" 60 | uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # 6.0.0 61 | with: 62 | name: SARIF file 63 | path: results.sarif 64 | retention-days: 5 65 | 66 | - name: "Upload to code-scanning" 67 | uses: github/codeql-action/upload-sarif@5d4e8d1aca955e8d8589aabd499c5cae939e33c7 # v4.31.9 68 | with: 69 | sarif_file: results.sarif 70 | -------------------------------------------------------------------------------- /src/site/xdoc/binaries.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 22 | 23 | Daemon : binaries 24 | Jean-Frederic Clere 25 | 26 | 27 | 28 |
29 |

30 | In the directory 31 | binaries 32 | you will find subdirectories containing archives 33 | corresponding to your operating system. Only the Windows builds are provided as a zip file. 34 |

35 |
36 | 37 |
38 | 39 |

40 | The Windows archive (e.g. commons-daemon-x.y.z-bin-windows.zip) contains 2 different executables: 41 |

42 |
    43 |
  • prunsrv.exe - service application for running applications as services.
  • 44 |
  • prunmgr.exe - the GUI manager application used to monitor and configure installed services.
  • 45 |
46 |

47 | There is only one prunmgr.exe application for all architectures. 48 | The prunsrv.exe executable is available in 2 different versions for different architectures. 49 | The version in the top-level directory is for 32-bit (x86) architectures. 50 | The lower level directories are for AMD/EMT 64-bit systems. Itanium is no longer supported. 51 |

52 |

53 | The Windows application prunsrv.exe is used to install an application as a service. 54 | Once installed, prunmgr.exe can be used to monitor and reconfigure the service. 55 | (see procrun for more information). 56 | The Windows binary zip archive should be unpacked into the location from which you wish to run it, for example: 57 | %ProgramFiles%\Apache Commons Daemon 58 |

59 |
60 |
61 | 62 | 63 |
64 | -------------------------------------------------------------------------------- /src/native/unix/INSTALL.txt: -------------------------------------------------------------------------------- 1 | To build the service libraries and binary under an UNIX operating 2 | system you will need: 3 | 4 | An ANSI-C compliant compiler (GCC is good) 5 | Java 8 or later JDK 6 | GNU Autotools (when building from Git). 7 | 8 | When building from Git you need to build the "configure" program with: 9 | 10 | sh support/buildconf.sh 11 | (Note it is possible to replace sh by any compatible shell like bash, ksh). 12 | 13 | Once the configure script is generated, run it (remember to specify 14 | either the --with-java= parameter or set the JAVA_HOME environment 15 | to point to your JDK installation). For example: 16 | 17 | ./configure --with-java=/usr/java 18 | 19 | or 20 | 21 | JAVA_HOME=/usr/java 22 | export JAVA_HOME 23 | ./configure 24 | 25 | Note: On Mac OS X is /System/Library/Frameworks/JavaVM.framework/Home. 26 | 27 | Depending on your JDK layout, configure might fail to find the JNI 28 | machine dependent include file (jni_md.h). If that's the case use the 29 | --with-os-type= parameter where subdir points to the directory 30 | within JDK include directory containing jni_md.h file. 31 | 32 | 33 | If your operating system is supported, configure will go through cleanly, 34 | otherwise it will report an error (please send us the details of your 35 | OS/JDK, or a patch against the sources). 36 | 37 | To build the binaries and libraries simply do: 38 | 39 | make 40 | 41 | This will generate the file: ./jsvc. 42 | It should be straightforward from here on. To check the allowed parameters 43 | for the jsvc binary simply do 44 | 45 | ./native/jsvc -help 46 | 47 | Note: On Linux the module capabilities should be loaded, when using -user root 48 | make sure you REALLY understand what capabilities does (for example for 49 | files access: the downgraded root may not be able to read some files!). 50 | 51 | Making 64-bit binaries 52 | 53 | To be able to build the 64-binaries for supported platforms enter the 54 | specific parameters before calling configure 55 | 56 | export CFLAGS=-m64 57 | export LDFLAGS=-m64 58 | ./configure 59 | make 60 | 61 | Making Universal binaries 62 | 63 | Some platforms like Mac OSX allow universal or fat binaries that allow 64 | both 32 and 64 binaries inside the same executable. To be able to build 65 | the fat binaries enter the specific parameters before calling configure 66 | 67 | export CFLAGS="-arch i386 -arch x86_64" 68 | export LDFLAGS="-arch i386 -arch x86_64" 69 | ./configure 70 | make 71 | 72 | Optional Build flags 73 | 74 | Make process allows specifying additional compilation flags at compile time 75 | by using EXTRA_CFLAGS and EXTRA_LDFLAGS either as environment variables 76 | or defined along the make command line 77 | 78 | make EXTRA_CFLAGS="-march=i586" 79 | 80 | will cause -march=i586 to be added to the configure generated CFLAGS. 81 | The same applies to EXTRA_LDFLAGS which will be added at link stage. 82 | -------------------------------------------------------------------------------- /src/native/windows/include/service.h: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _SERVICE_H_INCLUDED_ 18 | #define _SERVICE_H_INCLUDED_ 19 | 20 | __APXBEGIN_DECLS 21 | 22 | typedef struct APXSERVENTRY { 23 | WCHAR szServiceName[SIZ_RESLEN]; 24 | WCHAR szObjectName[SIZ_RESLEN]; 25 | WCHAR szServiceDescription[SIZ_DESLEN]; 26 | LPQUERY_SERVICE_CONFIGW lpConfig; 27 | BOOL bDelayedStart; 28 | SERVICE_STATUS stServiceStatus; 29 | SERVICE_STATUS_PROCESS stStatusProcess; 30 | 31 | } APXSERVENTRY, *LPAPXSERVENTRY; 32 | 33 | 34 | APXHANDLE apxCreateService(APXHANDLE hPool, DWORD dwOptions, 35 | BOOL bManagerMode); 36 | 37 | BOOL apxServiceOpen(APXHANDLE hService, LPCWSTR szServiceName, DWORD dwOptions); 38 | 39 | 40 | BOOL apxServiceSetNames(APXHANDLE hService, LPCWSTR szImagePath, 41 | LPCWSTR szDisplayName, LPCWSTR szDescription, 42 | LPCWSTR szUsername, LPCWSTR szPassword); 43 | 44 | BOOL apxServiceSetOptions(APXHANDLE hService, LPCWSTR lpDependencies, 45 | DWORD dwServiceType, DWORD dwStartType, 46 | BOOL bDelayedStart, DWORD dwErrorControl); 47 | 48 | BOOL apxServiceControl(APXHANDLE hService, DWORD dwControl, UINT uMsg, 49 | LPAPXFNCALLBACK fnControlCallback, 50 | LPVOID lpCbData); 51 | BOOL apxServiceCheckStop(APXHANDLE hService); 52 | BOOL apxServiceInstall(APXHANDLE hService, LPCWSTR szServiceName, 53 | LPCWSTR szDisplayName, LPCWSTR szImagePath, 54 | LPCWSTR lpDependencies, DWORD dwServiceType, 55 | DWORD dwStartType); 56 | 57 | LPAPXSERVENTRY apxServiceEntry(APXHANDLE hService, BOOL bRequeryStatus); 58 | 59 | /** Delete te service 60 | * Stops the service if running 61 | */ 62 | BOOL apxServiceDelete(APXHANDLE hService); 63 | 64 | DWORD apxGetMaxServiceTimeout(APXHANDLE hPool); 65 | 66 | __APXEND_DECLS 67 | 68 | #endif /* _SERVICE_H_INCLUDED_ */ 69 | -------------------------------------------------------------------------------- /src/native/windows/include/javajni.h: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _JAVAJNI_H_INCLUDED_ 18 | #define _JAVAJNI_H_INCLUDED_ 19 | 20 | __APXBEGIN_DECLS 21 | 22 | #define APX_JVM_DESTROY 0x00000001 23 | 24 | typedef struct stAPXJAVA_THREADARGS 25 | { 26 | LPVOID hJava; 27 | LPCSTR szClassPath; 28 | LPCVOID lpOptions; 29 | LPCVOID lpOptions9; 30 | DWORD dwMs; 31 | DWORD dwMx; 32 | DWORD dwSs; 33 | DWORD bJniVfprintf; 34 | LPCSTR szClassName; 35 | LPCSTR szMethodName; 36 | LPCVOID lpArguments; 37 | BOOL setErrorOrOut; 38 | LPCWSTR szStdErrFilename; 39 | LPCWSTR szStdOutFilename; 40 | LPCWSTR szLibraryPath; 41 | } APXJAVA_THREADARGS, *LPAPXJAVA_THREADARGS; 42 | 43 | APXHANDLE apxCreateJava(APXHANDLE hPool, LPCWSTR szJvmDllPath, LPCWSTR szJavaHome); 44 | 45 | BOOL apxJavaInitialize(APXHANDLE hJava, LPCSTR szClassPath, 46 | LPCVOID lpOptions, LPCVOID lpOptions9, 47 | DWORD dwMs, DWORD dwMx, DWORD dwSs, 48 | DWORD bJniVfprintf); 49 | DWORD 50 | apxJavaCmdInitialize(APXHANDLE hPool, LPCWSTR szClassPath, LPCWSTR szClass, 51 | LPCWSTR szOptions, DWORD dwMs, DWORD dwMx, 52 | DWORD dwSs, LPCWSTR szCmdArgs, LPWSTR **lppArray); 53 | 54 | BOOL apxJavaLoadMainClass(APXHANDLE hJava, LPCSTR szClassName, 55 | LPCSTR szMethodName, 56 | LPCVOID lpArguments); 57 | 58 | BOOL apxJavaStart(LPAPXJAVA_THREADARGS pArgs); 59 | 60 | DWORD apxJavaWait(APXHANDLE hJava, DWORD dwMilliseconds, BOOL bKill); 61 | 62 | BOOL apxJavaSetOut(APXHANDLE hJava, BOOL setErrorOrOut, 63 | LPCWSTR szFilename); 64 | DWORD apxJavaSetOptions(APXHANDLE hJava, DWORD dwOptions); 65 | 66 | BOOL apxDestroyJvm(DWORD dwTimeout); 67 | 68 | DWORD apxGetVmExitCode(); 69 | 70 | void apxSetVmExitCode(DWORD exitCode); 71 | 72 | void apxJavaDumpAllStacks(APXHANDLE hJava); 73 | 74 | __APXEND_DECLS 75 | 76 | #endif /* _JAVAJNI_H_INCLUDED_ */ 77 | -------------------------------------------------------------------------------- /src/native/windows/apps/prunmgr/Makefile: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | TARGET = GUI 17 | PROJECT = prunmgr 18 | !include <..\..\include\Makefile.inc> 19 | 20 | !IF !DEFINED(PREFIX) || "$(PREFIX)" == "" 21 | PREFIX = .\..\..\..\..\..\target 22 | !ENDIF 23 | !IF !DEFINED(SRCDIR) || "$(SRCDIR)" == "" 24 | SRCDIR = .\..\.. 25 | !ENDIF 26 | 27 | !IF "$(CPU)" == "X64" 28 | PREFIX = $(PREFIX)\amd64 29 | !ENDIF 30 | 31 | LFLAGS = $(LFLAGS) /version:1.0 /DYNAMICBASE /NXCOMPAT 32 | LIBS = $(LIBS) user32.lib gdi32.lib winspool.lib comdlg32.lib comctl32.lib shlwapi.lib 33 | INCLUDES = -I$(SRCDIR)\include -I$(SRCDIR)\src $(JAVA_INCLUDES) 34 | 35 | PDBFLAGS = -Fo$(WORKDIR)\ -Fd$(WORKDIR)\$(PROJECT)-src 36 | OBJECTS = \ 37 | $(WORKDIR)\cmdline.obj \ 38 | $(WORKDIR)\console.obj \ 39 | $(WORKDIR)\gui.obj \ 40 | $(WORKDIR)\handles.obj \ 41 | $(WORKDIR)\javajni.obj \ 42 | $(WORKDIR)\log.obj \ 43 | $(WORKDIR)\mclib.obj \ 44 | $(WORKDIR)\registry.obj \ 45 | $(WORKDIR)\rprocess.obj \ 46 | $(WORKDIR)\security.obj \ 47 | $(WORKDIR)\service.obj \ 48 | $(WORKDIR)\utils.obj \ 49 | $(WORKDIR)\prunmgr.obj 50 | 51 | BUILDEXE = $(WORKDIR)\$(PROJECT).exe 52 | BUILDLOC = $(PREFIX) 53 | !IF "$(CPU)" == "X64" 54 | BUILDLOC = $(PREFIX)\amd64 55 | !ENDIF 56 | BUILDPDB = $(WORKDIR)\$(PROJECT).pdb 57 | BUILDRES = $(WORKDIR)\$(PROJECT).res 58 | BUILDMAN = $(BUILDEXE).manifest 59 | 60 | all : $(WORKDIR) $(BUILDEXE) 61 | 62 | $(BUILDLOC) : 63 | @if not exist "$(BUILDLOC)\$(NULL)" mkdir "$(BUILDLOC)" 64 | 65 | $(WORKDIR) : 66 | @$(MAKEWORKDIR) 67 | 68 | {$(SRCDIR)\src}.c{$(WORKDIR)}.obj: 69 | $(CC) $(CFLAGS) $(INCLUDES) $(PDBFLAGS) $< 70 | 71 | {$(SRCDIR)\apps\prunmgr}.c{$(WORKDIR)}.obj: 72 | $(CC) $(CFLAGS) $(INCLUDES) $(PDBFLAGS) $< 73 | 74 | $(BUILDRES): $(SRCDIR)/apps/prunmgr/prunmgr.rc 75 | $(RC) $(RCFLAGS) /i "$(SRCDIR)\include" /fo $(BUILDRES) $(SRCDIR)/apps/prunmgr/prunmgr.rc 76 | 77 | $(BUILDEXE): $(WORKDIR) $(OBJECTS) $(BUILDRES) 78 | $(LINK) $(LFLAGS) $(OBJECTS) $(BUILDRES) $(LIBS) $(LDIRS) /pdb:$(BUILDPDB) /out:$(BUILDEXE) 79 | IF EXIST $(BUILDMAN) \ 80 | mt -nologo -manifest $(BUILDMAN) -outputresource:$(BUILDEXE);1 81 | 82 | clean: 83 | @$(CLEANTARGET) 84 | 85 | install: $(BUILDLOC) $(WORKDIR) $(BUILDEXE) 86 | @xcopy "$(WORKDIR)\*.exe" "$(BUILDLOC)" /Y /Q 87 | -------------------------------------------------------------------------------- /src/native/windows/apps/prunsrv/Makefile: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | TARGET = EXE 17 | PROJECT = prunsrv 18 | !include <..\..\include\Makefile.inc> 19 | 20 | !IF !DEFINED(PREFIX) || "$(PREFIX)" == "" 21 | PREFIX = .\..\..\..\..\..\target 22 | !ENDIF 23 | !IF !DEFINED(SRCDIR) || "$(SRCDIR)" == "" 24 | SRCDIR = .\..\.. 25 | !ENDIF 26 | 27 | !IF "$(CPU)" == "X86" 28 | LFLAGS = $(LFLAGS) /stack:0x64000 29 | !ENDIF 30 | 31 | LFLAGS = $(LFLAGS) /version:1.0 /DYNAMICBASE /NXCOMPAT 32 | LIBS = $(LIBS) user32.lib gdi32.lib winspool.lib comdlg32.lib comctl32.lib shlwapi.lib 33 | INCLUDES = -I$(SRCDIR)\include -I$(SRCDIR)\src $(JAVA_INCLUDES) 34 | 35 | PDBFLAGS = -Fo$(WORKDIR)\ -Fd$(WORKDIR)\$(PROJECT)-src 36 | OBJECTS = \ 37 | $(WORKDIR)\cmdline.obj \ 38 | $(WORKDIR)\console.obj \ 39 | $(WORKDIR)\gui.obj \ 40 | $(WORKDIR)\handles.obj \ 41 | $(WORKDIR)\javajni.obj \ 42 | $(WORKDIR)\log.obj \ 43 | $(WORKDIR)\mclib.obj \ 44 | $(WORKDIR)\registry.obj \ 45 | $(WORKDIR)\rprocess.obj \ 46 | $(WORKDIR)\security.obj \ 47 | $(WORKDIR)\service.obj \ 48 | $(WORKDIR)\utils.obj \ 49 | $(WORKDIR)\prunsrv.obj 50 | 51 | BUILDEXE = $(WORKDIR)\$(PROJECT).exe 52 | BUILDLOC = $(PREFIX) 53 | !IF "$(CPU)" == "X64" 54 | BUILDLOC = $(PREFIX)\amd64 55 | !ENDIF 56 | BUILDPDB = $(WORKDIR)\$(PROJECT).pdb 57 | BUILDRES = $(WORKDIR)\$(PROJECT).res 58 | BUILDMAN = $(BUILDEXE).manifest 59 | 60 | all : $(WORKDIR) $(BUILDEXE) 61 | 62 | $(BUILDLOC) : 63 | @if not exist "$(BUILDLOC)\$(NULL)" mkdir "$(BUILDLOC)" 64 | 65 | $(WORKDIR) : 66 | @$(MAKEWORKDIR) 67 | 68 | {$(SRCDIR)\src}.c{$(WORKDIR)}.obj: 69 | $(CC) $(CFLAGS) $(INCLUDES) $(PDBFLAGS) $< 70 | 71 | {$(SRCDIR)\apps\prunsrv}.c{$(WORKDIR)}.obj: 72 | $(CC) $(CFLAGS) $(INCLUDES) $(PDBFLAGS) $< 73 | 74 | $(BUILDRES): $(SRCDIR)/apps/prunsrv/prunsrv.rc 75 | $(RC) $(RCFLAGS) /i "$(SRCDIR)\include" /fo $(BUILDRES) $(SRCDIR)/apps/prunsrv/prunsrv.rc 76 | 77 | $(BUILDEXE): $(WORKDIR) $(OBJECTS) $(BUILDRES) 78 | $(LINK) $(LFLAGS) $(OBJECTS) $(BUILDRES) $(LIBS) $(LDIRS) /pdb:$(BUILDPDB) /out:$(BUILDEXE) 79 | IF EXIST $(BUILDMAN) \ 80 | mt -nologo -manifest $(BUILDMAN) -outputresource:$(BUILDEXE);1 81 | 82 | clean: 83 | @$(CLEANTARGET) 84 | 85 | install: $(BUILDLOC) $(WORKDIR) $(BUILDEXE) 86 | @xcopy "$(WORKDIR)\*.exe" "$(BUILDLOC)" /Y /Q 87 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/daemon/DaemonController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.daemon; 19 | 20 | /** 21 | * Defines methods needed by the DaemonLoader. 22 | */ 23 | public interface DaemonController 24 | { 25 | 26 | /** 27 | * Shuts down the daemon. 28 | * 29 | * @throws IllegalStateException If the daemon is not in a valid state to be 30 | * shutdown 31 | */ 32 | void shutdown() 33 | throws IllegalStateException; 34 | 35 | /** 36 | * Reloads daemon 37 | * 38 | * @throws IllegalStateException If the daemon is not in a valid state to be 39 | * reloaded 40 | */ 41 | void reload() 42 | throws IllegalStateException; 43 | 44 | /** 45 | * Shuts down daemon and logs failed message. 46 | * 47 | * @throws IllegalStateException If the daemon is not in a valid state to be 48 | * shutdown 49 | */ 50 | void fail() 51 | throws IllegalStateException; 52 | 53 | /** 54 | * Shuts down daemon and logs failed message. 55 | * 56 | * @param message The message to log 57 | * @throws IllegalStateException If the daemon is not in a valid state to be 58 | * shutdown 59 | */ 60 | void fail(String message) 61 | throws IllegalStateException; 62 | 63 | /** 64 | * Shuts down daemon and logs failed message. 65 | * 66 | * @param exception The exception to log 67 | * @throws IllegalStateException If the daemon is not in a valid state to be 68 | * shutdown 69 | */ 70 | void fail(Exception exception) 71 | throws IllegalStateException; 72 | 73 | /** 74 | * Shuts down daemon and logs failed message. 75 | * 76 | * @param message The message to log 77 | * @param exception The exception to log 78 | * @throws IllegalStateException If the daemon is not in a valid state to be 79 | * shutdown 80 | */ 81 | void fail(String message, Exception exception) 82 | throws IllegalStateException; 83 | 84 | } 85 | 86 | -------------------------------------------------------------------------------- /src/native/unix/support/apjava.m4: -------------------------------------------------------------------------------- 1 | dnl 2 | dnl Licensed to the Apache Software Foundation (ASF) under one or more 3 | dnl contributor license agreements. See the NOTICE file distributed with 4 | dnl this work for additional information regarding copyright ownership. 5 | dnl The ASF licenses this file to You under the Apache License, Version 2.0 6 | dnl (the "License"); you may not use this file except in compliance with 7 | dnl the License. You may obtain a copy of the License at 8 | dnl 9 | dnl https://www.apache.org/licenses/LICENSE-2.0 10 | dnl 11 | dnl Unless required by applicable law or agreed to in writing, software 12 | dnl distributed under the License is distributed on an "AS IS" BASIS, 13 | dnl WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | dnl See the License for the specific language governing permissions and 15 | dnl limitations under the License. 16 | dnl 17 | 18 | AC_DEFUN([AP_FIND_JAVA],[ 19 | AC_ARG_WITH(java,[ --with-java=DIR Specify the location of your JDK installation],[ 20 | AC_MSG_CHECKING([JAVA_HOME]) 21 | if test -d "$withval" 22 | then 23 | JAVA_HOME="$withval" 24 | AC_MSG_RESULT([$JAVA_HOME]) 25 | else 26 | AC_MSG_RESULT([failed]) 27 | AC_MSG_ERROR([$withval is not a directory]) 28 | fi 29 | AC_SUBST(JAVA_HOME) 30 | ]) 31 | if test "x$JAVA_HOME" = x 32 | then 33 | AC_MSG_CHECKING([for JDK location]) 34 | # Oh well, nobody set JAVA_HOME, have to guess 35 | # Check if we have java in the PATH. 36 | java_prog="`which java 2>/dev/null || true`" 37 | if test "x$java_prog" != x 38 | then 39 | java_bin="`dirname $java_prog`" 40 | java_top="`dirname $java_bin`" 41 | if test -f "$java_top/include/jni.h" 42 | then 43 | JAVA_HOME="$java_top" 44 | AC_MSG_RESULT([${java_top}]) 45 | fi 46 | fi 47 | fi 48 | if test x"$JAVA_HOME" = x 49 | then 50 | AC_MSG_ERROR([Java Home not defined. Rerun with --with-java=[...] parameter]) 51 | fi 52 | ]) 53 | 54 | AC_DEFUN([AP_FIND_JAVA_OS],[ 55 | tempval="" 56 | JAVA_OS="" 57 | AC_ARG_WITH(os-type,[ --with-os-type[=SUBDIR] Location of JDK os-type subdirectory.], 58 | [ 59 | tempval=$withval 60 | if test ! -d "$JAVA_HOME/$JAVA_INC/$tempval" 61 | then 62 | AC_MSG_ERROR(Not a directory: ${JAVA_HOME}/$JAVA_INC/${tempval}) 63 | fi 64 | JAVA_OS=$tempval 65 | ], 66 | [ 67 | AC_MSG_CHECKING(for JDK os include directory) 68 | JAVA_OS=NONE 69 | if test -f $JAVA_HOME/$JAVA_INC/jni_md.h 70 | then 71 | JAVA_OS="" 72 | else 73 | for f in $JAVA_HOME/$JAVA_INC/*/jni_md.h 74 | do 75 | if test -f $f; then 76 | JAVA_OS=`dirname $f` 77 | JAVA_OS=`basename $JAVA_OS` 78 | echo " $JAVA_OS" 79 | break 80 | fi 81 | done 82 | if test "x$JAVA_OS" = "xNONE"; then 83 | AC_MSG_RESULT(Cannot find jni_md.h in ${JAVA_HOME}/${JAVA_INC}/\${OS}) 84 | AC_MSG_ERROR(You should retry --with-os-type=SUBDIR) 85 | fi 86 | fi 87 | ]) 88 | ]) 89 | -------------------------------------------------------------------------------- /src/native/windows/include/cmdline.h: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _CMDLINE_H_INCLUDED_ 18 | #define _CMDLINE_H_INCLUDED_ 19 | 20 | __APXBEGIN_DECLS 21 | 22 | #define APXCMDOPT_NIL 0x00000000 /* Argopt value not needed */ 23 | #define APXCMDOPT_INT 0x00000001 /* Argopt value is unsigned integer */ 24 | #define APXCMDOPT_STR 0x00000002 /* Argopt value is string */ 25 | #define APXCMDOPT_STE 0x00000006 /* Argopt value is expandable string */ 26 | #define APXCMDOPT_MSZ 0x00000010 /* Multiline string '#' separated */ 27 | #define APXCMDOPT_BIN 0x00000020 /* Encrypted binary */ 28 | 29 | #define APXCMDOPT_REG 0x00000100 /* Save to registry */ 30 | #define APXCMDOPT_SRV 0x00000200 /* Save to service registry */ 31 | #define APXCMDOPT_USR 0x00000400 /* Save to user registry */ 32 | 33 | #define APXCMDOPT_FOUND 0x00001000 /* The option is present in cmdline as -- */ 34 | #define APXCMDOPT_ADD 0x00002000 /* The option is present in cmdline as ++ */ 35 | 36 | 37 | typedef struct APXCMDLINEOPT APXCMDLINEOPT; 38 | 39 | struct APXCMDLINEOPT { 40 | LPWSTR szName; /* Long Argument Name */ 41 | LPWSTR szRegistry; /* Registry Association */ 42 | LPWSTR szSubkey; /* Registry Association */ 43 | DWORD dwType; /* Argument type (string, number, multi-string */ 44 | LPWSTR szValue; /* Return string value */ 45 | DWORD dwValue; /* Return numeric value or present if NIL */ 46 | }; 47 | 48 | typedef struct APXCMDLINE { 49 | APXCMDLINEOPT *lpOptions; 50 | LPWSTR szArgv0; 51 | LPWSTR szExecutable; /* Parsed argv0 */ 52 | LPWSTR szExePath; /* Parsed argv0 */ 53 | LPWSTR szApplication; /* Fist string after //CMD// */ 54 | DWORD dwCmdIndex; /* Command index */ 55 | LPWSTR *lpArgvw; 56 | DWORD dwArgc; 57 | APXHANDLE hPool; 58 | 59 | } APXCMDLINE, *LPAPXCMDLINE; 60 | 61 | LPAPXCMDLINE apxCmdlineParse( 62 | APXHANDLE hPool, 63 | APXCMDLINEOPT *lpOptions, 64 | LPCWSTR *lpszCommands, 65 | LPCWSTR *lpszAltcmds 66 | ); 67 | 68 | void apxCmdlineLoadEnvVars( 69 | LPAPXCMDLINE lpCmdline 70 | ); 71 | 72 | void apxCmdlineFree( 73 | LPAPXCMDLINE lpCmdline 74 | ); 75 | 76 | 77 | __APXEND_DECLS 78 | 79 | #endif /* _CMDLINE_H_INCLUDED_ */ 80 | -------------------------------------------------------------------------------- /src/assembly/src.xml: -------------------------------------------------------------------------------- 1 | 17 | 20 | src 21 | 22 | tar.gz 23 | zip 24 | 25 | ${project.artifactId}-${project.version}-src 26 | 27 | 28 | 29 | CONTRIBUTING.md 30 | HOWTO-RELEASE.txt 31 | LICENSE.txt 32 | NOTICE.txt 33 | pom.xml 34 | PROPOSAL.html 35 | README.md 36 | RELEASE-NOTES.txt 37 | 38 | 39 | 40 | src 41 | 42 | 43 | native/unix/Makedefs 44 | native/unix/Makefile 45 | native/unix/autom4te.cache/** 46 | native/unix/config.log 47 | native/unix/config.nice 48 | native/unix/config.status 49 | native/unix/configure 50 | native/unix/jsvc 51 | native/unix/native/*.o 52 | native/unix/native/Makefile 53 | native/unix/native/libservice.a 54 | native/windows/apps/prunmgr/*_GUI_RELEASE/** 55 | native/windows/apps/prunsrv/*_RELEASE/** 56 | 57 | **/*.sh 58 | 59 | 60 | 61 | src 62 | 775 63 | 64 | **/*.sh 65 | native/unix/configure 66 | 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /src/native/unix/support/apfunctions.m4: -------------------------------------------------------------------------------- 1 | dnl 2 | dnl Licensed to the Apache Software Foundation (ASF) under one or more 3 | dnl contributor license agreements. See the NOTICE file distributed with 4 | dnl this work for additional information regarding copyright ownership. 5 | dnl The ASF licenses this file to You under the Apache License, Version 2.0 6 | dnl (the "License"); you may not use this file except in compliance with 7 | dnl the License. You may obtain a copy of the License at 8 | dnl 9 | dnl https://www.apache.org/licenses/LICENSE-2.0 10 | dnl 11 | dnl Unless required by applicable law or agreed to in writing, software 12 | dnl distributed under the License is distributed on an "AS IS" BASIS, 13 | dnl WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | dnl See the License for the specific language governing permissions and 15 | dnl limitations under the License. 16 | dnl 17 | 18 | AC_DEFUN([AP_MSG_HEADER],[ 19 | printf "*** %s ***\n" "$1" 1>&2 20 | AC_PROVIDE([$0]) 21 | ]) 22 | 23 | AC_DEFUN([AP_CANONICAL_HOST_CHECK],[ 24 | AC_MSG_CHECKING([cached host system type]) 25 | if { test x"${ac_cv_host_system_type+set}" = x"set" && 26 | test x"$ac_cv_host_system_type" != x"$host" ; } 27 | then 28 | AC_MSG_RESULT([$ac_cv_host_system_type]) 29 | AC_MSG_ERROR([remove the "$cache_file" file and re-run configure]) 30 | else 31 | AC_MSG_RESULT(ok) 32 | ac_cv_host_system_type="$host" 33 | fi 34 | AC_PROVIDE([$0]) 35 | ]) 36 | 37 | dnl Iteratively interpolate the contents of the second argument 38 | dnl until interpolation offers no new result. Then assign the 39 | dnl final result to $1. 40 | dnl 41 | dnl Example: 42 | dnl 43 | dnl foo=1 44 | dnl bar='${foo}/2' 45 | dnl baz='${bar}/3' 46 | dnl AP_EXPAND_VAR(fraz, $baz) 47 | dnl $fraz is now "1/2/3" 48 | dnl 49 | AC_DEFUN([AP_EXPAND_VAR], [ 50 | ap_last= 51 | ap_cur="$2" 52 | while test "x${ap_cur}" != "x${ap_last}"; 53 | do 54 | ap_last="${ap_cur}" 55 | ap_cur=`eval "echo ${ap_cur}"` 56 | done 57 | $1="${ap_cur}" 58 | ]) 59 | 60 | dnl 61 | dnl AP_CONFIG_NICE(filename) 62 | dnl 63 | dnl Saves a snapshot of the configure command-line for later reuse 64 | dnl 65 | AC_DEFUN([AP_CONFIG_NICE], [ 66 | rm -f $1 67 | cat >$1<> $1 75 | fi 76 | if test -n "$CFLAGS"; then 77 | echo "CFLAGS=\"$CFLAGS\"; export CFLAGS" >> $1 78 | fi 79 | if test -n "$CPPFLAGS"; then 80 | echo "CPPFLAGS=\"$CPPFLAGS\"; export CPPFLAGS" >> $1 81 | fi 82 | if test -n "$LDFLAGS"; then 83 | echo "LDFLAGS=\"$LDFLAGS\"; export LDFLAGS" >> $1 84 | fi 85 | if test -n "$LIBS"; then 86 | echo "LIBS=\"$LIBS\"; export LIBS" >> $1 87 | fi 88 | if test -n "$STRIPFLAGS"; then 89 | echo "STRIPFLAGS=\"$STRIPFLAGS\"; export STRIPFLAGS" >> $1 90 | fi 91 | if test -n "$INCLUDES"; then 92 | echo "INCLUDES=\"$INCLUDES\"; export INCLUDES" >> $1 93 | fi 94 | # Retrieve command-line arguments. 95 | eval "set x $[0] $ac_configure_args" 96 | shift 97 | 98 | for arg 99 | do 100 | AP_EXPAND_VAR(arg, $arg) 101 | echo "\"[$]arg\" \\" >> $1 102 | done 103 | echo '"[$]@"' >> $1 104 | chmod +x $1 105 | ])dnl 106 | -------------------------------------------------------------------------------- /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | name: "CodeQL" 17 | 18 | on: 19 | push: 20 | branches-ignore: 21 | - 'dependabot/**' 22 | pull_request: 23 | branches: [ master ] 24 | schedule: 25 | - cron: '33 9 * * 4' 26 | 27 | concurrency: 28 | group: ${{ github.workflow }}-${{ github.head_ref || github.ref_name }} 29 | cancel-in-progress: true 30 | 31 | permissions: 32 | contents: read 33 | 34 | jobs: 35 | analyze: 36 | name: Analyze 37 | runs-on: ubuntu-latest 38 | permissions: 39 | actions: read 40 | contents: read 41 | security-events: write 42 | 43 | strategy: 44 | fail-fast: false 45 | matrix: 46 | language: [ 'java', 'cpp' ] 47 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] 48 | # Learn more about CodeQL language support at https://git.io/codeql-language-support 49 | 50 | steps: 51 | - name: Checkout repository 52 | uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 53 | with: 54 | persist-credentials: false 55 | - uses: actions/cache@9255dc7a253b0ccc959486e2bca901246202afeb # v5.0.1 56 | with: 57 | path: ~/.m2/repository 58 | key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} 59 | restore-keys: | 60 | ${{ runner.os }}-maven- 61 | 62 | # Initializes the CodeQL tools for scanning. 63 | - name: Initialize CodeQL 64 | uses: github/codeql-action/init@5d4e8d1aca955e8d8589aabd499c5cae939e33c7 # v4.31.9 65 | with: 66 | languages: ${{ matrix.language }} 67 | # If you wish to specify custom queries, you can do so here or in a config file. 68 | # By default, queries listed here will override any specified in a config file. 69 | # Prefix the list here with "+" to use these queries and those in the config file. 70 | # queries: ./path/to/local/query, your-org/your-repo/queries@main 71 | 72 | - name: Autobuild 73 | if: ${{ matrix.language == 'java' }} 74 | uses: github/codeql-action/autobuild@5d4e8d1aca955e8d8589aabd499c5cae939e33c7 # v4.31.9 75 | 76 | - name: Build sources 77 | if: ${{ matrix.language == 'cpp' }} 78 | run: | 79 | cd src/native/unix 80 | sh support/buildconf.sh 81 | export CFLAGS=-m64 82 | export LDFLAGS=-m64 83 | ./configure 84 | make 85 | 86 | - name: Perform CodeQL Analysis 87 | uses: github/codeql-action/analyze@5d4e8d1aca955e8d8589aabd499c5cae939e33c7 # v4.31.9 88 | -------------------------------------------------------------------------------- /src/native/unix/native/arguments.h: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __JSVC_ARGUMENTS_H__ 18 | #define __JSVC_ARGUMENTS_H__ 19 | 20 | #ifdef __cplusplus 21 | extern "C" 22 | { 23 | #endif 24 | 25 | /** 26 | * The structure holding all parsed command line options. 27 | */ 28 | typedef struct { 29 | /** The name of the PID file. */ 30 | char *pidf; 31 | /** The name of the user. */ 32 | char *user; 33 | /** The name of the JVM to use. */ 34 | char *name; 35 | /** The JDK or JRE installation path (JAVA_HOME). */ 36 | char *home; 37 | /** Working directory (defaults to /). */ 38 | char *cwd; 39 | /** Options used to invoke the JVM. */ 40 | char **opts; 41 | /** Number of JVM options. */ 42 | int onum; 43 | /** The name of the class to invoke. */ 44 | char *clas; 45 | /** Command line arguments to the class. */ 46 | char **args; 47 | /** Number of class command line arguments. */ 48 | int anum; 49 | /** Whether to detach from parent process or not. */ 50 | bool dtch; 51 | /** Whether to print the VM version number or not. */ 52 | bool vers; 53 | /** Show the VM version and continue. */ 54 | bool vershow; 55 | /** Whether to display the help page or not. */ 56 | bool help; 57 | /** Only check environment without running the service. */ 58 | bool chck; 59 | /** Stop running jsvc */ 60 | bool stop; 61 | /** number of seconds to until service started */ 62 | int wait; 63 | /** max restarts **/ 64 | int restarts; 65 | /** Install as a service (win32) */ 66 | bool install; 67 | /** Remove when installed as a service (win32) */ 68 | bool remove; 69 | /** Run as a service (win32) */ 70 | bool service; 71 | /** Destination for stdout */ 72 | char *outfile; 73 | /** Destination for stderr */ 74 | char *errfile; 75 | /** Program name **/ 76 | char *procname; 77 | /** Whether to redirect stdin to /dev/null or not. Defaults to true **/ 78 | bool redirectstdin; 79 | /** What umask to use **/ 80 | int umask; 81 | } arg_data; 82 | 83 | /** 84 | * Parse command line arguments. 85 | * 86 | * @param argc The number of command line arguments. 87 | * @param argv Pointers to the different arguments. 88 | * @return A pointer to a arg_data structure containing the parsed command 89 | * line arguments, or NULL if an error was detected. 90 | */ 91 | arg_data *arguments(int argc, char *argv[]); 92 | 93 | #ifdef __cplusplus 94 | } 95 | #endif 96 | #endif /* ifndef __JSVC_ARGUMENTS_H__ */ 97 | 98 | -------------------------------------------------------------------------------- /src/docs/daemon.css: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | BODY { 19 | font-family: arial, helvetica, sans-serif; 20 | font-size: 10pt; 21 | text-align: justify; 22 | } 23 | 24 | H1 { 25 | border-width: 2px; 26 | border-style: ridge; 27 | border-color: #cccccc; 28 | background-color: #ddddff; 29 | font-size: 14pt; 30 | font-weight: bold; 31 | text-align: center; 32 | padding: 2px; 33 | } 34 | 35 | H2 { 36 | border-width: 2px; 37 | border-style: ridge; 38 | border-color: #cccccc; 39 | background-color: #eeeeff; 40 | font-size: 12pt; 41 | font-weight: bold; 42 | text-align: left; 43 | padding: 2px; 44 | } 45 | 46 | H3 { 47 | font-size: 10pt; 48 | font-weight: bold; 49 | text-align: left; 50 | } 51 | 52 | H4 { 53 | font-size: 8pt; 54 | font-weight: normal; 55 | font-style: italic; 56 | text-align: center; 57 | } 58 | 59 | P { 60 | margin-left: 20px; 61 | } 62 | 63 | P.note { 64 | border-width: 1px; 65 | border-style: ridge; 66 | border-color: #cccccc; 67 | background-color: #ffffee; 68 | font-size: 8pt; 69 | font-weight: normal; 70 | text-align: justify; 71 | margin-left: 20%; 72 | margin-right: 20%; 73 | padding: 4px; 74 | } 75 | 76 | P.copyright { 77 | font-size: 8pt; 78 | font-weight: normal; 79 | text-align: center; 80 | } 81 | 82 | PRE { 83 | border-width: 1px; 84 | border-style: ridge; 85 | border-color: #cccccc; 86 | background-color: #eeeeee; 87 | font-size: 8pt; 88 | font-weight: normal; 89 | text-align: left; 90 | margin-left: 10%; 91 | margin-right: 10%; 92 | padding: 4px; 93 | } 94 | 95 | CODE { 96 | font-size: 8pt; 97 | white-space: pre; 98 | font-weight: normal; 99 | } 100 | 101 | EM.key { 102 | color: #000099; 103 | font-style: normal; 104 | white-space: pre; 105 | } 106 | 107 | EM.ref { 108 | color: #990000; 109 | font-style: normal; 110 | white-space: pre 111 | } 112 | 113 | EM.com { 114 | color: #009900; 115 | font-style: normal; 116 | white-space: pre 117 | } 118 | 119 | OL { 120 | list-style: decimal outside; 121 | font-size: 10pt; 122 | } 123 | 124 | OL OL { 125 | list-style: lower-alpha outside; 126 | font-size: 8pt; 127 | } 128 | 129 | A:link { 130 | color: #0000ee; 131 | text-decoration: none; 132 | white-space: pre; 133 | } 134 | 135 | A:visited { 136 | color: #0000ee; 137 | text-decoration: none; 138 | white-space: pre; 139 | } 140 | 141 | A:active { 142 | color: #0000ee; 143 | text-decoration: none; 144 | white-space: pre; 145 | } 146 | -------------------------------------------------------------------------------- /.github/workflows/windows.yml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | name: Windows 17 | 18 | on: 19 | push: 20 | branches-ignore: 21 | - 'dependabot/**' 22 | paths-ignore: 23 | - 'src/docs/**' 24 | - 'src/main/java/**' 25 | pull_request: 26 | branches: [ master ] 27 | paths-ignore: 28 | - 'src/docs/**' 29 | - 'src/main/java/**' 30 | 31 | concurrency: 32 | group: ${{ github.workflow }}-${{ github.head_ref || github.ref_name }} 33 | cancel-in-progress: true 34 | 35 | jobs: 36 | build: 37 | strategy: 38 | fail-fast: false 39 | matrix: 40 | include: 41 | - name: Default 42 | triplet: x64-windows 43 | arch: x64 44 | build-type: Debug 45 | generator: "Ninja" 46 | 47 | runs-on: windows-latest 48 | timeout-minutes: 30 49 | name: ${{ matrix.name }} 50 | env: 51 | VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite" 52 | steps: 53 | - uses: actions/checkout@v5 54 | with: 55 | ref: master 56 | - name: Test JAVA_HOME 57 | shell: cmd 58 | run: | 59 | echo rem SPDX-License-Identifier: Apache-2.0> set_java_home.bat 60 | echo set JAVA_HOME=%JAVA_HOME_21_X64%>> set_java_home.bat 61 | call .\set_java_home.bat 62 | echo "JAVA_HOME: %JAVA_HOME%" 63 | - name: Build prunsrv 64 | shell: cmd 65 | run: | 66 | echo on 67 | call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\Tools\VsDevCmd.bat" -arch=${{ matrix.arch }} 68 | cd src/native/windows/apps/prunsrv 69 | echo "Building prunsrv for ${{ matrix.arch }}" 70 | nmake BUILD_CPU=${{ matrix.arch }} 71 | - name: Build prunmgr 72 | shell: cmd 73 | run: | 74 | echo on 75 | call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\Tools\VsDevCmd.bat" -arch=${{ matrix.arch }} 76 | cd src/native/windows/apps/prunmgr 77 | echo "Building prunmgr for ${{ matrix.arch }}" 78 | nmake BUILD_CPU=${{ matrix.arch }} 79 | - name: Build jar 80 | shell: cmd 81 | run: | 82 | call .\set_java_home.bat 83 | echo "JAVA_HOME: %JAVA_HOME%" 84 | mvn --batch-mode --no-transfer-progress install 85 | - name: Test 86 | shell: cmd 87 | run: | 88 | call .\set_java_home.bat 89 | echo "JAVA_HOME: %JAVA_HOME%" 90 | cd src/native/windows/apps/prunsrv/test/scripts 91 | test.bat 92 | - uses: actions/upload-artifact@v5 93 | with: 94 | name: windows-artifact 95 | path: src/native/windows/apps/prunsrv/*/prunsrv.exe 96 | -------------------------------------------------------------------------------- /src/native/unix/native/signals.c: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /* 18 | * as Windows does not support signal, jsvc uses events to emulate them. 19 | * The supported signal is SIGTERM. 20 | * The kills.c contains the kill logic. 21 | */ 22 | #ifdef OS_CYGWIN 23 | #include 24 | #include 25 | static void (*HandleTerm) (void) = NULL; /* address of the handler routine. */ 26 | 27 | /* 28 | * Event handling routine 29 | */ 30 | void v_difthf(LPVOID par) 31 | { 32 | HANDLE hevint; /* make a local copy because the parameter is shared! */ 33 | 34 | hevint = (HANDLE) par; 35 | 36 | for (;;) { 37 | if (WaitForSingleObject(hevint, INFINITE) == WAIT_FAILED) { 38 | /* something have gone wrong. */ 39 | return; /* may be something more is needed. */ 40 | } 41 | 42 | /* call the interrupt handler. */ 43 | if (HandleTerm == NULL) 44 | return; 45 | HandleTerm(); 46 | } 47 | } 48 | 49 | /* 50 | * set a routine handler for the signal 51 | * note that it cannot be used to change the signal handler 52 | */ 53 | int SetTerm(void (*func) (void)) 54 | { 55 | char Name[256]; 56 | HANDLE hevint, hthread; 57 | DWORD ThreadId; 58 | SECURITY_ATTRIBUTES sa; 59 | SECURITY_DESCRIPTOR sd; 60 | 61 | sprintf(Name, "TERM%ld", GetCurrentProcessId()); 62 | 63 | /* 64 | * event cannot be inherited. 65 | * the event is reset to nonsignaled after the waiting thread is released. 66 | * the start state is reset. 67 | */ 68 | 69 | /* Initialize the new security descriptor. */ 70 | InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION); 71 | 72 | /* Add a NULL descriptor ACL to the security descriptor. */ 73 | SetSecurityDescriptorDacl(&sd, TRUE, (PACL) NULL, FALSE); 74 | 75 | sa.nLength = sizeof(sa); 76 | sa.lpSecurityDescriptor = &sd; 77 | sa.bInheritHandle = TRUE; 78 | 79 | 80 | /* It works also with NULL instead &sa!! */ 81 | hevint = CreateEvent(&sa, FALSE, FALSE, Name); 82 | 83 | HandleTerm = func; 84 | 85 | if (hevint == NULL) 86 | return -1; /* failed */ 87 | 88 | /* create the thread to wait for event */ 89 | hthread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) v_difthf, 90 | (LPVOID) hevint, 0, &ThreadId); 91 | if (hthread == NULL) { 92 | /* failed remove the event */ 93 | CloseHandle(hevint); /* windows will remove it. */ 94 | return -1; 95 | } 96 | 97 | CloseHandle(hthread); /* not needed */ 98 | return 0; 99 | } 100 | #else 101 | const char __unused_signals_c[] = __FILE__; 102 | #endif 103 | -------------------------------------------------------------------------------- /src/native/windows/include/registry.h: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _REGISTRY_H_INCLUDED_ 18 | #define _REGISTRY_H_INCLUDED_ 19 | 20 | __APXBEGIN_DECLS 21 | 22 | #define APXREG_SOFTWARE 0x0001 23 | #define APXREG_SERVICE 0x0002 24 | #define APXREG_USER 0x0004 25 | 26 | #define APXREG_PARAMSOFTWARE 0x0010 27 | #define APXREG_PARAMSERVICE 0x0020 28 | #define APXREG_PARAMUSER 0x0040 29 | 30 | /** Create or open the process registry keys 31 | */ 32 | APXHANDLE apxCreateRegistryW(APXHANDLE hPool, REGSAM samDesired, 33 | LPCWSTR szRoot, LPCWSTR szKeyName, 34 | DWORD dwOptions); 35 | 36 | /** Delete the process registry keys 37 | * samDesired only needs to be KREG_WOW6432 or 0 38 | */ 39 | BOOL apxDeleteRegistryW(LPCWSTR szRoot, LPCWSTR szKeyName, 40 | REGSAM samDesired, BOOL bDeleteEmptyRoot); 41 | 42 | /** Get the JavaHome path from registry 43 | * and set the JAVA_HOME environment variable if not found 44 | * If bPreferJre is set use the JRE's path as JAVA_HOME 45 | */ 46 | LPWSTR apxGetJavaSoftHome(APXHANDLE hPool, BOOL bPreferJre); 47 | 48 | /** Get the Java RuntimeLib from registry (jvm.dll) 49 | */ 50 | LPWSTR apxGetJavaSoftRuntimeLib(APXHANDLE hPool); 51 | 52 | LPWSTR apxRegistryGetStringW(APXHANDLE hRegistry, DWORD dwFrom, 53 | LPCWSTR szSubkey, LPCWSTR szValueName); 54 | 55 | BOOL apxRegistrySetBinaryA(APXHANDLE hRegistry, DWORD dwFrom, 56 | LPCSTR szSubkey, LPCSTR szValueName, 57 | const LPBYTE lpData, DWORD dwLength); 58 | 59 | BOOL apxRegistrySetBinaryW(APXHANDLE hRegistry, DWORD dwFrom, 60 | LPCWSTR szSubkey, LPCWSTR szValueName, 61 | const LPBYTE lpData, DWORD dwLength); 62 | 63 | LPWSTR apxRegistryGetMzStrW(APXHANDLE hRegistry, DWORD dwFrom, 64 | LPCWSTR szSubkey, LPCWSTR szValueName, 65 | LPWSTR lpData, LPDWORD lpdwLength); 66 | 67 | BOOL apxRegistrySetMzStrW(APXHANDLE hRegistry, DWORD dwFrom, 68 | LPCWSTR szSubkey, LPCWSTR szValueName, 69 | LPCWSTR lpData, DWORD dwLength); 70 | 71 | BOOL apxRegistrySetStrW(APXHANDLE hRegistry, DWORD dwFrom, 72 | LPCWSTR szSubkey, LPCWSTR szValueName, 73 | LPCWSTR szValue); 74 | 75 | 76 | BOOL apxRegistrySetNumW(APXHANDLE hRegistry, DWORD dwFrom, 77 | LPCWSTR szSubkey, LPCWSTR szValueName, 78 | DWORD dwValue); 79 | 80 | DWORD apxRegistryGetNumberW(APXHANDLE hRegistry, DWORD dwFrom, 81 | LPCWSTR szSubkey, LPCWSTR szValueName); 82 | 83 | 84 | BOOL apxRegistryDeleteW(APXHANDLE hRegistry, DWORD dwFrom, 85 | LPCWSTR szSubkey, LPCWSTR szValueName); 86 | 87 | __APXEND_DECLS 88 | 89 | #endif /* _REGISTRY_H_INCLUDED_ */ 90 | -------------------------------------------------------------------------------- /src/site/xdoc/faq.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 22 | 23 | Daemon : FAQ 24 | Jean-Frederic Clere 25 | 26 | 27 | 28 |
29 |

30 | 31 | $ sh support/buildconf.sh 32 | autoconf: Undefined macros: 33 | ***BUG in Autoconf--please report*** AC_PATH 34 | ***BUG in Autoconf--please report*** AC_PATH 35 | ***BUG in Autoconf--please report*** AC_PATH 36 | 37 | Your version of autoconf is too old, upgrade your autoconf and retry. 38 | Or run support/buildconf.sh in another machine and copy the daemon tree in 39 | the machine where you want to compile jsvc. 40 |

41 |
42 | 43 |
44 |

45 | 46 | configure: creating ./config.status 47 | config.status: creating Makefile 48 | mv: Makefile: set owner/group (was: 1670/0): Operation not permitted 49 | config.status: creating Makedefs 50 | mv: Makedefs: set owner/group (was: 1670/0): Operation not permitted 51 | config.status: creating native/Makefile 52 | mv: native/Makefile: set owner/group (was: 1670/0): Operation not permitted 53 | *** All done *** 54 | Now you can issue "make" 55 | 56 | You should ignore those error messages they are normal in FreeBSD. 57 | config.status creates files in /tmp and move them in the current directory. 58 | When FreeBSD creates files it sets the group of the files to 59 | the group of the directory where the files are created. 60 | So if /tmp is group "wheel" the files are "wheel". When moving the files in 61 | the current directory (if you are not member of group "wheel") 62 | the group "wheel" cannot be set on the moved files. 63 |

64 |
65 |
66 |

67 | On Linux 2.6.x jsvc does not start and write the following error: 68 | 69 | jsvc.exec error: syscall failed in set_caps 70 | jsvc.exec error: Service exit with a return value of 4 71 | 72 | CONFIG_SECURITY_CAPABILITIES in missing in your kernel try the following in the kernel sources: 73 |

74 |
    75 |
  • 76 | Configure the kernel with "Default Linux Capabilities" and reboot 77 | (by make gconfig or make xconfig under "security options" and "Enable different security models") 78 |
  • 79 |
  • 80 | Insert the module "capability": 81 | 82 | modprobe capability 83 | 84 |
  • 85 |
86 |
87 | 88 |
89 |

90 | The configure of jsvc does not like spaces in directory name. 91 | To configure with java installed in directory whose name contains a space, 92 | use the 8 characters name of the directory. 93 | For example for java in installed in c:\Archivos de programa\java\jdk1.5.0_06: 94 | 95 | ./configure --with-java=/cygdrive/c/Archiv~1/java/jdk1.5.0_06 96 | 97 |

98 |
99 | 100 | 101 |
102 | -------------------------------------------------------------------------------- /src/native/windows/src/security.c: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "apxwin.h" 18 | #include "private.h" 19 | #include 20 | #include 21 | #include 22 | 23 | DWORD 24 | apxSecurityGrantFileAccessToUser( 25 | LPCWSTR szPath, 26 | LPCWSTR szUser) 27 | { 28 | WCHAR sPath[SIZ_PATHLEN]; 29 | WCHAR sUser[SIZ_RESLEN]; 30 | DWORD dwResult; 31 | PACL pOldDACL; 32 | PACL pNewDACL = NULL; 33 | PSECURITY_DESCRIPTOR pSD = NULL; 34 | EXPLICIT_ACCESS ea; 35 | 36 | if (szPath) { 37 | lstrlcpyW(sPath, SIZ_PATHLEN, szPath); 38 | } else { 39 | dwResult = GetSystemDirectoryW(sPath, MAX_PATH); 40 | if (dwResult) { 41 | goto cleanup; 42 | } 43 | lstrlcatW(sPath, MAX_PATH, LOG_PATH_DEFAULT); 44 | } 45 | if (szUser) { 46 | /* The API used to set file permissions doesn't always recognised the 47 | * same users as the API used to configured services. We do any 48 | * necessary conversion here. The known issues are: 49 | * LocalSystem is not recognised. It needs to be converted to 50 | * "NT Authority\System" 51 | * User names for the local machine that use the ".\username" form need 52 | * to have the leading ".\" removed. 53 | */ 54 | if (!StrCmpW(STAT_SYSTEM, szUser)) { 55 | lstrlcpyW(sUser, SIZ_RESLEN, STAT_SYSTEM_WITH_DOMAIN); 56 | } else { 57 | if (StrStrW(szUser, L".\\") == szUser) { 58 | szUser +=2; 59 | } 60 | lstrlcpyW(sUser, SIZ_RESLEN, szUser); 61 | } 62 | } else { 63 | lstrlcpyW(sUser, SIZ_RESLEN, DEFAULT_SERVICE_USER); 64 | } 65 | 66 | /* Old (current) ACL. */ 67 | dwResult = GetNamedSecurityInfoW( 68 | sPath, 69 | SE_FILE_OBJECT, 70 | DACL_SECURITY_INFORMATION, 71 | NULL, 72 | NULL, 73 | &pOldDACL, 74 | NULL, 75 | &pSD); 76 | if (dwResult) { 77 | goto cleanup; 78 | } 79 | 80 | /* Additional access. */ 81 | ZeroMemory(&ea, sizeof(EXPLICIT_ACCESS)); 82 | ea.grfAccessPermissions = GENERIC_EXECUTE + GENERIC_READ + GENERIC_WRITE; 83 | ea.grfAccessMode = SET_ACCESS; 84 | ea.grfInheritance = CONTAINER_INHERIT_ACE + OBJECT_INHERIT_ACE; 85 | ea.Trustee.TrusteeForm = TRUSTEE_IS_NAME; 86 | ea.Trustee.ptstrName = sUser; 87 | 88 | /* Merge old and additional into new ACL. */ 89 | dwResult = SetEntriesInAcl(1, &ea, pOldDACL, &pNewDACL); 90 | if (dwResult) { 91 | goto cleanup; 92 | } 93 | 94 | /* Set the new ACL. */ 95 | dwResult = SetNamedSecurityInfoW( 96 | sPath, 97 | SE_FILE_OBJECT, 98 | DACL_SECURITY_INFORMATION, 99 | NULL, 100 | NULL, 101 | pNewDACL, 102 | NULL); 103 | if (dwResult) { 104 | goto cleanup; 105 | } 106 | 107 | cleanup: 108 | if (pSD != NULL) { 109 | LocalFree((HLOCAL) pSD); 110 | } 111 | if (pNewDACL != NULL) { 112 | LocalFree((HLOCAL) pNewDACL); 113 | } 114 | 115 | return dwResult; 116 | } 117 | -------------------------------------------------------------------------------- /src/native/unix/native/replace.c: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "jsvc.h" 18 | 19 | /* Replace all occurrences of a string in another */ 20 | int replace(char *new, int len, char *old, char *mch, char *rpl) 21 | { 22 | char *tmp; 23 | int count; 24 | int shift; 25 | int nlen; 26 | int olen; 27 | int mlen; 28 | int rlen; 29 | int x; 30 | 31 | /* The new buffer is NULL, fail */ 32 | if (new == NULL) 33 | return -1; 34 | /* The length of the buffer is less than zero, fail */ 35 | if (len < 0) 36 | return -2; 37 | /* The old buffer is NULL, fail */ 38 | if (old == NULL) 39 | return -3; 40 | 41 | /* The string to be matched is NULL or empty, simply copy */ 42 | if ((mch == NULL) || (strlen(mch) == 0)) { 43 | olen = strlen(old); 44 | if (len <= olen) 45 | return (olen + 1); 46 | strcpy(new, old); 47 | return 0; 48 | } 49 | 50 | /* The string to be replaced is NULL, assume it's an empty string */ 51 | if (rpl == NULL) 52 | rpl = ""; 53 | 54 | /* Evaluate some lengths */ 55 | olen = strlen(old); 56 | mlen = strlen(mch); 57 | rlen = strlen(rpl); 58 | 59 | /* Calculate how many times the mch string appears in old */ 60 | tmp = old; 61 | count = 0; 62 | while ((tmp = strstr(tmp, mch)) != NULL) { 63 | count++; 64 | tmp += mlen; 65 | } 66 | 67 | /* We have no matches, simply copy */ 68 | if (count == 0) { 69 | olen = strlen(old); 70 | if (len <= olen) 71 | return (olen + 1); 72 | strcpy(new, old); 73 | return 0; 74 | } 75 | 76 | /* Calculate how big the buffer must be to hold the translation 77 | * and of how many bytes we need to shift the data 78 | */ 79 | shift = rlen - mlen; 80 | nlen = olen + (shift * count); 81 | /* printf("Count=%d Shift= %d OLen=%d NLen=%d\n",count,shift,olen,nlen); */ 82 | 83 | /* Check if we have enough size in the buffer */ 84 | if (nlen >= len) 85 | return (nlen + 1); 86 | 87 | /* Copy over the old buffer in the new one (save memory) */ 88 | strcpy(new, old); 89 | 90 | /* Start replacing */ 91 | tmp = new; 92 | while ((tmp = strstr(tmp, mch)) != NULL) { 93 | /* If shift is > 0 we need to move data from right to left */ 94 | if (shift > 0) { 95 | for (x = (strlen(tmp) + shift); x > shift; x--) { 96 | /* 97 | printf("src %c(%d) dst %c(%d)\n", 98 | tmp[x-shift],tmp[x-shift],tmp[x],tmp[x]); 99 | */ 100 | tmp[x] = tmp[x - shift]; 101 | } 102 | /* If shift is < 0 we need to move data from left to right */ 103 | } 104 | else if (shift < 0) { 105 | for (x = mlen; x < strlen(tmp) - shift; x++) { 106 | /* 107 | printf("src %c(%d) dst %c(%d)\n", 108 | tmp[x],tmp[x],tmp[x+shift],tmp[x+shift]); 109 | */ 110 | tmp[x + shift] = tmp[x]; 111 | } 112 | } 113 | /* If shift is = 0 we don't have to shift data */ 114 | strncpy(tmp, rpl, rlen); 115 | tmp += rlen; 116 | /* printf("\"%s\"\n",tmp); */ 117 | } 118 | return 0; 119 | } 120 | -------------------------------------------------------------------------------- /src/native/windows/include/log.h: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /* Logfile handling 18 | * Use Systemdir/Logfiles/Apache as a default path 19 | */ 20 | 21 | #ifndef _LOG_H_INCLUDED_ 22 | #define _LOG_H_INCLUDED_ 23 | 24 | __APXBEGIN_DECLS 25 | 26 | static LPCWSTR LOG_PATH_DEFAULT = L"\\LogFiles\\Apache"; 27 | 28 | #define LOG_MSG_MAX_LEN 4096 29 | 30 | #define APX_LOGLOCK(file) \ 31 | APXMACRO_BEGIN \ 32 | DWORD _lmax = 0; \ 33 | while(!LockFile(file, 0, 0, 512, 0)) { \ 34 | Sleep(10); \ 35 | if (_lmax++ > 1000) break; \ 36 | } \ 37 | SetFilePointer(file, 0, NULL, FILE_END); \ 38 | APXMACRO_END 39 | 40 | #define APX_LOGUNLOCK(file) \ 41 | APXMACRO_BEGIN \ 42 | UnlockFile(file, 0, 0, 512, 0); \ 43 | APXMACRO_END 44 | 45 | #define APX_LOGENTER() \ 46 | if (_pt_sys_loglock) \ 47 | EnterCriticalSection(_pt_sys_loglock); \ 48 | else (void)0 49 | 50 | #define APX_LOGLEAVE() \ 51 | if (_pt_sys_loglock) \ 52 | LeaveCriticalSection(_pt_sys_loglock); \ 53 | else (void)0 54 | 55 | #define APXLOG_LEVEL_TRACE 0 56 | #define APXLOG_LEVEL_DEBUG 1 57 | #define APXLOG_LEVEL_INFO 2 58 | #define APXLOG_LEVEL_WARN 3 59 | #define APXLOG_LEVEL_ERROR 4 60 | 61 | #define __func__ __FUNCTION__ 62 | #define APXLOG_MARK_INFO NULL, APXLOG_LEVEL_INFO, TRUE, __FILE__, __LINE__, __func__, "" 63 | #define APXLOG_MARK_WARN NULL, APXLOG_LEVEL_WARN, TRUE, __FILE__, __LINE__, __func__, "" 64 | #define APXLOG_MARK_ERROR NULL, APXLOG_LEVEL_ERROR, TRUE, __FILE__, __LINE__, __func__, "" 65 | #define APXLOG_MARK_DEBUG NULL, APXLOG_LEVEL_DEBUG, TRUE, __FILE__, __LINE__, __func__, "" 66 | #define APXLOG_MARK_TRACE NULL, APXLOG_LEVEL_TRACE, TRUE, __FILE__, __LINE__, __func__, "" 67 | #define APXLOG_MARK_RAW NULL, APXLOG_LEVEL_INFO, FALSE, NULL, NULL, 0, 68 | #define APXLOG_MARK_SYSERR NULL, APXLOG_LEVEL_ERROR, TRUE, __FILE__, __LINE__, __func__, NULL 69 | 70 | LPWSTR apxLogFile( 71 | APXHANDLE hPool, 72 | LPCWSTR szPath, 73 | LPCWSTR szPrefix, 74 | LPCWSTR szName, 75 | BOOL bTimeStamp, 76 | DWORD dwRotate 77 | ); 78 | 79 | HANDLE apxLogOpen( 80 | APXHANDLE hPool, 81 | LPCWSTR szPath, 82 | LPCWSTR szPrefix, 83 | DWORD dwRotate 84 | ); 85 | 86 | void apxLogClose( 87 | HANDLE hFile 88 | ); 89 | 90 | void apxLogLevelSet( 91 | HANDLE hFile, 92 | DWORD dwLevel 93 | ); 94 | 95 | void apxLogLevelSetW( 96 | HANDLE hFile, 97 | LPCWSTR szLevel 98 | ); 99 | 100 | int 101 | apxLogWrite( 102 | HANDLE hFile, 103 | DWORD dwLevel, 104 | BOOL bTimeStamp, 105 | LPCSTR szFile, 106 | DWORD dwLine, 107 | LPCSTR szFunction, 108 | LPCSTR szFormat, 109 | ... 110 | ); 111 | 112 | int 113 | apxDisplayError( 114 | BOOL bDisplay, 115 | LPCSTR szFile, 116 | DWORD dwLine, 117 | LPCSTR szFormat, 118 | ... 119 | ); 120 | 121 | DWORD 122 | apxGetMessage( 123 | DWORD dwMessageId, 124 | LPSTR lpBuffer, 125 | DWORD nSize); 126 | 127 | __APXEND_DECLS 128 | 129 | #endif /* _LOG_H_INCLUDED_ */ 130 | -------------------------------------------------------------------------------- /src/assembly/native-src.xml: -------------------------------------------------------------------------------- 1 | 17 | 20 | native-src 21 | 22 | tar.gz 23 | zip 24 | 25 | ${project.artifactId}-${project.version}-native-src 26 | 27 | 28 | 29 | LICENSE.txt 30 | NOTICE.txt 31 | RELEASE-NOTES.txt 32 | 33 | README 34 | 35 | 36 | 37 | src/native/unix 38 | unix 39 | lf 40 | 41 | 42 | Makedefs 43 | Makefile 44 | autom4te.cache/** 45 | config.log 46 | config.nice 47 | config.status 48 | configure 49 | jsvc 50 | native/*.o 51 | native/Makefile 52 | native/libservice.a 53 | 54 | **/*.sh 55 | 56 | **/*.formatted 57 | 58 | 59 | 60 | src/native/unix 61 | unix 62 | lf 63 | 775 64 | 65 | **/*.sh 66 | configure 67 | 68 | 69 | 70 | src/native/windows 71 | windows 72 | crlf 73 | 74 | 75 | apps/prunmgr/*_GUI_RELEASE/** 76 | apps/prunsrv/*_RELEASE/** 77 | 78 | **/*.ico 79 | **/*.bmp 80 | **/*.rc 81 | 82 | **/*.formatted 83 | 84 | 664 85 | 86 | 87 | src/native/windows 88 | windows 89 | 90 | **/*.ico 91 | **/*.bmp 92 | **/*.rc 93 | 94 | 664 95 | 96 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /src/native/windows/src/console.c: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "apxwin.h" 18 | #include "private.h" 19 | 20 | /** Console layout saved in the registry as binary */ 21 | typedef struct stAPXCONSOLE_LAYOUT { 22 | /** Main window size */ 23 | POINT ptSize; 24 | /** Main window size and position */ 25 | RECT rcPos; 26 | /** Client window size */ 27 | POINT ptClientSize; 28 | /** Client size and position */ 29 | RECT rcClientPos; 30 | /** Scroll position */ 31 | POINT ptScrollPos; 32 | /** Maximum Scroll position */ 33 | POINT ptScrollMax; 34 | /** Caret position */ 35 | POINT ptCaretPos; 36 | /** Background color */ 37 | COLORREF clrBackground; 38 | /** Text color */ 39 | COLORREF clrText; 40 | /** Selected text background color */ 41 | COLORREF clrSelectBackground; 42 | /** Selected text color */ 43 | COLORREF clrSelectText; 44 | /** Character size */ 45 | POINT ptCharSize; 46 | /** Current Screen size */ 47 | POINT ptScreenSize; 48 | /** Font size */ 49 | INT nFontSize; 50 | /** Caret size */ 51 | POINT ptCaretSize; 52 | /** Caret blink time in ms */ 53 | UINT nCaretBlinkTime; 54 | /** Typeface name of the font (32 char max including the null terminator) */ 55 | TCHAR szFontName[32]; 56 | 57 | } stAPXCONSOLE_LAYOUT, *APXCONSOLE_LAYOUT; 58 | 59 | typedef struct stAPXCONSOLE { 60 | /** Application instance handle */ 61 | HINSTANCE hInstance; 62 | /** Console Screen Buffer */ 63 | TCHAR lpScreenBuffer; 64 | /** The size of the Console Screen Buffer */ 65 | DWORD dwScreenBufferSize; 66 | /** Main window Handle */ 67 | HWND hWnd; 68 | /** Console window Handle */ 69 | HWND hConsole; 70 | /** Console Window Layout */ 71 | stAPXCONSOLE_LAYOUT stLayout; 72 | /** Console Keyboard Buffer */ 73 | TCHAR lpKeyboardBuffer; 74 | /** The size of the Keyboard Buffer */ 75 | DWORD dwKeyboardBufferSize; 76 | /** Console Handler routine */ 77 | PHANDLER_ROUTINE fnHandlerRoutine; 78 | /** Console Reference Count */ 79 | DWORD dwReferenceCount; 80 | } stAPXCONSOLE, *APXCONSOLE; 81 | 82 | APXHANDLE __st_sys_console = NULL; 83 | 84 | static BOOL __apxConsoleCallback(APXHANDLE hObject, UINT uMsg, 85 | WPARAM wParam, LPARAM lParam) 86 | { 87 | if (hObject->dwType != APXHANDLE_TYPE_CONSOLE) 88 | return FALSE; 89 | switch (uMsg) { 90 | case WM_CLOSE: 91 | 92 | break; 93 | default: 94 | break; 95 | } 96 | return TRUE; 97 | UNREFERENCED_PARAMETER(wParam); 98 | UNREFERENCED_PARAMETER(lParam); 99 | } 100 | 101 | APXHANDLE 102 | apxAllocConsoleHandle(APXHANDLE hPool) 103 | { 104 | APXHANDLE hConsole; 105 | 106 | hConsole = apxHandleCreate(hPool, APXHANDLE_HAS_EVENT | 107 | APXHANDLE_OWNS_LOCK, NULL, 108 | sizeof(stAPXCONSOLE), 109 | __apxConsoleCallback); 110 | 111 | return hConsole; 112 | } 113 | 114 | BOOL 115 | apxFreeConsoleHandle(APXHANDLE hConsole) 116 | { 117 | if (hConsole->dwType != APXHANDLE_TYPE_CONSOLE) 118 | return FALSE; 119 | 120 | return apxCloseHandle(hConsole); 121 | } 122 | 123 | 124 | 125 | 126 | 127 | /** Standard Console Functions */ 128 | BOOL 129 | apxAllocConsole() 130 | { 131 | 132 | if (!__st_sys_console) { 133 | __st_sys_console = apxAllocConsoleHandle(NULL); 134 | return TRUE; 135 | } 136 | else 137 | return FALSE; 138 | } 139 | 140 | BOOL 141 | apxFreeConsole() 142 | { 143 | if (apxFreeConsoleHandle(__st_sys_console)) { 144 | __st_sys_console = NULL; 145 | return TRUE; 146 | } 147 | else 148 | return FALSE; 149 | } 150 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/daemon/Daemon.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.daemon; 19 | 20 | /** 21 | * Provides support for native daemon invocation. Using 22 | * a platform dependant helper program, classes that implement the 23 | * {@code Daemon} interface can be initialized, started and 24 | * stopped according to the conventions of the underlying operating 25 | * system. 26 | *

27 | * Implementors of this interface must also provide a public constructor 28 | * with no arguments so that instances can be created in an automated 29 | * fashion. 30 | *

31 | */ 32 | public interface Daemon 33 | { 34 | 35 | /** 36 | * Initializes this {@code Daemon} instance. 37 | *

38 | * This method gets called once the JVM process is created and the 39 | * {@code Daemon} instance is created thru its empty public 40 | * constructor. 41 | *

42 | *

43 | * Under certain operating systems (typically Unix based operating 44 | * systems) and if the native invocation framework is configured to do 45 | * so, this method might be called with super-user privileges. 46 | *

47 | *

48 | * For example, it might be wise to create {@code ServerSocket} 49 | * instances within the scope of this method, and perform all operations 50 | * requiring super-user privileges in the underlying operating 51 | * system. 52 | *

53 | *

54 | * Apart from set up and allocation of native resources, this method 55 | * must not start the actual operation of the {@code Daemon} (such 56 | * as starting threads calling the {@code ServerSocket.accept()} 57 | * method) as this would impose some serious security hazards. The 58 | * start of operation must be performed in the {@code start()} 59 | * method. 60 | *

61 | * 62 | * @param context A {@code DaemonContext} object used to 63 | * communicate with the container. 64 | * @throws DaemonInitException An exception that prevented 65 | * initialization where you want to display a nice message to the user, 66 | * rather than a stack trace. 67 | * @throws Exception Any exception preventing a successful 68 | * initialization. 69 | */ 70 | void init(DaemonContext context) 71 | throws DaemonInitException, Exception; 72 | 73 | /** 74 | * Starts the operation of this {@code Daemon} instance. This 75 | * method is to be invoked by the environment after the init() 76 | * method has been successfully invoked and possibly the security 77 | * level of the JVM has been dropped. Implementors of this 78 | * method are free to start any number of threads, but need to 79 | * return control after having done that to enable invocation of 80 | * the stop()-method. 81 | * 82 | * @throws Exception If the start was not successful 83 | */ 84 | void start() 85 | throws Exception; 86 | 87 | /** 88 | * Stops the operation of this {@code Daemon} instance. Note 89 | * that the proper place to free any allocated resources such as 90 | * sockets or file descriptors is in the destroy method, as the 91 | * container may restart the Daemon by calling start() after 92 | * stop(). 93 | * 94 | * @throws Exception If the stop was not successful 95 | */ 96 | void stop() 97 | throws Exception; 98 | 99 | /** 100 | * Frees any resources allocated by this daemon such as file 101 | * descriptors or sockets. This method gets called by the container 102 | * after stop() has been called, before the JVM exits. The Daemon 103 | * cannot be restarted after this method has been called without a 104 | * new call to the init() method. 105 | */ 106 | void destroy(); 107 | } 108 | 109 | -------------------------------------------------------------------------------- /src/samples/AloneService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | import java.io.FileInputStream; 19 | import java.io.FileOutputStream; 20 | import java.io.PrintStream; 21 | import java.util.Enumeration; 22 | import java.util.Properties; 23 | 24 | /* 25 | * That is like the ServiceDaemon but it does not use the Daemon interface. 26 | */ 27 | public class AloneService { 28 | 29 | private Properties prop; 30 | private Process[] proc = null; 31 | private ServiceDaemonReadThread[] readout = null; 32 | private ServiceDaemonReadThread[] readerr = null; 33 | 34 | @Override 35 | protected void finalize() { 36 | System.err.println("ServiceDaemon: instance "+this.hashCode()+ 37 | " garbage collected"); 38 | } 39 | 40 | /** 41 | * init and destroy were added in jakarta-tomcat-daemon. 42 | * 43 | * @param arguments Unused 44 | * @throws Exception If the daemon cannot be initialized 45 | */ 46 | public void init(String[] arguments) throws Exception { 47 | // Set the err 48 | System.setErr(new PrintStream(new FileOutputStream("/ServiceDaemon.err", true))); 49 | System.err.println("ServiceDaemon: instance "+this.hashCode()+ 50 | " init"); 51 | 52 | // read the properties file 53 | prop = new Properties(); 54 | try { 55 | prop.load(new FileInputStream("startfile")); 56 | } 57 | catch (Exception e) { 58 | // Cannot find startfile.properties. 59 | // XXX: Should we print something? 60 | } 61 | /* create an array to store the processes */ 62 | int processCount = prop.size(); 63 | System.err.println("ServiceDaemon: init for " + processCount + " processes"); 64 | proc = new Process[processCount]; 65 | readout = new ServiceDaemonReadThread[processCount]; 66 | readerr = new ServiceDaemonReadThread[processCount]; 67 | for (int i = 0 ; i < processCount; i++) { 68 | proc[i] = null; 69 | readout[i] = null; 70 | readerr[i] = null; 71 | } 72 | 73 | System.err.println("ServiceDaemon: init done "); 74 | } 75 | 76 | public void start() { 77 | // Dump a message 78 | System.err.println("ServiceDaemon: starting"); 79 | 80 | // Start 81 | int i=0; 82 | for (Enumeration e = prop.keys(); e.hasMoreElements() ;) { 83 | String name = (String) e.nextElement(); 84 | System.err.println("ServiceDaemon: starting: " + name + " : " + prop.getProperty(name)); 85 | try { 86 | proc[i] = Runtime.getRuntime().exec(new String[] {prop.getProperty(name)}); 87 | } catch (Exception ex) { 88 | System.err.println("Exception: " + ex); 89 | } 90 | // Start threads to read from Error and Out streams 91 | readerr[i] = 92 | new ServiceDaemonReadThread(proc[i].getErrorStream()); 93 | readout[i] = 94 | new ServiceDaemonReadThread(proc[i].getInputStream()); 95 | readerr[i].start(); 96 | readout[i].start(); 97 | i++; 98 | } 99 | } 100 | 101 | public void stop() { 102 | // Dump a message 103 | System.err.println("ServiceDaemon: stopping"); 104 | 105 | for (int i=0;i 22 | 23 | #ifdef __bool_true_false_are_defined 24 | /* We define these differently than stdbool.h, so ignore the defs there */ 25 | #undef bool 26 | #undef true 27 | #undef false 28 | #endif 29 | 30 | 31 | /* Print an error message and abort all if a specified symbol wasn't found */ 32 | static void nosymbol(const char *s) 33 | { 34 | log_error("Cannot find symbol '%s' in library", s); 35 | abort(); 36 | } 37 | 38 | /* We found two symbols for the same name in two different modules */ 39 | static NSModule multiple(NSSymbol s, NSModule om, NSModule nm) 40 | { 41 | NSModule ret = nm; 42 | 43 | log_debug("Symbol \"%s\" found in modules \"%s\" and \"%s\" (using %s)", 44 | NSNameOfSymbol(s), NSNameOfModule(om), NSNameOfModule(nm), NSNameOfModule(ret)); 45 | 46 | return (ret); 47 | } 48 | 49 | /* We got an error while linking a module, and if it's not a warning we have 50 | to abort the whole program */ 51 | static void linkedit(NSLinkEditErrors category, int number, const char *file, const char *message) 52 | { 53 | log_error("Errors during link edit of file \"%s\" (error=%d): %s", file, number, message); 54 | /* Check if this error was only a warning */ 55 | if (category != NSLinkEditWarningError) { 56 | log_error("Cannot continue"); 57 | abort(); 58 | } 59 | } 60 | 61 | /* Initialize all DSO stuff */ 62 | bool dso_init() 63 | { 64 | NSLinkEditErrorHandlers h; 65 | 66 | h.undefined = nosymbol; 67 | h.multiple = multiple; 68 | h.linkEdit = linkedit; 69 | 70 | NSInstallLinkEditErrorHandlers(&h); 71 | return (true); 72 | } 73 | 74 | /* Attempt to link a library from a specified filename */ 75 | dso_handle dso_link(const char *path) 76 | { 77 | /* We need to load the library publicly as NSModuleFileImage is not 78 | yet implemented (at least for non MH_BUNDLE libraries */ 79 | if (NSAddLibrary(path) != TRUE) 80 | return (NULL); 81 | /* We need to return a non-null value, even if it has no meaning. One day 82 | this whole crap will be fixed */ 83 | return ((void *)!NULL); 84 | } 85 | 86 | /* Attempt to unload a library */ 87 | bool dso_unlink(dso_handle libr) 88 | { 89 | /* Check the handle */ 90 | if (libr == NULL) { 91 | log_error("Attempting to unload a module without handle"); 92 | return (false); 93 | } 94 | 95 | /* We don't have a module, so, we don't really have to do anything */ 96 | return (true); 97 | } 98 | 99 | /* Get the address for a specified symbol */ 100 | void *dso_symbol(dso_handle hdl, const char *nam) 101 | { 102 | NSSymbol sym = NULL; 103 | NSModule mod = NULL; 104 | char *und = NULL; 105 | void *add = NULL; 106 | int x = 0; 107 | 108 | /* Check parameters */ 109 | if (hdl == NULL) { 110 | log_error("Invalid library handler specified"); 111 | return (NULL); 112 | } 113 | 114 | if (nam == NULL) { 115 | log_error("Invalid symbol name specified"); 116 | return (NULL); 117 | } 118 | 119 | /* Process the correct name (add a _ before the name) */ 120 | while (nam[x] != '\0') 121 | x++; 122 | und = (char *)malloc(sizeof(char) * (x + 2)); 123 | while (x >= 0) 124 | und[x + 1] = nam[x--]; 125 | und[0] = '_'; 126 | 127 | /* Find the symbol */ 128 | sym = NSLookupAndBindSymbol(und); 129 | free(und); 130 | if (sym == NULL) 131 | return (NULL); 132 | 133 | /* Dump some debugging output since this part is shaky */ 134 | mod = NSModuleForSymbol(sym); 135 | add = NSAddressOfSymbol(sym); 136 | log_debug("Symbol \"%s\" found in module \"%s\" at address \"0x%08X\"", 137 | NSNameOfSymbol(sym), NSNameOfModule(mod), add); 138 | 139 | /* We want to return the address of the symbol */ 140 | return (add); 141 | } 142 | 143 | /* Return the error message from dlopen: Well we already print it */ 144 | char *dso_error() 145 | { 146 | return ("no additional message"); 147 | } 148 | 149 | #endif /* ifdef DSO_DYLD */ 150 | -------------------------------------------------------------------------------- /src/samples/build.xml: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 111 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | -------------------------------------------------------------------------------- /src/samples/ServiceDaemon.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | import java.io.File; 19 | import java.io.FileInputStream; 20 | import java.io.FileOutputStream; 21 | import java.io.IOException; 22 | import java.io.PrintStream; 23 | import java.util.Enumeration; 24 | import java.util.Properties; 25 | 26 | import org.apache.commons.daemon.Daemon; 27 | import org.apache.commons.daemon.DaemonContext; 28 | 29 | public class ServiceDaemon implements Daemon { 30 | 31 | private Properties prop; 32 | private Process[] proc = null; 33 | private ServiceDaemonReadThread[] readout = null; 34 | private ServiceDaemonReadThread[] readerr = null; 35 | 36 | public ServiceDaemon() { 37 | super(); 38 | System.err.println("ServiceDaemon: instance "+this.hashCode()+ 39 | " created"); 40 | } 41 | 42 | @Override 43 | protected void finalize() { 44 | System.err.println("ServiceDaemon: instance "+this.hashCode()+ 45 | " garbage collected"); 46 | } 47 | 48 | /** 49 | * init and destroy were added in jakarta-tomcat-daemon. 50 | */ 51 | @Override 52 | public void init(DaemonContext context) 53 | throws Exception { 54 | // Set the err 55 | System.setErr(new PrintStream(new FileOutputStream(new File("ServiceDaemon.err")), true)); 56 | System.err.println("ServiceDaemon: instance "+this.hashCode()+ 57 | " init"); 58 | 59 | // read the properties file 60 | prop = new Properties(); 61 | try { 62 | prop.load(new FileInputStream("startfile")); 63 | } 64 | catch (Exception e) { 65 | // Cannot find startfile.properties. 66 | // TODO: Should we print something? 67 | } 68 | // create an array to store the processes 69 | int processCount = prop.size(); 70 | System.err.println("ServiceDaemon: init for " + processCount + " processes"); 71 | proc = new Process[processCount]; 72 | readout = new ServiceDaemonReadThread[processCount]; 73 | readerr = new ServiceDaemonReadThread[processCount]; 74 | for (int i = 0 ; i < processCount; i++) { 75 | proc[i] = null; 76 | readout[i] = null; 77 | readerr[i] = null; 78 | } 79 | 80 | System.err.println("ServiceDaemon: init done "); 81 | } 82 | 83 | @Override 84 | public void start() { 85 | // Dump a message 86 | System.err.println("ServiceDaemon: starting"); 87 | 88 | // Start 89 | int i=0; 90 | for (Enumeration e = prop.keys(); e.hasMoreElements() ;) { 91 | String name = (String) e.nextElement(); 92 | System.err.println("ServiceDaemon: starting: " + name + " : " + prop.getProperty(name)); 93 | try { 94 | proc[i] = Runtime.getRuntime().exec(new String[] {prop.getProperty(name)}); 95 | } catch (Exception ex) { 96 | System.err.println("Exception: " + ex); 97 | } 98 | // Start threads to read from Error and Out streams 99 | readerr[i] = 100 | new ServiceDaemonReadThread(proc[i].getErrorStream()); 101 | readout[i] = 102 | new ServiceDaemonReadThread(proc[i].getInputStream()); 103 | readerr[i].start(); 104 | readout[i].start(); 105 | i++; 106 | } 107 | } 108 | 109 | @Override 110 | public void stop() 111 | throws IOException, InterruptedException { 112 | // Dump a message 113 | System.err.println("ServiceDaemon: stopping"); 114 | 115 | for (int i=0;i