return;
} else if (pid == 0) {
(void) umask(022);
- fd = open("/dev/null", O_RDWR);
- (void) dup2(fd, STDIN_FILENO);
- (void) dup2(fd, STDOUT_FILENO);
- (void) dup2(fd, STDERR_FILENO);
+ if ((fd = open("/dev/null", O_RDWR)) != -1) {
+ (void) dup2(fd, STDIN_FILENO);
+ (void) dup2(fd, STDOUT_FILENO);
+ (void) dup2(fd, STDERR_FILENO);
+ }
(void) dup2(zfd, ZEVENT_FILENO);
zed_file_close_from(ZEVENT_FILENO + 1);
execle(path, prog, NULL, env);
int rdret;
int j = 0;
+ if (fd < 0) {
+ (void) printf("%s: open <%s> again failed:"
+ " errno = %d\n", argv[0], dirpath, errno);
+ exit(-1);
+ }
+
while (j < op_num) {
(void) sleep(1);
rdret = read(fd, buf, 16);
int chownret;
int k = 0;
+ if (fd < 0) {
+ (void) printf("%s: open(<%s>, O_RDONLY) again failed:"
+ " errno (decimal)=%d\n", argv[0], dirpath, errno);
+ exit(-1);
+ }
+
while (k < op_num) {
(void) sleep(1);
chownret = fchown(fd, 0, 0);
int ret;
while (TRUE) {
- (void) close (*fd);
+ if (*fd != -1)
+ (void) close (*fd);
+
*fd = open(filebase, O_APPEND | O_RDWR | O_CREAT, 0644);
- if (*fd < 0)
- perror("refreshing file");
+ if (*fd == -1) {
+ perror("fail to open test file, refreshing it");
+ continue;
+ }
+
ret = write(*fd, "test\n", 5);
if (ret != 5)
perror("writing file");