Overview
Comment: | Updated to create separate interpreters per thread |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
cf4ca88d48cdde7696d9b534228ac2b4 |
User & Date: | rkeene on 2014-09-09 07:33:57 |
Other Links: | manifest | tags |
Context
2014-09-09
| ||
07:51 | Fixed bug where blank extraData was added check-in: 95ec92e5d0 user: rkeene tags: trunk | |
07:33 | Updated to create separate interpreters per thread check-in: cf4ca88d48 user: rkeene tags: trunk | |
06:46 | Implemented basic open() and read() check-in: a7c7a7a363 user: rkeene tags: trunk | |
Changes
Modified appfs.c from [4ed6fa78a6] to [9a50e0345b].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | #define FUSE_USE_VERSION 26 #include <sys/types.h> #include <sqlite3.h> #include <string.h> #include <stdarg.h> #include <stdlib.h> #include <unistd.h> #include <errno.h> #include <fcntl.h> #include <stdio.h> #include <fuse.h> #include <tcl.h> #define APPFS_CACHEDIR "/tmp/appfs-cache" #define APPFS_DEBUG(x...) { fprintf(stderr, "[debug] %s:%i:%s: ", __FILE__, __LINE__, __func__); fprintf(stderr, x); fprintf(stderr, "\n"); } struct appfs_thread_data { | > > > < > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | #define FUSE_USE_VERSION 26 #include <sys/types.h> #include <sqlite3.h> #include <pthread.h> #include <string.h> #include <stdarg.h> #include <stdlib.h> #include <unistd.h> #include <errno.h> #include <fcntl.h> #include <stdio.h> #include <fuse.h> #include <tcl.h> #define APPFS_CACHEDIR "/tmp/appfs-cache" #define APPFS_DEBUG(x...) { fprintf(stderr, "[debug] %s:%i:%s: ", __FILE__, __LINE__, __func__); fprintf(stderr, x); fprintf(stderr, "\n"); } static pthread_key_t interpKey; struct appfs_thread_data { sqlite3 *db; const char *cachedir; }; struct appfs_thread_data globalThread; typedef enum { APPFS_OS_UNKNOWN, APPFS_OS_ALL, |
︙ | ︙ | |||
163 164 165 166 167 168 169 170 171 172 173 174 175 176 | return("arm"); case APPFS_CPU_UNKNOWN: return("unknown"); } return("unknown"); } static int appfs_Tcl_Eval(Tcl_Interp *interp, int objc, const char *cmd, ...) { Tcl_Obj **objv; const char *arg; va_list argp; int retval; int i; | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | return("arm"); case APPFS_CPU_UNKNOWN: return("unknown"); } return("unknown"); } static Tcl_Interp *appfs_create_TclInterp(const char *cachedir) { Tcl_Interp *interp; int tcl_ret; interp = Tcl_CreateInterp(); if (interp == NULL) { fprintf(stderr, "Unable to create Tcl Interpreter. Aborting.\n"); return(NULL); } tcl_ret = Tcl_Init(interp); if (tcl_ret != TCL_OK) { fprintf(stderr, "Unable to initialize Tcl. Aborting.\n"); return(NULL); } tcl_ret = Tcl_Eval(interp, "" #include "appfs.tcl.h" ""); if (tcl_ret != TCL_OK) { fprintf(stderr, "Unable to initialize Tcl AppFS script. Aborting.\n"); fprintf(stderr, "Tcl Error is: %s\n", Tcl_GetStringResult(interp)); return(NULL); } if (Tcl_SetVar(interp, "::appfs::cachedir", cachedir, TCL_GLOBAL_ONLY) == NULL) { fprintf(stderr, "Unable to set cache directory. This should never fail.\n"); return(NULL); } tcl_ret = Tcl_Eval(interp, "::appfs::init"); if (tcl_ret != TCL_OK) { fprintf(stderr, "Unable to initialize Tcl AppFS script (::appfs::init). Aborting.\n"); fprintf(stderr, "Tcl Error is: %s\n", Tcl_GetStringResult(interp)); return(NULL); } return(interp); } static int appfs_Tcl_Eval(Tcl_Interp *interp, int objc, const char *cmd, ...) { Tcl_Obj **objv; const char *arg; va_list argp; int retval; int i; |
︙ | ︙ | |||
191 192 193 194 195 196 197 198 199 200 | for (i = 0; i < objc; i++) { Tcl_DecrRefCount(objv[i]); } ckfree((void *) objv); return(retval); } | > > > > | > > > > > > > > > > | | | | > > > > > > > > | | | | > > > > > > > > | | | | | 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 | for (i = 0; i < objc; i++) { Tcl_DecrRefCount(objv[i]); } ckfree((void *) objv); if (retval != TCL_OK) { APPFS_DEBUG("Tcl command failed, ::errorInfo contains: %s\n", Tcl_GetVar(interp, "::errorInfo", 0)); } return(retval); } static void appfs_update_index(const char *hostname) { Tcl_Interp *interp; int tcl_ret; APPFS_DEBUG("Enter: hostname = %s", hostname); interp = pthread_getspecific(interpKey); if (interp == NULL) { interp = appfs_create_TclInterp(globalThread.cachedir); pthread_setspecific(interpKey, interp); } tcl_ret = appfs_Tcl_Eval(interp, 2, "::appfs::getindex", hostname); if (tcl_ret != TCL_OK) { APPFS_DEBUG("Call to ::appfs::getindex failed: %s", Tcl_GetStringResult(interp)); return; } return; } static const char *appfs_getfile(const char *hostname, const char *sha1) { Tcl_Interp *interp; char *retval; int tcl_ret; interp = pthread_getspecific(interpKey); if (interp == NULL) { interp = appfs_create_TclInterp(globalThread.cachedir); pthread_setspecific(interpKey, interp); } tcl_ret = appfs_Tcl_Eval(interp, 3, "::appfs::download", hostname, sha1); if (tcl_ret != TCL_OK) { APPFS_DEBUG("Call to ::appfs::download failed: %s", Tcl_GetStringResult(interp)); return(NULL); } retval = strdup(Tcl_GetStringResult(interp)); return(retval); } static void appfs_update_manifest(const char *hostname, const char *sha1) { Tcl_Interp *interp; int tcl_ret; interp = pthread_getspecific(interpKey); if (interp == NULL) { interp = appfs_create_TclInterp(globalThread.cachedir); pthread_setspecific(interpKey, interp); } tcl_ret = appfs_Tcl_Eval(interp, 3, "::appfs::getpkgmanifest", hostname, sha1); if (tcl_ret != TCL_OK) { APPFS_DEBUG("Call to ::appfs::getpkgmanifest failed: %s", Tcl_GetStringResult(interp)); return; } return; } #define appfs_free_list_type(id, type) static void appfs_free_list_ ## id(type *head) { \ type *obj, *next; \ for (obj = head; obj; obj = next) { \ next = obj->_next; \ |
︙ | ︙ | |||
324 325 326 327 328 329 330 | return(0); } static struct appfs_package *appfs_getindex(const char *hostname, int *package_count_p) { struct appfs_package *head = NULL; char *sql; | | | < < < | 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 | return(0); } static struct appfs_package *appfs_getindex(const char *hostname, int *package_count_p) { struct appfs_package *head = NULL; char *sql; int sqlite_ret; if (package_count_p == NULL) { return(NULL); } appfs_update_index(hostname); sql = sqlite3_mprintf("SELECT package, version, sha1, os, cpuArch, isLatest FROM packages WHERE hostname = %Q;", hostname); if (sql == NULL) { APPFS_DEBUG("Call to sqlite3_mprintf failed."); return(NULL); } |
︙ | ︙ | |||
383 384 385 386 387 388 389 | return(0); } static struct appfs_children *appfs_getchildren(const char *hostname, const char *package_hash, const char *path, int *children_count_p) { struct appfs_children *head = NULL; char *sql; | | | < < < < | < < < | 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 | return(0); } static struct appfs_children *appfs_getchildren(const char *hostname, const char *package_hash, const char *path, int *children_count_p) { struct appfs_children *head = NULL; char *sql; int sqlite_ret; if (children_count_p == NULL) { return(NULL); } appfs_update_index(hostname); appfs_update_manifest(hostname, package_hash); sql = sqlite3_mprintf("SELECT file_name FROM files WHERE package_sha1 = %Q AND file_directory = %Q;", package_hash, path); if (sql == NULL) { APPFS_DEBUG("Call to sqlite3_mprintf failed."); return(NULL); } |
︙ | ︙ | |||
434 435 436 437 438 439 440 | return(0); } static char *appfs_lookup_package_hash(const char *hostname, const char *package, appfs_os_t os, appfs_cpuArch_t cpuArch, const char *version) { char *sql; char *retval = NULL; | | | < < < | 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 | return(0); } static char *appfs_lookup_package_hash(const char *hostname, const char *package, appfs_os_t os, appfs_cpuArch_t cpuArch, const char *version) { char *sql; char *retval = NULL; int sqlite_ret; appfs_update_index(hostname); sql = sqlite3_mprintf("SELECT sha1 FROM packages WHERE hostname = %Q AND package = %Q AND os = %Q AND cpuArch = %Q AND version = %Q;", hostname, package, appfs_convert_os_toString(os), appfs_convert_cpuArch_toString(cpuArch), version |
︙ | ︙ | |||
523 524 525 526 527 528 529 | /* Until this is used, prevent the compiler from complaining */ source = source; } static int appfs_getfileinfo(const char *hostname, const char *package_hash, const char *_path, struct appfs_pathinfo *pathinfo) { char *directory, *file, *path; char *sql; | | | < < < < | < < < | 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 | /* Until this is used, prevent the compiler from complaining */ source = source; } static int appfs_getfileinfo(const char *hostname, const char *package_hash, const char *_path, struct appfs_pathinfo *pathinfo) { char *directory, *file, *path; char *sql; int sqlite_ret; if (pathinfo == NULL) { return(-EIO); } appfs_update_index(hostname); appfs_update_manifest(hostname, package_hash); path = strdup(_path); directory = path; file = strrchr(path, '/'); if (file == NULL) { file = path; directory = ""; |
︙ | ︙ | |||
1006 1007 1008 1009 1010 1011 1012 | .read = appfs_fuse_read }; #endif int main(int argc, char **argv) { const char *cachedir = APPFS_CACHEDIR; char dbfilename[1024]; | | < | < < < | < | | < < < < < < < < < < < < < < < < < < < < < < < < | 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 | .read = appfs_fuse_read }; #endif int main(int argc, char **argv) { const char *cachedir = APPFS_CACHEDIR; char dbfilename[1024]; int pthread_ret, snprintf_ret, sqlite_ret; globalThread.cachedir = cachedir; pthread_ret = pthread_key_create(&interpKey, NULL); if (pthread_ret != 0) { fprintf(stderr, "Unable to create TSD key for Tcl. Aborting.\n"); return(1); } snprintf_ret = snprintf(dbfilename, sizeof(dbfilename), "%s/%s", cachedir, "cache.db"); if (snprintf_ret >= sizeof(dbfilename)) { fprintf(stderr, "Unable to set database filename. Aborting.\n"); |
︙ | ︙ |