@@ -196,9 +196,9 @@ strerror(int err_no)
196
196
#endif /* HAVE_STERRROR */
197
197
198
198
static void
199
- usage (FILE * ofp , int exitval )
199
+ usage ()
200
200
{
201
- fprintf ( ofp , "\
201
+ printf ( "\
202
202
usage: strace [-CdffhiqrtttTvVwxxy] [-I n] [-e expr]...\n\
203
203
[-a column] [-o file] [-s strsize] [-P path]...\n\
204
204
-p pid... / [-D] [-E var=val]... [-u username] PROG [ARGS]\n\
@@ -267,7 +267,7 @@ Miscellaneous:\n\
267
267
-z -- print only succeeding syscalls\n\
268
268
*/
269
269
, DEFAULT_ACOLUMN , DEFAULT_STRLEN , DEFAULT_SORTBY );
270
- exit (exitval );
270
+ exit (0 );
271
271
}
272
272
273
273
static void ATTRIBUTE_NORETURN
@@ -327,6 +327,17 @@ void error_msg_and_die(const char *fmt, ...)
327
327
die ();
328
328
}
329
329
330
+ void error_msg_and_help (const char * fmt , ...)
331
+ {
332
+ if (fmt != NULL ) {
333
+ va_list p ;
334
+ va_start (p , fmt );
335
+ verror_msg (0 , fmt , p );
336
+ }
337
+ fprintf (stderr , "Try '%s -h' for more information.\n" , progname );
338
+ die ();
339
+ }
340
+
330
341
void perror_msg (const char * fmt , ...)
331
342
{
332
343
va_list p ;
@@ -346,7 +357,7 @@ void perror_msg_and_die(const char *fmt, ...)
346
357
static void
347
358
error_opt_arg (int opt , const char * arg )
348
359
{
349
- error_msg_and_die ( "Invalid -%c argument: '%s'" , opt , arg );
360
+ error_msg_and_help ( "invalid -%c argument: '%s'" , opt , arg );
350
361
}
351
362
352
363
#if USE_SEIZE
@@ -1488,13 +1499,13 @@ init(int argc, char *argv[])
1488
1499
break ;
1489
1500
case 'c' :
1490
1501
if (cflag == CFLAG_BOTH ) {
1491
- error_msg_and_die ("-c and -C are mutually exclusive" );
1502
+ error_msg_and_help ("-c and -C are mutually exclusive" );
1492
1503
}
1493
1504
cflag = CFLAG_ONLY_STATS ;
1494
1505
break ;
1495
1506
case 'C' :
1496
1507
if (cflag == CFLAG_ONLY_STATS ) {
1497
- error_msg_and_die ("-c and -C are mutually exclusive" );
1508
+ error_msg_and_help ("-c and -C are mutually exclusive" );
1498
1509
}
1499
1510
cflag = CFLAG_BOTH ;
1500
1511
break ;
@@ -1511,7 +1522,7 @@ init(int argc, char *argv[])
1511
1522
followfork ++ ;
1512
1523
break ;
1513
1524
case 'h' :
1514
- usage (stdout , 0 );
1525
+ usage ();
1515
1526
break ;
1516
1527
case 'i' :
1517
1528
iflag = 1 ;
@@ -1597,7 +1608,7 @@ init(int argc, char *argv[])
1597
1608
error_opt_arg (c , optarg );
1598
1609
break ;
1599
1610
default :
1600
- usage ( stderr , 1 );
1611
+ error_msg_and_help ( NULL );
1601
1612
break ;
1602
1613
}
1603
1614
}
@@ -1609,22 +1620,23 @@ init(int argc, char *argv[])
1609
1620
acolumn_spaces [acolumn ] = '\0' ;
1610
1621
1611
1622
/* Must have PROG [ARGS], or -p PID. Not both. */
1612
- if (!argv [0 ] == !nprocs )
1613
- usage (stderr , 1 );
1623
+ if (!argv [0 ] == !nprocs ) {
1624
+ error_msg_and_help ("must have PROG [ARGS] or -p PID" );
1625
+ }
1614
1626
1615
1627
if (nprocs != 0 && daemonized_tracer ) {
1616
- error_msg_and_die ("-D and -p are mutually exclusive" );
1628
+ error_msg_and_help ("-D and -p are mutually exclusive" );
1617
1629
}
1618
1630
1619
1631
if (!followfork )
1620
1632
followfork = optF ;
1621
1633
1622
1634
if (followfork >= 2 && cflag ) {
1623
- error_msg_and_die ("(-c or -C) and -ff are mutually exclusive" );
1635
+ error_msg_and_help ("(-c or -C) and -ff are mutually exclusive" );
1624
1636
}
1625
1637
1626
1638
if (count_wallclock && !cflag ) {
1627
- error_msg_and_die ("-w must be given with (-c or -C)" );
1639
+ error_msg_and_help ("-w must be given with (-c or -C)" );
1628
1640
}
1629
1641
1630
1642
if (cflag == CFLAG_ONLY_STATS ) {
@@ -1685,7 +1697,7 @@ init(int argc, char *argv[])
1685
1697
* when using popen, so prohibit it.
1686
1698
*/
1687
1699
if (followfork >= 2 )
1688
- error_msg_and_die ( "Piping the output and -ff are mutually exclusive" );
1700
+ error_msg_and_help ( "piping the output and -ff are mutually exclusive" );
1689
1701
shared_log = strace_popen (outfname + 1 );
1690
1702
}
1691
1703
else if (followfork < 2 )
0 commit comments