#!/bin/sh

. /etc/control.d/functions

new_summary "libzmalloc - secure replacement for malloc() calls"

new_help disabled "Use standard malloc() call in programs linked with libc"
new_help enabled "Use secure replacement for malloc() call in programs linked with libc"

REQUEST="$*"

case "$REQUEST" in
    help|'help '*)
        control_help "${REQUEST#help}"
        ;;
    list)
        control_list
        ;;
    summary)
        control_summary
        ;;
    status|'')
        if zmalloc-ctrl --status --quiet; then
            echo "enabled"
        else
            echo "disabled"
        fi
        ;;
    disabled)
        zmalloc-ctrl --disable --quiet
        ;;
    enabled)
        zmalloc-ctrl --enable --quiet
        ;;
    *)
        printf '%s: %s\n' "${0##*/}" "Invalid mode: $REQUEST" >&2
        exit 1
        ;;
esac

# vim: autoindent tabstop=2 shiftwidth=2 expandtab softtabstop=2 filetype=sh
