]> sourceware.org Git - systemtap.git/commitdiff
2007-03-18 Martin Hunt <hunt@redhat.com>
authorhunt <hunt>
Sun, 18 Mar 2007 18:19:26 +0000 (18:19 +0000)
committerhunt <hunt>
Sun, 18 Mar 2007 18:19:26 +0000 (18:19 +0000)
* staprun.h (VERSION_CMD): Command to use for version check.
Changes to support runtime decision on new or old transport.
* mainloop.c (init_staprun): Check the kernel version at runtime
instead of at compile time.
(cleanup_and_exit): Call the correct relayfs close function.
(stp_main_loop): Call the correct relayfs init function.
* relay.c: Remove ifdef wrapper. File is always compiled and used
if the kernel version is appropriate.
* relay_old.c: Ditto.

runtime/staprun/ChangeLog
runtime/staprun/ChangeLog~ [deleted file]
runtime/staprun/mainloop.c
runtime/staprun/relay.c
runtime/staprun/relay_old.c
runtime/staprun/staprun.h
runtime/staprun/stp_merge.c~ [deleted file]

index 9f8a6595e40b591c083e797fbc31f838f967dedc..c82ddb07a86faf410e6e122f9df070e32c8a6bc3 100644 (file)
@@ -1,3 +1,15 @@
+2007-03-18  Martin Hunt  <hunt@redhat.com>
+
+       * staprun.h (VERSION_CMD): Command to use for version check.
+       Changes to support runtime decision on new or old transport.
+       * mainloop.c (init_staprun): Check the kernel version at runtime
+       instead of at compile time.
+       (cleanup_and_exit): Call the correct relayfs close function.
+       (stp_main_loop): Call the correct relayfs init function.
+       * relay.c: Remove ifdef wrapper. File is always compiled and used
+       if the kernel version is appropriate.
+       * relay_old.c: Ditto.
+
 2007-03-14  Martin Hunt  <hunt@redhat.com>
 
        * staprun.c: Renamed from stpd.c. Removed quiet and print_only 
