Added sync call for Linux only

This commit is contained in:
Michiel Broek 2004-01-18 13:05:56 +00:00
parent 879753a6a1
commit 6e1108f1b3
2 changed files with 27 additions and 2 deletions

View File

@ -2,6 +2,11 @@ $Id$
v0.39.7 14-Jan-2004 v0.39.7 14-Jan-2004
libcommon.a:
In execute and execsh on Linux systems sync() is called before
and after running the external program to make sure diskbuffers
are committed.
v0.39.6 11-Jan-2004 - 14-Jan-2004 v0.39.6 11-Jan-2004 - 14-Jan-2004

View File

@ -4,7 +4,7 @@
* Purpose ...............: Execute subprogram * Purpose ...............: Execute subprogram
* *
***************************************************************************** *****************************************************************************
* Copyright (C) 1997-2003 * Copyright (C) 1997-2004
* *
* Michiel Broek FIDO: 2:280/2802 * Michiel Broek FIDO: 2:280/2802
* Beekmansbos 10 * Beekmansbos 10
@ -42,7 +42,7 @@ int e_pid = 0; /* Execute child pid */
int execute(char *cmd, char *file, char *pkt, char *in, char *out, char *err) int execute(char *cmd, char *file, char *pkt, char *in, char *out, char *err)
{ {
char buf[512]; char buf[PATH_MAX];
char *vector[16]; char *vector[16];
int i, pid, status = 0, rc = 0; int i, pid, status = 0, rc = 0;
@ -52,6 +52,13 @@ int execute(char *cmd, char *file, char *pkt, char *in, char *out, char *err)
sprintf(buf, "%s %s %s", cmd, file, pkt); sprintf(buf, "%s %s %s", cmd, file, pkt);
Syslog('+', "Execute: %s",buf); Syslog('+', "Execute: %s",buf);
#ifdef __linux__
/*
* Linux has async diskwrites by default.
*/
sync();
#endif
memset(vector, 0, sizeof(vector)); memset(vector, 0, sizeof(vector));
i = 0; i = 0;
vector[i++] = strtok(buf," \t\n"); vector[i++] = strtok(buf," \t\n");
@ -103,6 +110,11 @@ int execute(char *cmd, char *file, char *pkt, char *in, char *out, char *err)
} while (((rc > 0) && (rc != pid)) || ((rc == -1) && (errno == EINTR))); } while (((rc > 0) && (rc != pid)) || ((rc == -1) && (errno == EINTR)));
setpriority(PRIO_PROCESS, 0, 0); setpriority(PRIO_PROCESS, 0, 0);
#ifdef __linux__
sync();
#endif
switch (rc) { switch (rc) {
case -1: case -1:
WriteError("$Wait returned %d, status %d,%d", rc,status>>8,status&0xff); WriteError("$Wait returned %d, status %d,%d", rc,status>>8,status&0xff);
@ -141,6 +153,10 @@ int execsh(char *cmd, char *in, char *out, char *err)
fflush(stdout); fflush(stdout);
fflush(stderr); fflush(stderr);
#ifdef __linux__
sync();
#endif
if ((pid = fork()) == 0) { if ((pid = fork()) == 0) {
if (in) { if (in) {
close(0); close(0);
@ -185,6 +201,10 @@ int execsh(char *cmd, char *in, char *out, char *err)
return MBERR_EXEC_FAILED; return MBERR_EXEC_FAILED;
} }
#ifdef __linux__
sync();
#endif
return status; return status;
} }