Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2018, 2023 Cedric Chabanois and others.
* Copyright (c) 2018, 2025 Cedric Chabanois and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -11,6 +11,7 @@
* Contributors:
* Cedric Chabanois (cchabanois@gmail.com) - Launching command line exceeds the process creation command limit on *nix - https://bugs.eclipse.org/bugs/show_bug.cgi?id=385738
* IBM Corporation - Launching command line exceeds the process creation command limit on Windows - https://bugs.eclipse.org/bugs/show_bug.cgi?id=327193
* Tue Ton - support for FreeBSD
*******************************************************************************/
package org.eclipse.jdt.internal.launching;

Expand Down Expand Up @@ -54,9 +55,11 @@
*/
public class ClasspathShortener implements IProcessTempFileCreator {
private static final String CLASSPATH_ENV_VAR_PREFIX = "CLASSPATH="; //$NON-NLS-1$
public static final int ARG_MAX_FREEBSD = 2097152;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ARG_MAX_FREEBSD & ARG_MAX_LINUX have identical values, can you reuse ARG_MAX_LINUX for freeBSD ?

public static final int ARG_MAX_LINUX = 2097152;
public static final int ARG_MAX_WINDOWS = 32767;
public static final int ARG_MAX_MACOS = 262144;
public static final int MAX_ARG_STRLEN_FREEBSD = 131072;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possible to reuse MAX_ARG_STRLEN_LINUX ?

public static final int MAX_ARG_STRLEN_LINUX = 131072;
private final String os;
private final String javaVersion;
Expand Down Expand Up @@ -261,6 +264,9 @@ protected int getMaxCommandLineLength() {
// POSIX suggests to subtract 2048 additionally so that the process may safely modify its environment.
// see https://www.in-ulm.de/~mascheck/various/argmax/
switch (os) {
case Platform.OS_FREEBSD:
// ARG_MAX will be 1/4 of the stack size. 2097152 by default
return ARG_MAX_FREEBSD - getEnvironmentLength() - 2048;
case Platform.OS_LINUX:
// ARG_MAX will be 1/4 of the stack size. 2097152 by default
return ARG_MAX_LINUX - getEnvironmentLength() - 2048;
Expand All @@ -277,6 +283,11 @@ protected int getMaxCommandLineLength() {
}

protected int getMaxArgLength() {
if (os.equals(Platform.OS_FREEBSD)) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks similar to if (os.equals(Platform.OS_LINUX)) block, as both are same, I would recommend something like
if (os.equals(Platform.OS_LINUX) || os.equals(Platform.OS_FREEBSD)) { .... }

// On FreeBSD, MAX_ARG_STRLEN is the maximum length of a command line argument (or environment variable).
// Its value cannot be changed without recompiling the kernel.
return MAX_ARG_STRLEN_FREEBSD - 2048;
}
if (os.equals(Platform.OS_LINUX)) {
// On Linux, MAX_ARG_STRLEN (kernel >= 2.6.23) is the maximum length of a command line argument (or environment variable). Its value
// cannot be changed without recompiling the kernel.
Expand Down
Loading