--- 2nash.c.orig 2022-03-10 02:42:46.000000000 -0700
+++ 2nash.c 2022-03-31 08:11:01.829106492 -0600
@@ -9,6 +9,7 @@
#include <unistd.h>
#include <stdio.h>
#include <signal.h>
+#include <fcntl.h>
int main(int argc, char *argv[])
{
@@ -28,14 +29,16 @@
if(cpid[l-1] == 0) {
//forked threads
// n= sprintf(buffer, "lrs %s > out%i", argv[l], l);
+ sprintf(buffer, "out%i", l);
+ int fd = creat(buffer, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+ dup2(fd, 1);
if(l==1) {
- int n= sprintf(buffer, "lrsnash %s %s > out%i", argv[1], argv[2], l);
+ execlp("lrsnash", "lrsnash", argv[1], argv[2], NULL);
}
else {
- int n= sprintf(buffer, "lrsnash %s %s > out%i", argv[2], argv[1], l);
+ execlp("lrsnash", "lrsnash", argv[2], argv[1], NULL);
}
- int i=system(buffer);
_exit(0);
}
}
@@ -50,18 +53,18 @@
printf("lrsnash %s %s finished first\n", argv[2], argv[1]);
printf("player numbers will be reversed in output\n");
}
+ sprintf(buffer, "out%i", j);
if(argc == 4) {
printf("output file: %s\n", argv[3]);
- int n = sprintf(buffer, "/bin/mv -f out%i %s", j, argv[3]);
+ rename(buffer, argv[3]);
}
else {
printf("output file: out\n");
- int n = sprintf(buffer, "/bin/mv -f out%i out", j);
+ rename(buffer, "out");
}
- int i = system(buffer);
} else {
- int n = sprintf(buffer, "/bin/rm -f out%i", j);
- int i = system(buffer);
+ sprintf(buffer, "out%i", j);
+ unlink(buffer);
}
}
printf("the other process will be "); /*...will be killed */
--- lrslib.c.orig 2022-03-10 02:42:46.000000000 -0700
+++ lrslib.c 2022-03-31 08:11:06.044105122 -0600
@@ -81,10 +81,10 @@ char *basename(char *path);
/* signals handling */
/*******************************/
#ifndef SIGNALS
-static void checkpoint ();
-static void die_gracefully ();
+static void checkpoint (int signum);
+static void die_gracefully (int signum);
static void setup_signals (void);
-static void timecheck ();
+static void timecheck (int signum);
#endif
/*******************************/
@@ -5673,7 +5673,7 @@ setup_signals ()
}
static void
-timecheck ()
+timecheck (int signum __attribute__((unused)))
{
lrs_dump_state ();
errcheck ("signal", signal (SIGALRM, timecheck));
@@ -5681,14 +5681,14 @@ timecheck ()
}
static void
-checkpoint ()
+checkpoint (int signum __attribute__((unused)))
{
lrs_dump_state ();
errcheck ("signal", signal (SIGUSR1, checkpoint));
}
static void
-die_gracefully ()
+die_gracefully (int signum __attribute__((unused)))
{
lrs_dump_state ();