diff --git a/runtime/staprun/ChangeLog~ b/runtime/staprun/ChangeLog~
deleted file mode 100644 (file)
index 858f4e6..0000000
+++ /dev/null
@@ -1,396 +0,0 @@
-2006-12-11  Martin Hunt  <hunt@redhat.com>
-
-       * symbols.c (get_sections): Set buffer sizes to large enough
-       sizes to hold all possible values, but also include checks in case
-       we are wrong.
-
-2006-11-15  Martin Hunt  <hunt@redhat.com>
-
-       * symbols.c (do_kernel_symbols): Add sizeof(long) to sym_base
-       to preserve 64-bit alignment.
-
-2006-11-09  Martin Hunt  <hunt@redhat.com>
-
-       * librelay.c: Change all references to transport messages
-       to use the new names with "_stp" prefix.
-       (stp_main_loop): For STP_SYMBOLS, check pointer size and 
-       endianess to confirm staprun is compatible with the kernel.
-
-       * librelay.h: Move a bunch of common includes here.
-       * stpd.c: Cleanup includes.
-       * symbols.c: Ditto.
-       
-2006-11-02  Martin Hunt  <hunt@redhat.com>
-
-       * symbols.c: New file. Sends symbol and module information to
-       the systemtap module.
-       
-       * librelay.c (stp_main_loop): Add STP_MODULE and STP_SYMBOLS
-       message handling.
-
-       * librelay.h: Add some new function prototypes.
-
-       * Makefile (CFLAGS): Set to be the same as for building modules.
-       Added symbols.c to sources.
-
-2006-10-10  Tom Zanussi  <zanussi@us.ibm.com>
-       
-       * librelay.c (merge_output): Add check for min when writing
-       output, otherwise last write happens twice.
-
-2006-09-26  David Smith  <dsmith@redhat.com>
-
-       * Makefile: Changed 'stpd' references to 'staprun'.
-       * librelay.c: Ditto.
-       * stpd.c: Ditto.
-       
-2006-09-25  Tom Zanussi  <zanussi@us.ibm.com>
-       
-       * librelay.c (kill_percpu_threads): Remove printf.
-       (wait_for_percpu_threads): New.
-       (process_subbufs): Remove processing, processing_mutex, exit
-       thread if exiting flag set.
-       (read_last_buffers): Removed.
-       (cleanup_and_exit): Remove call to read_last_buffers, wait for
-       threads to read flushed buffers instead.
-       (stp_main_loop): Remove mutex init.     
-
-2006-09-22  Tom Zanussi  <zanussi@us.ibm.com>
-       
-       * librelay.c (init_relayfs): Cleanup if stp_check fails.
-
-2006-09-19  Tom Zanussi  <zanussi@us.ibm.com>
-       
-       * librelay.c (init_relayfs): Add debugfs path to relay files and
-       add new systemtap directory to path.
-       (init_stp): rmmod module on failure.
-       (merge_output): Remove debugging printfs left in code.
-       (close_relay_files): Clear relay_file descriptor after close.
-       (cleanup_and_exit): Allow cleanup and exit even if there was an
-       error opening relay files.
-       (stp_main_loop): Call cleanup_and_exit() if init_relayfs() fails.
-
-2006-09-18  Martin Hunt  <hunt@redhat.com>
-
-       * stpd.c (usage): Remove "-m" option.
-       (main): Print warning if "-m" is used.
-       * librelay.c (merge_output): Rewrite to handle
-       new format that support binary.
-       (stp_main_loop): Read merge option from the
-       transport info message.
-
-2006-09-13  Martin Hunt  <hunt@redhat.com>
-
-       * librelay.c (init_relayfs): Exec stp_check and find
-       relay_filebase.
-
-       * librelay.h (stp_main_loop): Fix declaration of init_stp().
-
-       * stpd.c (usage): Remove "-r" option.
-       (main): Don't find stpd_filebase and don't send it to init_stp().
-       
-
-2006-08-02  Tom Zanussi  <zanussi@us.ibm.com>
-
-       * stpd.c (main): Use modname rather than driver_pid in
-       stpd_filebase.
-
-2006-07-20  Martin Hunt  <hunt@redhat.com>
-
-       * librelay.c (stp_main_loop): If module doesn't start, kill any
-       target command.
-
-2006-06-23  Tom Zanussi  <zanussi@us.ibm.com>
-
-       * librelay.c (cleanup_and_exit): Close relay files even if
-       not merging.
-
-2006-06-13  Martin Hunt  <hunt@redhat.com>
-
-       * librelay.c (start_cmd): Rewrite using sigwait() to eliminate
-       a race.
-
-2006-05-18  Martin Hunt  <hunt@redhat.com>
-
-       * librelay.c (stp_main_loop): Set output to always be line
-       buffered.
-
-2006-04-08  Martin Hunt  <hunt@redhat.com>
-
-       * librelay.c (stp_main_loop): Write with fwrite() instead 
-       of fputs() so we can write binary data.
-
-2006-04-05  Martin Hunt  <hunt@redhat.com>
-       * librelay.c (merge_output): Remove ANSI codes and write
-       warning to stderr.
-
-2006-04-05  Martin Hunt  <hunt@redhat.com>     
-       * librelay.c (merge_output): Set the output filename if necessary.
-       (merge_output): 
-
-       * stpd.c (main): Don't reset output_filename just because 
-       relayfs is possible. Move that code to librelay.c.
-
-2006-04-04  Roland McGrath  <roland@redhat.com>
-
-       * stpd.c (main): Cast f_type when comparing; type differs by machine.
-
-2006-04-04  Tom Zanussi  <zanussi@us.ibm.com>
-
-       * stpd.c (main): Check that /mnt/relay is actually relayfs.
-
-2006-03-15  Tom Zanussi  <zanussi@us.ibm.com>
-
-       * stpd.c (main): Add runtime check for relayfs vs relay-on-proc.
-
-2006-03-06  Martin Hunt  <hunt@redhat.com>
-
-       * librelay.c (start_cmd): Set proper uid/gid before execing
-       command.
-       (system_cmd): New function.
-       (cleanup_and_exit): Wait for any child processes to complete.
-       (stp_main_loop): Recognize STP_SYSTEM message.
-
-       * stpd.c (main): Add support for "-u username".
-
-2006-02-25  Martin Hunt  <hunt@redhat.com>
-
-       * librelay.c (init_stp): Better error handling and cleanup.
-
-2006-02-23  Frank Ch. Eigler  <fche@elastic.org>
-
-       PR 1304
-       * stpd.c (mdooptions): New array.
-       (main): Populate it with leftover arguments.
-       * librelay.c (init_stp): Pass it to execve().
-
-2005-12-08  Frank Ch. Eigler  <fche@elastic.org>
-
-       PR 1937
-       * stpd.c (main): Support new "-d" option.
-       (usage): Document it.
-       * librelay.c (driver_poll): New function to react to death of
-       driver process.
-       (stp_main_loop): Call it if "-d PID" given.  Treat SIGHUP like others.
-
-2005-10-19  Tom Zanussi  <zanussi@us.ibm.com>
-
-       * librelay.c: Move output_file var to stpd.c.
-       (stp_main_loop): If the output_file option was specified,
-       and streaming mode is being used, send output to the file
-       instead of stdout.  If !streaming, send output to the file
-       instead of probe.out.
-       * stpd.c (usage): Add comment for -o option.
-       (main): Add -o option.
-
-2005-10-19  Tom Zanussi  <zanussi@us.ibm.com>
-
-       * librelay.c (merge_output): Switch to binary TIMESTAMP.
-       * stp_dump.c (main): Switch to binary TIMESTAMP.
-       * stp_merge.c (main): Switch to binary TIMESTAMP.
-
-2005-10-14  Tom Zanussi  <zanussi@us.ibm.com>
-
-       PR 1476
-       * librelay.c: Add flag for buffer processing.
-       (reader_thread): Disable/enable cancel state around buffer
-       processing, and update flag to show we're busy processing.
-       (cleanup_and_exit): Wait for any threads busy processing.
-       (stp_main_loop): Initialize processing mutex.
-
-2005-09-06  Martin Hunt  <hunt@redhat.com>
-
-       * librelay.c: Remove all USE_PROCFS ifdefs.
-       (sig_usr): Signal handler for SIGUSR1.
-       (start_cmd): New function to handle "-c" option, forks()
-       off a new process then waits for SIGUSR1 to exec it.
-       (init_stp): Call start_cmd().
-       (stp_main_loop): Set a signal handler for SIGCHLD.
-
-       * stpd.c (main): Add "-t" and "-c" options.
-       (usage): Update with new options.
-
-2005-08-29  Martin Hunt  <hunt@redhat.com>
-
-       * stpd.c main): Add enable_relayfs flag.
-       Turn it off with "-r".
-
-2005-08-24  Martin Hunt  <hunt@redhat.com>
-
-       * librelay.c (sigproc): Removed the "Exiting..."
-       message for now.
-
-2005-08-24  Martin Hunt  <hunt@redhat.com>
-
-       * librelay.c (sigproc): Reestablish signal handler so
-       impatient people don't hit ^C twice and terminate the
-       program before it saves the data and removes the module.
-       Also print a message to stderr that it is exiting.
-       (stp_main_loop): Write OOB data (warnings, errors, etc)
-       to stderr instead of stdout.
-       * librelay.h: Write debug info to stderr.
-       * Makefile: add librelay.h to dependencies.
-
-2005-08-23  Martin Hunt  <hunt@redhat.com>
-
-       * librelay.c (merge_output): Don't add an extra \n.
-
-2005-08-23  Martin Hunt  <hunt@redhat.com>
-
-       * librelay.c (read_last_buffers): New function. Directly grab the
-       last buffers.
-       (info_pending): Deleted.
-       (request_last_buffers): Deleted.
-
-2005-08-22  Martin Hunt  <hunt@redhat.com>
-
-       * Makefile (debug): Add debug target.
-       * librelay.h (dbug): Define.
-       * librelay.c: Enable some dbug lines.
-
-2005-08-19  Martin Hunt  <hunt@redhat.com>
-
-       * librelay.c (reader_thread): Check the return value for write().
-
-2005-08-19  Frank Ch. Eigler  <fche@elastic.org>
-
-       * librelay.c (modpath): New global.  Use it for insmod only.
-       * stpd.c (main): Set both modpath and modname, to support
-       modules specified by full path name.
-
-2005-08-19  Martin Hunt  <hunt@redhat.com>
-
-       * stpd.c (main): Simplify buffer size code.
-       * librelay.c: Major changes to support procfs instead of netlink.
-
-2005-08-03  Tom Zanussi  <trz@us.ibm.com>
-
-       * librelay.c: Track subbuf info requests/replies
-       so we know unequivocally when it's ok to do final
-       processing.
-       (reader_thread): Remove buffer-full warning.
-
-2005-08-03  Martin Hunt  <hunt@redhat.com>
-       * librelay.c (init_stp): Change variable name to eliminate shadow warning.
-
-2005-08-03  Martin Hunt  <hunt@redhat.com>
-       * librelay.c (open_control_channel): Set the receive buffer
-       to 512K, or the max allowed.
-
-       * stpd.c: Remove "-n" subbug option and change "-b" option
-       so you can specify buffering in different ways. Add a verbose option.
-       Exec the "stp_check" script.
-
-2005-08-01  Frank Ch. Eigler  <fche@redhat.com>
-
-       * librelay.c: Correct fwrite api usage.
-       * all: Correct copyright holder name.
-
-2005-08-01  Martin Hunt  <hunt@redhat.com>
-
-       * librelay.h: Get structs and enums from
-       ../transport/transport_msgs.h  to eliminate duplication.
-
-       * librelay.c (send_request): Retry if send fails.
-       (open_relayfs_files): Use fopen() instead of open() for the
-       percpu tmpfiles.
-       (request_last_buffers): Just send cpu number for STP_BUF_INFO request.
-       (reader_thread): Ditto.
-       (process_subbufs): Use fwrite_unlocked() instead of write().
-       (sigchld): Removed.
-       (init_stp): Go back to using system() instead of fork and exec
-       to load module. When done, send a TRANSPORT_INFO request.
-       (cleanup_and_exit): Change parameter to simple flag to
-       indicate if the module needs removing.
-       (sigproc): Remove complicated logic and just send STP_EXIT.
-       (stp_main_loop): When receiving STP_TRANSPORT_INFO, set
-       the local params and reply with a STP_START.  When
-       receiving STP_START, there was an error, so cleanup and exit.
-
-       * stpd.c (main): Added new options to set number of
-       buffers and their size.
-
-2005-07-29  Roland McGrath  <roland@redhat.com>
-
-       * librelay.c (process_subbufs): Use unsigned for I.
-       (sigproc): Add  __attribute__((unused)) on parameter.
-       (sigchld): Likewise.  Avoid shadowing global variable name.
-       (stp_main_loop): Add a cast.
-
-2005-07-18  Martin Hunt  <hunt@redhat.com>
-
-       * stp_merge.c (main): Fix dropped count calculation.
-
-2005-07-14  Tom Zanussi  <zanussi@us.ibm.com>
-
-       * librelay.c (reader_thread): Add missing pthread_mutex_lock
-
-2005-07-14  Frank Ch. Eigler  <fche@redhat.com>
-
-       * stpd.c (main): Pass !quiet mode to init_stp().
-       * librelay.c (init_relayfs): Be quiet if !print_totals.
-
-2005-07-13  Martin Hunt  <hunt@redhat.com>
-
-       * stpd.c (usage): Fix usage string.
-
-       * librelay.c (init_stp): Change last arg to NULL, not 0.
-
-2005-07-08  Martin Hunt  <hunt@redhat.com>
-
-       * librelay.c (sigchld): Signal handler to detect
-       completion of module loading.
-       (init_stp): Use fork/exec instead of system() so
-       we can get async signal of module load success/failure.
-       (cleanup_and_exit): New function.
-       (sigproc): If module is not loaded, don't send message to it.
-       (stp_main_loop): Call cleanup_and_exit() when STP_EXIT
-       is received. Don't send a request for the transport
-       mode. The module will send notification to the daemon
-       when it is ready.
-
-       * stpd.c (main): Don't print message until module
-       is loaded.
-
-2005-07-01  Martin Hunt  <hunt@redhat.com>
-
-       * librelay.c: Removed the color coding of cpu output.
-
-2005-06-28  Martin Hunt  <hunt@redhat.com>
-
-       * librelay.c (merge_output): Use unlocked stdio
-       to improve speed.
-
-       * stp_merge.c: New file.
-
-       * Makefile: Add stp_merge.
-
-2005-06-27  Martin Hunt  <hunt@redhat.com>
-
-       * stpd.c (main): Add new command line arg, "-m"
-       to disable the per-cpu merging.
-
-       * librelay.c (merge_output): Replacement for sort_output().
-       Efficiently merges per-cpu streams.
-
-
-2005-06-20  Tom Zanussi  <zanussi@us.ibm.com>
-
-       * librelay.c: Large refactoring, important changes are
-       added transport_mode command, for relayfs transport
-       display results only when probe completes and/or write
-       output file, merge, sort and delete the per-cpu files
-       in postprocessing, refactor so that relayfs files aren't
-       created until transport command received, removed sigalrm,
-       read the final subbuffers on exit
-
-       * stpd.c: Remove all command-line args except for -p
-       and -q as well as all code related to buffer sizes.
-
-       * librelay.h: Add transport mode command and struct.
-
-2005-05-16  Martin Hunt  <hunt@redhat.com>
-
-       * librelay.c (sigproc): If STP_EXIT send fails, keep retrying
-       every 10ms.
-       (init_stp): Don't set n_subbufs and subbuf_size params.
index 7ef2efd099d00851ff03f6a09a33c951ee75dc22..b18976fcc2b74ce611318a1d3df073ae8c950c7d 100644 (file)
@@ -15,6 +15,7 @@
 /* globals */
 int control_channel = 0;
 int ncpus;
