#include <sys/types.h>
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <string.h>
#include <wait.h>
#include <limits.h>
#include "machdep.h"
#include "sgs.h"
#include "rtc.h"
#include "conv.h"
#include "_crle.h"
#include "msg.h"
int
dump(Crle_desc * crle)
{
const char *orgapp = (const char *)crle->c_app;
int fildes[2], pid;
if (orgapp == 0)
orgapp = conv_lddstub(M_CLASS);
if (pipe(fildes) == -1) {
int err = errno;
(void) fprintf(stderr, MSG_INTL(MSG_SYS_PIPE),
crle->c_name, strerror(err));
return (1);
}
if ((pid = fork()) == -1) {
int err = errno;
(void) fprintf(stderr, MSG_INTL(MSG_SYS_FORK),
crle->c_name, strerror(err));
return (1);
}
if (pid) {
int error = 0, status;
FILE *fd;
char buffer[PATH_MAX];
(void) close(fildes[1]);
if ((fd = fdopen(fildes[0], MSG_ORIG(MSG_STR_READ))) != NULL) {
char *str;
Rtc_head *rtc = (Rtc_head *)crle->c_tempheadaddr;
while (fgets(buffer, PATH_MAX, fd) != NULL) {
if (strncmp(MSG_ORIG(MSG_AUD_PRF), buffer,
MSG_AUD_PRF_SIZE))
continue;
str = strrchr(buffer, '\n');
*str = '\0';
str = buffer + MSG_AUD_PRF_SIZE;
if (strncmp(MSG_ORIG(MSG_AUD_RESBGN),
str, MSG_AUD_RESBGN_SIZE) == 0) {
rtc->ch_resbgn =
strtoull(str + MSG_AUD_RESBGN_SIZE,
(char **)NULL, 0);
} else if (strncmp(MSG_ORIG(MSG_AUD_RESEND),
str, MSG_AUD_RESEND_SIZE) == 0) {
rtc->ch_resend =
strtoull(str + MSG_AUD_RESEND_SIZE,
(char **)NULL, 0);
} else {
continue;
}
}
(void) fclose(fd);
} else
error = errno;
while (wait(&status) != pid)
;
if (status) {
if (WIFSIGNALED(status)) {
(void) fprintf(stderr,
MSG_INTL(MSG_SYS_EXEC), crle->c_name,
orgapp, (WSIGMASK & status),
((status & WCOREFLG) ?
MSG_INTL(MSG_SYS_CORE) :
MSG_ORIG(MSG_STR_EMPTY)));
}
return (status);
}
return (error);
} else {
char efds[MSG_ENV_AUD_FD_SIZE + 10];
char eflg[MSG_ENV_AUD_FLAGS_SIZE + 10];
char ecnf[PATH_MAX];
(void) close(fildes[0]);
(void) snprintf(efds, (MSG_ENV_AUD_FD_SIZE + 10),
MSG_ORIG(MSG_ENV_AUD_FD), fildes[1]);
(void) snprintf(eflg, (MSG_ENV_AUD_FLAGS_SIZE + 10),
MSG_ORIG(MSG_ENV_AUD_FLAGS), crle->c_dlflags);
(void) snprintf(ecnf, PATH_MAX, MSG_ORIG(MSG_ENV_LD_CONFIG),
crle->c_tempname);
if ((putenv(efds) != 0) || (putenv(eflg) != 0) ||
(putenv(ecnf) != 0) || (putenv(crle->c_audit) != 0) ||
(putenv((char *)MSG_ORIG(MSG_ENV_LD_FLAGS)) != 0)) {
int err = errno;
(void) fprintf(stderr, MSG_INTL(MSG_SYS_PUTENV),
crle->c_name, strerror(err));
return (1);
}
if (execlp(orgapp, orgapp, 0) == -1) {
int err = errno;
(void) fprintf(stderr, MSG_INTL(MSG_SYS_EXECLP),
crle->c_name, orgapp, strerror(err));
_exit(err);
}
}
return (0);
}