Obsolete
/
libipc-old
Archived
3
0
Fork 0
more_to_read
Philippe PITTOLI 2016-05-26 21:56:43 +02:00
parent da51d3ef3d
commit e2142f0c72
3 changed files with 53 additions and 25 deletions

View File

@ -45,47 +45,50 @@ int service_close (const char *fifopath)
return 0; return 0;
} }
// TODO only works for a single process
void service_get_new_processes (struct process **proc, int *nproc, int sfifo) void service_get_new_processes (struct process **proc, int *nproc, int sfifo)
{ {
char buf[BUFSIZ]; char buf[BUFSIZ];
bzero (buf, BUFSIZ); bzero (buf, BUFSIZ);
read (sfifo, buf, BUFSIZ); read (sfifo, buf, BUFSIZ);
// TODO proc = malloc(sizeof(struct process*) * 1); // FIXME
#if 0 proc[0] = malloc(sizeof(struct process) * 1); // FIXME
unsigned long long int val = strtoull(s, NULL, 10);
// unsigned long long int val = strtoul(s, NULL, 10);
char *token, *saveptr; char *token, *saveptr;
char *str; char *str;
int i, j; int i;
// printf("%d fields :: ", f->nbfields); for (str = buf, i = 1; ; str = NULL, i++) {
// for( i = 0 ; i < f->nbfields ; i++) { token = strtok_r(str, " ", &saveptr);
// printf("%u, ", f->fields[i]);
// }
// printf("\n");
for (str = s, i = 1; ; str = NULL, i++) {
token = strtok_r(str, delim, &saveptr);
if (token == NULL) if (token == NULL)
break; break;
// check if we need to print the current token humanized // do something
int found = 0; if (i == 1) {
// FIXME
for (j = 0 ; j < f->nbfields && found == 0; j++ ) { proc[0]->pid = strtoul(token, NULL, 10);
if( i == f->fields[j] ) { }
print_token_to_human(token); else if (i == 2) {
found = 1; // FIXME
} proc[0]->version = strtoul(token, NULL, 10);
} }
// print the current token not humanized
if (found == 0) {
printf("%s ", token);
}
} }
#endif }
void struct_process_free (struct process * p)
{
free (p);
}
void service_free_processes (struct process **procs, int nproc)
{
while (--nproc != -1) {
struct_process_free (procs[nproc]);
}
} }
void gen_process_structure (struct process *p void gen_process_structure (struct process *p
@ -168,10 +171,32 @@ int process_close (struct process *proc)
int process_read (struct process *proc, void * buf, size_t * msize) int process_read (struct process *proc, void * buf, size_t * msize)
{ {
if ((*msize = read (proc->in, buf, *msize)))
return *msize;
return 0; return 0;
} }
int process_write (struct process *proc, void * buf, size_t msize) int process_write (struct process *proc, void * buf, size_t msize)
{ {
if ((msize = write (proc->out, buf, msize)))
return msize;
return 0;
}
int service_read (struct process *proc, void * buf, size_t * msize)
{
if ((*msize = read (proc->out, buf, *msize)))
return *msize;
return 0;
}
int service_write (struct process *proc, void * buf, size_t msize)
{
if ((msize = write (proc->in, buf, msize)))
return msize;
return 0; return 0;
} }

View File

@ -43,6 +43,7 @@ int service_create (const char *sname);
int service_close (const char *sname); int service_close (const char *sname);
void service_get_new_processes (struct process **, int *nproc, int sfifo); void service_get_new_processes (struct process **, int *nproc, int sfifo);
void service_free_processes (struct process **, int nproc);
int process_create (struct process *, int index); // called by the application int process_create (struct process *, int index); // called by the application
int process_destroy (struct process *); // called by the application int process_destroy (struct process *); // called by the application

View File

@ -48,6 +48,8 @@ void main_loop (const char *spath)
exit (1); exit (1);
} }
} }
service_free_processes (&proc, nproc);
} while (0); // it's a test, we only do it once } while (0); // it's a test, we only do it once
close (sfifo); // closes the service named pipe close (sfifo); // closes the service named pipe