From 3d217c6ed1dc213a6a81764ec863da167f3879de Mon Sep 17 00:00:00 2001 From: Jon Trulson Date: Tue, 24 Mar 2020 17:51:24 -0600 Subject: [PATCH] merge: fix to use per-proc filenames rather than hardcoding them The localized/utils/merge utility used hardcoded temporary filenames to do its thing. This prevented any Makefiles that called merge from enabling parallel builds in order avoid the file collisions that would result. Now we: - use filenames that embed the PID in them, making them unique per-process - place them in /tmp, rather than the current directory As a result, we can now re-enable parallel builds for localized app-defaults, config, and types. --- cde/programs/localized/util/merge.c | 49 +++++++++++++++++------------ 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/cde/programs/localized/util/merge.c b/cde/programs/localized/util/merge.c index 576fb5fb..7ae9aa1d 100644 --- a/cde/programs/localized/util/merge.c +++ b/cde/programs/localized/util/merge.c @@ -96,6 +96,9 @@ #include #include #include +#include +#include + #include nl_catd catfile[2] = {NULL, NULL}; /* [0] for primary, [1] for default */ @@ -108,21 +111,27 @@ int bs = 0; int crt_line[3] = {0, 0, 1}; /* current line [0]: Primary message file */ /* [1]: Default message file */ /* [2]: Template file */ - -void process_message (); -int get_char (); -void cat_open (); -int find_message (); -int find_msg_in_file (); -void get_message (); -void fatal (); -void get_option (); - +char pFilename[PATH_MAX]; +char dFilename[PATH_MAX]; +pid_t procPID = 0; + +/* merge.c */ +void process_message(void); +int get_char(void); +void cat_open(void); +int find_message(int msg); +int find_msg_in_file(int msg, int file); +void fatal(char *m, int line, int file); +void get_option(int *argc, char *argv[]); void main (int argc, char *argv []) { int c; + procPID = getpid(); + snprintf(pFilename, PATH_MAX, "/tmp/dt_pfile.%d.cat", procPID); + snprintf(dFilename, PATH_MAX, "/tmp/dt_dfile.%d.cat", procPID); + get_option(&argc, argv); if(pfile == NULL) @@ -171,8 +180,8 @@ void main (int argc, char *argv []) if ( catfile[1] ) catclose(catfile[1]); - unlink("./.dt_pfile.cat"); - unlink("./.dt_dfile.cat"); + unlink(pFilename); + unlink(dFilename); exit (0); } @@ -234,25 +243,25 @@ int get_char (void) */ void cat_open (void) { - char line[255]; + char line[PATH_MAX]; - unlink("./.dt_pfile.cat"); - unlink("./.dt_dfile.cat"); + unlink(pFilename); + unlink(dFilename); if(pfile != NULL) { - sprintf(line,"gencat ./.dt_pfile.cat %s",pfile); + snprintf(line, PATH_MAX, "gencat %s %s", pFilename, pfile); if ( system(line) != 0 ) { fatal("primary .tmsg file would not gencat\n",0,9); } } - catfile[0] = catopen("./.dt_pfile.cat",0); + catfile[0] = catopen(pFilename, 0); if(dfile != NULL) { - sprintf(line,"gencat ./.dt_dfile.cat %s",dfile); + sprintf(line,"gencat %s %s", dFilename, dfile); if ( system(line) != 0 ) { fatal("default .tmsg file would not gencat\n",0,9); @@ -260,10 +269,10 @@ void cat_open (void) } - catfile[1] = catopen("./.dt_dfile.cat",0); + catfile[1] = catopen(dFilename, 0); /* if all fails */ - if(catfile[0] == NULL && catfile[1] == NULL) + if (catfile[0] == NULL && catfile[1] == NULL) fatal("Can't open message files.\n", 0, 9); } -- 2.25.1