Now always print its name first when issuing error messages.

fclose() is now actually called.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@11949 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2005-03-22 02:35:55 +00:00
parent 5680579795
commit 0efd929e4d
+27 -26
View File
@@ -42,7 +42,8 @@ extern void get_syscalls17(vector<Syscall*> &syscalls);
extern void get_syscalls18(vector<Syscall*> &syscalls); extern void get_syscalls18(vector<Syscall*> &syscalls);
extern void get_syscalls19(vector<Syscall*> &syscalls); extern void get_syscalls19(vector<Syscall*> &syscalls);
static const char *kDefaultCommandName = "strace"; extern const char *__progname;
static const char *kCommandName = __progname;
// usage // usage
static const char *kUsage = static const char *kUsage =
@@ -88,13 +89,8 @@ static map<string, Syscall*> sSyscallMap;
void void
print_usage(bool error) print_usage(bool error)
{ {
// get nice program name
const char *programName = (sArgc > 0 ? sArgv[0] : kDefaultCommandName);
if (const char *lastSlash = strrchr(programName, '/'))
programName = lastSlash + 1;
// print usage // print usage
fprintf((error ? stderr : stdout), kUsage, programName); fprintf((error ? stderr : stdout), kUsage, kCommandName);
} }
// print_usage_and_exit // print_usage_and_exit
@@ -212,8 +208,8 @@ set_team_debugging_flags(port_id nubPort, int32 flags)
return; return;
if (error != B_INTERRUPTED) { if (error != B_INTERRUPTED) {
fprintf(stderr, "Failed to set team debug flags: %s\n", fprintf(stderr, "%s: Failed to set team debug flags: %s\n",
strerror(error)); kCommandName, strerror(error));
exit(1); exit(1);
} }
} }
@@ -235,8 +231,8 @@ set_thread_debugging_flags(port_id nubPort, thread_id thread, int32 flags)
return; return;
if (error != B_INTERRUPTED) { if (error != B_INTERRUPTED) {
fprintf(stderr, "Failed to set thread debug flags: %s\n", fprintf(stderr, "%s: Failed to set thread debug flags: %s\n",
strerror(error)); kCommandName, strerror(error));
exit(1); exit(1);
} }
} }
@@ -259,8 +255,8 @@ continue_thread(port_id nubPort, thread_id thread)
return; return;
if (error != B_INTERRUPTED) { if (error != B_INTERRUPTED) {
fprintf(stderr, "Failed to run thread %ld: %s\n", fprintf(stderr, "%s: Failed to run thread %ld: %s\n",
thread, strerror(error)); kCommandName, thread, strerror(error));
exit(1); exit(1);
} }
} }
@@ -460,8 +456,8 @@ main(int argc, const char *const *argv)
outputFile = fopen(filename, "w+"); outputFile = fopen(filename, "w+");
if (outputFile == NULL) { if (outputFile == NULL) {
fprintf(stderr, "Could not open `%s': %s\n", filename, fprintf(stderr, "%s: Could not open `%s': %s\n",
strerror(errno)); kCommandName, filename, strerror(errno));
exit(1); exit(1);
} }
} else { } else {
@@ -495,8 +491,8 @@ main(int argc, const char *const *argv)
// we've been given an executable and need to load it // we've been given an executable and need to load it
thread = load_program(programArgs, programArgCount, traceLoading); thread = load_program(programArgs, programArgCount, traceLoading);
if (thread < 0) { if (thread < 0) {
fprintf(stderr, "Failed to start `%s': %s\n", programArgs[0], fprintf(stderr, "%s: Failed to start `%s': %s\n", kCommandName,
strerror(thread)); programArgs[0], strerror(thread));
exit(1); exit(1);
} }
} }
@@ -506,8 +502,8 @@ main(int argc, const char *const *argv)
thread_info threadInfo; thread_info threadInfo;
status_t error = get_thread_info(thread, &threadInfo); status_t error = get_thread_info(thread, &threadInfo);
if (error != B_OK) { if (error != B_OK) {
fprintf(stderr, "Failed to get info for thread %ld: %s\n", thread, fprintf(stderr, "%s: Failed to get info for thread %ld: %s\n",
strerror(error)); kCommandName, thread, strerror(error));
exit(1); exit(1);
} }
team = threadInfo.team; team = threadInfo.team;
@@ -516,16 +512,16 @@ main(int argc, const char *const *argv)
// create a debugger port // create a debugger port
port_id debuggerPort = create_port(10, "debugger port"); port_id debuggerPort = create_port(10, "debugger port");
if (debuggerPort < 0) { if (debuggerPort < 0) {
fprintf(stderr, "Failed to create debugger port: %s\n", fprintf(stderr, "%s: Failed to create debugger port: %s\n",
strerror(debuggerPort)); kCommandName, strerror(debuggerPort));
exit(1); exit(1);
} }
// install ourselves as the team debugger // install ourselves as the team debugger
port_id nubPort = install_team_debugger(team, debuggerPort); port_id nubPort = install_team_debugger(team, debuggerPort);
if (nubPort < 0) { if (nubPort < 0) {
fprintf(stderr, "Failed to install team debugger: %s\n", fprintf(stderr, "%s: Failed to install team debugger: %s\n",
strerror(nubPort)); kCommandName, strerror(nubPort));
exit(1); exit(1);
} }
@@ -551,6 +547,7 @@ main(int argc, const char *const *argv)
// debug loop // debug loop
while (true) { while (true) {
bool quitLoop = false;
int32 code; int32 code;
debug_debugger_message_data message; debug_debugger_message_data message;
ssize_t messageSize = read_port(debuggerPort, &code, &message, ssize_t messageSize = read_port(debuggerPort, &code, &message,
@@ -560,8 +557,8 @@ main(int argc, const char *const *argv)
if (messageSize == B_INTERRUPTED) if (messageSize == B_INTERRUPTED)
continue; continue;
fprintf(stderr, "Reading from debugger port failed: %s\n", fprintf(stderr, "%s: Reading from debugger port failed: %s\n",
strerror(messageSize)); kCommandName, strerror(messageSize));
exit(1); exit(1);
} }
@@ -591,9 +588,13 @@ main(int argc, const char *const *argv)
case B_DEBUGGER_MESSAGE_TEAM_DELETED: case B_DEBUGGER_MESSAGE_TEAM_DELETED:
// the debugged team is gone // the debugged team is gone
exit(0); quitLoop = true;
break;
} }
if (quitLoop)
break;
// tell the thread to continue (only when there is a thread and the // tell the thread to continue (only when there is a thread and the
// message was synchronous) // message was synchronous)
if (message.origin.thread >= 0 && message.origin.nub_port >= 0) if (message.origin.thread >= 0 && message.origin.nub_port >= 0)