This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch] to gcc: use xexit/xatexit in fixinc
- To: gcc-patches at gcc dot gnu dot org
- Subject: [patch] to gcc: use xexit/xatexit in fixinc
- From: msokolov at ivan dot Harhan dot ORG (Michael Sokolov)
- Date: Mon, 25 Dec 00 19:45:58 PST
Hi there,
The fixinc code in the current gcc uses atexit right now, which is not
portable. In particular, there is no atexit or any similar mechanism on 4.3BSD
UNIX. I have been told that rather than try to implement atexit for UNIX in
libiberty, we should change fixinc to use libiberty's xexit/xatexit instead.
The patch below does this. It got through stage 1 on vax-dec-bsd. Stage 2
cannot currently be built due to problems in the VAX port.
--
Michael Sokolov
Public Service Agent
International Engineering and Science Task Force
1351 VINE AVE APT 27 Phone: +1-714-738-5409
FULLERTON CA 92833-4291 USA (home office)
E-mail: msokolov@ivan.Harhan.ORG (ARPA TCP/SMTP)
2000-12-25 Michael Sokolov <msokolov@ivan.Harhan.ORG>
* fixinc/fixfixes.c: Use xexit instead of exit or return from main
throughout.
* fixinc/fixincl.c: Likewise.
* fixinc/fixlib.c: Likewise.
* fixinc/fixtests.c: Likewise.
* fixinc/procopen.c: Likewise.
* fixinc/server.c (server_setup): Use xatexit instead of atexit.
Index: fixinc/fixfixes.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/fixinc/fixfixes.c,v
retrieving revision 1.40
diff -p -r1.40 fixfixes.c
*** fixfixes.c 2000/12/13 20:07:45 1.40
--- fixfixes.c 2000/12/26 03:31:18
*************** Here are the rules:
*** 24,30 ****
4. Do not read anything from stdin. It is closed.
5. Write to stderr only in the event of a reportable error
! In such an event, call "exit (EXIT_FAILURE)".
6. You have access to the fixDescList entry for the fix in question.
This may be useful, for example, if there are interesting strings
--- 24,30 ----
4. Do not read anything from stdin. It is closed.
5. Write to stderr only in the event of a reportable error
! In such an event, call "xexit (EXIT_FAILURE)".
6. You have access to the fixDescList entry for the fix in question.
This may be useful, for example, if there are interesting strings
*************** FIX_PROC_HEAD( format_fix )
*** 265,271 ****
if (pz_fmt == (tCC*)NULL)
{
fprintf( stderr, zNeedsArg, p_fixd->fix_name, "replacement format", 0 );
! exit (EXIT_BROKEN);
}
/*
--- 265,271 ----
if (pz_fmt == (tCC*)NULL)
{
fprintf( stderr, zNeedsArg, p_fixd->fix_name, "replacement format", 0 );
! xexit (EXIT_BROKEN);
}
/*
*************** FIX_PROC_HEAD( format_fix )
*** 281,287 ****
if (ct-- <= 0)
{
fprintf( stderr, zNeedsArg, p_fixd->fix_name, "search text", 1 );
! exit (EXIT_BROKEN);
}
if (pTD->type == TT_EGREP)
--- 281,287 ----
if (ct-- <= 0)
{
fprintf( stderr, zNeedsArg, p_fixd->fix_name, "search text", 1 );
! xexit (EXIT_BROKEN);
}
if (pTD->type == TT_EGREP)
*************** FIX_PROC_HEAD( char_macro_use_fix )
*** 341,347 ****
if (str == NULL)
{
fprintf (stderr, zNeedsArg, p_fixd->fix_name, "ioctl type", 0);
! exit (EXIT_BROKEN);
}
len = strlen (str);
--- 341,347 ----
if (str == NULL)
{
fprintf (stderr, zNeedsArg, p_fixd->fix_name, "ioctl type", 0);
! xexit (EXIT_BROKEN);
}
len = strlen (str);
*************** FIX_PROC_HEAD( char_macro_def_fix )
*** 426,432 ****
if (str == NULL)
{
fprintf (stderr, zNeedsArg, p_fixd->fix_name, "ioctl type", 0);
! exit (EXIT_BROKEN);
}
len = strlen (str);
--- 426,432 ----
if (str == NULL)
{
fprintf (stderr, zNeedsArg, p_fixd->fix_name, "ioctl type", 0);
! xexit (EXIT_BROKEN);
}
len = strlen (str);
*************** FIX_PROC_HEAD( gnu_type_fix )
*** 686,692 ****
if (ct-- <= 0)
{
fprintf (stderr, zNeedsArg, p_fixd->fix_name, "search text", 1);
! exit (EXIT_BROKEN);
}
if (pTD->type == TT_EGREP)
--- 686,692 ----
if (ct-- <= 0)
{
fprintf (stderr, zNeedsArg, p_fixd->fix_name, "search text", 1);
! xexit (EXIT_BROKEN);
}
if (pTD->type == TT_EGREP)
*************** apply_fix( p_fixd, filname )
*** 743,749 ****
{
fprintf (stderr, "fixincl error: the `%s' fix is unknown\n",
fixname );
! exit (EXIT_BROKEN);
}
pfe++;
}
--- 743,749 ----
{
fprintf (stderr, "fixincl error: the `%s' fix is unknown\n",
fixname );
! xexit (EXIT_BROKEN);
}
pfe++;
}
*************** main( argc, argv )
*** 772,778 ****
{
usage_failure:
fputs (z_usage, stderr);
! return EXIT_FAILURE;
}
{
--- 772,778 ----
{
usage_failure:
fputs (z_usage, stderr);
! xexit (EXIT_FAILURE);
}
{
*************** main( argc, argv )
*** 791,797 ****
if (freopen (argv[3], "r", stdin) != stdin)
{
fprintf (stderr, z_reopen, errno, strerror( errno ), argv[3], "in");
! return EXIT_FAILURE;
}
pz_tmptmp = (char*)xmalloc( strlen( argv[4] ) + 5 );
--- 791,797 ----
if (freopen (argv[3], "r", stdin) != stdin)
{
fprintf (stderr, z_reopen, errno, strerror( errno ), argv[3], "in");
! xexit (EXIT_FAILURE);
}
pz_tmptmp = (char*)xmalloc( strlen( argv[4] ) + 5 );
*************** main( argc, argv )
*** 810,816 ****
if (freopen (pz_tmptmp, "w", stdout) != stdout)
{
fprintf (stderr, z_reopen, errno, strerror( errno ), pz_tmptmp, "out");
! return EXIT_FAILURE;
}
apply_fix (pFix, argv[1]);
--- 810,816 ----
if (freopen (pz_tmptmp, "w", stdout) != stdout)
{
fprintf (stderr, z_reopen, errno, strerror( errno ), pz_tmptmp, "out");
! xexit (EXIT_FAILURE);
}
apply_fix (pFix, argv[1]);
*************** main( argc, argv )
*** 821,829 ****
{
fprintf (stderr, "error %d (%s) renaming %s to %s\n", errno,
strerror( errno ), pz_tmptmp, argv[4]);
! return EXIT_FAILURE;
}
! return EXIT_SUCCESS;
}
#endif
--- 821,829 ----
{
fprintf (stderr, "error %d (%s) renaming %s to %s\n", errno,
strerror( errno ), pz_tmptmp, argv[4]);
! xexit (EXIT_FAILURE);
}
! xexit (EXIT_SUCCESS);
}
#endif
Index: fixinc/fixincl.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/fixinc/fixincl.c,v
retrieving revision 1.48
diff -p -r1.48 fixincl.c
*** fixincl.c 2000/12/13 22:25:21 1.48
--- fixincl.c 2000/12/26 03:31:20
*************** main (argc, argv)
*** 130,136 ****
if (file_name_buf == (char *) NULL)
{
fputs ("No file names listed for fixing\n", stderr);
! exit (EXIT_FAILURE);
}
for (;;)
--- 130,136 ----
if (file_name_buf == (char *) NULL)
{
fputs ("No file names listed for fixing\n", stderr);
! xexit (EXIT_FAILURE);
}
for (;;)
*************** Altering %5d of them\n";
*** 184,190 ****
# ifdef SEPARATE_FIX_PROC
unlink( pz_temp_file );
# endif
! return EXIT_SUCCESS;
}
--- 184,190 ----
# ifdef SEPARATE_FIX_PROC
unlink( pz_temp_file );
# endif
! xexit (EXIT_SUCCESS);
}
*************** do_version ()
*** 203,211 ****
sprintf (zBuf, zFmt, program_id);
#ifndef SEPARATE_FIX_PROC
puts (zBuf + 5);
! exit (strcmp (run_shell (zBuf), program_id));
#else
! exit (system (zBuf));
#endif
}
--- 203,211 ----
sprintf (zBuf, zFmt, program_id);
#ifndef SEPARATE_FIX_PROC
puts (zBuf + 5);
! xexit (strcmp (run_shell (zBuf), program_id));
#else
! xexit (system (zBuf));
#endif
}
*************** ENV_TABLE
*** 240,258 ****
{
fprintf (stderr, "Error %d (%s) reopening %s as stdin\n",
errno, xstrerror (errno), argv[1] );
! exit (EXIT_FAILURE);
}
break;
default:
fputs ("fixincl ERROR: too many command line arguments\n", stderr);
! exit (EXIT_FAILURE);
}
#define _ENV_(v,m,n,t) { tSCC var[] = n; \
v = getenv (var); if (m && (v == NULL)) { \
fprintf (stderr, var_not_found, var); \
! exit (EXIT_FAILURE); } }
ENV_TABLE
--- 240,258 ----
{
fprintf (stderr, "Error %d (%s) reopening %s as stdin\n",
errno, xstrerror (errno), argv[1] );
! xexit (EXIT_FAILURE);
}
break;
default:
fputs ("fixincl ERROR: too many command line arguments\n", stderr);
! xexit (EXIT_FAILURE);
}
#define _ENV_(v,m,n,t) { tSCC var[] = n; \
v = getenv (var); if (m && (v == NULL)) { \
fprintf (stderr, var_not_found, var); \
! xexit (EXIT_FAILURE); } }
ENV_TABLE
*************** create_file ()
*** 585,591 ****
{
fprintf (stderr, "Error %d (%s) creating %s\n",
errno, xstrerror (errno), fname);
! exit (EXIT_FAILURE);
}
if (NOT_SILENT)
fprintf (stderr, "Fixed: %s\n", pz_curr_file);
--- 585,591 ----
{
fprintf (stderr, "Error %d (%s) creating %s\n",
errno, xstrerror (errno), fname);
! xexit (EXIT_FAILURE);
}
if (NOT_SILENT)
fprintf (stderr, "Fixed: %s\n", pz_curr_file);
*************** internal_fix (read_fd, p_fixd)
*** 817,823 ****
if (pipe( fd ) != 0)
{
fprintf (stderr, "Error %d on pipe(2) call\n", errno );
! exit (EXIT_FAILURE);
}
for (;;)
--- 817,823 ----
if (pipe( fd ) != 0)
{
fprintf (stderr, "Error %d on pipe(2) call\n", errno );
! xexit (EXIT_FAILURE);
}
for (;;)
*************** internal_fix (read_fd, p_fixd)
*** 850,856 ****
{
static int failCt = 0;
if ((errno != EAGAIN) || (++failCt > 10))
! exit (EXIT_FAILURE);
sleep (1);
}
} do_child_task:;
--- 850,856 ----
{
static int failCt = 0;
if ((errno != EAGAIN) || (++failCt > 10))
! xexit (EXIT_FAILURE);
sleep (1);
}
} do_child_task:;
*************** internal_fix (read_fd, p_fixd)
*** 870,876 ****
fcntl (read_fd, F_DUPFD, STDIN_FILENO);
apply_fix (p_fixd, pz_curr_file);
! exit (0);
}
#endif /* !SEPARATE_FIX_PROC */
--- 870,876 ----
fcntl (read_fd, F_DUPFD, STDIN_FILENO);
apply_fix (p_fixd, pz_curr_file);
! xexit (0);
}
#endif /* !SEPARATE_FIX_PROC */
*************** start_fixer (read_fd, p_fixd, pz_fix_fil
*** 1079,1085 ****
p_fixd->fix_name);
if ((errno != EAGAIN) || (++failCt > 10))
! exit (EXIT_FAILURE);
sleep (1);
}
--- 1079,1085 ----
p_fixd->fix_name);
if ((errno != EAGAIN) || (++failCt > 10))
! xexit (EXIT_FAILURE);
sleep (1);
}
*************** process ()
*** 1379,1385 ****
{
fprintf (stderr, "Error %d (%s) opening %s\n", errno,
xstrerror (errno), pz_curr_file);
! exit (EXIT_FAILURE);
}
/* Ensure we do not get duplicate output */
--- 1379,1385 ----
{
fprintf (stderr, "Error %d (%s) opening %s\n", errno,
xstrerror (errno), pz_curr_file);
! xexit (EXIT_FAILURE);
}
/* Ensure we do not get duplicate output */
Index: fixinc/fixlib.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/fixinc/fixlib.c,v
retrieving revision 1.15
diff -p -r1.15 fixlib.c
*** fixlib.c 2000/12/02 19:46:32 1.15
--- fixlib.c 2000/12/26 03:31:20
*************** compile_re( pat, re, match, e1, e2 )
*** 207,213 ****
char rerrbuf[1024];
regerror (err, re, rerrbuf, 1024);
fprintf (stderr, z_bad_comp, e1, e2, pat, rerrbuf);
! exit (EXIT_FAILURE);
}
}
--- 207,213 ----
char rerrbuf[1024];
regerror (err, re, rerrbuf, 1024);
fprintf (stderr, z_bad_comp, e1, e2, pat, rerrbuf);
! xexit (EXIT_FAILURE);
}
}
Index: fixinc/fixtests.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/fixinc/fixtests.c,v
retrieving revision 1.24
diff -p -r1.24 fixtests.c
*** fixtests.c 2000/12/13 20:07:46 1.24
--- fixtests.c 2000/12/26 03:31:21
*************** Here are the rules:
*** 24,30 ****
4. Do not write anything to stdout. It may be closed.
5. Write to stderr only in the event of a reportable error
! In such an event, call "exit(1)".
= = = = = = = = = = = = = = = = = = = = = = = = =
--- 24,30 ----
4. Do not write anything to stdout. It may be closed.
5. Write to stderr only in the event of a reportable error
! In such an event, call "xexit(1)".
= = = = = = = = = = = = = = = = = = = = = = = = =
*************** run_test( tname, fname, text )
*** 145,149 ****
} while (--ct > 0);
fprintf( stderr, "fixincludes error: the `%s' fix test is unknown\n",
tname );
! exit( 3 );
}
--- 145,149 ----
} while (--ct > 0);
fprintf( stderr, "fixincludes error: the `%s' fix test is unknown\n",
tname );
! xexit( 3 );
}
Index: fixinc/procopen.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/fixinc/procopen.c,v
retrieving revision 1.7
diff -p -r1.7 procopen.c
*** procopen.c 2000/12/13 20:07:46 1.7
--- procopen.c 2000/12/26 03:31:21
*************** chain_open (stdin_fd, pp_args, p_child)
*** 170,176 ****
execvp (pz_cmd, (char**)pp_args);
fprintf (stderr, "Error %d: Could not execvp( '%s', ... ): %s\n",
errno, pz_cmd, xstrerror (errno));
! exit (EXIT_PANIC);
}
--- 170,176 ----
execvp (pz_cmd, (char**)pp_args);
fprintf (stderr, "Error %d: Could not execvp( '%s', ... ): %s\n",
errno, pz_cmd, xstrerror (errno));
! xexit (EXIT_PANIC);
}
Index: fixinc/server.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/fixinc/server.c,v
retrieving revision 1.17
diff -p -r1.17 server.c
*** server.c 2000/12/13 20:07:46 1.17
--- server.c 2000/12/26 03:31:22
*************** server_setup ()
*** 205,211 ****
static int atexit_done = 0;
if (atexit_done++ == 0)
! atexit (close_server);
else
fputs ("NOTE: server restarted\n", stderr);
--- 205,211 ----
static int atexit_done = 0;
if (atexit_done++ == 0)
! xatexit (close_server);
else
fputs ("NOTE: server restarted\n", stderr);