summaryrefslogtreecommitdiffstats
path: root/runtime/staprun/stapio.c
diff options
context:
space:
mode:
authordsmith <dsmith>2007-08-14 15:23:59 +0000
committerdsmith <dsmith>2007-08-14 15:23:59 +0000
commit5eddf13b73a01f3b334e5be80fc3cc1b312d1fea (patch)
tree1c74859db1203887498df3975b851f91228ed8f4 /runtime/staprun/stapio.c
parent615d0e8b9a906c6d1db1e82866a2530194ebed36 (diff)
downloadsystemtap-steved-5eddf13b73a01f3b334e5be80fc3cc1b312d1fea.tar.gz
systemtap-steved-5eddf13b73a01f3b334e5be80fc3cc1b312d1fea.tar.xz
systemtap-steved-5eddf13b73a01f3b334e5be80fc3cc1b312d1fea.zip
2007-08-14 David Smith <dsmith@redhat.com>
Merge from setuid-branch. Changes also by Martin Hunt <hunt@redhat.com>. * staprun.c (init_staprun): Drop CAP_SYS_ADMIN when we're done with it. (main): Calls parse_modpath instead of path_parse_modname. Just call parse_modpath with argv[optind]. Let it allocate and set modpath and modname. If no modulename was given, display usage and exit. Drop CAP_SYS_NICE when we're done with it. Set atexit(exit_cleanup) so cleanup always gets called and modules get removed. Call handle_symbols. (run_stapio): Set argv[0] to stapio so that it executes as itself instead of staprun. (cleanup): Only do cleanups once and only try to remove module when appropriate. (exit_cleanup): New. Calls cleanup(). (mountfs): Sets uid to root before making directory and then restores uid. (setup_ctl_channel): Uses DEBUGFS define and improved error message. (setup_relayfs): Ditto. (setup_oldrelayfs): Uses DEBUGFS and RELAYFS defines. (run_stp_check): Replaced by mountfs(). (mountfs): New function. Replaces an external script with C code. (init_staprun): Calls mountfs() instead of run_stp_check(). * staprun.h: Renamed path_parse_modname to parse_modpath. Added MODULE_NAME_LEN define. Added [_][p]err macros. Removed VERSION_CMD. * mainloop.c (cleanup_and_exit): Make sure initialized is 2 before exiting with code 2. (stp_main_loop): Set initialized to 2 when STP_TRANSPORT is received. Call cleanup_and_exit() with proper status. (start_cmd): exit 1 instead of -1. (system_cmd): Ditto. (init_staprun): Renamed init_stapio. (cleanup_and_exit): Set exit status. * cap.c: New file. * common.c: New file. * stapio.c: New file. * staprun_funcs.c: New file. * Makefile: Removed. * symbols.c (get_sections): Move the filter code up so that uninteresting section names are filtered out before attempting to open them. (do_kernel_symbols): Better detect overfow conditions and realloc new space. (do_module): After sending all modules, send a null message to indicate we are finished. * ctl.c (init_ctl_channel): When attempting to attach, if the control channel doesn't exist, print a better error message. * relay_old.c (init_oldrelayfs): Errors out if open_relayfs_files() couldn't open any files. PR 4795 * mainloop.c (send_request): Fixed buffer overflow check. * staprun.h: Added buffer overflow checking versions of strcpy/sprintf/snprintf. * common.c (path_parse_modname): Checks for overflows on strcpy/sprintf/snprintf. (read_buffer_info): Ditto. * ctl.c (init_ctl_channel): Ditto. * relay.c (init_relayfs): Ditto. * relay_old.c (open_relayfs_files): Ditto. (init_oldrelayfs): Ditto. * staprun_funcs.c (insert_module): Ditto. (check_path): Ditto. * symbols.c (get_sections): Ditto.
Diffstat (limited to 'runtime/staprun/stapio.c')
-rw-r--r--runtime/staprun/stapio.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/runtime/staprun/stapio.c b/runtime/staprun/stapio.c
new file mode 100644
index 00000000..696167af
--- /dev/null
+++ b/runtime/staprun/stapio.c
@@ -0,0 +1,69 @@
+/* -*- linux-c -*-
+ *
+ * stapio.c - SystemTap module io handler.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Copyright (C) 2005-2007 Red Hat, Inc.
+ *
+ */
+
+#include "staprun.h"
+#include <pwd.h>
+char *__name__ = "stapio";
+
+int main(int argc, char **argv)
+{
+ setup_signals();
+
+ parse_args(argc, argv);
+
+ if (buffer_size)
+ dbug(1, "Using a buffer of %u bytes.\n", buffer_size);
+
+ if (optind < argc) {
+ parse_modpath(argv[optind++]);
+ dbug(2, "modpath=\"%s\", modname=\"%s\"\n", modpath, modname);
+ }
+
+ if (optind < argc) {
+ if (attach_mod) {
+ err("ERROR: Cannot have module options with attach (-A).\n");
+ usage(argv[0]);
+ } else {
+ unsigned start_idx = 3; /* reserve three slots in modoptions[] */
+ while (optind < argc && start_idx+1 < MAXMODOPTIONS)
+ modoptions[start_idx++] = argv[optind++];
+ modoptions[start_idx] = NULL;
+ }
+ }
+
+ if (modpath == NULL || *modpath == '\0') {
+ err("ERROR: Need a module name or path to load.\n");
+ usage(argv[0]);
+ }
+
+ if (init_stapio())
+ exit(1);
+
+ initialized = 1;
+
+ if (stp_main_loop()) {
+ err("ERROR: Couldn't enter main loop. Exiting.\n");
+ exit(1);
+ }
+
+ return 0;
+}