Skip to content
Open
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
39 changes: 38 additions & 1 deletion config_arch
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,45 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.

# Function to check directory writability and noexec flag
check_dir() {
local dir=$1
local mount_point

# Check if directory exists and is writable
if [[ -d "$dir" && -w "$dir" ]]; then
# Find the mount point for the directory
mount_point=$(df --output=target "$dir" | tail -1)

# Check if the mount point has the noexec flag
if ! mount | grep " on $mount_point type " | grep -q 'noexec'; then
# Return success if the directory is suitable
return 0
fi
fi

# Return failure
return 1
}

# Initialize working_path as an empty string
working_path=""

# Check /tmp, /dev/shm, and current directory in order
if check_dir "/tmp"; then
working_path="/tmp"
elif check_dir "/dev/shm"; then
working_path="/dev/shm"
elif check_dir "$(pwd)"; then
working_path="$(pwd)"
fi

if [ -z "$working_path" ]; then
exit 1
fi

topdir="$(cd "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" && pwd)"
dir=$(mktemp -d)
dir=$(mktemp -d -p $working_path)
src=$dir/arch.c
exe=$dir/arch
cat <<EOF >$src
Expand Down