version 1.6, 2010/03/06 18:29:06
|
version 1.42, 2012/05/20 17:28:26
|
Line 1
|
Line 1
|
/* |
/* |
================================================================================ |
================================================================================ |
RPL/2 (R) version 4.0.12 |
RPL/2 (R) version 4.1.8 |
Copyright (C) 1989-2010 Dr. BERTRAND Joël |
Copyright (C) 1989-2012 Dr. BERTRAND Joël |
|
|
This file is part of RPL/2. |
This file is part of RPL/2. |
|
|
Line 20
|
Line 20
|
*/ |
*/ |
|
|
|
|
#include "rpl.conv.h" |
#include "rpl-conv.h" |
|
|
|
|
/* |
/* |
Line 77 creation_nom_fichier(struct_processus *s
|
Line 77 creation_nom_fichier(struct_processus *s
|
|
|
do |
do |
{ |
{ |
sprintf(tampon, "RPL2-%lu-%lu-%lu", (unsigned long) getpid(), |
sprintf(tampon, "RPL-%lu-%lu-%lu", (unsigned long) getpid(), |
(unsigned long) pthread_self(), ordre); |
(unsigned long) pthread_self(), ordre); |
|
|
if (chemin == NULL) |
if (chemin == NULL) |
Line 222 recherche_chemin_fichiers_temporaires(st
|
Line 222 recherche_chemin_fichiers_temporaires(st
|
{ |
{ |
if (chemins[i][0] == '$') |
if (chemins[i][0] == '$') |
{ |
{ |
candidat = getenv("RPL_TMP_PATH"); |
candidat = getenv(chemins[i] + 1); |
|
|
if (candidat != NULL) |
if (candidat != NULL) |
{ |
{ |
if ((nom_candidat = creation_nom_fichier(s_etat_processus, |
if ((nom_candidat = creation_nom_fichier(s_etat_processus, |
candidat)) == NULL) |
candidat)) == NULL) |
{ |
{ |
return NULL; |
return(NULL); |
} |
} |
|
|
if ((fichier = fopen(nom_candidat, "w+")) != NULL) |
if ((fichier = fopen(nom_candidat, "w+")) != NULL) |
Line 245 recherche_chemin_fichiers_temporaires(st
|
Line 245 recherche_chemin_fichiers_temporaires(st
|
} |
} |
else |
else |
{ |
{ |
return NULL; |
return(NULL); |
} |
} |
} |
} |
else |
else |
Line 259 recherche_chemin_fichiers_temporaires(st
|
Line 259 recherche_chemin_fichiers_temporaires(st
|
if ((nom_candidat = creation_nom_fichier(s_etat_processus, |
if ((nom_candidat = creation_nom_fichier(s_etat_processus, |
chemins[i])) == NULL) |
chemins[i])) == NULL) |
{ |
{ |
return NULL; |
return(NULL); |
} |
} |
|
|
if ((fichier = fopen(nom_candidat, "w+")) != NULL) |
if ((fichier = fopen(nom_candidat, "w+")) != NULL) |
Line 275 recherche_chemin_fichiers_temporaires(st
|
Line 275 recherche_chemin_fichiers_temporaires(st
|
} |
} |
else |
else |
{ |
{ |
return NULL; |
return(NULL); |
} |
} |
} |
} |
else |
else |
Line 287 recherche_chemin_fichiers_temporaires(st
|
Line 287 recherche_chemin_fichiers_temporaires(st
|
i++; |
i++; |
} |
} |
|
|
return chemin; |
return(chemin); |
} |
} |
|
|
|
|
Line 348 caracteristiques_fichier(struct_processu
|
Line 348 caracteristiques_fichier(struct_processu
|
l_element_courant = (*l_element_courant).suivant; |
l_element_courant = (*l_element_courant).suivant; |
} |
} |
} |
} |
|
else if (errno == EACCES) |
|
{ |
|
// Le répertoire n'est pas accessible en écriture. On tente |
|
// l'ouverture du fichier. |
|
|
|
if ((descripteur = open(nom, O_RDONLY, S_IRUSR | S_IWUSR)) == -1) |
|
{ |
|
// Le fichier n'existe pas. |
|
close(descripteur); |
|
erreur = d_absence_erreur; |
|
} |
|
else |
|
{ |
|
erreur = d_absence_erreur; |
|
(*existence) = d_vrai; |
|
|
|
// On chercher à savoir si le fichier est ouvert. |
|
// S'il est ouvert, on renvoie son unité de rattachement. |
|
|
|
l_element_courant = (*s_etat_processus).s_fichiers; |
|
|
|
while(l_element_courant != NULL) |
|
{ |
|
if (strcmp((*((struct_descripteur_fichier *) |
|
(*l_element_courant).donnee)).nom, nom) == 0) |
|
{ |
|
if (((*((struct_descripteur_fichier *) |
|
(*l_element_courant).donnee)).pid == getpid()) |
|
&& (pthread_equal( |
|
(*((struct_descripteur_fichier *) |
|
(*l_element_courant).donnee)).tid, |
|
pthread_self()) != 0)) |
|
{ |
|
(*ouverture) = d_vrai; |
|
|
|
(*unite) = (unsigned long) |
|
fileno((*((struct_descripteur_fichier *) |
|
(*l_element_courant).donnee)) |
|
.descripteur_c); |
|
break; |
|
} |
|
} |
|
|
|
l_element_courant = (*l_element_courant).suivant; |
|
} |
|
} |
|
} |
else |
else |
{ |
{ |
erreur = d_erreur; |
erreur = d_erreur; |
Line 391 caracteristiques_fichier(struct_processu
|
Line 438 caracteristiques_fichier(struct_processu
|
|
|
static logical1 |
static logical1 |
initialisation_controle(struct_processus *s_etat_processus, sqlite3 *sqlite, |
initialisation_controle(struct_processus *s_etat_processus, sqlite3 *sqlite, |
logical1 fichier_indexe) |
integer8 position_clef, logical1 fichier_indexe) |
{ |
{ |
const char commande1[] = |
const char commande1[] = |
"create table control(id integer primary key asc, lock text)"; |
"create table control(id integer primary key asc, key integer)"; |
const char commande2[] = |
const char commande2[] = |
"insert into control (id, lock) values (2, '0')"; |
"insert into control (id, key) values (1, %lld)"; |
const char *queue; |
const char *queue; |
|
|
sqlite3_stmt *ppStmt; |
sqlite3_stmt *ppStmt; |
|
|
|
unsigned char *commande; |
|
|
if (sqlite3_prepare_v2(sqlite, commande1, strlen(commande1), &ppStmt, |
if (sqlite3_prepare_v2(sqlite, commande1, strlen(commande1), &ppStmt, |
&queue) != SQLITE_OK) |
&queue) != SQLITE_OK) |
{ |
{ |
Line 422 initialisation_controle(struct_processus
|
Line 471 initialisation_controle(struct_processus
|
|
|
if (fichier_indexe == d_vrai) |
if (fichier_indexe == d_vrai) |
{ |
{ |
if (sqlite3_prepare_v2(sqlite, commande2, strlen(commande2), &ppStmt, |
if (alsprintf(&commande, commande2, position_clef) < 0) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return(d_erreur); |
|
} |
|
|
|
if (sqlite3_prepare_v2(sqlite, commande, strlen(commande), &ppStmt, |
&queue) != SQLITE_OK) |
&queue) != SQLITE_OK) |
{ |
{ |
|
free(commande); |
(*s_etat_processus).erreur_systeme = d_es_erreur_fichier; |
(*s_etat_processus).erreur_systeme = d_es_erreur_fichier; |
return(d_erreur); |
return(d_erreur); |
} |
} |
|
|
if (sqlite3_step(ppStmt) != SQLITE_DONE) |
if (sqlite3_step(ppStmt) != SQLITE_DONE) |
{ |
{ |
|
free(commande); |
(*s_etat_processus).erreur_systeme = d_es_erreur_fichier; |
(*s_etat_processus).erreur_systeme = d_es_erreur_fichier; |
return(d_erreur); |
return(d_erreur); |
} |
} |
|
|
if (sqlite3_finalize(ppStmt) != SQLITE_OK) |
if (sqlite3_finalize(ppStmt) != SQLITE_OK) |
{ |
{ |
|
free(commande); |
(*s_etat_processus).erreur_systeme = d_es_erreur_fichier; |
(*s_etat_processus).erreur_systeme = d_es_erreur_fichier; |
return(d_erreur); |
return(d_erreur); |
} |
} |
|
|
|
free(commande); |
} |
} |
|
|
return(d_absence_erreur); |
return(d_absence_erreur); |
Line 447 initialisation_controle(struct_processus
|
Line 507 initialisation_controle(struct_processus
|
|
|
logical1 |
logical1 |
initialisation_fichier_acces_indexe(struct_processus *s_etat_processus, |
initialisation_fichier_acces_indexe(struct_processus *s_etat_processus, |
sqlite3 *sqlite, logical1 binaire) |
sqlite3 *sqlite, integer8 position_clef, logical1 binaire) |
{ |
{ |
const char commande1[] = |
const char commande1[] = |
"create table data(id integer primary key asc, key_id integer, " |
"create table data(id integer primary key asc, key_id integer, " |
"lock text)"; |
"data text, sequence integer)"; |
const char commande10[] = |
const char commande10[] = |
"create table key(id integer primary key asc, key text)"; |
"create table key(id integer primary key asc, key text)"; |
const char commande2[] = |
const char commande2[] = |
"create table data(id integer primary key asc, key_id integer, " |
"create table data(id integer primary key asc, key_id integer, " |
"lock blob)"; |
"data blob, sequence integer)"; |
const char commande20[] = |
const char commande20[] = |
"create table key(id integer primary key asc, key blob)"; |
"create table key(id integer primary key asc, key blob)"; |
const char commande3[] = |
const char commande3[] = |
Line 467 initialisation_fichier_acces_indexe(stru
|
Line 527 initialisation_fichier_acces_indexe(stru
|
|
|
sqlite3_stmt *ppStmt; |
sqlite3_stmt *ppStmt; |
|
|
if (initialisation_controle(s_etat_processus, sqlite, d_vrai) |
if (initialisation_controle(s_etat_processus, sqlite, position_clef, d_vrai) |
!= d_absence_erreur) |
!= d_absence_erreur) |
{ |
{ |
return(d_erreur); |
return(d_erreur); |
Line 600 initialisation_fichier_acces_direct(stru
|
Line 660 initialisation_fichier_acces_direct(stru
|
sqlite3 *sqlite, logical1 binaire) |
sqlite3 *sqlite, logical1 binaire) |
{ |
{ |
const char commande1[] = |
const char commande1[] = |
"create table data(id integer primary key asc, lock text)"; |
"create table data(id integer primary key asc, data text)"; |
const char commande2[] = |
const char commande2[] = |
"create table data(id integer primary key asc, lock blob)"; |
"create table data(id integer primary key asc, data blob)"; |
const char commande3[] = |
const char commande3[] = |
"create index data_idx on data(id)"; |
"create index data_idx on data(id)"; |
const char *queue; |
const char *queue; |
|
|
sqlite3_stmt *ppStmt; |
sqlite3_stmt *ppStmt; |
|
|
if (initialisation_controle(s_etat_processus, sqlite, d_faux) |
if (initialisation_controle(s_etat_processus, sqlite, (integer8) 0, d_faux) |
!= d_absence_erreur) |
!= d_absence_erreur) |
{ |
{ |
return(d_erreur); |
return(d_erreur); |
Line 680 initialisation_fichier_acces_direct(stru
|
Line 740 initialisation_fichier_acces_direct(stru
|
return(d_absence_erreur); |
return(d_absence_erreur); |
} |
} |
|
|
unsigned char * |
|
verrouillage_fichier_sqlite(struct_processus *s_etat_processus, |
|
sqlite3 *sqlite, unsigned char *operation) |
|
{ |
|
const char commande1[] = |
|
"select lock from control where id = 1"; |
|
const char commande2[] = |
|
"update control set lock = '%s'"; |
|
const char *queue; |
|
|
|
const unsigned char *resultat; |
|
|
|
sqlite3_stmt *ppStmt; |
|
|
|
unsigned char *verrou; |
|
|
|
resultat = NULL; |
|
|
|
if (operation == NULL) |
|
{ |
|
// Lecture du verrou |
|
|
|
if (sqlite3_prepare_v2(sqlite, commande1, strlen(commande1), &ppStmt, |
|
&queue) != SQLITE_OK) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_erreur_fichier; |
|
return(NULL); |
|
} |
|
|
|
if (sqlite3_step(ppStmt) != SQLITE_ROW) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_erreur_fichier; |
|
return(NULL); |
|
} |
|
|
|
if (sqlite3_column_type(ppStmt, 0) != SQLITE_TEXT) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_erreur_fichier; |
|
return(NULL); |
|
} |
|
|
|
resultat = sqlite3_column_text(ppStmt, 0); |
|
|
|
if ((verrou = malloc((strlen(resultat) + 1) * sizeof(unsigned char))) |
|
== NULL) |
|
{ |
|
return(NULL); |
|
} |
|
|
|
strcpy(verrou, resultat); |
|
|
|
if (sqlite3_finalize(ppStmt) != SQLITE_OK) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_erreur_fichier; |
|
return(NULL); |
|
} |
|
} |
|
else |
|
{ |
|
// Positionnement d'un verrou |
|
|
|
if (alsprintf(&verrou, commande2, operation) < 0) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return(NULL); |
|
} |
|
|
|
if (sqlite3_prepare_v2(sqlite, verrou, strlen(verrou), &ppStmt, |
|
&queue) != SQLITE_OK) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_erreur_fichier; |
|
return(NULL); |
|
} |
|
|
|
if (sqlite3_step(ppStmt) != SQLITE_DONE) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_erreur_fichier; |
|
return(NULL); |
|
} |
|
|
|
if (sqlite3_finalize(ppStmt) != SQLITE_OK) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_erreur_fichier; |
|
return(NULL); |
|
} |
|
|
|
free(verrou); |
|
verrou = NULL; |
|
} |
|
|
|
return(verrou); |
|
} |
|
|
|
// vim: ts=4 |
// vim: ts=4 |