1 /* Determine the Java version supported by javaexec.
2 Copyright (C) 2006-2024 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2006.
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
21 #include "javaversion.h"
27 #if ENABLE_RELOCATABLE
28 # include "relocatable.h"
30 # define relocate(pathname) (pathname)
31 # define relocate2(pathname,allocatedp) (*(allocatedp) = NULL, (pathname))
35 #include "spawn-pipe.h"
36 #include "wait-process.h"
40 #define _(str) gettext (str)
43 #include "configmake.h"
53 execute_and_read_line (const char *progname
,
54 const char *prog_path
, const char * const *prog_argv
,
57 struct locals
*l
= (struct locals
*) private_data
;
65 /* Open a pipe to the JVM. */
66 child
= create_pipe_in (progname
, prog_path
, prog_argv
, NULL
, NULL
,
67 DEV_NULL
, false, true, false, fd
);
72 /* Retrieve its result. */
73 fp
= fdopen (fd
[0], "r");
75 error (EXIT_FAILURE
, errno
, _("fdopen() failed"));
77 line
= NULL
; linesize
= 0;
78 linelen
= getline (&line
, &linesize
, fp
);
79 if (linelen
== (size_t)(-1))
81 error (0, 0, _("%s subprocess I/O error"), progname
);
83 wait_subprocess (child
, progname
, true, false, true, false, NULL
);
89 if (linelen
> 0 && line
[linelen
- 1] == '\n')
90 line
[linelen
- 1] = '\0';
94 /* Remove zombie process from process list, and retrieve exit status. */
96 wait_subprocess (child
, progname
, true, false, true, false, NULL
);
108 javaexec_version (void)
110 const char *class_name
= "javaversion";
111 char *malloc_pkgdatadir
;
112 const char *pkgdatadir
= relocate2 (PKGDATADIR
, &malloc_pkgdatadir
);
114 struct locals locals
;
118 execute_java_class (class_name
, &pkgdatadir
, 1, true, NULL
, args
,
119 false, false, execute_and_read_line
, &locals
);
121 free (malloc_pkgdatadir
);