Skip to content
Open
Show file tree
Hide file tree
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
3 changes: 1 addition & 2 deletions Makefile.global
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,11 @@ endef
# Library objects required in multiple places:
LIBSBASE = $(addprefix $(TOPDIR)/lib/,lib.error lib.misc)
LIBHEADERS = $(addsuffix .h,$(LIBSBASE))
LIBSOURCES = $(addsuffix .c,$(LIBSBASE))
LIBOBJECTS = $(addsuffix $(OBJEXT),$(LIBSBASE))
CFLAGS += -I$(TOPDIR)/lib -I$(TOPDIR)/etc
CXXFLAGS += -I$(TOPDIR)/lib -I$(TOPDIR)/etc

$(LIBOBJECTS): %$(OBJEXT): %.c %.h
$(LIBOBJECTS):
Copy link
Member

Choose a reason for hiding this comment

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

Did you test that these changes work and trigger a rebuild if you change either the source or the header? I'm assuming you're relying on implicit make rules?

$(MAKE) -C $(TOPDIR)/lib $(notdir $@)

# Default recursive targets; these should always at least call the
Expand Down
12 changes: 6 additions & 6 deletions judge/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ judgehost: $(TARGETS) $(SUBST_FILES)
$(SUBST_FILES): %: %.in $(TOPDIR)/paths.mk
$(substconfigvars)

evict: evict.cc $(LIBHEADERS) $(LIBSOURCES)
$(CXX) $(CXXFLAGS) -o $@ $< $(LIBSOURCES)
evict: evict.cc $(LIBOBJECTS)
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $< $(LIBOBJECTS)

runguard: runguard.cc $(LIBHEADERS) $(LIBSOURCES) $(TOPDIR)/etc/runguard-config.h
$(CXX) $(CXXFLAGS) -o $@ $< $(LIBSOURCES) $(LIBCGROUP)
runguard: runguard.cc $(LIBOBJECTS) $(TOPDIR)/etc/runguard-config.h
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $< $(LIBOBJECTS) $(LIBCGROUP)

runpipe: runpipe.cc $(LIBHEADERS) $(LIBSOURCES)
$(CXX) $(CXXFLAGS) -static -o $@ $< $(LIBSOURCES)
runpipe: runpipe.cc $(LIBOBJECTS)
$(CXX) $(CXXFLAGS) $(LDFLAGS) -static -o $@ $< $(LIBOBJECTS)

install-judgehost:
$(INSTALL_PROG) -t $(DESTDIR)$(judgehost_libjudgedir) \
Expand Down
3 changes: 2 additions & 1 deletion judge/evict.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
#include <cstring>
#include <cstdlib>

#include "lib.misc.h"

extern "C" {
#include "lib.error.h"
#include "lib.misc.h"
}

#define PROGRAM "evict"
Expand Down
13 changes: 2 additions & 11 deletions judge/runguard.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

#include "config.h"

#include "lib.misc.h"

/* Some system/site specific config: VALID_USERS, CHROOT_PREFIX */
#include "runguard-config.h"

Expand Down Expand Up @@ -346,17 +348,6 @@ void write_meta(const char *key, const char *format, ...)
va_end(ap);
}

void version(const char *prog, const char *vers)
{
printf("\
%s -- part of DOMjudge version %s\n\
Written by the DOMjudge developers\n\n\
DOMjudge comes with ABSOLUTELY NO WARRANTY. This is free software, and you\n\
are welcome to redistribute it under certain conditions. See the GNU\n\
General Public Licence for details.\n", prog, vers);
exit(0);
}

void usage()
{
printf("\
Expand Down
22 changes: 9 additions & 13 deletions judge/runpipe.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
#include "lib.misc.h"

#include <algorithm>
#include <array>
#include <chrono>
#include <csignal>
#include <cstring>
Expand Down Expand Up @@ -232,22 +233,17 @@ struct process_t {

// Fork and exec the child process, redirecting its standard I/O.
void spawn() {
fd_t stdio[3] = {stdin_fd, stdout_fd, FDREDIR_NONE};

char pid_buf[12];
vector<const char *> argv;
for (size_t i = 0; i < args.size(); i++) {
argv.push_back(args[i].c_str());
if (i == 1 && cmd == "sudo" &&
args[i].find("/runguard") != string::npos) {
std::array<int, 3> stdio = {stdin_fd, stdout_fd, FDREDIR_NONE};

auto exec_args = args;
if (cmd == "sudo" && exec_args.size() > 1 && exec_args[1].find("/runguard") != string::npos) {
// This is a hack, and can be improved significantly after implementing
// https://docs.google.com/document/d/1WZRwdvJUamsczYC7CpP3ZIBU8xG6wNqYqrNJf7osxYs/edit#heading=h.i7kgdnmw8qd7
argv.push_back("-U");
sprintf(pid_buf, "%d", getpid());
argv.push_back(pid_buf);
}
exec_args.push_back("-U");
exec_args.push_back(std::to_string(getpid()));
}
pid = execute(cmd.c_str(), argv.data(), argv.size(), stdio, 0);

pid = execute(cmd, exec_args, stdio, false);
if (pid < 0) {
error(errno, "failed to execute command #%ld", index);
}
Expand Down
3 changes: 2 additions & 1 deletion lib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ OBJECTS = $(addsuffix $(OBJEXT),lib.error lib.misc)

build: $(OBJECTS)

$(OBJECTS): %$(OBJEXT): %.c %.h
lib.error$(OBJEXT): lib.error.c lib.error.h
lib.misc$(OBJEXT): lib.misc.cc lib.misc.h

clean-l:
rm -f $(OBJECTS)
Expand Down
262 changes: 0 additions & 262 deletions lib/lib.misc.c

This file was deleted.

Loading
Loading