Skip to content

Instantly share code, notes, and snippets.

@zmwangx
Last active July 22, 2018 22:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zmwangx/f70e6bcae5a533fef8d5f74d3b6b9cdc to your computer and use it in GitHub Desktop.
Save zmwangx/f70e6bcae5a533fef8d5f74d3b6b9cdc to your computer and use it in GitHub Desktop.
Trivial program to reload apache without root
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main() {
if (setuid(0) != 0) {
perror("setuid");
exit(1);
};
execl("/usr/sbin/service", "/usr/sbin/service", "apache2", "graceful", NULL);
perror("execl");
exit(1);
}
PREFIX ?= /usr/local
CFLAGS += -Wall -Wextra
BINDIR = $(DESTDIR)$(PREFIX)/bin
.PHONY: all install clean distclean
all: a2graceful
a2graceful: a2graceful.o
$(LINK.c) $^ -o $@
install: a2graceful
install -m 4755 a2graceful $(BINDIR)
clean:
@- $(RM) a2graceful.o a2graceful
distclean: clean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment