From a5e8d632f443c6a882dcabc669236dc4798b1fd7 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Wed, 25 Mar 2009 17:25:06 -0700 Subject: Add the kernel tree's git revision to the hash To better support kernel developers who work out of a single source tree, this adds the git HEAD revision to our caching hash. --- util.cxx | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'util.cxx') diff --git a/util.cxx b/util.cxx index 7d191cd2..68cc27f7 100644 --- a/util.cxx +++ b/util.cxx @@ -248,4 +248,31 @@ const string cmdstr_quoted(const string& cmd) return quoted_cmd; } + +string +git_revision(const string& path) +{ + string revision = "(not-a-git-repository)"; + string git_dir = path + "/.git/"; + + struct stat st; + if (stat(git_dir.c_str(), &st) == 0) + { + string command = "git --git-dir=\"" + git_dir + + "\" rev-parse HEAD 2>/dev/null"; + + char buf[50]; + FILE *fp = popen(command.c_str(), "r"); + if (fp != NULL) + { + char *bufp = fgets(buf, sizeof(buf), fp); + int rc = pclose(fp); + if (bufp != NULL && rc == 0) + revision = buf; + } + } + + return revision; +} + /* vim: set sw=2 ts=8 cino=>4,n-2,{2,^-2,t0,(0,u0,w1,M1 : */ -- cgit From 4cc40e829870dd6a1d9714706d38f5fd4b2ec982 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Wed, 1 Apr 2009 14:49:12 -0700 Subject: PR10016: Purge stap of all pgrp and system() usage We hereby no longer try to manipulate process groups in any way. We don't set a private process group, and we never kill() our entire group either. Instead of using system(), we now have a stap_system() which saves the child PID, so when we get a terminating signal we can pass it along to the child. Signals sent through the TTY have always worked, since the TTY sends it to the entire pgrp. However, if we're running as part of a wrapper script or GUI, which may not have a separate process group for stap, we still would like to allow "kill -TERM $STAPPID" to terminate stap nicely. There's still a short window of failure in the time that staprun is active, because we can't kill a setuid process from a user process. Once staprun drops privileges and execs to stapio though, everything should work fine. --- util.cxx | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) (limited to 'util.cxx') diff --git a/util.cxx b/util.cxx index 68cc27f7..5fa7a5f2 100644 --- a/util.cxx +++ b/util.cxx @@ -20,13 +20,15 @@ #include extern "C" { -#include -#include +#include #include -#include +#include #include #include -#include +#include +#include +#include +#include } using namespace std; @@ -275,4 +277,35 @@ git_revision(const string& path) return revision; } + +static pid_t spawned_pid = 0; + +// Runs a command with a saved PID, so we can kill it from the signal handler +int +stap_system(const char *command) +{ + const char * argv[] = { "sh", "-c", command, NULL }; + int ret, status; + + spawned_pid = 0; + ret = posix_spawn(&spawned_pid, "/bin/sh", NULL, NULL, + const_cast(argv), environ); + if (ret == 0) + { + if (waitpid(spawned_pid, &status, 0) == spawned_pid) + ret = WIFEXITED(status) ? WEXITSTATUS(status) : 128 + WTERMSIG(status); + else + ret = errno; + } + spawned_pid = 0; + return ret; +} + +// Send a signal to our spawned command +int +kill_stap_spawn(int sig) +{ + return spawned_pid ? kill(spawned_pid, sig) : 0; +} + /* vim: set sw=2 ts=8 cino=>4,n-2,{2,^-2,t0,(0,u0,w1,M1 : */ -- cgit From 2035bcd40b17832439df0a1eb28403b99a71b74f Mon Sep 17 00:00:00 2001 From: Dave Brolley Date: Mon, 4 May 2009 16:05:22 -0400 Subject: Module signing and verification using a separate file for the module signature. --- util.cxx | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'util.cxx') diff --git a/util.cxx b/util.cxx index 5fa7a5f2..5c05a1dd 100644 --- a/util.cxx +++ b/util.cxx @@ -1,5 +1,5 @@ // Copyright (C) Andrew Tridgell 2002 (original file) -// Copyright (C) 2006 Red Hat Inc. (systemtap changes) +// Copyright (C) 2006, 2009 Red Hat Inc. (systemtap changes) // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License as @@ -135,6 +135,25 @@ create_dir(const char *dir) return 0; } +// Remove a file or directory +int +remove_file_or_dir (const char *name) +{ + int rc; + struct stat st; + + if ((rc = stat(name, &st)) != 0) + { + if (errno == ENOENT) + return 0; + return 1; + } + + if (remove (name) != 0) + return 1; + cerr << "remove returned 0" << endl; + return 0; +} void tokenize(const string& str, vector& tokens, -- cgit