#10 Process specific backup log files
A process will open outbuf/inbuf.pid.log and move it to the outbuf/inbuf.log upon close, allowing for multiple processes to be open at once
This commit is contained in:
parent
40adb336fb
commit
1989c36886
5 changed files with 96 additions and 21 deletions
|
|
@ -414,10 +414,14 @@ read_state()
|
||||||
{
|
{
|
||||||
struct stat st;
|
struct stat st;
|
||||||
char *buf;
|
char *buf;
|
||||||
char *cwd = getcwd(NULL, 0);
|
char *cwd;
|
||||||
char *home = getenv("HOME");
|
char *home = getenv("HOME");
|
||||||
FILE *fd;
|
FILE *fd;
|
||||||
|
|
||||||
|
if (!home)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
cwd = getcwd(NULL, 0);
|
||||||
chdir(home);
|
chdir(home);
|
||||||
|
|
||||||
fd = fopen(".config/bytenuts/inbuf.log", "r");
|
fd = fopen(".config/bytenuts/inbuf.log", "r");
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,6 @@ int
|
||||||
cheerios_start(bytenuts_t *bytenuts)
|
cheerios_start(bytenuts_t *bytenuts)
|
||||||
{
|
{
|
||||||
char *home = getenv("HOME");
|
char *home = getenv("HOME");
|
||||||
char *cwd;
|
|
||||||
|
|
||||||
memset(&cheerios, 0, sizeof(cheerios_t));
|
memset(&cheerios, 0, sizeof(cheerios_t));
|
||||||
|
|
||||||
|
|
@ -43,11 +42,25 @@ cheerios_start(bytenuts_t *bytenuts)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cwd = getcwd(NULL, 0);
|
if (home) {
|
||||||
chdir(home);
|
pid_t pid;
|
||||||
cheerios.backup = fopen(".config/bytenuts/outbuf.log", "w");
|
int name_len;
|
||||||
chdir(cwd);
|
|
||||||
free(cwd);
|
/* ensure that a process has a unique log */
|
||||||
|
pid = getpid();
|
||||||
|
name_len = snprintf(
|
||||||
|
NULL, 0,
|
||||||
|
"%s/.config/bytenuts/outbuf.%d.log",
|
||||||
|
home, pid
|
||||||
|
);
|
||||||
|
cheerios.backup_filename = calloc(1, name_len + 1);
|
||||||
|
snprintf(
|
||||||
|
cheerios.backup_filename, name_len + 1,
|
||||||
|
"%s/.config/bytenuts/outbuf.%d.log",
|
||||||
|
home, pid
|
||||||
|
);
|
||||||
|
cheerios.backup = fopen(cheerios.backup_filename, "w");
|
||||||
|
}
|
||||||
|
|
||||||
pthread_cond_init(&cheerios.cond, NULL);
|
pthread_cond_init(&cheerios.cond, NULL);
|
||||||
pthread_mutex_init(&cheerios.lock, NULL);
|
pthread_mutex_init(&cheerios.lock, NULL);
|
||||||
|
|
@ -138,7 +151,6 @@ cheerios_stop()
|
||||||
{
|
{
|
||||||
cheerios.running = 0;
|
cheerios.running = 0;
|
||||||
pthread_join(cheerios.thr, NULL);
|
pthread_join(cheerios.thr, NULL);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -338,8 +350,33 @@ cheerios_thread(void *arg)
|
||||||
|
|
||||||
if (cheerios.log)
|
if (cheerios.log)
|
||||||
fclose(cheerios.log);
|
fclose(cheerios.log);
|
||||||
if (cheerios.backup)
|
|
||||||
|
if (cheerios.backup) {
|
||||||
|
char *out_filename;
|
||||||
|
int out_filename_len;
|
||||||
|
char *home = getenv("HOME");
|
||||||
|
|
||||||
|
/* do not chdir as other threads can still be running */
|
||||||
|
out_filename_len = snprintf(
|
||||||
|
NULL, 0,
|
||||||
|
"%s/.config/bytenuts/outbuf.log",
|
||||||
|
home
|
||||||
|
);
|
||||||
|
out_filename = calloc(1, out_filename_len + 1);
|
||||||
|
snprintf(
|
||||||
|
out_filename, out_filename_len + 1,
|
||||||
|
"%s/.config/bytenuts/outbuf.log",
|
||||||
|
home
|
||||||
|
);
|
||||||
|
|
||||||
|
/* move this processes log to the path that can be loaded on resumption */
|
||||||
fclose(cheerios.backup);
|
fclose(cheerios.backup);
|
||||||
|
rename(cheerios.backup_filename, out_filename);
|
||||||
|
|
||||||
|
free(out_filename);
|
||||||
|
free(cheerios.backup_filename);
|
||||||
|
}
|
||||||
|
|
||||||
pthread_exit(NULL);
|
pthread_exit(NULL);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,8 +35,9 @@ typedef struct cheerios_struct {
|
||||||
pthread_mutex_t *term_lock;
|
pthread_mutex_t *term_lock;
|
||||||
int ser_fd;
|
int ser_fd;
|
||||||
line_buffer_t lines;
|
line_buffer_t lines;
|
||||||
FILE *log;
|
FILE *log; /* log file which was opened with -l */
|
||||||
FILE *backup;
|
char *backup_filename; /* realpath to the backup outbuf.pid.log */
|
||||||
|
FILE *backup; /* backup log file object */
|
||||||
bytenuts_config_t *config;
|
bytenuts_config_t *config;
|
||||||
volatile int mode;
|
volatile int mode;
|
||||||
pthread_cond_t cond;
|
pthread_cond_t cond;
|
||||||
|
|
|
||||||
52
src/ingest.c
52
src/ingest.c
|
|
@ -40,19 +40,29 @@ ingest_start(bytenuts_t *bytenuts)
|
||||||
|
|
||||||
HOME = getenv("HOME");
|
HOME = getenv("HOME");
|
||||||
if (HOME) {
|
if (HOME) {
|
||||||
char *cwd = getcwd(NULL, 0);
|
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
|
int name_len;
|
||||||
chdir(HOME);
|
pid_t pid;
|
||||||
|
|
||||||
while (!read_cmd_page(idx)) {
|
while (!read_cmd_page(idx)) {
|
||||||
idx++;
|
idx++;
|
||||||
}
|
}
|
||||||
|
|
||||||
ingest.history_fd = fopen(".config/bytenuts/inbuf.log", "w");
|
/* ensure that a process has a unique log */
|
||||||
|
pid = getpid();
|
||||||
|
name_len = snprintf(
|
||||||
|
NULL, 0,
|
||||||
|
"%s/.config/bytenuts/inbuf.%d.log",
|
||||||
|
HOME, pid
|
||||||
|
);
|
||||||
|
ingest.history_filename = calloc(1, name_len + 1);
|
||||||
|
snprintf(
|
||||||
|
ingest.history_filename, name_len + 1,
|
||||||
|
"%s/.config/bytenuts/inbuf.%d.log",
|
||||||
|
HOME, pid
|
||||||
|
);
|
||||||
|
|
||||||
chdir(cwd);
|
ingest.history_fd = fopen(ingest.history_filename, "w");
|
||||||
free(cwd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ingest.cmd_pgs_n > 0) {
|
if (ingest.cmd_pgs_n > 0) {
|
||||||
|
|
@ -73,10 +83,6 @@ ingest_stop()
|
||||||
{
|
{
|
||||||
ingest.running = 0;
|
ingest.running = 0;
|
||||||
pthread_join(ingest.thr, NULL);
|
pthread_join(ingest.thr, NULL);
|
||||||
|
|
||||||
if (ingest.history_fd)
|
|
||||||
fclose(ingest.history_fd);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -419,6 +425,32 @@ ingest_thread(void *arg)
|
||||||
sched_yield();
|
sched_yield();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ingest.history_fd) {
|
||||||
|
char *in_filename;
|
||||||
|
int in_filename_len;
|
||||||
|
char *home = getenv("HOME");
|
||||||
|
|
||||||
|
/* do not chdir as other threads can still be running */
|
||||||
|
in_filename_len = snprintf(
|
||||||
|
NULL, 0,
|
||||||
|
"%s/.config/bytenuts/inbuf.log",
|
||||||
|
home
|
||||||
|
);
|
||||||
|
in_filename = calloc(1, in_filename_len + 1);
|
||||||
|
snprintf(
|
||||||
|
in_filename, in_filename_len + 1,
|
||||||
|
"%s/.config/bytenuts/inbuf.log",
|
||||||
|
home
|
||||||
|
);
|
||||||
|
|
||||||
|
/* move this processes history to the path that can be loaded on resumption */
|
||||||
|
fclose(ingest.history_fd);
|
||||||
|
rename(ingest.history_filename, in_filename);
|
||||||
|
|
||||||
|
free(in_filename);
|
||||||
|
free(ingest.history_filename);
|
||||||
|
}
|
||||||
|
|
||||||
pthread_exit(NULL);
|
pthread_exit(NULL);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ typedef struct ingest_struct {
|
||||||
int inpos; /* cursor position within the inbuf itself */
|
int inpos; /* cursor position within the inbuf itself */
|
||||||
int inlen; /* length of the input buffer */
|
int inlen; /* length of the input buffer */
|
||||||
char **history; /* array of strings representing the command history */
|
char **history; /* array of strings representing the command history */
|
||||||
|
char *history_filename; /* realpath of inbuf.pid.log */
|
||||||
FILE *history_fd;
|
FILE *history_fd;
|
||||||
char tmp_history[4096]; /* copy of inbuf before we load in history */
|
char tmp_history[4096]; /* copy of inbuf before we load in history */
|
||||||
int history_len;
|
int history_len;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue