stress2: Update test to ensure propper cleanup of fifo files
This commit is contained in:
parent
7ba7bf48d5
commit
9ac518adf0
@ -26,82 +26,63 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <stdio.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <signal.h>
|
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <string.h>
|
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "stress.h"
|
#include "stress.h"
|
||||||
|
|
||||||
static char path[MAXPATHLEN+1];
|
static char path[MAXPATHLEN+1];
|
||||||
#define NB (1 * 1024 * 1024)
|
static int bufsize, freespace;
|
||||||
|
|
||||||
static int bufsize;
|
|
||||||
static int freespace;
|
|
||||||
|
|
||||||
static void
|
|
||||||
handler2(int i __unused)
|
|
||||||
{
|
|
||||||
_exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
reader(void) {
|
reader(void) {
|
||||||
int fd;
|
fd_set set;
|
||||||
int i, n, *buf;
|
struct timeval tv;
|
||||||
|
int *buf, fd, n;
|
||||||
|
|
||||||
setproctitle("reader");
|
setproctitle("reader");
|
||||||
signal(SIGALRM, handler2);
|
if ((fd = open(path, O_RDONLY | O_NONBLOCK)) < 0)
|
||||||
alarm(60);
|
|
||||||
if ((fd = open(path, O_RDWR, 0600)) < 0) {
|
|
||||||
unlink(path);
|
|
||||||
err(1, "open(%s)", path);
|
err(1, "open(%s)", path);
|
||||||
}
|
|
||||||
if ((buf = malloc(bufsize)) == NULL)
|
if ((buf = malloc(bufsize)) == NULL)
|
||||||
err(1, "malloc(%d), %s:%d", bufsize, __FILE__, __LINE__);
|
err(1, "malloc(%d), %s:%d", bufsize, __FILE__, __LINE__);
|
||||||
for (i = 0; i < NB; i+= bufsize) {
|
n = 0;
|
||||||
|
FD_ZERO(&set);
|
||||||
|
FD_SET(fd, &set);
|
||||||
|
tv.tv_sec = 10;
|
||||||
|
tv.tv_usec = 0;
|
||||||
|
if (select(fd + 1, &set, NULL, NULL, &tv) == 1) {
|
||||||
if ((n = read(fd, buf, bufsize)) < 0)
|
if ((n = read(fd, buf, bufsize)) < 0)
|
||||||
err(1, "read(), %s:%d", __FILE__, __LINE__);
|
err(1, "read(), %s:%d", __FILE__, __LINE__);
|
||||||
if (n == 0) break;
|
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
free(buf);
|
free(buf);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
writer(void) {
|
writer(void) {
|
||||||
int i, *buf;
|
int *buf, fd;
|
||||||
int fd;
|
|
||||||
|
|
||||||
signal(SIGALRM, handler2);
|
|
||||||
alarm(60);
|
|
||||||
|
|
||||||
setproctitle("writer");
|
setproctitle("writer");
|
||||||
if ((fd = open(path, O_RDWR, 0600)) < 0) {
|
if ((fd = open(path, O_WRONLY)) < 0) {
|
||||||
unlink(path);
|
unlink(path);
|
||||||
err(1, "open(%s)", path);
|
err(1, "open(%s)", path);
|
||||||
}
|
}
|
||||||
if ((buf = malloc(bufsize)) == NULL)
|
if ((buf = malloc(bufsize)) == NULL)
|
||||||
err(1, "malloc(%d), %s:%d", bufsize, __FILE__, __LINE__);
|
err(1, "malloc(%d), %s:%d", bufsize, __FILE__, __LINE__);
|
||||||
for (i = 0; i < bufsize / (int)sizeof(int); i++)
|
memset(buf, 0, bufsize);
|
||||||
buf[i] = i;
|
|
||||||
|
|
||||||
for (i = 0; i < NB; i+= bufsize) {
|
if (write(fd, buf, bufsize) < 0)
|
||||||
if (write(fd, buf, bufsize) < 0) {
|
err(1, "write(%d), %s:%d", fd, __FILE__, __LINE__);
|
||||||
err(1, "write(%d), %s:%d", fd,
|
|
||||||
__FILE__, __LINE__);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
close(fd);
|
close(fd);
|
||||||
free(buf);
|
free(buf);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -134,6 +115,7 @@ setup(int nb)
|
|||||||
if (!freespace)
|
if (!freespace)
|
||||||
_exit(0);
|
_exit(0);
|
||||||
bufsize = 2 << random_int(2, 12);
|
bufsize = 2 << random_int(2, 12);
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,5 +161,6 @@ test(void)
|
|||||||
err(1, "fork(), %s:%d", __FILE__, __LINE__);
|
err(1, "fork(), %s:%d", __FILE__, __LINE__);
|
||||||
|
|
||||||
unlink(path);
|
unlink(path);
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user