+int use_old_transport = 0;
 
 /**
  *     send_request - send request to kernel over control channel
@@ -155,6 +156,12 @@ int init_staprun(void)
                 return 1;
         }
 
+       
+       if (system(VERSION_CMD)) {
+               dbug("Using OLD TRANSPORT\n");
+               use_old_transport = 1;
+       }
+
        /* insert module */
        sprintf(buf, "_stp_pid=%d", (int)getpid());
        sprintf(bufcmd, "_stp_bufsize=%d", buffer_size);
@@ -221,7 +228,10 @@ void cleanup_and_exit (int closed)
                fprintf(stderr,"\nWaititing for processes to exit\n");
        while(wait(NULL) > 0) ;
 
-       close_relayfs();
+       if (use_old_transport)
+               close_oldrelayfs();
+       else
+               close_relayfs();
 
        dbug("closing control channel\n");
        close_ctl_channel();
@@ -281,10 +291,12 @@ int stp_main_loop(void)
        signal(SIGTERM, sigproc);
        signal(SIGHUP, sigproc);
        signal(SIGCHLD, sigproc);
+       signal(SIGQUIT, sigproc);
 
+/*
         if (driver_pid)
                driver_poll(0);
-
+*/
        dbug("in main loop\n");
 
        while (1) { /* handle messages from control channel */
@@ -336,12 +348,15 @@ int stp_main_loop(void)
                case STP_TRANSPORT:
                {
                        struct _stp_msg_start ts;
-                       if (init_relayfs((struct _stp_msg_trans *)data) < 0)
-                               cleanup_and_exit(0);
-                       else {
-                               ts.target = target_pid;
-                               send_request(STP_START, &ts, sizeof(ts));
+                       if (use_old_transport) {
+                               if (init_oldrelayfs((struct _stp_msg_trans *)data) < 0)
+                                       cleanup_and_exit(0);
+                       } else {
+                               if (init_relayfs((struct _stp_msg_trans *)data) < 0)
+                                       cleanup_and_exit(0);
                        }
+                       ts.target = target_pid;
+                       send_request(STP_START, &ts, sizeof(ts));
                        break;
                }
                case STP_MODULE:
index 98f064b6be403faa9a407e43c7579e41131b05cf..6d505a22d125d9d394ee79feb8ba7eb55bed82dc 100644 (file)
@@ -12,8 +12,6 @@
 
 #include "staprun.h"
 
-#ifndef STP_OLD_TRANSPORT
-
 int out_fd[NR_CPUS];
 static pthread_t reader[NR_CPUS];
 static int relay_fd[NR_CPUS];
@@ -186,4 +184,3 @@ void close_relayfs(void)
        dbug("closed files\n");
 }
 
-#endif /* !STP_OLD_TRANSPORT */
index e4ab5fe620beecb7f0c73a74a10a3cbd5a07a157..049d193a275f2fa12e658b729260fe608e854718 100644 (file)
@@ -12,9 +12,7 @@
  */
 
 #include "staprun.h"
-#ifdef STP_OLD_TRANSPORT
 
-int out_fd[NR_CPUS];
 /* temporary per-cpu output written here for relayfs, filebase0...N */
 static char *percpu_tmpfilebase = "stpd_cpu";
 static int relay_fd[NR_CPUS];
@@ -53,7 +51,7 @@ static void close_relayfs_files(int cpu)
 /**
  *     close_all_relayfs_files - close and munmap buffers and output files
  */
-void close_relayfs(void)
+void close_oldrelayfs(void)
 {
        int i;
 
@@ -212,7 +210,7 @@ static void *reader_thread(void *data)
  *
  *     Returns 0 if successful, negative otherwise
  */
-int init_relayfs(struct _stp_msg_trans *t)
+int init_oldrelayfs(struct _stp_msg_trans *t)
 {
        int i, j;
        struct statfs st;
@@ -274,4 +272,3 @@ err:
        return -1;
 }
 
-#endif /* STP_OLD_TRANSPORT */
index d86648025ebf399b0796032adaff675bef0f7f14..7a3fd00cfa906d8383929f697caa28bb204fb786 100644 (file)
 #include <sys/statfs.h>
 #include <linux/version.h>
 
-#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,15)
+#ifdef DEBUG
+#define dbug(args...) {fprintf(stderr,"%s:%d ",__FUNCTION__, __LINE__); fprintf(stderr,args); }
+#else
+#define dbug(args...) ;
+#endif /* DEBUG */
+
+/* we define this so we are compatible with old transport, but we don't have to use it. */
 #define STP_OLD_TRANSPORT
-#endif
 #include "../transport/transport_msgs.h"
 
+/* command to check system's kernel version */
+/* KERNEL_VERSION(2.6.15) = 132623 */
+#define VERSION_CMD "uname -r | awk \'{split($1,a,\".\"); split(a[3],b,\"-\"); exit (a[1]*65536+a[2]*256+b[1] <= 132623)}\'"
+extern int use_old_transport;
 
 #define RELAYFS_MAGIC                  0xF0B4A981
 #define DEBUGFS_MAGIC                  0x64626720
 
-#ifdef DEBUG
-#define dbug(args...) {fprintf(stderr,"%s:%d ",__FUNCTION__, __LINE__); fprintf(stderr,args); }
-#else
-#define dbug(args...) ;
-#endif /* DEBUG */
-
 /*
  * function prototypes
  */
@@ -59,9 +62,11 @@ void cleanup_and_exit (int);
 int do_module(void *);
 void do_kernel_symbols(void);
 int init_ctl_channel(void);
+void close_ctl_channel(void);
 int init_relayfs(struct _stp_msg_trans *);
 void close_relayfs(void);
-void close_ctl_channel(void);
+int init_oldrelayfs(struct _stp_msg_trans *);
+void close_oldrelayfs(void);
 
 /*
  * variables 
@@ -87,5 +92,5 @@ extern gid_t cmd_gid;
 /* maximum number of CPUs we can handle */
 #define NR_CPUS 256
 
-/* output fd's (percpu) */
+/* relay*.c uses these */
 extern int out_fd[NR_CPUS];
diff --git a/runtime/staprun/stp_merge.c~ b/runtime/staprun/stp_merge.c~
deleted file mode 100644 (file)
index b67b417..0000000
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * stp_merge.c - stp merge program
- *
- * 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) Red Hat Inc, 2005
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <errno.h>
-
-static void usage (char *prog)
-{
-       fprintf(stderr, "%s [-o output_filename] input_files ...\n", prog);
-       exit(1);
-}
-
-#define TIMESTAMP_SIZE (sizeof(int))
-#define NR_CPUS 256
-
-int main (int argc, char *argv[])
-{
-       char *outfile_name = NULL;
-       char buf[8192];
-       int c, i, j, dropped=0;
-       long count=0, min, num[NR_CPUS];
-       FILE *ofp, *fp[NR_CPUS];
-       int ncpus, len;
-
-       while ((c = getopt (argc, argv, "o:")) != EOF)  {
-               switch (c) {
-               case 'o':
-                       outfile_name = optarg;
-                       break;
-               default:
-                       usage(argv[0]);
-               }
-       }
-       
-       if (optind == argc)
-               usage (argv[0]);
-
-       i = 0;
-       while (optind < argc) {
-               fp[i] = fopen(argv[optind++], "r");
-               if (!fp[i]) {
-                       fprintf(stderr, "error opening file %s.\n", argv[optind - 1]);
-                       return -1;
-               }
-               if (fread (buf, TIMESTAMP_SIZE, 1, fp[i]))
-                       num[i] = *((int *)buf);
-               else
-                       num[i] = 0;
-               i++;
-       }
-       ncpus = i;
-
-       if (!outfile_name)
-               ofp = stdout;
-       else {
-               ofp = fopen(outfile_name, "w"); 
-               if (!ofp) {
-                       fprintf(stderr, "ERROR: couldn't open output file %s: errcode = %s\n", 
-                               outfile_name, strerror(errno));
-                       return -1;
-               }
-       }
-       
-       do {
-               min = num[0];
-               j = 0;
-               for (i = 1; i < ncpus; i++) {
-                       if (min == 0 || (num[i] && num[i] < min)) {
-                               min = num[i];
-                               j = i;
-                       }
-               }
-
-               if (fread(&len, sizeof(int), 1, fp[j])) {
-                 fread(buf, len, 1, fp[j]);
-                 fwrite(buf, len, 1, ofp);
-               }
-
-               if (min && ++count != min) {
-                       fprintf(stderr, "got %ld. expected %ld\n", min, count);
-                       dropped += min - count ;
-                       count = min;
-               }
-
-               if (fread (buf, TIMESTAMP_SIZE, 1, fp[j]))
-                       num[j] = *((int *)buf);
-               else
-                       num[j] = 0;
-       } while (min);
-
-       fputs ("\n", ofp);
-
-       for (i = 0; i < ncpus; i++)
-               fclose (fp[i]);
-       fclose (ofp);
-       printf ("sequence had %d drops\n", dropped);
-       return 0;
-}
This page took 0.044638 seconds and 5 git commands to generate.